meriyah: Bare block statement
There 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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (15 by maintainers)
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 😃