Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

Zirak
Copy link
Contributor

@Zirak Zirak commented Nov 14, 2015

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:

> console.log(console.log(1,
... 2)
SyntaxError: missing ) after argument list

After:

> console.log(console.log(1,
... 2),
... 3)
1 2
undefined 3
undefined

@r-52 r-52 added the repl Issues and PRs related to the REPL subsystem. label Nov 14, 2015
@@ -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);
Copy link
Member

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?

Copy link
Contributor Author

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));

Copy link
Member

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.

Copy link
Contributor

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);

Copy link
Contributor Author

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.

Copy link
Contributor

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

@bnoordhuis
Copy link
Member

LGTM apart from a style issue.

{ client: client_unix, send: '2)',
expect: prompt_multiline },
{ client: client_unix, send: ')',
expect: 'undefined' },
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Nov 14, 2015
@jasnell
Copy link
Member

jasnell commented Nov 14, 2015

semver-minor only because it's technically adding new capability, not fixing a bug. Very good fix tho.
LGTM.

@Zirak
Copy link
Contributor Author

Zirak commented Nov 14, 2015

@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?

@jasnell
Copy link
Member

jasnell commented Nov 16, 2015

@jasnell
Copy link
Member

jasnell commented Nov 16, 2015

@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)

@thefourtheye
Copy link
Contributor

@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');
}
Copy link
Member

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); ?

Copy link
Contributor

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 :)

Copy link
Member

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem :)

Copy link
Contributor Author

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.

@thefourtheye
Copy link
Contributor

@jasnell
Copy link
Member

jasnell commented Feb 15, 2016

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.
@Zirak
Copy link
Contributor Author

Zirak commented Feb 16, 2016

@thefourtheye Squashed the commits into one.

thefourtheye pushed a commit that referenced this pull request Feb 16, 2016
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]>
@thefourtheye
Copy link
Contributor

Thanks @Zirak :-) Landed in a06066c

rvagg pushed a commit that referenced this pull request Feb 18, 2016
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]>
stefanmb pushed a commit to stefanmb/node that referenced this pull request Feb 23, 2016
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]>
@cjihrig
Copy link
Contributor

cjihrig commented Feb 25, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants