Skip to content

Commit

Permalink
Get rid of the legacy module resolution mode.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=163011841
  • Loading branch information
tbreisacher authored and brad4d committed Jul 26, 2017
1 parent 4530c7c commit c2cd433
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 194 deletions.
58 changes: 0 additions & 58 deletions src/com/google/javascript/jscomp/deps/LegacyModuleResolver.java

This file was deleted.

19 changes: 4 additions & 15 deletions src/com/google/javascript/jscomp/deps/ModuleLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,13 @@ public ModuleLoader(
this.moduleResolver =
new BrowserModuleResolver(this.modulePaths, this.moduleRootPaths, this.errorHandler);
break;
case LEGACY:
default:
this.moduleResolver =
new LegacyModuleResolver(this.modulePaths, this.moduleRootPaths, this.errorHandler);
break;
case NODE:
this.moduleResolver =
new NodeModuleResolver(
this.modulePaths, this.moduleRootPaths, packageJsonMainEntries, this.errorHandler);
break;
default:
throw new RuntimeException("Unexpected resolution mode " + resolutionMode);
}
}

Expand Down Expand Up @@ -355,15 +352,6 @@ public enum ResolutionMode {
*/
BROWSER,

/**
* Keeps the same behavior the compiler has used historically.
*
* Modules which do not begin with a "." or "/" character are assumed to be relative to the
* compilation root.
* ".js" file extensions are added if the import omits them.
*/
LEGACY,

/**
* Uses the node module resolution algorithm.
*
Expand All @@ -375,7 +363,8 @@ public enum ResolutionMode {
NODE
}

private final class NoopErrorHandler implements ErrorHandler {
private static final class NoopErrorHandler implements ErrorHandler {
@Override
public void report(CheckLevel level, JSError error) {}
}
}
38 changes: 0 additions & 38 deletions test/com/google/javascript/jscomp/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import com.google.javascript.jscomp.CompilerOptions.J2clPassMode;
import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
import com.google.javascript.jscomp.CompilerOptions.Reach;
import com.google.javascript.jscomp.deps.ModuleLoader;
import com.google.javascript.jscomp.deps.ModuleLoader.ResolutionMode;
import com.google.javascript.jscomp.testing.NodeSubject;
import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.Token;
Expand Down Expand Up @@ -632,42 +630,6 @@ public void testExportTestFunctionsOn2() {
});
}

/**
* Check that valid ES6 modules compile to valid goog.require()/goog.provide() statements.
*/
public void testES6Modules() {
CompilerOptions options = createCompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT_2015);
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setModuleResolutionMode(ResolutionMode.LEGACY);
test(
options,
new String[] {
"import {x} from './i1'; alert(x);", "export var x = 5;",
},
new String[] {
"goog.provide('module$i0'); goog.require('module$i1'); alert(module$i1.x);",
"goog.provide('module$i1'); var x$$module$i1 = 5; module$i1.x = x$$module$i1;",
});
}

/**
* Check that the expected warning is reported when an ES6 module tries to import a nonexistent
* module.
*/
public void testES6Modules_missing() {
CompilerOptions options = createCompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT_2015);
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setModuleResolutionMode(ResolutionMode.LEGACY);
test(
options,
new String[] {
"import {x} from './i2'; alert(x);", "export var x = 5;",
},
ModuleLoader.LOAD_WARNING);
}

public void testAngularPassOff() {
testSame(createCompilerOptions(),
"/** @ngInject */ function f() {} " +
Expand Down
14 changes: 7 additions & 7 deletions test/com/google/javascript/jscomp/deps/DepsGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testEs6Modules() throws Exception {
ImmutableList.of("/base/"),
ImmutableList.<DependencyInfo>of(),
ModuleLoader.PathResolver.ABSOLUTE,
ModuleLoader.ResolutionMode.LEGACY));
ModuleLoader.ResolutionMode.BROWSER));
String output = depsGenerator.computeDependencyCalls();

