Objects with strings as keys throw a syntax error when not bound to a variable
Categories
(Firefox :: Untriaged, defect)
Tracking
()
People
(Reporter: u648529, Unassigned)
Details
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0
Steps to reproduce:
Open the console. Enter { "a": 1 }.
Or: run a JavaScript file containing a line like this.
Actual results:
A syntax error is thrown.
Expected results:
It should parse successfully regardless of the quotes, like { a: 1 } which works.
Notably, this problem does not occur when the object is bound to a variable like let x = { "a": 1 }.
Comment 1•6 years ago
|
||
if you start a statement with {, it's not an object literal, but block statement.
so, { a: 1 } is a block statement that contains a labelled statement with a label, and the body is an expression statement with 1 expression.
and if you write { "a": 1 }, it's a block statement that contains expression "a" first, and it has unexpected : token after that, and it results in syntax error.
Description
•