Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e8c91e7

Browse filesBrowse files
Trottevanlucas
authored andcommitted
repl: refine handling of illegal tokens
Illegal tokens are only recoverable in string literals, RegExp literals, and block comments. If not in one of these constructs, immediately return an error rather than giving the user false hope by giving them a chance to try to recover. PR-URL: #7104 Fixes: #3611 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 1600966 commit e8c91e7
Copy full SHA for e8c91e7

File tree

Expand file treeCollapse file tree

2 files changed

+19
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-3
lines changed
Open diff view settings
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+15-3Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,11 @@ REPLServer.prototype.convertToContext = function(cmd) {
11541154
return cmd;
11551155
};
11561156

1157+
function bailOnIllegalToken(parser) {
1158+
return parser._literal === null &&
1159+
!parser.blockComment &&
1160+
!parser.regExpLiteral;
1161+
}
11571162

11581163
// If the error is that we've unexpectedly ended the input,
11591164
// then let the user try to recover by adding more input.
@@ -1166,9 +1171,16 @@ function isRecoverableError(e, self) {
11661171
return true;
11671172
}
11681173

1169-
return message.startsWith('Unexpected end of input') ||
1170-
message.startsWith('Unexpected token') ||
1171-
message.startsWith('missing ) after argument list');
1174+
if (message.startsWith('Unexpected end of input') ||
1175+
message.startsWith('missing ) after argument list'))
1176+
return true;
1177+
1178+
if (message.startsWith('Unexpected token')) {
1179+
if (message.includes('ILLEGAL') && bailOnIllegalToken(self.lineParser))
1180+
return false;
1181+
else
1182+
return true;
1183+
}
11721184
}
11731185
return false;
11741186
}
Collapse file

‎test/parallel/test-repl.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ function error_test() {
324324
'undefined\n' + prompt_unix },
325325
{ client: client_unix, send: '{ var x = 4; }',
326326
expect: 'undefined\n' + prompt_unix },
327+
// Illegal token is not recoverable outside string literal, RegExp literal,
328+
// or block comment. https://github.com/nodejs/node/issues/3611
329+
{ client: client_unix, send: 'a = 3.5e',
330+
expect: /^SyntaxError: Unexpected token ILLEGAL/ },
327331
]);
328332
}
329333

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.