-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repl: do not consider ...
as a REPL command
#14467
Conversation
This fix makes ... in REPL to be considered as a javascript construct rather than a REPL keyword Fixes: nodejs#14426
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! Please add a test! REPL tests can be tricky, but this is probably something that can be tested by adding something to test/parallel/test-repl.js
. Additional info about our tests in general can be found in https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md
Change looks good. For adding a test, check out https://github.com/nodejs/node/blob/master/test/parallel/test-repl.js. |
lib/repl.js
Outdated
@@ -419,7 +419,7 @@ function REPLServer(prompt, | |||
// Check to see if a REPL keyword was used. If it returns true, | |||
// display next prompt and return. | |||
if (trimmedCmd) { | |||
if (trimmedCmd.charAt(0) === '.' && isNaN(parseFloat(trimmedCmd))) { | |||
if (trimmedCmd.charAt(0) === '.' && trimmedCmd.charAt(1) != '.' && isNaN(parseFloat(trimmedCmd))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use strict not equals, so trimmedCmd.charAt(1) !== '.'
FWIW commit message is missing a space after the colon. |
...
as a REPL command...
as a REPL command
@shivanth thank for your contribution 🥇. Don't be alarmed by all the reviews, as far as I can see they are just in order to make your submission even better. I would really want to see you follow up, so this PR will land. |
P.S. as far as I can see this change also enables |
@refack The
I came across this when I tried to add a new test case |
That's something that should be investigated separately. Any kind of invalid syntax does it, but is has its uses too:
Same also works on the shell:
The question is if it can be determined if a line can never be valid, like As a first step, I'm fine if you just make sure it not gets parsed as a REPL command. |
Because my test case is leaving the REPL in an inconsistent state, the tests that follow my new test fails ...
|
Done 👍 |
The test as it stands right now does not fail on current master so it is not testing the feature implemented here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -414,7 +414,14 @@ function error_test() { | |||
expect: `${prompt_multiline}'foo \\n'\n${prompt_unix}` }, | |||
// Whitespace is not evaluated. | |||
{ client: client_unix, send: ' \t \n', | |||
expect: prompt_unix } | |||
expect: prompt_unix }, | |||
//Do not parse `...[]` as a REPL keyword |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the linter might fail due to no space between the comment start?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It passes as we do not use the spaced-comment rule. I fixed it anyways.
Thanks, landed in 46d3ff2! I fixed the whitespace issues in the test and wrapped the long line in |
Should this be backported to |
I'd say so. @shivanth wanna do it? |
I'm in 👍 |
This fix makes ... in REPL to be considered as a javascript construct rather than a REPL keyword. Fixes: nodejs#14426 PR-URL: nodejs#14467 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This fix makes ... in REPL to be considered as a javascript construct rather than a REPL keyword. Fixes: #14426 Backport-PR-URL: #14915 PR-URL: #14467 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Was an issue ever created for the aforementioned problem where some syntax errors put the repl in an 'inconsistent' I found #18915, but its a PR... |
This fix makes
...
in REPL to be considered as a javascript constructrather than a REPL keyword
Fixes: #14426
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
repl