Skip to content

Syntax error thrown for correct syntax within node shell #36513

Closed
@jadutter

Description

@jadutter
  • 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
> }
}
^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions