question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bare block statement

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
3cpcommented, Oct 31, 2020

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).

⋊> ~/playground cat > t.js
{a:1,b:2}
⋊> ~/playground node t.js
/Users/huocp/playground/t.js:1
{a:1,b:2}
      ^

SyntaxError: Unexpected token ':'

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.

1reaction
3cpcommented, Oct 28, 2020

I am not going to try this hard topic anytime soon 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found