Skip to content

Commit

Permalink
Don't allow goog.module calls in an ES6 module. Gets rid of a TODO! :D
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=136382030
  • Loading branch information
tbreisacher authored and blickly committed Oct 17, 2016
1 parent 8e1fa1f commit 4a18689
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/com/google/javascript/jscomp/deps/JsFileParser.java
Expand Up @@ -199,9 +199,8 @@ private DependencyInfo parseReader(String filePath,

private void setModuleType(ModuleType type) {
if (moduleType != type && moduleType != ModuleType.NON_MODULE) {
// TODO(sdh): should this be an error?
errorManager.report(
CheckLevel.WARNING, JSError.make(ModuleLoader.MODULE_CONFLICT, file.toString()));
CheckLevel.ERROR, JSError.make(ModuleLoader.MODULE_CONFLICT, file.toString()));
}
moduleType = type;
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/deps/ModuleLoader.java
Expand Up @@ -39,7 +39,7 @@
*/
public final class ModuleLoader {

public static final DiagnosticType MODULE_CONFLICT = DiagnosticType.warning(
public static final DiagnosticType MODULE_CONFLICT = DiagnosticType.error(
"JSC_MODULE_CONFLICT", "File has both goog.module and ES6 modules: {0}");

/** According to the spec, the forward slash should be the delimiter on all platforms. */
Expand Down
Expand Up @@ -20,6 +20,7 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
import com.google.javascript.jscomp.deps.DependencyInfo;
import com.google.javascript.jscomp.deps.ModuleLoader;
import com.google.javascript.jscomp.deps.SimpleDependencyInfo;
Expand Down Expand Up @@ -122,15 +123,17 @@ public void testParseIsLazy() {

public void testModuleConflict() {
Compiler compiler = new Compiler();
compiler.initOptions(new CompilerOptions());
CompilerOptions options = new CompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT6_STRICT);
compiler.initOptions(options);
JsAst ast = new JsAst(SourceFile.fromCode("file.js", "export let foo = 42;"));
SimpleDependencyInfo delegate =
new SimpleDependencyInfo("", "my/js.js", EMPTY, EMPTY, ImmutableMap.of("module", "goog"));
DependencyInfo info = new LazyParsedDependencyInfo(delegate, ast, compiler);

assertThat(Arrays.asList(compiler.getErrorManager().getWarnings())).isEmpty();
assertThat(Arrays.asList(compiler.getErrorManager().getErrors())).isEmpty();
assertThat(info.getLoadFlags()).containsExactly("module", "es6", "lang", "es6");
assertThat(Arrays.asList(compiler.getErrorManager().getWarnings()))
assertThat(Arrays.asList(compiler.getErrorManager().getErrors()))
.containsExactly(JSError.make(ModuleLoader.MODULE_CONFLICT, "my/js.js"));
}

Expand Down

0 comments on commit 4a18689

Please sign in to comment.