mirror of
https://github.com/github/codeql.git
synced 2026-02-23 18:33:42 +01:00
JS: recognize Closure modules files as modules
This commit is contained in:
@@ -560,6 +560,7 @@ public class ASTExtractor {
|
||||
} else if (sourceType == SourceType.MODULE) {
|
||||
Label moduleScopeKey = trapwriter.globalID("module;{" + locationManager.getFileLabel() + "}," + locationManager.getStartLine() + "," + locationManager.getStartColumn());
|
||||
scopeManager.enterScope(3, moduleScopeKey, toplevelLabel);
|
||||
scopeManager.addVariables("exports"); // needed for Closure modules - spuriously added for ES6 modules
|
||||
trapwriter.addTuple("isModule", toplevelLabel);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ public class JSExtractor {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
// heuristic: if `import` or `export` appears at the beginning of a line, it's probably a module
|
||||
private static final Pattern containsImportOrExport = Pattern.compile("(?m)^([ \t]*)(import|export)\\b");
|
||||
// heuristic: if `import`, `export`, or `goog.module` appears at the beginning of a line, it's probably a module
|
||||
private static final Pattern containsModuleIndicator = Pattern.compile("(?m)^([ \t]*)(import|export|goog\\.module)\\b");
|
||||
|
||||
public Pair<Label, LoCInfo> extract(TextualExtractor textualExtractor, String source, int toplevelKind, ScopeManager scopeManager) throws ParseError {
|
||||
// if the file starts with `{ "<string>":` it won't parse as JavaScript; try parsing as JSON instead
|
||||
@@ -69,7 +69,7 @@ public class JSExtractor {
|
||||
if (sourceType != SourceType.AUTO)
|
||||
return sourceType;
|
||||
if (config.getEcmaVersion().compareTo(ECMAVersion.ECMA2015) >= 0) {
|
||||
Matcher m = containsImportOrExport.matcher(source);
|
||||
Matcher m = containsModuleIndicator.matcher(source);
|
||||
if (m.find() && (allowLeadingWS || m.group(1).isEmpty()))
|
||||
return SourceType.MODULE;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Main {
|
||||
* such a way that it may produce different tuples for the same file under the same
|
||||
* {@link ExtractorConfig}.
|
||||
*/
|
||||
public static final String EXTRACTOR_VERSION = "2019-01-29";
|
||||
public static final String EXTRACTOR_VERSION = "2019-02-04";
|
||||
|
||||
public static final Pattern NEWLINE = Pattern.compile("\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user