1
1
'use strict' ;
2
2
3
3
const acorn = require ( 'internal/deps/acorn/acorn/dist/acorn' ) ;
4
+ const privateMethods =
5
+ require ( 'internal/deps/acorn-plugins/acorn-private-methods/index' ) ;
6
+ const bigInt = require ( 'internal/deps/acorn-plugins/acorn-bigint/index' ) ;
7
+ const classFields =
8
+ require ( 'internal/deps/acorn-plugins/acorn-class-fields/index' ) ;
9
+ const numericSeparator =
10
+ require ( 'internal/deps/acorn-plugins/acorn-numeric-separator/index' ) ;
11
+ const staticClassFeatures =
12
+ require ( 'internal/deps/acorn-plugins/acorn-static-class-features/index' ) ;
4
13
const { tokTypes : tt , Parser : AcornParser } = acorn ;
5
14
6
15
// If the error is that we've unexpectedly ended the input,
7
16
// then let the user try to recover by adding more input.
8
17
// Note: `e` (the original exception) is not used by the current implementation,
9
18
// but may be needed in the future.
10
19
function isRecoverableError ( e , code ) {
20
+ // For similar reasons as `defaultEval`, wrap expressions starting with a
21
+ // curly brace with parenthesis. Note: only the open parenthesis is added
22
+ // here as the point is to test for potentially valid but incomplete
23
+ // expressions.
24
+ if ( / ^ \s * \{ / . test ( code ) && isRecoverableError ( e , `(${ code } ` ) ) return true ;
25
+
11
26
let recoverable = false ;
12
27
13
28
// Determine if the point of any error raised is at the end of the input.
@@ -26,34 +41,39 @@ function isRecoverableError(e, code) {
26
41
// change these messages in the future, this will lead to a test
27
42
// failure, indicating that this code needs to be updated.
28
43
//
29
- const RecoverableParser = AcornParser . extend ( ( Parser ) => {
30
- return class extends Parser {
31
- nextToken ( ) {
32
- super . nextToken ( ) ;
33
- if ( this . type === tt . eof ) recoverable = true ;
34
- }
35
- raise ( pos , message ) {
36
- switch ( message ) {
37
- case 'Unterminated template' :
38
- case 'Unterminated comment' :
39
- recoverable = true ;
40
- break ;
44
+ const RecoverableParser = AcornParser
45
+ . extend (
46
+ privateMethods ,
47
+ bigInt ,
48
+ classFields ,
49
+ numericSeparator ,
50
+ staticClassFeatures ,
51
+ ( Parser ) => {
52
+ return class extends Parser {
53
+ nextToken ( ) {
54
+ super . nextToken ( ) ;
55
+ if ( this . type === tt . eof )
56
+ recoverable = true ;
57
+ }
58
+ raise ( pos , message ) {
59
+ switch ( message ) {
60
+ case 'Unterminated template' :
61
+ case 'Unterminated comment' :
62
+ recoverable = true ;
63
+ break ;
41
64
42
- case 'Unterminated string constant' :
43
- const token = this . input . slice ( this . lastTokStart , this . pos ) ;
44
- // See https://www.ecma-international.org/ecma-262/#sec-line-terminators
45
- recoverable = / \\ (?: \r \n ? | \n | \u2028 | \u2029 ) $ / . test ( token ) ;
46
- }
47
- super . raise ( pos , message ) ;
65
+ case 'Unterminated string constant' :
66
+ const token = this . input . slice ( this . lastTokStart , this . pos ) ;
67
+ // See https://www.ecma-international.org/ecma-262/#sec-line-terminators
68
+ if ( / \\ (?: \r \n ? | \n | \u2028 | \u2029 ) $ / . test ( token ) ) {
69
+ recoverable = true ;
70
+ }
71
+ }
72
+ super . raise ( pos , message ) ;
73
+ }
74
+ } ;
48
75
}
49
- } ;
50
- } ) ;
51
-
52
- // For similar reasons as `defaultEval`, wrap expressions starting with a
53
- // curly brace with parenthesis. Note: only the open parenthesis is added
54
- // here as the point is to test for potentially valid but incomplete
55
- // expressions.
56
- if ( / ^ \s * \{ / . test ( code ) && isRecoverableError ( e , `(${ code } ` ) ) return true ;
76
+ ) ;
57
77
58
78
// Try to parse the code with acorn. If the parse fails, ignore the acorn
59
79
// error and return the recoverable status.
0 commit comments