Skip to content

Commit

Permalink
Roll forward [] [NTI] Rearrange the order of some pre-typechecking tr…
Browse files Browse the repository at this point in the history
…anspilation passes.

NEW: Fixed problem caused by broken handling of shorthand properties in []

Automated g4 rollback of changelist 173565377.

*** Reason for rollback ***

Roll forward, now that shorthand properties are normalized earlier.

*** Original change description ***

Automated g4 rollback of changelist 173489405.

*** Reason for rollback ***

Breaks [] Details in comment added to []

*** Original change description ***

[NTI] Rearrange the order of some pre-typechecking transpilation passes.

This allows removing TranspilationPasses#addEs6LatePasses and replacing it with the two calls, addEs6LatePassesBeforeNti and addEs6LatePassesAfterNti.  We will be further rearranging the passes as NTI becomes capable of handling more ES6 features.

***

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=175729519
  • Loading branch information
shicks authored and Tyler Breisacher committed Nov 14, 2017
1 parent a710d70 commit 6116456
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
14 changes: 8 additions & 6 deletions src/com/google/javascript/jscomp/DefaultPassConfig.java
Expand Up @@ -183,7 +183,8 @@ protected List<PassFactory> getTranspileOnlyPasses() {
// can be removed. // can be removed.
if (options.needsTranspilationFrom(ES6) || options.needsTranspilationFrom(ES7)) { if (options.needsTranspilationFrom(ES6) || options.needsTranspilationFrom(ES7)) {
TranspilationPasses.addEs6EarlyPasses(passes); TranspilationPasses.addEs6EarlyPasses(passes);
TranspilationPasses.addEs6LatePasses(passes); TranspilationPasses.addEs6LatePassesBeforeNti(passes);
TranspilationPasses.addEs6LatePassesAfterNti(passes);
TranspilationPasses.addPostCheckPasses(passes); TranspilationPasses.addPostCheckPasses(passes);
if (options.rewritePolyfills) { if (options.rewritePolyfills) {
TranspilationPasses.addRewritePolyfillPass(passes); TranspilationPasses.addRewritePolyfillPass(passes);
Expand Down Expand Up @@ -394,10 +395,9 @@ protected List<PassFactory> getChecks() {
} }


if (options.needsTranspilationFrom(ES6)) { if (options.needsTranspilationFrom(ES6)) {
if (options.getTypeCheckEs6Natively()) { TranspilationPasses.addEs6LatePassesBeforeNti(checks);
TranspilationPasses.addEs6PassesBeforeNTI(checks); if (!options.getTypeCheckEs6Natively()) {
} else { TranspilationPasses.addEs6LatePassesAfterNti(checks);
TranspilationPasses.addEs6LatePasses(checks);
} }
} }


Expand Down Expand Up @@ -437,7 +437,9 @@ protected List<PassFactory> getChecks() {
} }


if (options.needsTranspilationFrom(ES6)) { if (options.needsTranspilationFrom(ES6)) {
TranspilationPasses.addEs6PassesAfterNTI(checks); if (options.getTypeCheckEs6Natively()) {
TranspilationPasses.addEs6LatePassesAfterNti(checks);
}
checks.add(setFeatureSet(options.getLanguageOut().toFeatureSet())); checks.add(setFeatureSet(options.getLanguageOut().toFeatureSet()));
} }
} }
Expand Down
17 changes: 3 additions & 14 deletions src/com/google/javascript/jscomp/TranspilationPasses.java
Expand Up @@ -60,35 +60,24 @@ public static void addEs6EarlyPasses(List<PassFactory> passes) {
passes.add(es6RewriteArrowFunction); passes.add(es6RewriteArrowFunction);
} }


/** Adds all the late ES6 transpilation passes, which go after the Dart pass */
public static void addEs6LatePasses(List<PassFactory> passes) {
// TODO(b/64811685): Delete this method and use addEs6PassesBeforeNTI and addEs6PassesAfterNTI.
passes.add(es6ExtractClasses);
passes.add(es6RewriteClass);
passes.add(earlyConvertEs6ToEs3);
passes.add(lateConvertEs6ToEs3);
passes.add(rewriteBlockScopedDeclaration);
passes.add(rewriteGenerators);
}

/** /**
* Adds all the late ES6 transpilation passes, which go after the Dart pass * Adds all the late ES6 transpilation passes, which go after the Dart pass
* and go before TypeChecking * and go before TypeChecking.
* *
* <p>Includes ES6 features that are best handled natively by the compiler. * <p>Includes ES6 features that are best handled natively by the compiler.
* As we convert more passes to handle these features, we will be moving the * As we convert more passes to handle these features, we will be moving the
* transpilation later in the compilation, and eventually only transpiling * transpilation later in the compilation, and eventually only transpiling
* when the output is lower than ES6. * when the output is lower than ES6.
*/ */
public static void addEs6PassesBeforeNTI(List<PassFactory> passes) { public static void addEs6LatePassesBeforeNti(List<PassFactory> passes) {
passes.add(es6ExtractClasses); passes.add(es6ExtractClasses);
passes.add(es6RewriteClass); passes.add(es6RewriteClass);
passes.add(earlyConvertEs6ToEs3); passes.add(earlyConvertEs6ToEs3);
passes.add(rewriteBlockScopedDeclaration); passes.add(rewriteBlockScopedDeclaration);
} }


/** Adds all transpilation passes that runs after NTI */ /** Adds all transpilation passes that runs after NTI */
public static void addEs6PassesAfterNTI(List<PassFactory> passes) { public static void addEs6LatePassesAfterNti(List<PassFactory> passes) {
passes.add(lateConvertEs6ToEs3); passes.add(lateConvertEs6ToEs3);
passes.add(rewriteGenerators); passes.add(rewriteGenerators);
} }
Expand Down
3 changes: 2 additions & 1 deletion test/com/google/javascript/jscomp/CompilerTestCase.java
Expand Up @@ -1786,7 +1786,8 @@ private static void transpileToEs5(AbstractCompiler compiler, Node externsRoot,
TranspilationPasses.addEs2017Passes(factories); TranspilationPasses.addEs2017Passes(factories);
TranspilationPasses.addEs2016Passes(factories); TranspilationPasses.addEs2016Passes(factories);
TranspilationPasses.addEs6EarlyPasses(factories); TranspilationPasses.addEs6EarlyPasses(factories);
TranspilationPasses.addEs6LatePasses(factories); TranspilationPasses.addEs6LatePassesBeforeNti(factories);
TranspilationPasses.addEs6LatePassesAfterNti(factories);
TranspilationPasses.addRewritePolyfillPass(factories); TranspilationPasses.addRewritePolyfillPass(factories);
for (PassFactory factory : factories) { for (PassFactory factory : factories) {
factory.create(compiler).process(externsRoot, codeRoot); factory.create(compiler).process(externsRoot, codeRoot);
Expand Down
Expand Up @@ -254,17 +254,17 @@ private void parseAndTypeCheck(String externs, String js) {
TranspilationPasses.addEs2017Passes(passes); TranspilationPasses.addEs2017Passes(passes);
TranspilationPasses.addEs2016Passes(passes); TranspilationPasses.addEs2016Passes(passes);
TranspilationPasses.addEs6EarlyPasses(passes); TranspilationPasses.addEs6EarlyPasses(passes);
TranspilationPasses.addEs6PassesBeforeNTI(passes); TranspilationPasses.addEs6LatePassesBeforeNti(passes);
if (!compilerOptions.getTypeCheckEs6Natively()) { if (!compilerOptions.getTypeCheckEs6Natively()) {
TranspilationPasses.addEs6PassesAfterNTI(passes); TranspilationPasses.addEs6LatePassesAfterNti(passes);
TranspilationPasses.addRewritePolyfillPass(passes); TranspilationPasses.addRewritePolyfillPass(passes);
} }
} }
passes.add(makePassFactory("GlobalTypeInfo", new GlobalTypeInfoCollector(compiler))); passes.add(makePassFactory("GlobalTypeInfo", new GlobalTypeInfoCollector(compiler)));
passes.add(makePassFactory("NewTypeInference", new NewTypeInference(compiler))); passes.add(makePassFactory("NewTypeInference", new NewTypeInference(compiler)));
if (compilerOptions.needsTranspilationFrom(FeatureSet.ES6) if (compilerOptions.needsTranspilationFrom(FeatureSet.ES6)
&& compilerOptions.getTypeCheckEs6Natively()) { && compilerOptions.getTypeCheckEs6Natively()) {
TranspilationPasses.addEs6PassesAfterNTI(passes); TranspilationPasses.addEs6LatePassesAfterNti(passes);
TranspilationPasses.addRewritePolyfillPass(passes); TranspilationPasses.addRewritePolyfillPass(passes);
} }


Expand Down
3 changes: 2 additions & 1 deletion test/com/google/javascript/jscomp/TypeCheckTest.java
Expand Up @@ -17997,7 +17997,8 @@ private TypeCheckResult parseAndTypeCheckWithScope(String externs, String js) {
TranspilationPasses.addEs2017Passes(passes); TranspilationPasses.addEs2017Passes(passes);
TranspilationPasses.addEs2016Passes(passes); TranspilationPasses.addEs2016Passes(passes);
TranspilationPasses.addEs6EarlyPasses(passes); TranspilationPasses.addEs6EarlyPasses(passes);
TranspilationPasses.addEs6LatePasses(passes); TranspilationPasses.addEs6LatePassesBeforeNti(passes);
TranspilationPasses.addEs6LatePassesAfterNti(passes);
TranspilationPasses.addRewritePolyfillPass(passes); TranspilationPasses.addRewritePolyfillPass(passes);
PhaseOptimizer phaseopt = new PhaseOptimizer(compiler, null); PhaseOptimizer phaseopt = new PhaseOptimizer(compiler, null);
phaseopt.consume(passes); phaseopt.consume(passes);
Expand Down

0 comments on commit 6116456

Please sign in to comment.