-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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: allow multiline function call #3823
Conversation
@@ -1126,7 +1126,7 @@ function isRecoverableError(e, self) { | |||
self._inTemplateLiteral = true; | |||
return true; | |||
} | |||
return /^(Unexpected end of input|Unexpected token)/.test(message); | |||
return /^(Unexpected end of input|Unexpected token|missing \) after argument list)/.test(message); |
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.
Can you wrap this at 80 columns?
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.
As much as it pains me, the indentation + the regexp itself are at 80 characters, and multiline regexp isn't a thing in js.
It can be made a little shorter by moving the regexp to a variable, or if you'd rather I can cook something up which doesn't use regexps, maybe:
var prefixes = [
'Unexpected end of input',
// ...
];
return prefixes.some(message.startsWith.bind(message));
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.
I know, but you can break it up into multiple regular expressions or compile one dynamically with new RegExp(...)
. I'd take the multi-regex approach.
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.
@Zirak Perhaps, this?
const recoverableErrors = ['Unexpected end of input',
'Unexpected token',
'missing \\) after argument list'
];
const recoverableErrorsRegEx = new RegExp(`^(${recoverableErrors.join('|')})`);
...
return recoverableErrorsRegEx.test(message);
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.
@thefourtheye hrngh, I thought about new RegExp
, but every time I do something like that some paranoid part of me worries about escaping.
Multiple regexps (or the array one I posted above) is a bit more verbose, but may be better in that regard.
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.
@Zirak mmm, then lets do it as multiple regexps. I am actually eager to see that solution, as I didn't understand it :D
LGTM apart from a style issue. |
{ client: client_unix, send: '2)', | ||
expect: prompt_multiline }, | ||
{ client: client_unix, send: ')', | ||
expect: 'undefined' }, |
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.
I think prompt_unix
should immediately follow the undefined
. Can you please test and include that as well?
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 last send
closes off the outer function call and prints the output, so there's no prompt_multiline
prepending the result.
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.
@Zirak prompt_multiline
is ...
and prompt_unix
is the >
which we get in the REPL.
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.
@thefourtheye huh, that's weird. I (of course) ran the tests as committed and they pass, but expecting a 'undefined\n' + prompt_unix
also passed the test. I'll edit that in as you requested.
semver-minor only because it's technically adding new capability, not fixing a bug. Very good fix tho. |
@bnoordhuis, @thefourtheye Should be fixed now, I went with the "dumb" way of doing it, following the example of the previous lines. Just list them out, nothing fancy, nothing special. Meta-question, is this the proper way of fixing the PR, or should it be squashed? |
@Zirak .. either way, really. While a PR is still being reviewed, there's no reason to squash -- in fact, in many cases keeping them separate helps with the review. Before landing, the commits ought to be squashed... which can be done by the person landing the PR but ideally ought to be done by the submitter (simply because it's helpful, I'll typically squash commits when I land tho) |
@Zirak yes. The commits have to be squashed. If you can do it, it would be awesome. Otherwise we can do it while landing |
|
||
return message.startsWith('Unexpected end of input') || | ||
message.startsWith('Unexpected token') || | ||
message.startsWith('missing ) after argument list'); | ||
} |
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.
Perhaps a better approach would be defining a const as:
const remsg = new RegExp(
'^(Unexpected end of input|' +
'Unexpected token|' +
'missing \\) after argument list)'
);
and using return remsg.test(message);
?
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.
Yup. We had discussed that in one of the old comments :)
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.
Oh lol. Sorry, missed that entirely ;)
On Nov 17, 2015 10:28 PM, "thefourtheye" [email protected] wrote:
In lib/repl.js
#3823 (comment):@@ -1126,7 +1126,10 @@ function isRecoverableError(e, self) {
self._inTemplateLiteral = true;
return true;
}
- return /^(Unexpected end of input|Unexpected token)/.test(message);
- return message.startsWith('Unexpected end of input') ||
message.startsWith('Unexpected token') ||
}message.startsWith('missing ) after argument list');
Yup. We had discussed that in one of the old comments :)
—
Reply to this email directly or view it on GitHub
https://github.com/nodejs/node/pull/3823/files#r45164076.
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.
No problem :)
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.
@jasnell I spent some time thinking about which way to go about this, and at the end decided with the "dumb" way. Doing it in fancy ways is possible, but doesn't give us readability or extensibility or anything else. So I fought the urge to rewrite that part.
...even though it's so tempting.
LGTM. CI Run: https://ci.nodejs.org/job/node-test-pull-request/1655/ |
There was an odd build bot failure on OSX.. running CI again: https://ci.nodejs.org/job/node-test-pull-request/1663/ |
Currently, the repl allows multiline function declarations, strings, and all sorts of niceties by catching the SyntaxErrors they issue and ignoring them. However, the SyntaxError raised by multiline function calls was not caught. This commit adds to the whitelist.
@thefourtheye Squashed the commits into one. |
Currently, the repl allows multiline function declarations, strings, and all sorts of niceties by catching the SyntaxErrors they issue and ignoring them. However, the SyntaxError raised by multiline function calls was not caught. This commit adds to the whitelist. PR-URL: #3823 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Currently, the repl allows multiline function declarations, strings, and all sorts of niceties by catching the SyntaxErrors they issue and ignoring them. However, the SyntaxError raised by multiline function calls was not caught. This commit adds to the whitelist. PR-URL: #3823 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Currently, the repl allows multiline function declarations, strings, and all sorts of niceties by catching the SyntaxErrors they issue and ignoring them. However, the SyntaxError raised by multiline function calls was not caught. This commit adds to the whitelist. PR-URL: nodejs#3823 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
This appears to be an error that we weren't properly handling before. I'd like to float the idea of this as semver-patch instead of semver-minor, unless someone has strong feelings otherwise. Refs: #5437 |
Currently, the repl allows multiline function declarations, strings, and
all sorts of niceties by catching the SyntaxErrors they issue and
ignoring them. However, the SyntaxError raised by multiline function
calls was not caught. This commit adds to the whitelist.
Behaviour before this commit:
After: