mirror of
https://github.com/github/codeql.git
synced 2026-04-27 01:35:13 +02:00
try to parse JS files without using the supported extensions
This commit is contained in:
@@ -28,20 +28,29 @@ public class JcornWrapper {
|
||||
.onToken(tokens)
|
||||
.preserveParens(true)
|
||||
.allowReturnOutsideFunction(true);
|
||||
if (config.isMozExtensions()) options.mozExtensions(true);
|
||||
if (config.isJscript()) options.jscript(true);
|
||||
if (config.isJsx()) options = new JSXOptions(options);
|
||||
if (config.isEsnext()) options.esnext(true);
|
||||
if (config.isV8Extensions()) options.v8Extensions(true);
|
||||
if (config.isE4X()) options.e4x(true);
|
||||
|
||||
Program program = null;
|
||||
List<ParseError> errors = new ArrayList<>();
|
||||
|
||||
try {
|
||||
if (config.isTolerateParseErrors())
|
||||
options.onRecoverableError((err) -> errors.add(mkParseError(err)));
|
||||
|
||||
program = sourceType.createParser(options, source, 0).parse();
|
||||
try {
|
||||
// First try to parse as a regular JavaScript program.
|
||||
program = sourceType.createParser(options, source, 0).parse();
|
||||
} catch (SyntaxError e) {
|
||||
// If that fails, try to enable all the extensions that we support.
|
||||
if (config.isTolerateParseErrors())
|
||||
options.onRecoverableError((err) -> errors.add(mkParseError(err)));
|
||||
comments.clear();
|
||||
tokens.clear();
|
||||
if (config.isMozExtensions()) options.mozExtensions(true);
|
||||
if (config.isJscript()) options.jscript(true);
|
||||
if (config.isJsx()) options = new JSXOptions(options);
|
||||
if (config.isV8Extensions()) options.v8Extensions(true);
|
||||
if (config.isE4X()) options.e4x(true);
|
||||
if (config.isEsnext()) options.allowFlowTypes(true); // allow the flow-parser to parse types.
|
||||
program = sourceType.createParser(options, source, 0).parse();
|
||||
}
|
||||
} catch (SyntaxError e) {
|
||||
errors.add(mkParseError(e));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user