Skip to content

Commit ce84d28

Browse files
author
Rob Figueiredo
committed
JsChecker: support extensionless ES6 imports
1 parent b2a6fb7 commit ce84d28

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

closure/compiler/test/BUILD

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,27 @@ sh_test(
237237
":exports_data",
238238
],
239239
)
240+
241+
# TEST: ES6 module can import another via a workspace-relative extensionless import path.
242+
243+
closure_js_library(
244+
name = "es6module1",
245+
srcs = ["es6module1.js"],
246+
no_closure_library = True,
247+
)
248+
249+
closure_js_library(
250+
name = "es6module2",
251+
srcs = ["es6module2.js"],
252+
# suppress = ["moduleLoad"],
253+
no_closure_library = True,
254+
deps = [":es6module1"],
255+
)
256+
257+
closure_js_binary(
258+
name = "es6module_bin",
259+
compilation_level = "ADVANCED",
260+
entry_points = ["/closure/compiler/test/es6module2"],
261+
language = "ECMASCRIPT5",
262+
deps = [":es6module2"],
263+
)

closure/compiler/test/es6module1.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2019 The Closure Rules Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
export const name = "module1";

closure/compiler/test/es6module2.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2019 The Closure Rules Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { name } from "/closure/compiler/test/es6module1";
16+
17+
console.log(name);

java/com/google/javascript/jscomp/CheckStrictDeps.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ private void visitEs6Import(NodeTraversal t, Node n) {
136136
private void checkNamespaceIsProvided(NodeTraversal t, Node n, String namespace) {
137137
if (namespace.startsWith("/") || namespace.startsWith(".")) {
138138
// TODO(jart): Unify path resolution with ModuleLoader.
139+
// NOTE(robfig): To enable usage of extensionless ES6 modules,
140+
// copy these 3 lines from NodeModuleResolver.java.
141+
if (!namespace.endsWith(".js")) {
142+
namespace += ".js";
143+
}
144+
139145
Webpath me = Webpath.get(t.getSourceName());
140146
if (!me.isAbsolute()) {
141147
me = Webpath.get("/").resolve(me);

0 commit comments

Comments
 (0)