Skip to content

Commit fb44dfb

Browse files
Julien Gillimscdex
Julien Gilli
authored andcommitted
repl: make 'Unexpected token' errors recoverable
Fix the regexp used to detect 'Unexpected token' errors so that they can be considered as recoverable. This fixes the following use case: > var foo = 'bar \ ... baz'; undefined > foo 'bar baz' > Fixes: nodejs/node-v0.x-archive#8874 PR-URL: nodejs/node-v0.x-archive#8875 PR-URL: nodejs#2052 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 9d99dbe commit fb44dfb

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ function isRecoverableError(e, self) {
994994
self._inTemplateLiteral = true;
995995
return true;
996996
}
997-
return /^(Unexpected end of input|Unexpected token :)/.test(message);
997+
return /^(Unexpected end of input|Unexpected token)/.test(message);
998998
}
999999
return false;
10001000
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
/*
3+
* This is a regression test for https://github.com/joyent/node/issues/8874.
4+
*/
5+
var common = require('../common');
6+
var assert = require('assert');
7+
8+
var spawn = require('child_process').spawn;
9+
// use -i to force node into interactive mode, despite stdout not being a TTY
10+
var args = [ '-i' ];
11+
var child = spawn(process.execPath, args);
12+
13+
var input = 'var foo = "bar\\\nbaz"';
14+
// Match '...' as well since it marks a multi-line statement
15+
var expectOut = /^> ... undefined\n/;
16+
17+
child.stderr.setEncoding('utf8');
18+
child.stderr.on('data', function(c) {
19+
throw new Error('child.stderr be silent');
20+
});
21+
22+
child.stdout.setEncoding('utf8');
23+
var out = '';
24+
child.stdout.on('data', function(c) {
25+
out += c;
26+
});
27+
28+
child.stdout.on('end', function() {
29+
assert(expectOut.test(out));
30+
console.log('ok');
31+
});
32+
33+
child.stdin.end(input);

0 commit comments

Comments
 (0)