You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Node CLI eval option can't take unary negation operator #43397
Before any brave soul goes on fixing this: we probably don't want node -pe "-something" to be interpreted as anything but node -pesomthing or node -p -e -s -o -m -e -t -h -i -n -g.
I think, the proper command should look more like node -pe -- -42, where -- argument will mean that all further arguments are NOT options.
Obviously, we can't solve the issue "literally" by detecting numeric expressions
Commonly, short options should allow stacking together (-ab == -a -b)
Commonly, if short option requires argument, it should allow it without delimeter (-afoo == -a foo)
Otherwise, short options should allow arbitrary order (-b -a == -a -b)
Commonly, any argument starting with dash should be parsed as option (-a -foo -b == -a -f -o -o -b). If we need a positional argument starting (or potentially starting) with dash, we can use double dash separator (-a -b -- -foo).
Thus said, this is how I'd like to expect parsing to work:
node -e42 should work the same as node -e 42, not "bad option"
Otherwise, node -ep 42 might work the same as node -pe 42 as long as it's unambiguous
node -e --throw-deprecation [...] should never attempt to evaluate --throw-deprecation as js code
node --help does mention -- which should indicate that following arguments are positional. However, neither node -e -- 42 or node -- "-dashfile.js" are available.
For users who prefer setting mandatory option arguments rather than positional arguments, node --print --eval=-42 already works. :)
Activity
bnoordhuis commentedon Jun 13, 2022
It's rather doing it too well! It parses
-42as a flag, not as a positional argument.I agree it's a bug but I pity whoever goes in to grapple with node's option parser. You're a braver person than I am.
LiviaMedeiros commentedon Jun 13, 2022
Before any brave soul goes on fixing this: we probably don't want
node -pe "-something"to be interpreted as anything butnode -pesomthingornode -p -e -s -o -m -e -t -h -i -n -g.I think, the proper command should look more like
node -pe -- -42, where--argument will mean that all further arguments are NOT options.bnoordhuis commentedon Jun 14, 2022
Can you explain your line of thought? Why should it be
node -pesomthingornode -p -e -s -o -m -e -t -h -i -n -g?LiviaMedeiros commentedon Jun 14, 2022
My line of thought is based on:
-ab==-a -b)-afoo==-a foo)Otherwise, short options should allow arbitrary order (
-b -a==-a -b)-a -foo -b==-a -f -o -o -b). If we need a positional argument starting (or potentially starting) with dash, we can use double dash separator (-a -b -- -foo).Thus said, this is how I'd like to expect parsing to work:
node -e42should work the same asnode -e 42, not "bad option"Otherwise,
node -ep 42might work the same asnode -pe 42as long as it's unambiguousnode -e --throw-deprecation [...]should never attempt to evaluate--throw-deprecationas js codenode --helpdoes mention--which should indicate that following arguments are positional. However, neithernode -e -- 42ornode -- "-dashfile.js"are available.For users who prefer setting mandatory option arguments rather than positional arguments,
node --print --eval=-42already works. :)doc,test: clarify --eval syntax for leading '-' scripts
doc,test: clarify --eval syntax for leading '-' scripts
doc,test: clarify --eval syntax for leading '-' scripts
doc,test: clarify --eval syntax for leading '-' scripts
doc,test: clarify --eval syntax for leading '-' scripts
doc,test: clarify --eval syntax for leading '-' scripts
doc,test: clarify --eval syntax for leading '-' scripts
doc,test: clarify --eval syntax for leading '-' scripts
doc,test: clarify --eval syntax for leading '-' scripts
doc,test: clarify --eval syntax for leading '-' scripts
doc,test: clarify --eval syntax for leading '-' scripts