Skip to content

Commit

Permalink
Rollback of
Browse files Browse the repository at this point in the history
  "Skip most ES6 check and transpilation passes if the parser detects no ES6
  feature in a file"
because it induced build failures.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=130572009
  • Loading branch information
brad4d authored and dimvar committed Aug 18, 2016
1 parent b26cf72 commit 04a3ccb
Show file tree
Hide file tree
Showing 23 changed files with 71 additions and 235 deletions.
7 changes: 5 additions & 2 deletions src/com/google/javascript/jscomp/CheckMissingSuper.java
Expand Up @@ -36,12 +36,15 @@ public CheckMissingSuper(AbstractCompiler compiler) {

@Override
public void process(Node externs, Node root) {
TranspilationPasses.processCheck(compiler, root, this);
if (!compiler.getOptions().getLanguageIn().isEs6OrHigher()) {
return;
}
NodeTraversal.traverseEs6(compiler, root, this);
}

@Override
public void hotSwapScript(Node scriptRoot, Node originalRoot) {
TranspilationPasses.hotSwapCheck(compiler, scriptRoot, this);
process(null, scriptRoot);
}

@Override
Expand Down
10 changes: 1 addition & 9 deletions src/com/google/javascript/jscomp/Compiler.java
Expand Up @@ -998,18 +998,10 @@ void stopTracer(Tracer t, String passName) {
*/
public Result getResult() {
PassConfig.State state = getPassConfig().getIntermediateState();
Set<SourceFile> transpiledFiles = new HashSet<>();
if (jsRoot != null) {
for (Node scriptNode : jsRoot.children()) {
if (scriptNode.getBooleanProp(Node.TRANSPILED)) {
transpiledFiles.add(getSourceFileByName(scriptNode.getSourceFileName()));
}
}
}
return new Result(getErrors(), getWarnings(), debugLog.toString(),
state.variableMap, state.propertyMap,
state.anonymousFunctionNameMap, state.stringMap, functionInformationMap,
sourceMap, externExports, state.cssNames, state.idGeneratorMap, transpiledFiles);
sourceMap, externExports, state.cssNames, state.idGeneratorMap);
}

/**
Expand Down
11 changes: 1 addition & 10 deletions src/com/google/javascript/jscomp/DefaultPassConfig.java
Expand Up @@ -195,7 +195,7 @@ protected List<PassFactory> getTranspileOnlyPasses() {
}

passes.add(checkMissingSuper);
passes.add(checkVariableReferencesForTranspileOnly);
passes.add(checkVariableReferences);

// It's important that the Dart super accessors pass run *before* es6ConvertSuper,
// which is a "late" ES6 pass. This is enforced in the assertValidOrder method.
Expand Down Expand Up @@ -1549,15 +1549,6 @@ public void process(Node externs, Node root) {
}
};

/** Checks that references to variables look reasonable. */
private final HotSwapPassFactory checkVariableReferencesForTranspileOnly =
new HotSwapPassFactory("checkVariableReferences", true) {
@Override
protected HotSwapCompilerPass create(AbstractCompiler compiler) {
return new VariableReferenceCheck(compiler, true);
}
};

/** Checks that references to variables look reasonable. */
private final HotSwapPassFactory checkVariableReferences =
new HotSwapPassFactory("checkVariableReferences", true) {
Expand Down
7 changes: 3 additions & 4 deletions src/com/google/javascript/jscomp/Es6ConvertSuper.java
Expand Up @@ -170,13 +170,12 @@ private Node baseCall(String baseClass, String methodName, Node arguments) {

@Override
public void process(Node externs, Node root) {
// Might need to synthesize constructors for ambient classes in .d.ts externs
TranspilationPasses.processTranspile(compiler, externs, this);
TranspilationPasses.processTranspile(compiler, root, this);
NodeTraversal.traverseEs6(compiler, externs, this);
NodeTraversal.traverseEs6(compiler, root, this);
}

@Override
public void hotSwapScript(Node scriptRoot, Node originalRoot) {
TranspilationPasses.hotSwapTranspile(compiler, scriptRoot, this);
NodeTraversal.traverseEs6(compiler, scriptRoot, this);
}
}
7 changes: 5 additions & 2 deletions src/com/google/javascript/jscomp/Es6ExtractClasses.java
Expand Up @@ -26,6 +26,7 @@
import com.google.javascript.rhino.JSDocInfoBuilder;
import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.Token;

import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -67,12 +68,14 @@ public final class Es6ExtractClasses

@Override
public void process(Node externs, Node root) {
TranspilationPasses.processTranspile(compiler, root, this, new SelfReferenceRewriter());
NodeTraversal.traverseRootsEs6(compiler, this, externs, root);
NodeTraversal.traverseRootsEs6(compiler, new SelfReferenceRewriter(), externs, root);
}

@Override
public void hotSwapScript(Node scriptRoot, Node originalRoot) {
TranspilationPasses.hotSwapTranspile(compiler, scriptRoot, this, new SelfReferenceRewriter());
NodeTraversal.traverseEs6(compiler, scriptRoot, this);
NodeTraversal.traverseEs6(compiler, scriptRoot, new SelfReferenceRewriter());
}

@Override
Expand Down
Expand Up @@ -18,6 +18,7 @@

import com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback;
import com.google.javascript.rhino.Node;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -85,12 +86,13 @@ public final boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {

@Override
public void process(Node externs, Node root) {
TranspilationPasses.processTranspile(compiler, root, this);
NodeTraversal.traverseEs6(compiler, externs, this);
NodeTraversal.traverseEs6(compiler, root, this);
}

@Override
public void hotSwapScript(Node scriptRoot, Node originalRoot) {
TranspilationPasses.hotSwapTranspile(compiler, scriptRoot, this);
NodeTraversal.traverseEs6(compiler, scriptRoot, this);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/com/google/javascript/jscomp/Es6RewriteArrowFunction.java
Expand Up @@ -39,12 +39,13 @@ public Es6RewriteArrowFunction(AbstractCompiler compiler) {

@Override
public void process(Node externs, Node root) {
TranspilationPasses.processTranspile(compiler, root, this);
NodeTraversal.traverseEs6(compiler, externs, this);
NodeTraversal.traverseEs6(compiler, root, this);
}

@Override
public void hotSwapScript(Node scriptRoot, Node originalRoot) {
TranspilationPasses.hotSwapTranspile(compiler, scriptRoot, this);
NodeTraversal.traverseEs6(compiler, scriptRoot, this);
}

@Override
Expand Down
Expand Up @@ -28,6 +28,7 @@
import com.google.javascript.rhino.JSTypeExpression;
import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.Token;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -110,27 +111,24 @@ && inLoop(n)) {

@Override
public void process(Node externs, Node root) {
// Since block-scoped function declarations can appear in any language mode, we need to run
// this pass unconditionally.
NodeTraversal.traverseEs6(compiler, root, new CollectUndeclaredNames());
NodeTraversal.traverseEs6(compiler, root, this);
// Needed for let / const declarations in .d.ts externs.
TranspilationPasses.processTranspile(compiler, externs, this);
NodeTraversal.traverseEs6(compiler, root, new Es6RenameReferences(renameMap));
NodeTraversal.traverseRootsEs6(compiler, new CollectUndeclaredNames(), externs, root);
NodeTraversal.traverseRootsEs6(compiler, this, externs, root);
NodeTraversal.traverseRootsEs6(compiler, new Es6RenameReferences(renameMap), externs, root);

LoopClosureTransformer transformer = new LoopClosureTransformer();
NodeTraversal.traverseEs6(compiler, root, transformer);
NodeTraversal.traverseRootsEs6(compiler, transformer, externs, root);
transformer.transformLoopClosure();
varify();
TranspilationPasses.processTranspile(
compiler, externs, new RewriteBlockScopedFunctionDeclaration());
NodeTraversal.traverseEs6(compiler, root, new RewriteBlockScopedFunctionDeclaration());
NodeTraversal.traverseRootsEs6(
compiler, new RewriteBlockScopedFunctionDeclaration(), externs, root);
}

@Override
public void hotSwapScript(Node scriptRoot, Node originalRoot) {
NodeTraversal.traverseEs6(compiler, scriptRoot, new CollectUndeclaredNames());
NodeTraversal.traverseEs6(compiler, scriptRoot, this);
NodeTraversal.traverseEs6(compiler, scriptRoot, new Es6RenameReferences(renameMap));

LoopClosureTransformer transformer = new LoopClosureTransformer();
NodeTraversal.traverseEs6(compiler, scriptRoot, transformer);
transformer.transformLoopClosure();
Expand Down
5 changes: 3 additions & 2 deletions src/com/google/javascript/jscomp/Es6RewriteDestructuring.java
Expand Up @@ -41,12 +41,13 @@ public Es6RewriteDestructuring(AbstractCompiler compiler) {

@Override
public void process(Node externs, Node root) {
TranspilationPasses.processTranspile(compiler, root, this);
NodeTraversal.traverseEs6(compiler, externs, this);
NodeTraversal.traverseEs6(compiler, root, this);
}

@Override
public void hotSwapScript(Node scriptRoot, Node originalRoot) {
TranspilationPasses.hotSwapTranspile(compiler, scriptRoot, this);
NodeTraversal.traverseEs6(compiler, scriptRoot, this);
}

@Override
Expand Down
7 changes: 5 additions & 2 deletions src/com/google/javascript/jscomp/Es6RewriteGenerators.java
Expand Up @@ -26,6 +26,7 @@
import com.google.javascript.rhino.JSDocInfoBuilder;
import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.Token;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -97,12 +98,14 @@ public Es6RewriteGenerators(AbstractCompiler compiler) {

@Override
public void process(Node externs, Node root) {
TranspilationPasses.processTranspile(compiler, root, new DecomposeYields(compiler), this);
NodeTraversal.traverseEs6(compiler, root, new DecomposeYields(compiler));
NodeTraversal.traverseEs6(compiler, root, this);
}

@Override
public void hotSwapScript(Node scriptRoot, Node originalRoot) {
TranspilationPasses.hotSwapTranspile(compiler, scriptRoot, new DecomposeYields(compiler), this);
NodeTraversal.traverseEs6(compiler, scriptRoot, new DecomposeYields(compiler));
NodeTraversal.traverseEs6(compiler, scriptRoot, this);
}

@Override
Expand Down
Expand Up @@ -45,12 +45,13 @@ public Es6SplitVariableDeclarations(AbstractCompiler compiler) {

@Override
public void process(Node externs, Node root) {
TranspilationPasses.processTranspile(compiler, root, this);
NodeTraversal.traverseEs6(compiler, externs, this);
NodeTraversal.traverseEs6(compiler, root, this);
}

@Override
public void hotSwapScript(Node scriptRoot, Node originalRoot) {
TranspilationPasses.hotSwapTranspile(compiler, scriptRoot, this);
NodeTraversal.traverseEs6(compiler, scriptRoot, this);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/Es6SuperCheck.java
Expand Up @@ -38,7 +38,7 @@ final class Es6SuperCheck extends AbstractPostOrderCallback implements CompilerP

@Override
public void process(Node externs, Node root) {
TranspilationPasses.processCheck(compiler, root, this);
NodeTraversal.traverseEs6(compiler, root, this);
}

@Override
Expand Down
34 changes: 3 additions & 31 deletions src/com/google/javascript/jscomp/Es6ToEs3Converter.java
Expand Up @@ -19,8 +19,6 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
import com.google.javascript.jscomp.parsing.parser.FeatureSet;
import com.google.javascript.jscomp.parsing.parser.FeatureSet.Feature;
import com.google.javascript.rhino.IR;
import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.JSDocInfoBuilder;
Expand Down Expand Up @@ -99,39 +97,13 @@ public Es6ToEs3Converter(AbstractCompiler compiler) {

@Override
public void process(Node externs, Node root) {
// TODO(moz): Currently, only .d.ts externs could have ES6 features in them. We should avoid
// traversing the externs in the common use case.
TranspilationPasses.processTranspile(compiler, externs, this);

for (Node singleRoot : root.children()) {
FeatureSet features = (FeatureSet) singleRoot.getProp(Node.FEATURE_SET);
if (features == null) {
continue;
}
// TODO(moz): getter / setter should be processed in a separate pass
if (TranspilationPasses.isScriptEs6ImplOrHigher(singleRoot)) {
singleRoot.putBooleanProp(Node.TRANSPILED, true);
NodeTraversal.traverseEs6(compiler, singleRoot, this);
} else if (features.contains(Feature.GETTER)
|| features.contains(Feature.SETTER)) {
NodeTraversal.traverseEs6(compiler, singleRoot, this);
}
}
NodeTraversal.traverseEs6(compiler, externs, this);
NodeTraversal.traverseEs6(compiler, root, this);
}

@Override
public void hotSwapScript(Node scriptRoot, Node originalRoot) {
FeatureSet features = (FeatureSet) scriptRoot.getProp(Node.FEATURE_SET);
if (features == null) {
return;
}
if (TranspilationPasses.isScriptEs6ImplOrHigher(scriptRoot)) {
scriptRoot.putBooleanProp(Node.TRANSPILED, true);
NodeTraversal.traverseEs6(compiler, scriptRoot, this);
} else if (features.contains(Feature.GETTER)
|| features.contains(Feature.SETTER)) {
NodeTraversal.traverseEs6(compiler, scriptRoot, this);
}
NodeTraversal.traverseEs6(compiler, scriptRoot, this);
}

/**
Expand Down
Expand Up @@ -28,6 +28,7 @@
import com.google.javascript.rhino.StaticSourceFile;
import com.google.javascript.rhino.StaticSymbolTable;
import com.google.javascript.rhino.Token;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -114,10 +115,6 @@ public void process(Node externs, Node root) {
NodeTraversal.traverseRoots(compiler, this, externs, root);
}

public void process(Node root) {
NodeTraversal.traverse(compiler, root, this);
}

/**
* Targets reference collection to a particular scope.
*/
Expand Down
13 changes: 4 additions & 9 deletions src/com/google/javascript/jscomp/Result.java
Expand Up @@ -16,9 +16,7 @@

package com.google.javascript.jscomp;

import com.google.common.annotations.VisibleForTesting;
import java.util.Map;
import java.util.Set;

/**
* Compilation results
Expand All @@ -37,18 +35,16 @@ public class Result {
public final Map<String, Integer> cssNames;
public final String externExport;
public final String idGeneratorMap;
public final Set<SourceFile> transpiledFiles;

Result(JSError[] errors, JSError[] warnings, String debugLog,
VariableMap variableMap, VariableMap propertyMap,
VariableMap namedAnonFunctionMap,
VariableMap stringMap,
FunctionInformationMap functionInformationMap,
SourceMap sourceMap, String externExport,
Map<String, Integer> cssNames, String idGeneratorMap,
Set<SourceFile> transpiledFiles) {
Map<String, Integer> cssNames, String idGeneratorMap) {
this.success = errors.length == 0;
this.errors = errors;
this.errors = errors;
this.warnings = warnings;
this.debugLog = debugLog;
this.variableMap = variableMap;
Expand All @@ -60,17 +56,16 @@ public class Result {
this.externExport = externExport;
this.cssNames = cssNames;
this.idGeneratorMap = idGeneratorMap;
this.transpiledFiles = transpiledFiles;
}

@VisibleForTesting
// Visible for testing only.
public Result(JSError[] errors, JSError[] warnings, String debugLog,
VariableMap variableMap, VariableMap propertyMap,
VariableMap namedAnonFunctionMap,
FunctionInformationMap functionInformationMap,
SourceMap sourceMap, String externExport) {
this(errors, warnings, debugLog, variableMap, propertyMap,
namedAnonFunctionMap, null, functionInformationMap, sourceMap,
externExport, null, null, null);
externExport, null, null);
}
}

0 comments on commit 04a3ccb

Please sign in to comment.