Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error thrown for correct syntax within node shell #36513

Closed
jadutter opened this issue Dec 14, 2020 · 3 comments
Closed

Syntax error thrown for correct syntax within node shell #36513

jadutter opened this issue Dec 14, 2020 · 3 comments

Comments

@jadutter
Copy link

  • Version: v14.15.1
  • Platform: Darwin LM-BWI-40009439 19.6.0 Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 x86_64
  • Subsystem:

The node shell does not correctly parse a multiline function that uses optional chaining, ternary operator, and an identity operator.

These commands work as expected

ser@HOST ~ % nvm use 14
Now using node v14.15.1 (npm v6.14.8)

user@HOST ~ % node -v
v14.15.1

user@HOST ~ % node < <( echo '
    const test1 = (value) => { return (value?.constructor); }
    const test2 = (value) => { return (value.constructor === Array) ? value : [value]; }
    const test3 = (value) => { return (value?.constructor) ? value : [value]; }
    const test4 = (value) => { return ((value?.constructor) === Array) ? value : [value]; }
    const test5 = (value) => { 
        return ((value?.constructor) === Array) ? value : [value]; 
    }
    const arr = new Array();
    console.log(test5(arr))
    ')
[]

However, attempting to define function test5 from within a node shell fails


user@HOST ~ % node
> const test1 = (value) => { return (value?.constructor); }
undefined
> const test2 = (value) => { return (value.constructor === Array) ? value : [value]; }
undefined
> const test3 = (value) => { return (value?.constructor) ? value : [value]; }
undefined
> const test4 = (value) => { return ((value?.constructor) === Array) ? value : [value]; }
undefined
> const test5 = (value) => { 
...     return ((value?.constructor) === Array) ? value : [value]; 



Uncaught SyntaxError: Unexpected end of input
> }
}
^
@richardlau
Copy link
Member

Are you able to test the proposed v14.15.2 release (#36476)? I suspect this may be addressed by the acorn parser related changes.

@jadutter
Copy link
Author

It appears to be fixed in 14.15.2
To make sure I followed the correct steps, this is how I tested:

git clone https://github.com/nodejs/node.git
cd node
git fetch origin v14.15.2-proposal
git checkout v14.15.2-proposal
./configure && make -j4 test

Once it was finished building, I found the path to the 14.15.2 version I just built

node_file_type="$(file -b "$(which node)" )"
new_node_path="$(find ./out/Release \
    -type f \
    -name node \
    -exec file {} + | \
    grep "$node_file_type" | \
    cut -d: -f1)"
$new_node_path -v 

Then I used it to open a node shell and pasted the lines that failed in 14.15.1

$new_node_path
const test1 = (value) => { return (value?.constructor); }
const test2 = (value) => { return (value.constructor === Array) ? value : [value]; }
const test3 = (value) => { return (value?.constructor) ? value : [value]; }
const test4 = (value) => { return ((value?.constructor) === Array) ? value : [value]; }
const test5 = (value) => { 
    return ((value?.constructor) === Array) ? value : [value]; 
}
const arr = new Array();
console.log(test5(arr))

It did not throw an error.

@richardlau
Copy link
Member

Should be fixed in https://nodejs.org/en/blog/release/v14.15.2/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants