Skip to content

Node CLI eval option can't take unary negation operator #43397

Open
@k-tten

Description

@k-tten

Version

v17.9.0

Platform

Darwin [redacted] 19.6.0 Darwin Kernel Version 19.6.0: Tue Feb 15 21:39:11 PST 2022; root:xnu-6153.141.59~1/RELEASE_X86_64 x86_64

Subsystem

No response

What steps will reproduce the bug?

Execute the following:

$ node -pe "-0"

And you will get back:

node: --eval requires an argument

In fact, anything where the - comes first, you get this message.

For example, all of the following also result in the above message:

$ node -pe "-42"
$ node -pe "-"
$ node -pe "-NaN"

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

It's always reproducable (at least on this version and machine).

What is the expected behavior?

I'd like it to not spit back an error message and give me the evaluated value, please.

What do you see instead?

An error message detailing that the "eval" option was not given a value.

Additional information

It seems that the CLI is not properly parsing its arguments?

Prefixing the expression with 0 seems to work:

$ node -pe "0-42"
42

As well as using a comma operator:

$ node -pe "(0, -42)"
-42

Metadata

Metadata

Assignees

No one assigned

    Labels

    cliIssues and PRs related to the Node.js command line interface.confirmed-bugIssues with confirmed bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions