diff --git a/java/com/google/javascript/jscomp/CheckStrictDeps.java b/java/com/google/javascript/jscomp/CheckStrictDeps.java index 70109ddbc2..ed3de2e4b8 100644 --- a/java/com/google/javascript/jscomp/CheckStrictDeps.java +++ b/java/com/google/javascript/jscomp/CheckStrictDeps.java @@ -136,6 +136,12 @@ private void visitEs6Import(NodeTraversal t, Node n) { private void checkNamespaceIsProvided(NodeTraversal t, Node n, String namespace) { if (namespace.startsWith("/") || namespace.startsWith(".")) { // TODO(jart): Unify path resolution with ModuleLoader. + // NOTE(robfig): To enable usage of extensionless ES6 modules, + // copy these 3 lines from NodeModuleResolver.java. + if (!namespace.endsWith(".js")) { + namespace += ".js"; + } + Webpath me = Webpath.get(t.getSourceName()); if (!me.isAbsolute()) { me = Webpath.get("/").resolve(me); diff --git a/java/com/google/javascript/jscomp/JsChecker.java b/java/com/google/javascript/jscomp/JsChecker.java index 5470f8e7d5..04a53eb24b 100644 --- a/java/com/google/javascript/jscomp/JsChecker.java +++ b/java/com/google/javascript/jscomp/JsChecker.java @@ -27,6 +27,7 @@ import com.google.common.collect.Sets; import com.google.javascript.jscomp.CompilerOptions.IncrementalCheckMode; import com.google.javascript.jscomp.CompilerOptions.LanguageMode; +import com.google.javascript.jscomp.deps.ModuleLoader.ResolutionMode; import com.google.javascript.jscomp.parsing.Config; import io.bazel.rules.closure.BuildInfo.ClosureJsLibrary; import io.bazel.rules.closure.worker.CommandLineProgram; @@ -132,6 +133,11 @@ public final class JsChecker { usage = "Invert exit code and disable printing warnings") private boolean expectFailure; + @Option( + name = "--module_resolution", + usage = "Specifies how the compiler locates modules") + private String moduleResolution = ResolutionMode.BROWSER.name(); + @Option( name = "--help", usage = "Displays this message on stdout and exit") @@ -182,6 +188,7 @@ private boolean run() throws IOException { options.setPreserveDetailedSourceInfo(true); options.setEmitUseStrict(false); options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE); + options.setModuleResolutionMode(ResolutionMode.valueOf(moduleResolution)); JsCheckerErrorFormatter errorFormatter = new JsCheckerErrorFormatter(compiler, state.roots, labels); errorFormatter.setColorize(true);