-
Notifications
You must be signed in to change notification settings - Fork 7.3k
REPL: Fix for multiline input when using custom eval function #25587
Conversation
Multiline input doesn't work if user overrides "eval" in REPL.start. Overriding default eval will stop multiline inputs on syntax errors because of the current error checking in the finish callback. This fixes that issue and allows for a custom recoverableError check function to be passed the the REPL server for more customisable use. fixes nodejs#8640
@@ -49,6 +49,8 @@ the following values: | |||
|
|||
- `eval` - function that will be used to eval each given line. Defaults to | |||
an async wrapper for `eval()`. See below for an example of a custom `eval`. | |||
|
|||
- `recoverable` - function that will return a `bool` when passed an error and report if it is recoverable. Use if your `eval` returns none standard errors but you still want the benefits of multiline input. |
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 this should read non-standard rather than none standard.
thanks @davidchambers updated the copy. |
Can we see an example to reproduce the problem? |
Hey @thefourtheye this fix was submitted because it breaks multi-line support in Babel.js #1741 To reproduce the error you can simply use a custom eval function passed to the REPL server, in the // If error was SyntaxError and not JSON.parse error
if (e) {
if (e instanceof Recoverable) {
// Start buffering data like that:
// {
// ... x: 1
// ... }
self.bufferedCommand += cmd + '\n';
self.displayPrompt();
return;
} else {
self._domain.emit('error', e);
}
} In the fix I also included a recoverable test option for instances where a custom eval might throw an error that is recoverable but the message is non-standard (this happens in the case of Babel) and will not be matched by |
@joyent/node-tsc ... this change proposes adding a new option, which is technically an API change, but it's for a good reason. Thoughts on this one? |
@@ -94,6 +94,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) { | |||
ignoreUndefined = options.ignoreUndefined; | |||
prompt = options.prompt; | |||
dom = options.domain; | |||
recoverableCheck = options.recoverable || isRecoverableError; |
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.
This would be better as a ternary based on whether options.recoverable
is a function or not.
@jasnell I left a few comments. I don't really have an opinion on whether this gets in or not. |
@cjihrig I'll add your suggestions to the PR, in terms of testing you're right it isn't really tested but neither was the eval function (unless I'm missing something??) so I just kept it in line with that as it directly affects that. |
No newline at end of file
@mikeybox Here's the relevant issue on nodejs/node#2939 |
are there any news on this? |
@CestDiego there is a similar fix in a PR which is further along nodejs/node#3488. |
Multiline input doesn't work if user overrides "eval" in
REPL.start. Overriding default eval will stop multiline
inputs on syntax errors because of the current error checking
in the finish callback.
This fixes that issue and allows for a custom recoverableError
check function to be passed the the REPL server for more
customisable use.
fixes #8640