Node: Wrong hint message when parsing expression such as {a:1}['a'] === 1 in node

Created on 16 Feb 2020  路  6Comments  路  Source: nodejs/node

image

Welcome to Node.js v13.8.0.
Type ".help" for more information.

{a:1}['a'] === 1
false
{a:1}['a'] === 1
true (have not press enter, if press enter it turns to false)

  • Version: 13.8
  • Platform: Linux
  • Subsystem: NA

I tested on Chrome, it always shows false. I'm sure this is a bug.

What steps will reproduce the bug?

Type {a:1}['a'] === 1 in a node console.

How often does it reproduce? Is there a required condition?

Every time.

What is the expected behavior?

The gray font of 'true' in this image should be 'false'!

repl

Most helpful comment

Mind if i take a stab at this one?

All 6 comments

@BridgeAR

The two ways this is parsed:

  • ({ a: 1 }['a'] === 1); in preview
  • { a:1; }; ['a'] === 1; in repl eval

We should probably eagerly try to wrap all input in parens in the actual evaluator.

Mind if i take a stab at this one?

We should probably eagerly try to wrap all input in parens in the actual evaluator.

That might break working code, or am I missing something?

class Foo {} function foo() {} contains two valid declarations, but not if wrapped as an expression in parentheses.

@tniessen if the code isn't valid with parens, parens are not used. the logic should more or less be: try { parse(wrap(input)); input = wrap(input); } catch {}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sandeepks1 picture sandeepks1  路  3Comments

srl295 picture srl295  路  3Comments

mcollina picture mcollina  路  3Comments

filipesilvaa picture filipesilvaa  路  3Comments

Brekmister picture Brekmister  路  3Comments