File tree 2 files changed +75
-10
lines changed
2 files changed +75
-10
lines changed Original file line number Diff line number Diff line change @@ -1454,14 +1454,15 @@ function isRecoverableError(e, code) {
1454
1454
if ( e && e . name === 'SyntaxError' ) {
1455
1455
var message = e . message ;
1456
1456
if ( message === 'Unterminated template literal' ||
1457
- message === 'Missing } in template expression ' ) {
1457
+ message === 'Unexpected end of input ' ) {
1458
1458
return true ;
1459
1459
}
1460
1460
1461
- if ( message . startsWith ( 'Unexpected end of input' ) ||
1462
- message . startsWith ( 'missing ) after argument list' ) ||
1463
- message . startsWith ( 'Unexpected token' ) )
1464
- return true ;
1461
+ if ( message === 'missing ) after argument list' ) {
1462
+ const frames = e . stack . split ( / \r ? \n / ) ;
1463
+ const pos = frames . findIndex ( ( f ) => f . match ( / ^ \s * \^ + $ / ) ) ;
1464
+ return pos > 0 && frames [ pos - 1 ] . length === frames [ pos ] . length ;
1465
+ }
1465
1466
1466
1467
if ( message === 'Invalid or unexpected token' )
1467
1468
return isCodeRecoverable ( code ) ;
Original file line number Diff line number Diff line change @@ -163,13 +163,23 @@ const errorTests = [
163
163
send : '.break' ,
164
164
expect : ''
165
165
} ,
166
- // Template expressions can cross lines
166
+ // Template expressions
167
167
{
168
168
send : '`io.js ${"1.0"' ,
169
+ expect : [
170
+ kSource ,
171
+ kArrow ,
172
+ '' ,
173
+ / ^ S y n t a x E r r o r : / ,
174
+ ''
175
+ ]
176
+ } ,
177
+ {
178
+ send : '`io.js ${' ,
169
179
expect : '... '
170
180
} ,
171
181
{
172
- send : '+ ".2"}`' ,
182
+ send : '"1.0" + ".2"}`' ,
173
183
expect : '\'io.js 1.0.2\''
174
184
} ,
175
185
// Dot prefix in multiline commands aren't treated as commands
@@ -644,14 +654,68 @@ const errorTests = [
644
654
} ,
645
655
// Do not parse `...[]` as a REPL keyword
646
656
{
647
- send : '...[]\n' ,
648
- expect : '... ... '
657
+ send : '...[]' ,
658
+ expect : [
659
+ kSource ,
660
+ kArrow ,
661
+ '' ,
662
+ / ^ S y n t a x E r r o r : / ,
663
+ ''
664
+ ]
649
665
} ,
650
666
// bring back the repl to prompt
651
667
{
652
668
send : '.break' ,
653
669
expect : ''
654
- }
670
+ } ,
671
+ {
672
+ send : 'console.log("Missing comma in arg list" process.version)' ,
673
+ expect : [
674
+ kSource ,
675
+ kArrow ,
676
+ '' ,
677
+ / ^ S y n t a x E r r o r : / ,
678
+ ''
679
+ ]
680
+ } ,
681
+ {
682
+ send : 'x = {\nfield\n{' ,
683
+ expect : [
684
+ '... ... {' ,
685
+ kArrow ,
686
+ '' ,
687
+ / ^ S y n t a x E r r o r : / ,
688
+ ''
689
+ ]
690
+ } ,
691
+ {
692
+ send : '(2 + 3))' ,
693
+ expect : [
694
+ kSource ,
695
+ kArrow ,
696
+ '' ,
697
+ / ^ S y n t a x E r r o r : / ,
698
+ ''
699
+ ]
700
+ } ,
701
+ {
702
+ send : 'if (typeof process === "object"); {' ,
703
+ expect : '... '
704
+ } ,
705
+ {
706
+ send : 'console.log("process is defined");' ,
707
+ expect : '... '
708
+ } ,
709
+ {
710
+ send : '} else {' ,
711
+ expect : [
712
+ kSource ,
713
+ kArrow ,
714
+ '' ,
715
+ / ^ S y n t a x E r r o r : / ,
716
+ ''
717
+ ]
718
+ } ,
655
719
] ;
656
720
657
721
const tcpTests = [
You can’t perform that action at this time.
0 commit comments