Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c52ed91

Browse files
committed
JS: handle .mjs files correctly
1 parent 79b9784 commit c52ed91

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ public Label visit(Program nd, Context c) {
553553
if (sourceType.hasLocalScope()) {
554554
Label moduleScopeKey = trapwriter.globalID("module;{" + locationManager.getFileLabel() + "}," + locationManager.getStartLine() + "," + locationManager.getStartColumn());
555555
scopeManager.enterScope(3, moduleScopeKey, toplevelLabel);
556-
scopeManager.addVariables(sourceType.getPredefinedLocals(platform));
556+
scopeManager.addVariables(sourceType.getPredefinedLocals(platform, locationManager.getSourceFileExtension()));
557557
trapwriter.addTuple("isModule", toplevelLabel);
558558
}
559559

javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ public boolean isStrictMode() {
107107
* <p/>
108108
* If this source type has no local scope, the empty set is returned.
109109
*/
110-
public Set<String> getPredefinedLocals(Platform platform) {
110+
public Set<String> getPredefinedLocals(Platform platform, String extension) {
111111
switch (this) {
112112
case CLOSURE_MODULE:
113113
return closureLocals;
114114
case COMMONJS_MODULE:
115115
return commonJsLocals;
116116
case MODULE:
117-
if (platform == Platform.NODE) {
117+
if (platform == Platform.NODE && !extension.equals(".mjs")) {
118118
// An ES2015 module that is compiled to a Node.js module effectively has the locals
119119
// from Node.js even if they are not part of the ES2015 standard.
120120
return commonJsLocals;

0 commit comments

Comments
 (0)