Skip to content

Commit

Permalink
JsChecker: support extensionless ES6 imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Figueiredo committed Aug 15, 2019
1 parent b2a6fb7 commit bb5ff0a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions java/com/google/javascript/jscomp/CheckStrictDeps.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions java/com/google/javascript/jscomp/JsChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bb5ff0a

Please sign in to comment.