Node CLI eval option can't take unary negation operator
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.3k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 283
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先使用文档中的 node -pe "-0" 和相关命令重现该问题,然后跟踪 Node 针对 eval 选项的 CLI 参数解析。为以 - 开头的表达式添加回归测试覆盖,并验证这些命令能够成功求值,而不是报告 eval 没有参数。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- cli
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100