Node CLI eval option can't take unary negation operator
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the documented node -pe "-0" and related commands, then trace Node's CLI argument parsing for the eval option. Add regression coverage for expressions beginning with - and verify that the commands evaluate successfully instead of reporting that eval has no argument.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100