From fe6a73b57707debb0e137a6f3fb5f19daf2437f4 Mon Sep 17 00:00:00 2001 From: tjgq Date: Wed, 24 Oct 2018 15:48:13 -0700 Subject: [PATCH] Clean up the code to find modules from entry points. The comments mistakenly suggest that entry-point based pruning happens here. It actually happens in JSModuleGraph#manageDependencies. The only thing happening here is setting the ModuleType on reachable inputs. We also don't need to accumulate and return an ordered input list since it's not used anywhere. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=218591483 --- .../google/javascript/jscomp/Compiler.java | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/src/com/google/javascript/jscomp/Compiler.java b/src/com/google/javascript/jscomp/Compiler.java index f818035c0c6..d34606e9f17 100644 --- a/src/com/google/javascript/jscomp/Compiler.java +++ b/src/com/google/javascript/jscomp/Compiler.java @@ -1726,7 +1726,7 @@ Node parseInputs() { } if (options.getDependencyOptions().needsManagement()) { - findDependenciesFromEntryPoints( + findModulesFromEntryPoints( options.getLanguageIn().toFeatureSet().has(Feature.MODULES), options.processCommonJSModules); } else if (options.needsTranspilationFrom(FeatureSet.ES6_MODULES) @@ -1869,16 +1869,17 @@ void orderInputs() { } /** - * Find dependencies by recursively traversing each dependency of an input starting with the entry - * points. Causes a full parse of each file, but since the file is reachable by walking the graph, - * this would be required in later compilation passes regardless. + * Find modules by recursively traversing dependencies starting with the entry points. * - *

Inputs which are not reachable during graph traversal will be dropped. + *

Causes a regex parse of every file, and a full parse of every file reachable from the entry + * points (which would be required by later compilation passes regardless). * - *

If the dependency mode is set to LOOSE, inputs for which the deps package did not find a - * provide statement or detect as a module will be treated as entry points. + *

If the dependency mode is set to LOOSE, inputs which the regex parse does not identify as ES + * modules and which do not contain any provide statements are considered to be additional entry + * points. */ - void findDependenciesFromEntryPoints(boolean supportEs6Modules, boolean supportCommonJSModules) { + private void findModulesFromEntryPoints( + boolean supportEs6Modules, boolean supportCommonJSModules) { hoistExterns(); List entryPoints = new ArrayList<>(); Map inputsByProvide = new HashMap<>(); @@ -1907,7 +1908,7 @@ void findDependenciesFromEntryPoints(boolean supportEs6Modules, boolean supportC Set workingInputSet = Sets.newHashSet(moduleGraph.getAllInputs()); for (CompilerInput entryPoint : entryPoints) { - depthFirstDependenciesFromInput( + findModulesFromInput( entryPoint, /* wasImportedByModule = */ false, workingInputSet, @@ -1918,8 +1919,8 @@ void findDependenciesFromEntryPoints(boolean supportEs6Modules, boolean supportC } } - /** For a given input, order it's dependencies in a depth first traversal */ - private List depthFirstDependenciesFromInput( + /** Traverse an input's dependencies to find additional modules. */ + private void findModulesFromInput( CompilerInput input, boolean wasImportedByModule, Set inputs, @@ -1927,7 +1928,6 @@ private List depthFirstDependenciesFromInput( Map inputsByProvide, boolean supportEs6Modules, boolean supportCommonJSModules) { - List orderedInputs = new ArrayList<>(); if (!inputs.remove(input)) { // It's possible for a module to be included as both a script // and a module in the same compilation. In these cases, it should @@ -1935,8 +1935,7 @@ private List depthFirstDependenciesFromInput( if (wasImportedByModule && input.getJsModuleType() == CompilerInput.ModuleType.NONE) { input.setJsModuleType(CompilerInput.ModuleType.IMPORTED_SCRIPT); } - - return orderedInputs; + return; } FindModuleDependencies findDeps = @@ -1965,19 +1964,16 @@ private List depthFirstDependenciesFromInput( } if (requiredInput != null) { - orderedInputs.addAll( - depthFirstDependenciesFromInput( - requiredInput, - requiredByModuleImport, - inputs, - inputsByIdentifier, - inputsByProvide, - supportEs6Modules, - supportCommonJSModules)); - } - } - orderedInputs.add(input); - return orderedInputs; + findModulesFromInput( + requiredInput, + requiredByModuleImport, + inputs, + inputsByIdentifier, + inputsByProvide, + supportEs6Modules, + supportCommonJSModules); + } + } } /**