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

Skip to content

Commit 79b9784

Browse files
committed
JS: handle ES2015 modules compiling to Node.js modules
1 parent 5e10e95 commit 79b9784

2 files changed

Lines changed: 9 additions & 2 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());
556+
scopeManager.addVariables(sourceType.getPredefinedLocals(platform));
557557
trapwriter.addTuple("isModule", toplevelLabel);
558558
}
559559

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,19 @@ 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() {
110+
public Set<String> getPredefinedLocals(Platform platform) {
111111
switch (this) {
112112
case CLOSURE_MODULE:
113113
return closureLocals;
114114
case COMMONJS_MODULE:
115115
return commonJsLocals;
116+
case MODULE:
117+
if (platform == Platform.NODE) {
118+
// An ES2015 module that is compiled to a Node.js module effectively has the locals
119+
// from Node.js even if they are not part of the ES2015 standard.
120+
return commonJsLocals;
121+
}
122+
return Collections.emptySet();
116123
default:
117124
return Collections.emptySet();
118125
}

0 commit comments

Comments
 (0)