Skip to content

Commit ba7086e

Browse files
committed
refactor: add try-catch for parser
1 parent 245332e commit ba7086e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/generators/lexer.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ export class Lexer {
4444
this._code = code.trim()
4545
this._isClass = options.isClass ?? false
4646
this._ignoredKeys = options.ignoredKeys ?? []
47-
this._ast = Parser.parse(code, {
48-
ecmaVersion: 'latest',
49-
sourceType: 'module',
50-
// Will interpret code inside an async function so return is allowed
51-
allowReturnOutsideFunction: true,
52-
})
47+
try {
48+
this._ast = Parser.parse(code, {
49+
ecmaVersion: 'latest',
50+
sourceType: 'module',
51+
// Will interpret code inside an async function so return is allowed
52+
allowReturnOutsideFunction: true,
53+
})
54+
} catch (error) {
55+
throw new Error('Failed to parse code\n\n' + code + '\n\n' + error.stack)
56+
}
5357
this._identifiers = null
5458
this._ignoreIdTypes = []
5559
this._replacedIdentifiers = {}

0 commit comments

Comments
 (0)