From 1e330f2b877b92f126b4c5265d3c1bd35fd299f3 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Tue, 29 Aug 2023 12:34:06 +0100 Subject: [PATCH] Use `allowNewTargetOutsideFunction` Babel parse option [improve] Closes #446. --- lib/instrument/instrument.js | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/lib/instrument/instrument.js b/lib/instrument/instrument.js index ae1c6c7a..9d3837b8 100644 --- a/lib/instrument/instrument.js +++ b/lib/instrument/instrument.js @@ -46,27 +46,15 @@ const babelOptionsCache = {}; function parseImpl( code, filename, isEsm, isCommonJs, isDirectEval, isJsx, isStrict, sourceMaps, inputSourceMap ) { - // Parse code to AST. - // `errorRecovery` is workaround until https://github.com/babel/babel/pull/15114 is merged. - // TODO Just use `allowNewTargetOutsideFunction` option once it's available. - const allowNewTargetOutsideFunction = isCommonJs || isDirectEval; + // Parse code to AST const ast = parse(code, { sourceType: isEsm ? 'module' : 'script', strictMode: isStrict, allowReturnOutsideFunction: isCommonJs, - errorRecovery: allowNewTargetOutsideFunction, + allowNewTargetOutsideFunction: isCommonJs || isDirectEval, plugins: ['v8intrinsic', ...(isJsx ? ['jsx'] : [])] }); - if (allowNewTargetOutsideFunction && ast.errors.length > 0) { - for (const error of ast.errors) { - if (error.code !== 'BABEL_PARSER_SYNTAX_ERROR' || error.reasonCode !== 'UnexpectedNewTarget') { - throw error; - } - } - ast.errors.length = 0; - } - // Parse source map comment if present, and remove source map comments from AST. // Do not parse source map comment if source maps disabled, or input source map already provided. const parsedSourceMap = parseSourceMapComment(