|
8 | 8 | ArrayPrototypePush, |
9 | 9 | FunctionPrototype, |
10 | 10 | ObjectKeys, |
| 11 | + StringPrototypeEndsWith, |
| 12 | + StringPrototypeIncludes, |
| 13 | + StringPrototypeReplace, |
| 14 | + StringPrototypeSplit, |
11 | 15 | SyntaxError, |
12 | 16 | } = primordials; |
13 | 17 |
|
@@ -110,20 +114,18 @@ function processTopLevelAwait(src) { |
110 | 114 | // Convert keyword parse errors on await into their original errors when |
111 | 115 | // possible. |
112 | 116 | if (errPos === awaitPos + 6 && |
113 | | - src.slice(errPos - 6, errPos - 1) === 'await' && |
114 | | - e.message.includes('Expecting Unicode escape sequence')) |
| 117 | + StringPrototypeIncludes(e.message, 'Expecting Unicode escape sequence')) |
115 | 118 | return null; |
116 | 119 | if (errPos === awaitPos + 7 && |
117 | | - src.slice(errPos - 7, errPos - 2) === 'await' && |
118 | | - e.message.includes('Unexpected token')) |
| 120 | + StringPrototypeIncludes(e.message, 'Unexpected token')) |
119 | 121 | return null; |
120 | 122 | const { line, column } = e.loc; |
121 | | - let message = '\n' + src.split('\n')[line - 2] + '\n'; |
| 123 | + let message = '\n' + StringPrototypeSplit(src, '\n')[line - 2] + '\n'; |
122 | 124 | let i = 0; |
123 | 125 | while (i++ < column) message += ' '; |
124 | | - message += '^\n\n' + e.message.replace(/ \([^)]+\)/, ''); |
| 126 | + message += '^\n\n' + StringPrototypeReplace(e.message, / \([^)]+\)/, ''); |
125 | 127 | // V8 unexpected token errors include the token string. |
126 | | - if (message.endsWith('Unexpected token')) |
| 128 | + if (StringPrototypeEndsWith(message, 'Unexpected token')) |
127 | 129 | message += " '" + src[e.pos - wrapPrefix.length] + "'"; |
128 | 130 | // eslint-disable-next-line no-restricted-syntax |
129 | 131 | throw new SyntaxError(message); |
|
0 commit comments