Bare block statement
See original GitHub issueThere is a troublesome change in latest various js implementations.
When a statement starts with {
, it used to be a block statement.
I am pretty sure that’s the case in early 2016. Back then, when you write bare {a:1}
, it’s not an object literal, Chrome (and every other js implementations) thinks is a block statement with one inner statement 1
and it’s labelled with a
, similar with
{
loop: while(false) {
}
}
Firefox still keeps this old behavior, but nodejs/chome (v8), safari are changed.
{a: 1} | {a:1,b:2} | {a:while(false){}} | |
---|---|---|---|
chrome/nodejs | object literal | object literal | block statement |
firefox | block statement | syntax error | block statement |
safari | object literal | object literal | syntax error |
I am not clear about ECMA spec, it seems following the old behaviour (firefox)?? Many parsers are still using the old behaviour including babel parser. But v8 and safari have moved to a more intuitive behaviour. What should we do here?
Related to #136
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (15 by maintainers)
Top Results From Across the Web
block - JavaScript - MDN Web Docs
A block statement is used to group zero or more statements. The block is delimited by a pair of braces ("curly brackets") and...
Read more >Bare Engine Blocks at Summit Racing
Whether you're building a new engine or working on a rebuild, explore Summit Racing's selection of bare engine blocks to complete your ...
Read more >RCW 42.45.140: Short form certificates. - WA.gov
Signed and sworn to (or affirmed) before me on (date) by (name(s) of individuals making statement). . . . . (Signature of notary...
Read more >Engine block - Wikipedia
In an internal combustion engine, the engine block is the structure which contains the cylinders and other components. In an early automotive engine, ......
Read more >What is the difference between a let block statement and an ...
You can use both with and let statements to achieve the same goal but I see two significant differences here. In the end,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Bingo! This is a false alarm.
As you checked webkit and v8 source code, it’s indeed parsed as statement. I can confirm this with nodejs (not the interactive console).
So it’s just some special parsing in nodejs/chrome/safari interactive console. I totally understand why they do this in interactive console.
The real js parsers were not changed.
I am not going to try this hard topic anytime soon 😃