diff --git a/src/com/google/javascript/jscomp/Es6RewriteModules.java b/src/com/google/javascript/jscomp/Es6RewriteModules.java
index 800da6a3a62..5e9796db5b9 100644
--- a/src/com/google/javascript/jscomp/Es6RewriteModules.java
+++ b/src/com/google/javascript/jscomp/Es6RewriteModules.java
@@ -16,7 +16,6 @@
package com.google.javascript.jscomp;
import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.javascript.jscomp.ClosureCheckModule.MODULE_USES_GOOG_MODULE_GET;
import static com.google.javascript.jscomp.ClosureRewriteModule.INVALID_GET_CALL_SCOPE;
@@ -26,7 +25,6 @@
import static com.google.javascript.jscomp.ProcessClosurePrimitives.INVALID_CLOSURE_CALL_ERROR;
import static com.google.javascript.jscomp.parsing.parser.FeatureSet.Feature.MODULES;
-import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
@@ -35,7 +33,6 @@
import com.google.javascript.jscomp.ModuleMetadata.Module;
import com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback;
import com.google.javascript.jscomp.deps.ModuleLoader;
-import com.google.javascript.jscomp.deps.ModuleLoader.ModulePath;
import com.google.javascript.jscomp.deps.ModuleLoader.ResolutionMode;
import com.google.javascript.rhino.IR;
import com.google.javascript.rhino.JSDocInfo;
@@ -85,24 +82,6 @@ public final class Es6RewriteModules extends AbstractPostOrderCallback
"JSC_PATH_REQUIRE_IN_NON_GOOG_MODULE",
"Cannot goog.require by path outside of goog.modules.");
- static final DiagnosticType PATH_REQUIRE_IN_GOOG_PROVIDE_FILE =
- DiagnosticType.error(
- "JSC_PATH_REQUIRE_IN_GOOG_PROVIDE_FILE",
- "goog.provide'd files can only goog.require namespaces. goog.require by path is only "
- + "valid in goog.modules.");
-
- static final DiagnosticType PATH_REQUIRE_IN_ES6_MODULE =
- DiagnosticType.error(
- "JSC_PATH_REQUIRE_IN_ES6_MODULE",
- "Import other ES6 modules and goog.require namespaces in ES6 modules. Do not "
- + "goog.require paths in ES6 modules.");
-
- static final DiagnosticType PATH_REQUIRE_IN_GOOG_MODULE_WITH_NO_PATH =
- DiagnosticType.error(
- "JSC_PATH_REQUIRE_IN_GOOG_MODULE_WITH_NO_PATH",
- "The goog.module {0} cannot require by path. It has been loaded without path "
- + "information (is the path argument to goog.loadModule provided?).");
-
private final AbstractCompiler compiler;
@Nullable private final PreprocessorSymbolTable preprocessorSymbolTable;
@@ -224,14 +203,6 @@ public void visit(NodeTraversal t, Node n, Node parent) {
String name = n.getLastChild().getString();
Module data = moduleMetadata.getModulesByGoogNamespace().get(name);
- boolean isPathRequire = false;
-
- // Can only goog.module.get by namespace.
- if (data == null && isRequire && ModuleLoader.isRelativeIdentifier(name)) {
- data = resolvePathRequire(t, n);
- isPathRequire = true;
- }
-
if (data == null || !data.isEs6Module()) {
return;
}
@@ -244,14 +215,9 @@ public void visit(NodeTraversal t, Node n, Node parent) {
Node statementNode = NodeUtil.getEnclosingStatement(n);
boolean importHasAlias = NodeUtil.isNameDeclaration(statementNode);
if (importHasAlias) {
- // const module = goog.require('./es6.js');
- // const module = module$es6;
- //
// const module = goog.require('an.es6.namespace');
// const module = module$es6;
- n.replaceWith(
- IR.name(isPathRequire ? data.getGlobalName() : data.getGlobalName(name))
- .useSourceInfoFromForTree(n));
+ n.replaceWith(IR.name(data.getGlobalName(name)).useSourceInfoFromForTree(n));
t.reportCodeChange();
} else {
if (parent.isExprResult()) {
@@ -265,70 +231,6 @@ public void visit(NodeTraversal t, Node n, Node parent) {
}
}
}
-
- @Nullable
- private Module resolvePathRequire(NodeTraversal t, Node requireCall) {
- String name = requireCall.getLastChild().getString();
- Module thisModule = moduleMetadata.getContainingModule(requireCall);
- checkNotNull(thisModule);
-
- if (!thisModule.isGoogModule()) {
- t.report(
- requireCall,
- thisModule.isGoogProvide()
- ? PATH_REQUIRE_IN_GOOG_PROVIDE_FILE
- : PATH_REQUIRE_IN_NON_GOOG_MODULE);
- return null;
- }
-
- if (thisModule.getPath() == null) {
- t.report(
- requireCall,
- PATH_REQUIRE_IN_GOOG_MODULE_WITH_NO_PATH,
- Iterables.getOnlyElement(thisModule.getGoogNamespaces()));
- return null;
- }
-
- ModulePath path =
- thisModule
- .getPath()
- .resolveJsModule(
- name, t.getSourceName(), requireCall.getLineno(), requireCall.getCharno());
-
- // If path is null then resolveJsModule has logged an error.
- if (path != null) {
- Module requiredModule = moduleMetadata.getModulesByPath().get(path.toString());
- checkNotNull(requiredModule);
- if (!requiredModule.isEs6Module()) {
- reportPathRequireForNonEs6Module(requiredModule, t, requireCall);
- }
- return requiredModule;
- }
- return null;
- }
- }
-
- private void reportPathRequireForNonEs6Module(
- Module requiredModule, NodeTraversal t, Node requireCall) {
- String suggestion = "";
-
- if (requiredModule.getGoogNamespaces().size() == 1) {
- suggestion =
- " Did you mean to goog.require "
- + Iterables.getOnlyElement(requiredModule.getGoogNamespaces())
- + "?";
- } else if (requiredModule.getGoogNamespaces().size() > 1) {
- suggestion =
- " Did you mean to goog.require one of ("
- + Joiner.on(", ").join(requiredModule.getGoogNamespaces())
- + ")?";
- }
-
- t.report(
- requireCall,
- PATH_REQUIRE_FOR_NON_ES6_MODULE,
- t.getInput().getPath().toString(),
- suggestion);
}
@Override
@@ -740,11 +642,7 @@ private void visitRequire(NodeTraversal t, Node requireCall, Node parent, boolea
Module m = moduleMetadata.getModulesByGoogNamespace().get(namespace);
if (m == null) {
- if (ModuleLoader.isRelativeIdentifier(namespace)) {
- t.report(requireCall, PATH_REQUIRE_IN_ES6_MODULE, namespace);
- } else {
- t.report(requireCall, MISSING_MODULE_OR_PROVIDE, namespace);
- }
+ t.report(requireCall, MISSING_MODULE_OR_PROVIDE, namespace);
return;
}
diff --git a/src/com/google/javascript/jscomp/ModuleMetadata.java b/src/com/google/javascript/jscomp/ModuleMetadata.java
index 02932cb78ca..1d2c9e36c63 100644
--- a/src/com/google/javascript/jscomp/ModuleMetadata.java
+++ b/src/com/google/javascript/jscomp/ModuleMetadata.java
@@ -42,12 +42,9 @@
*
TODO(johnplaisted): There's an opportunity for reuse here in ClosureRewriteModules, which
* would involve putting this in some common location. Currently this is only used as a helper class
* for Es6RewriteModules. CompilerInput already has some (not all) of this information but it is not
- * always populated. Additionally we'd ideally unwrap the goog.loadModule calls so each becomes its
- * own CompilerInput, otherwise goog.require(path) from loadModules won't work correctly. But not
- * having a 1:1 mapping of actual inputs to compiler inputs may cause issues. It may also be ideal
- * to include CommonJS here too as ES6 modules can import them. That would allow decoupling of how
- * these modules are written; right now Es6RewriteModule only checks this for goog.requires and
- * goog: imports, not for ES6 path imports.
+ * always populated. It may also be ideal to include CommonJS here too as ES6 modules can import
+ * them. That would allow decoupling of how these modules are written; right now Es6RewriteModule
+ * only checks this for goog.requires and goog: imports, not for ES6 path imports.
*/
final class ModuleMetadata {
/** Various types of Javascript "modules" that can be found in the JS Compiler. */
@@ -313,11 +310,7 @@ public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
case CALL:
if (n.isCall() && n.getFirstChild().matchesQualifiedName("goog.loadModule")) {
loadModuleCall = n;
- if (n.getChildCount() > 2 && n.getChildAtIndex(2).isString()) {
- enterModule(n, compiler.getModuleLoader().resolve(n.getChildAtIndex(2).getString()));
- } else {
- enterModule(n, null);
- }
+ enterModule(n, null);
}
break;
default:
diff --git a/src/com/google/javascript/jscomp/deps/DependencyInfo.java b/src/com/google/javascript/jscomp/deps/DependencyInfo.java
index feeaab5b95c..fb902d2079f 100644
--- a/src/com/google/javascript/jscomp/deps/DependencyInfo.java
+++ b/src/com/google/javascript/jscomp/deps/DependencyInfo.java
@@ -48,11 +48,6 @@ abstract class Require implements Serializable {
public enum Type {
/** Standard goog.require call for a symbol from a goog.provide or goog.module. */
GOOG_REQUIRE_SYMBOL,
- /**
- * goog.require call with a path argument. Currently only supported in goog.modules for ES6
- * modules.
- */
- GOOG_REQUIRE_PATH,
/** ES6 import statement. */
ES6_IMPORT,
/** Parsed from an existing Closure dependency file. */
@@ -75,14 +70,6 @@ public static Require googRequireSymbol(String symbol) {
.build();
}
- public static Require googRequirePath(String symbol, String rawPath) {
- return builder()
- .setRawText(rawPath)
- .setSymbol(symbol)
- .setType(Type.GOOG_REQUIRE_PATH)
- .build();
- }
-
public static Require es6Import(String symbol, String rawPath) {
return builder().setRawText(rawPath).setSymbol(symbol).setType(Type.ES6_IMPORT).build();
}
diff --git a/src/com/google/javascript/jscomp/deps/DepsGenerator.java b/src/com/google/javascript/jscomp/deps/DepsGenerator.java
index d1c2570d8fe..a00a88f751d 100644
--- a/src/com/google/javascript/jscomp/deps/DepsGenerator.java
+++ b/src/com/google/javascript/jscomp/deps/DepsGenerator.java
@@ -78,21 +78,6 @@ public static enum InclusionStrategy {
"DEPS_ES6_IMPORT_FOR_NON_ES6_MODULE",
"Cannot import file \"{0}\" because it is not an ES6 module.");
- static final DiagnosticType GOOG_REQUIRE_PATH_BETWEEN_ES6_MODULES =
- DiagnosticType.warning(
- "DEPS_GOOG_REQUIRE_PATH_BETWEEN_ES6_MODULES",
- "Use ES6 import rather than goog.require to import ES6 module \"{0}\".");
-
- static final DiagnosticType GOOG_REQUIRE_PATH_FOR_NON_ES6_MODULE =
- DiagnosticType.warning(
- "DEPS_GOOG_REQUIRE_PATH_FOR_NON_ES6_MODULE",
- "Cannot goog.require \"{0}\" by path. It is not an ES6 module.");
-
- static final DiagnosticType GOOG_REQUIRE_PATH_FROM_NON_GOOG_MODULE =
- DiagnosticType.warning(
- "DEPS_GOOG_REQUIRE_PATH_FROM_NON_GOOG_MODULE",
- "Cannot goog.require by path outside of a goog.module.");
-
static final DiagnosticType UNKNOWN_PATH_IMPORT =
DiagnosticType.warning("DEPS_UNKNOWN_PATH_IMPORT", "Could not find file \"{0}\".");
@@ -218,8 +203,7 @@ private Map removeMungedSymbols(
for (DependencyInfo dependencyInfo : jsFiles.values()) {
ArrayList newRequires = new ArrayList<>();
for (Require require : dependencyInfo.getRequires()) {
- if (require.getType() == Require.Type.ES6_IMPORT
- || require.getType() == Require.Type.GOOG_REQUIRE_PATH) {
+ if (require.getType() == Require.Type.ES6_IMPORT) {
// Symbols are unique per file and have nothing to do with paths so map lookups are safe
// here.
DependencyInfo provider = providesMap.get(require.getSymbol());
@@ -303,8 +287,7 @@ private void validateDependencies(Iterable preparsedFileDependen
} else if (provider == depInfo) {
reportSameFile(namespace, depInfo);
} else {
- boolean isGoogModule = depInfo.isModule();
- boolean isEs6Module = "es6".equals(depInfo.getLoadFlags().get("module"));
+ depInfo.isModule();
boolean providerIsEs6Module = "es6".equals(provider.getLoadFlags().get("module"));
switch (require.getType()) {
@@ -313,18 +296,6 @@ private void validateDependencies(Iterable preparsedFileDependen
reportEs6ImportForNonEs6Module(provider, depInfo);
}
break;
- case GOOG_REQUIRE_PATH:
- if (isEs6Module && providerIsEs6Module) {
- reportGoogRequirePathBetweenEs6Modules(provider, depInfo);
- } else {
- if (!isGoogModule) {
- reportGoogRequirePathFromNonGoogModule(depInfo);
- }
- if (!providerIsEs6Module) {
- reportGoogRequirePathForNonEs6Module(provider, depInfo);
- }
- }
- break;
case GOOG_REQUIRE_SYMBOL:
case PARSED_FROM_DEPS:
break;
@@ -349,28 +320,6 @@ private void reportEs6ImportForNonEs6Module(DependencyInfo provider, DependencyI
JSError.make(depInfo.getName(), -1, -1, ES6_IMPORT_FOR_NON_ES6_MODULE, provider.getName()));
}
- private void reportGoogRequirePathBetweenEs6Modules(
- DependencyInfo provider, DependencyInfo depInfo) {
- errorManager.report(
- CheckLevel.ERROR,
- JSError.make(
- depInfo.getName(), -1, -1, GOOG_REQUIRE_PATH_BETWEEN_ES6_MODULES, provider.getName()));
- }
-
- private void reportGoogRequirePathForNonEs6Module(
- DependencyInfo provider, DependencyInfo depInfo) {
- errorManager.report(
- CheckLevel.ERROR,
- JSError.make(
- depInfo.getName(), -1, -1, GOOG_REQUIRE_PATH_FOR_NON_ES6_MODULE, provider.getName()));
- }
-
- private void reportGoogRequirePathFromNonGoogModule(DependencyInfo depInfo) {
- errorManager.report(
- CheckLevel.ERROR,
- JSError.make(depInfo.getName(), -1, -1, GOOG_REQUIRE_PATH_FROM_NON_GOOG_MODULE));
- }
-
private void reportSameFile(String namespace, DependencyInfo depInfo) {
errorManager.report(CheckLevel.WARNING,
JSError.make(depInfo.getName(), -1, -1,
diff --git a/src/com/google/javascript/jscomp/deps/JsFileParser.java b/src/com/google/javascript/jscomp/deps/JsFileParser.java
index e26a5eacc03..c3d5fc25a0a 100644
--- a/src/com/google/javascript/jscomp/deps/JsFileParser.java
+++ b/src/com/google/javascript/jscomp/deps/JsFileParser.java
@@ -280,14 +280,6 @@ protected boolean parseLine(String line) throws ParseException {
} else if (!"goog".equals(arg)) {
// goog is always implicit.
Require require = Require.googRequireSymbol(arg);
- if (ModuleLoader.isRelativeIdentifier(arg)) {
- ModuleLoader.ModulePath path = file.resolveJsModule(arg);
- if (path == null) {
- path = file.resolveModuleAsPath(arg);
- }
- String symbol = path.toModuleName();
- require = Require.googRequirePath(symbol, arg);
- }
requires.add(require);
}
} else {
diff --git a/test/com/google/javascript/jscomp/Es6RewriteModulesWithGoogInteropTest.java b/test/com/google/javascript/jscomp/Es6RewriteModulesWithGoogInteropTest.java
index 3caf958a214..f0284f97705 100644
--- a/test/com/google/javascript/jscomp/Es6RewriteModulesWithGoogInteropTest.java
+++ b/test/com/google/javascript/jscomp/Es6RewriteModulesWithGoogInteropTest.java
@@ -21,11 +21,6 @@
import static com.google.javascript.jscomp.ClosureRewriteModule.MISSING_MODULE_OR_PROVIDE;
import static com.google.javascript.jscomp.Es6RewriteModules.LHS_OF_GOOG_REQUIRE_MUST_BE_CONST;
import static com.google.javascript.jscomp.Es6RewriteModules.NAMESPACE_IMPORT_CANNOT_USE_STAR;
-import static com.google.javascript.jscomp.Es6RewriteModules.PATH_REQUIRE_FOR_NON_ES6_MODULE;
-import static com.google.javascript.jscomp.Es6RewriteModules.PATH_REQUIRE_IN_ES6_MODULE;
-import static com.google.javascript.jscomp.Es6RewriteModules.PATH_REQUIRE_IN_GOOG_MODULE_WITH_NO_PATH;
-import static com.google.javascript.jscomp.Es6RewriteModules.PATH_REQUIRE_IN_GOOG_PROVIDE_FILE;
-import static com.google.javascript.jscomp.Es6RewriteModules.PATH_REQUIRE_IN_NON_GOOG_MODULE;
import static com.google.javascript.jscomp.ProcessClosurePrimitives.INVALID_CLOSURE_CALL_ERROR;
import com.google.common.collect.ImmutableList;
@@ -173,136 +168,6 @@ public void testGoogModuleGetForEs6Module() {
"closure.js", "goog.module('my.module'); function f() { const y = module$es6; }")));
}
- public void testRewriteGoogRequiresForEs6ModulePath() {
- String srcEs6 = "export var x;";
- String expectedEs6 =
- "var x$$module$es6;/** @const */ var module$es6={};module$es6.x=x$$module$es6;";
-
- test(
- srcs(
- SourceFile.fromCode("es6.js", srcEs6),
- SourceFile.fromCode(
- "goog.js", "goog.module('m'); const es6 = goog.require('./es6.js'); use(es6.x);")),
- expected(
- SourceFile.fromCode("es6.js", expectedEs6),
- SourceFile.fromCode(
- "goog.js", "goog.module('m'); const es6 = module$es6; use(es6.x);")));
-
- test(
- srcs(
- SourceFile.fromCode("nested0/es6.js", srcEs6),
- SourceFile.fromCode(
- "nested1/goog.js",
- "goog.module('m'); const {x} = goog.require('../nested0/es6.js');")),
- expected(
- SourceFile.fromCode(
- "nested0/es6.js",
- lines(
- "var x$$module$nested0$es6;",
- "/** @const */ var module$nested0$es6={};",
- "module$nested0$es6.x=x$$module$nested0$es6;")),
- SourceFile.fromCode(
- "nested1/goog.js", "goog.module('m'); const {x} = module$nested0$es6")));
-
- test(
- srcs(
- SourceFile.fromCode("es6.js", srcEs6),
- SourceFile.fromCode("goog.js", "goog.module('m'); goog.require('./es6.js');")),
- expected(
- SourceFile.fromCode("es6.js", expectedEs6),
- SourceFile.fromCode("goog.js", "goog.module('m');")));
-
- testError(
- ImmutableList.of(
- SourceFile.fromCode("es6.js", srcEs6),
- SourceFile.fromCode("goog.js", "goog.provide('m'); goog.require('./es6.js');")),
- PATH_REQUIRE_IN_GOOG_PROVIDE_FILE);
-
- testError(
- ImmutableList.of(
- SourceFile.fromCode("es6.js", srcEs6),
- SourceFile.fromCode("goog.js", "export {}; goog.require('./es6.js');")),
- PATH_REQUIRE_IN_ES6_MODULE);
-
- testError(
- ImmutableList.of(
- SourceFile.fromCode("es6.js", srcEs6),
- SourceFile.fromCode("goog.js", "goog.require('./es6.js');")),
- PATH_REQUIRE_IN_NON_GOOG_MODULE);
-
- testError(
- ImmutableList.of(
- SourceFile.fromCode("not_es6.js", "goog.module('a');"),
- SourceFile.fromCode("goog.js", "goog.module('m'); goog.require('./not_es6.js');")),
- PATH_REQUIRE_FOR_NON_ES6_MODULE);
- }
-
- public void testRewriteGoogRequiresForEs6ModulePathInLoadModule() {
- String srcEs6 = "export var x;";
- String expectedEs6 =
- "var x$$module$es6;/** @const */ var module$es6={};module$es6.x=x$$module$es6;";
-
- testError(
- ImmutableList.of(
- SourceFile.fromCode("es6.js", srcEs6),
- SourceFile.fromCode(
- "bundle.js",
- lines(
- "goog.loadModule(function() {",
- " goog.module('m');",
- " const es6 = goog.require('./es6.js');",
- "});"))),
- PATH_REQUIRE_IN_GOOG_MODULE_WITH_NO_PATH);
-
- test(
- srcs(
- SourceFile.fromCode("es6.js", srcEs6),
- SourceFile.fromCode(
- "bundle.js",
- lines(
- "goog.loadModule(function() {",
- " goog.module('m');",
- " const es6 = goog.require('../es6.js');",
- "}, 'nested/goog.js');"))),
- expected(
- SourceFile.fromCode("es6.js", expectedEs6),
- SourceFile.fromCode(
- "bundle.js",
- lines(
- "goog.loadModule(function() {",
- " goog.module('m');",
- " const es6 = module$es6;",
- "}, 'nested/goog.js');"))));
-
- test(
- srcs(
- SourceFile.fromCode("es6.js", srcEs6),
- SourceFile.fromCode(
- "bundle.js",
- lines(
- "goog.loadModule(function() {",
- " goog.module('m');",
- " const es6 = goog.require('./es6.js');",
- "}, 'goog.js');",
- "goog.loadModule(function() {",
- " goog.module('m2');",
- " const es6 = goog.require('../es6.js');",
- "}, 'nested/goog.js');"))),
- expected(
- SourceFile.fromCode("es6.js", expectedEs6),
- SourceFile.fromCode(
- "bundle.js",
- lines(
- "goog.loadModule(function() {",
- " goog.module('m');",
- " const es6 = module$es6;",
- "}, 'goog.js');",
- "goog.loadModule(function() {",
- " goog.module('m2');",
- " const es6 = module$es6;",
- "}, 'nested/goog.js');"))));
- }
-
public void testDeclareNamespace() {
SourceFile srcEs6 =
SourceFile.fromCode("es6.js", "export var x; goog.module.declareNamespace('my.es6');");
diff --git a/test/com/google/javascript/jscomp/ModuleMetadataTest.java b/test/com/google/javascript/jscomp/ModuleMetadataTest.java
index 97c7b627ad2..a93b4ead87f 100644
--- a/test/com/google/javascript/jscomp/ModuleMetadataTest.java
+++ b/test/com/google/javascript/jscomp/ModuleMetadataTest.java
@@ -117,23 +117,6 @@ public void testLoadModule() {
assertThat(m.isScript()).isTrue();
}
- public void testLoadModuleWithPath() {
- testSame("goog.loadModule(function() { goog.module('my.module'); }, '/my/file.js');");
- assertThat(metadata.getModulesByGoogNamespace().keySet()).containsExactly("my.module");
-
- Module m = metadata.getModulesByGoogNamespace().get("my.module");
- assertThat(m.getGoogNamespaces()).containsExactly("my.module");
- assertThat(m.isNonLegacyGoogModule()).isTrue();
-
- m = metadata.getModulesByPath().get("testcode");
- assertThat(m.getGoogNamespaces()).isEmpty();
- assertThat(m.isScript()).isTrue();
-
- m = metadata.getModulesByPath().get("/my/file.js");
- assertThat(m.getGoogNamespaces()).containsExactly("my.module");
- assertThat(m.isNonLegacyGoogModule()).isTrue();
- }
-
public void testEs6Module() {
testSame("export var x;");
assertThat(metadata.getModulesByGoogNamespace().keySet()).isEmpty();
diff --git a/test/com/google/javascript/jscomp/deps/DepsGeneratorTest.java b/test/com/google/javascript/jscomp/deps/DepsGeneratorTest.java
index b8052e78af9..55c5737ce18 100644
--- a/test/com/google/javascript/jscomp/deps/DepsGeneratorTest.java
+++ b/test/com/google/javascript/jscomp/deps/DepsGeneratorTest.java
@@ -118,14 +118,18 @@ public void testEs6Modules() throws Exception {
assertEquals(expected, output);
}
- public void testGoogPathRequireForEs6ModuleFromGoogModule() throws Exception {
+ public void testEs6ModuleDeclareNamespace() throws Exception {
List srcs = new ArrayList<>();
srcs.add(
SourceFile.fromCode(
"/base/javascript/foo/foo.js",
+ "goog.module.declareNamespace('my.namespace');\nexport {};"));
+ srcs.add(
+ SourceFile.fromCode(
+ "/base/javascript/closure/goog/googmodule.js",
LINE_JOINER.join(
- "goog.module('foo');", "const es6 = goog.require('../closure/goog/es6.js');")));
- srcs.add(SourceFile.fromCode("/base/javascript/closure/goog/es6.js", "export var es6;"));
+ "goog.module('my.goog.module');",
+ "const namespace = goog.require('my.namespace');")));
DepsGenerator depsGenerator =
new DepsGenerator(
ImmutableList.of(),
@@ -149,102 +153,15 @@ public void testGoogPathRequireForEs6ModuleFromGoogModule() throws Exception {
// Write the expected output.
String expected =
LINE_JOINER.join(
- "goog.addDependency('../foo/foo.js', ['foo'], "
- + "['goog/es6.js'], {'lang': 'es6', 'module': 'goog'});",
- "goog.addDependency('goog/es6.js', [], " + "[], {'lang': 'es6', 'module': 'es6'});",
- "");
-
- assertEquals(expected, output);
- }
-
- public void testGoogPathRequireForEs6ModuleInDepsFileFromGoogModule() throws Exception {
- ImmutableList deps =
- ImmutableList.of(
- SourceFile.fromCode(
- "deps.js",
- "goog.addDependency('goog/es6.js', [], [], {'lang': 'es6', 'module': 'es6'})"));
- ImmutableList srcs =
- ImmutableList.of(
- SourceFile.fromCode(
- "/base/javascript/foo/foo.js",
- LINE_JOINER.join(
- "goog.module('foo');", "const es6 = goog.require('../closure/goog/es6.js');")));
- DepsGenerator depsGenerator =
- new DepsGenerator(
- deps,
- srcs,
- DepsGenerator.InclusionStrategy.ALWAYS,
- "/base/javascript/closure",
- errorManager,
- new ModuleLoader(
- null,
- ImmutableList.of("/base/"),
- ImmutableList.of(),
- BrowserModuleResolver.FACTORY,
- ModuleLoader.PathResolver.ABSOLUTE));
- String output = depsGenerator.computeDependencyCalls();
-
- assertNoWarnings();
-
- // Write the output.
- assertWithMessage("There should be output").that(output).isNotEmpty();
-
- // Write the expected output.
- String expected =
- LINE_JOINER.join(
- "goog.addDependency('../foo/foo.js', ['foo'], "
- + "['goog/es6.js'], {'lang': 'es6', 'module': 'goog'});",
- "",
- "// Included from: deps.js",
- "goog.addDependency('goog/es6.js', [], [], {'lang': 'es6', 'module': 'es6'});",
+ "goog.addDependency('../foo/foo.js', ['my.namespace'], "
+ + "[], {'lang': 'es6', 'module': 'es6'});",
+ "goog.addDependency('goog/googmodule.js', ['my.goog.module'], ['my.namespace'], "
+ + "{'lang': 'es6', 'module': 'goog'});",
"");
assertEquals(expected, output);
}
- public void testGoogPathRequireForGoogModuleFromGoogModuleIsInvalid() throws Exception {
- List srcs = new ArrayList<>();
- srcs.add(
- SourceFile.fromCode(
- "/base/javascript/foo/foo.js",
- LINE_JOINER.join(
- "goog.module('foo');",
- "const examplemodule = goog.require('../closure/goog/examplemodule.js');")));
- srcs.add(
- SourceFile.fromCode(
- "/base/javascript/closure/goog/examplemodule.js",
- "goog.module('goog.examplemodule');"));
-
- doErrorMessagesRun(
- ImmutableList.of(),
- srcs,
- true /* fatal */,
- "Cannot goog.require \"/base/javascript/closure/goog/examplemodule.js\" by path. It is "
- + "not an ES6 module.");
- }
-
- public void testGoogPathRequireForGoogModuleFromEs6ModuleIsInvalid() throws Exception {
- List srcs = new ArrayList<>();
- srcs.add(
- SourceFile.fromCode(
- "/base/javascript/foo/foo.js",
- LINE_JOINER.join(
- "const examplemodule = goog.require('../closure/goog/examplemodule.js');",
- "export default examplemodule;")));
- srcs.add(
- SourceFile.fromCode(
- "/base/javascript/closure/goog/examplemodule.js",
- "goog.module('goog.examplemodule');"));
-
- doErrorMessagesRun(
- ImmutableList.of(),
- srcs,
- true /* fatal */,
- "Cannot goog.require \"/base/javascript/closure/goog/examplemodule.js\" by path. It is "
- + "not an ES6 module.",
- "Cannot goog.require by path outside of a goog.module.");
- }
-
/**
* Ensures that deps files are handled correctly both when listed as deps and when listed as
* sources.
@@ -620,39 +537,6 @@ public void testUnknownEs6Module() throws Exception {
"Could not find file \"./missing.js\".");
}
- public void testGoogPathRequireFromNonModuleIsInvalid() throws Exception {
- List srcs = new ArrayList<>();
- srcs.add(
- SourceFile.fromCode(
- "/base/javascript/foo/foo.js",
- LINE_JOINER.join(
- "goog.provide('foo');",
- "const array = goog.require('../closure/goog/array.js');")));
- srcs.add(SourceFile.fromCode("/base/javascript/closure/goog/array.js", "export var array;"));
-
- doErrorMessagesRun(
- ImmutableList.of(),
- srcs,
- true /* fatal */,
- "Cannot goog.require by path outside of a goog.module.");
- }
-
- public void testGoogPathRequireBetweenEs6ModulesIsInvalid() throws Exception {
- List srcs = new ArrayList<>();
- srcs.add(
- SourceFile.fromCode(
- "/base/javascript/foo/foo.js",
- "export var foo; const array = goog.require('../closure/goog/array.js');"));
- srcs.add(SourceFile.fromCode("/base/javascript/closure/goog/array.js", "export var array;"));
-
- doErrorMessagesRun(
- ImmutableList.of(),
- srcs,
- true /* fatal */,
- "Use ES6 import rather than goog.require to import ES6 module "
- + "\"/base/javascript/closure/goog/array.js\".");
- }
-
private void assertErrorWarningCount(int errorCount, int warningCount) {
if (errorManager.getErrorCount() != errorCount) {
fail(String.format("Expected %d errors but got\n%s",
diff --git a/test/com/google/javascript/jscomp/deps/JsFileParserTest.java b/test/com/google/javascript/jscomp/deps/JsFileParserTest.java
index 8b3452fd8b2..7f2e809f9fa 100644
--- a/test/com/google/javascript/jscomp/deps/JsFileParserTest.java
+++ b/test/com/google/javascript/jscomp/deps/JsFileParserTest.java
@@ -18,7 +18,6 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.javascript.jscomp.deps.DependencyInfo.Require.es6Import;
-import static com.google.javascript.jscomp.deps.DependencyInfo.Require.googRequirePath;
import static com.google.javascript.jscomp.deps.DependencyInfo.Require.googRequireSymbol;
import com.google.common.collect.ImmutableList;
@@ -534,29 +533,6 @@ public void testIncludeGoog4() {
assertDeps(expected, result);
}
- public void testParseGoogRequirePath() {
- String contents =
- ""
- + "goog.module('yes1');\n"
- + "var yes2=goog.require('yes2');\n"
- + "var C=goog.require('./c.js');\n"
- + "var DQuote=goog.require(\"../d/quote.js\");";
-
- DependencyInfo expected =
- SimpleDependencyInfo.builder(CLOSURE_PATH, SRC_PATH)
- .setProvides("yes1")
- .setRequires(
- googRequireSymbol("yes2"),
- googRequirePath("module$c", "./c.js"),
- googRequirePath("module$__$d$quote", "../d/quote.js"))
- .setLoadFlags(ImmutableMap.of("module", "goog"))
- .build();
-
- DependencyInfo result = parser.parseFile(SRC_PATH, CLOSURE_PATH, contents);
-
- assertDeps(expected, result);
- }
-
/** Asserts the deps match without errors */
private void assertDeps(DependencyInfo expected, DependencyInfo actual) {
assertThat(actual).isEqualTo(expected);