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 Sep 11, 2019
1 parent b2a6fb7 commit 2715d4f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions closure/compiler/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,27 @@ sh_test(
":exports_data",
],
)

# TEST: ES6 module can import another via a workspace-relative extensionless import path.

closure_js_library(
name = "es6module1",
srcs = ["es6module1.js"],
no_closure_library = True,
)

closure_js_library(
name = "es6module2",
srcs = ["es6module2.js"],
# suppress = ["moduleLoad"],
no_closure_library = True,
deps = [":es6module1"],
)

closure_js_binary(
name = "es6module_bin",
compilation_level = "ADVANCED",
entry_points = ["/closure/compiler/test/es6module2"],
language = "ECMASCRIPT5",
deps = [":es6module2"],
)
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

0 comments on commit 2715d4f

Please sign in to comment.