diff --git a/javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java b/javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java index 573b65c40d0..886cacd87a6 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java +++ b/javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java @@ -553,7 +553,7 @@ public class ASTExtractor { if (sourceType.hasLocalScope()) { Label moduleScopeKey = trapwriter.globalID("module;{" + locationManager.getFileLabel() + "}," + locationManager.getStartLine() + "," + locationManager.getStartColumn()); scopeManager.enterScope(3, moduleScopeKey, toplevelLabel); - scopeManager.addVariables(sourceType.getPredefinedLocals(platform)); + scopeManager.addVariables(sourceType.getPredefinedLocals(platform, locationManager.getSourceFileExtension())); trapwriter.addTuple("isModule", toplevelLabel); } diff --git a/javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java b/javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java index f5de7e8bb05..bd42953e240 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java +++ b/javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java @@ -107,14 +107,14 @@ public class ExtractorConfig { *

* If this source type has no local scope, the empty set is returned. */ - public Set getPredefinedLocals(Platform platform) { + public Set getPredefinedLocals(Platform platform, String extension) { switch (this) { case CLOSURE_MODULE: return closureLocals; case COMMONJS_MODULE: return commonJsLocals; case MODULE: - if (platform == Platform.NODE) { + if (platform == Platform.NODE && !extension.equals(".mjs")) { // An ES2015 module that is compiled to a Node.js module effectively has the locals // from Node.js even if they are not part of the ES2015 standard. return commonJsLocals;