assertNoWarnings();
Expand Down Expand Up @@ -157,7 +157,7 @@ public void testWithDepsAndSources() throws Exception {
ImmutableList.of("/base/"),
ImmutableList.<DependencyInfo>of(),
ModuleLoader.PathResolver.ABSOLUTE,
ModuleLoader.ResolutionMode.LEGACY));
ModuleLoader.ResolutionMode.BROWSER));

String output = depsGenerator.computeDependencyCalls();

Expand All @@ -178,7 +178,7 @@ public void testWithDepsAndSources() throws Exception {
ImmutableList.of("/base/"),
ImmutableList.<DependencyInfo>of(),
ModuleLoader.PathResolver.ABSOLUTE,
ModuleLoader.ResolutionMode.LEGACY));
ModuleLoader.ResolutionMode.BROWSER));

String expectedWithDepsAsSources =
LINE_JOINER.join(
Expand Down Expand Up @@ -233,7 +233,7 @@ public void testDepsAsSrcs() throws Exception {
ImmutableList.of("/base/" + "/"),
ImmutableList.<DependencyInfo>of(),
ModuleLoader.PathResolver.ABSOLUTE,
ModuleLoader.ResolutionMode.LEGACY));
ModuleLoader.ResolutionMode.BROWSER));

String output = depsGenerator.computeDependencyCalls();

Expand Down Expand Up @@ -290,7 +290,7 @@ private String testMergeStrategyHelper(DepsGenerator.InclusionStrategy mergeStra
ImmutableList.of("/base/"),
ImmutableList.<DependencyInfo>of(),
ModuleLoader.PathResolver.ABSOLUTE,
ModuleLoader.ResolutionMode.LEGACY));
ModuleLoader.ResolutionMode.BROWSER));

String output = depsGenerator.computeDependencyCalls();

Expand All @@ -316,7 +316,7 @@ private void doErrorMessagesRun(
ImmutableList.of(""),
ImmutableList.<DependencyInfo>of(),
ModuleLoader.PathResolver.ABSOLUTE,
ModuleLoader.ResolutionMode.LEGACY));
ModuleLoader.ResolutionMode.BROWSER));
String output = depsGenerator.computeDependencyCalls();

if (fatal) {
Expand Down Expand Up @@ -383,7 +383,7 @@ public void testDuplicateProvidesIgnoredIfInClosureDirectory() throws Exception
ImmutableList.of("."),
ImmutableList.<DependencyInfo>of(),
ModuleLoader.PathResolver.ABSOLUTE,
ModuleLoader.ResolutionMode.LEGACY));
ModuleLoader.ResolutionMode.BROWSER));

String output = worker.computeDependencyCalls();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void testParseEs6Module4() {
null,
ImmutableList.of("/foo"),
ImmutableList.<DependencyInfo>of(),
ModuleLoader.ResolutionMode.LEGACY);
ModuleLoader.ResolutionMode.BROWSER);

String contents = ""
+ "import './a';\n"
Expand Down
78 changes: 3 additions & 75 deletions test/com/google/javascript/jscomp/deps/ModuleLoaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,83 +38,11 @@ public void testWindowsAddresses() {
null,
ImmutableList.of("."),
inputs("js\\a.js", "js\\b.js"),
ModuleLoader.ResolutionMode.LEGACY);
ModuleLoader.ResolutionMode.NODE);
assertUri("js/a.js", loader.resolve("js\\a.js"));
assertUri("js/b.js", loader.resolve("js\\a.js").resolveJsModule("./b"));
}

public void testJsExtensionLegacy() {
ModuleLoader loader =
new ModuleLoader(
null,
ImmutableList.of("."),
inputs("js/a.js", "js/b.js"),
ModuleLoader.ResolutionMode.LEGACY);
assertUri("js/a.js", loader.resolve("js/a.js"));
assertUri("js/b.js", loader.resolve("js/a.js").resolveJsModule("./b"));
assertUri("js/b.js", loader.resolve("js/a.js").resolveJsModule("./b.js"));
}

