JS: handle .mjs files correctly

This commit is contained in:
Asger F
2019-02-06 09:12:10 +00:00
parent 79b9784b08
commit c52ed9152f
2 changed files with 3 additions and 3 deletions

View File

@@ -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);
}

View File

@@ -107,14 +107,14 @@ public class ExtractorConfig {
* <p/>
* If this source type has no local scope, the empty set is returned.
*/
public Set<String> getPredefinedLocals(Platform platform) {
public Set<String> 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;