Closed as not planned
Closed as not planned
Description
Version
v19.2.0
Platform
No response
Subsystem
No response
What steps will reproduce the bug?
Evaluate { a: 1 }['a']
in the REPL
$ node
> { a: 1 }['a']
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
$ node -p "{ a: 1 }['a']"
[ 'a' ]
$ node
> { a: 1 }['a']
[ 'a' ]
What do you see instead?
$ node -p "{ a: 1 }['a']"
[ 'a' ]
$ node
> { a: 1 }['a']
1
Additional information
The REPL tries to wrap the code that starts with {
in parentheses eagerly ('eager wrapping' was introduced at #31943) and { a: 1 }['a']
is converted into an ExpressionStatement ({ a: 1 }['a'])
that is evaluated to 1
. However, technically speaking, { a: 1 }['a']
should be parsed as the combination of a BlockStatement {a:1}
and an ExpressionStatement ['a']
, yielding a result of ['a']
.
The results of { a: 1 }['a']
in other runtimes:
- ChromeDevTools:
['a']
- Safari WebInspector:
['a']
- Deno REPL:
1