public void testLocateJsLegacy() throws Exception {
ModuleLoader loader =
new ModuleLoader(
null,
ImmutableList.of("."),
inputs("A/index.js", "B/index.js", "app.js"),
ModuleLoader.ResolutionMode.LEGACY);

input("A/index.js");
input("B/index.js");
input("app.js");
assertUri("A/index.js", loader.resolve("A/index.js"));
assertUri("A.js", loader.resolve("B/index.js").resolveJsModule("../A"));
assertUri("A/index.js", loader.resolve("B/index.js").resolveJsModule("../A/index"));
assertUri("A/index.js", loader.resolve("app.js").resolveJsModule("./A/index"));
assertUri("A/index.js", loader.resolve("app.js").resolveJsModule("A/index"));
assertUri("A/index.js", loader.resolve("folder/app.js").resolveJsModule("A/index"));
assertUri("index.js", loader.resolve("folder/app.js").resolveJsModule("index"));
}

public void testLocateNodeModuleLegacy() throws Exception {
ImmutableList<CompilerInput> compilerInputs =
inputs(
"/A/index.js",
"/A/index.json",
"/node_modules/A/index.js",
"/node_modules/A/foo.js",
"/node_modules/A/node_modules/A/index.json",
"/B/package.json",
"/B/lib/b.js",
"/node_modules/B/package.json",
"/node_modules/B/lib/b.js");


ModuleLoader loader =
new ModuleLoader(
null,
(new ImmutableList.Builder<String>()).build(),
compilerInputs,
ModuleLoader.ResolutionMode.LEGACY);

assertUri("/A.js", loader.resolve("/foo.js").resolveJsModule("/A"));
assertUri("/A/index.js", loader.resolve("/foo.js").resolveJsModule("/A/index.js"));
assertUri("/A.js", loader.resolve("/foo.js").resolveJsModule("./A"));
assertUri("/A/index.js", loader.resolve("/foo.js").resolveJsModule("./A/index.js"));
assertUri("/A.js", loader.resolve("/foo.js").resolveJsModule("/A"));
assertUri("/A/index.js", loader.resolve("/foo.js").resolveJsModule("/A/index"));
assertUri("/A/index.json.js", loader.resolve("/foo.js").resolveJsModule("/A/index.json"));

assertUri("A.js", loader.resolve("/foo.js").resolveJsModule("A"));
assertUri("A.js", loader.resolve("/node_modules/A/foo.js").resolveJsModule("A"));
assertUri(
"/node_modules/A/foo.js",
loader.resolve("/node_modules/A/index.js").resolveJsModule("./foo"));

assertUri("/B.js", loader.resolve("/app.js").resolveJsModule("/B"));

assertUri("B.js", loader.resolve("/app.js").resolveJsModule("B"));
}

public void testJsExtensionNode() {
ModuleLoader loader =
new ModuleLoader(
Expand Down Expand Up @@ -277,7 +205,7 @@ public void testLocateNodeModuleBrowser() throws Exception {
public void testNormalizeUris() throws Exception {
ModuleLoader loader =
new ModuleLoader(
null, ImmutableList.of("a", "b", "/c"), inputs(), ModuleLoader.ResolutionMode.LEGACY);
null, ImmutableList.of("a", "b", "/c"), inputs(), ModuleLoader.ResolutionMode.BROWSER);
assertUri("a.js", loader.resolve("a/a.js"));
assertUri("a.js", loader.resolve("a.js"));
assertUri("some.js", loader.resolve("some.js"));
Expand All @@ -292,7 +220,7 @@ public void testDuplicateUris() throws Exception {
null,
ImmutableList.of("a", "b"),
inputs("a/f.js", "b/f.js"),
ModuleLoader.ResolutionMode.LEGACY);
ModuleLoader.ResolutionMode.BROWSER);
fail("Expected error");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage()).contains("Duplicate module path");
Expand Down

0 comments on commit c2cd433

Please sign in to comment.