From 61164561f049ea5507c5e7f4ae6b3a8884536ae3 Mon Sep 17 00:00:00 2001 From: sdh Date: Tue, 14 Nov 2017 13:50:51 -0800 Subject: [PATCH] Roll forward [] [NTI] Rearrange the order of some pre-typechecking transpilation 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 --- .../javascript/jscomp/DefaultPassConfig.java | 14 ++++++++------ .../javascript/jscomp/TranspilationPasses.java | 17 +++-------------- .../javascript/jscomp/CompilerTestCase.java | 3 ++- .../jscomp/NewTypeInferenceTestBase.java | 6 +++--- .../google/javascript/jscomp/TypeCheckTest.java | 3 ++- 5 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/com/google/javascript/jscomp/DefaultPassConfig.java b/src/com/google/javascript/jscomp/DefaultPassConfig.java index aebc0a74162..4e117a0d736 100644 --- a/src/com/google/javascript/jscomp/DefaultPassConfig.java +++ b/src/com/google/javascript/jscomp/DefaultPassConfig.java @@ -183,7 +183,8 @@ protected List getTranspileOnlyPasses() { // can be removed. if (options.needsTranspilationFrom(ES6) || options.needsTranspilationFrom(ES7)) { TranspilationPasses.addEs6EarlyPasses(passes); - TranspilationPasses.addEs6LatePasses(passes); + TranspilationPasses.addEs6LatePassesBeforeNti(passes); + TranspilationPasses.addEs6LatePassesAfterNti(passes); TranspilationPasses.addPostCheckPasses(passes); if (options.rewritePolyfills) { TranspilationPasses.addRewritePolyfillPass(passes); @@ -394,10 +395,9 @@ protected List getChecks() { } if (options.needsTranspilationFrom(ES6)) { - if (options.getTypeCheckEs6Natively()) { - TranspilationPasses.addEs6PassesBeforeNTI(checks); - } else { - TranspilationPasses.addEs6LatePasses(checks); + TranspilationPasses.addEs6LatePassesBeforeNti(checks); + if (!options.getTypeCheckEs6Natively()) { + TranspilationPasses.addEs6LatePassesAfterNti(checks); } } @@ -437,7 +437,9 @@ protected List getChecks() { } if (options.needsTranspilationFrom(ES6)) { - TranspilationPasses.addEs6PassesAfterNTI(checks); + if (options.getTypeCheckEs6Natively()) { + TranspilationPasses.addEs6LatePassesAfterNti(checks); + } checks.add(setFeatureSet(options.getLanguageOut().toFeatureSet())); } } diff --git a/src/com/google/javascript/jscomp/TranspilationPasses.java b/src/com/google/javascript/jscomp/TranspilationPasses.java index c4c670e86a4..9be549387aa 100644 --- a/src/com/google/javascript/jscomp/TranspilationPasses.java +++ b/src/com/google/javascript/jscomp/TranspilationPasses.java @@ -60,27 +60,16 @@ public static void addEs6EarlyPasses(List passes) { passes.add(es6RewriteArrowFunction); } - /** Adds all the late ES6 transpilation passes, which go after the Dart pass */ - public static void addEs6LatePasses(List 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 - * and go before TypeChecking + * and go before TypeChecking. * *

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 * transpilation later in the compilation, and eventually only transpiling * when the output is lower than ES6. */ - public static void addEs6PassesBeforeNTI(List passes) { + public static void addEs6LatePassesBeforeNti(List passes) { passes.add(es6ExtractClasses); passes.add(es6RewriteClass); passes.add(earlyConvertEs6ToEs3); @@ -88,7 +77,7 @@ public static void addEs6PassesBeforeNTI(List passes) { } /** Adds all transpilation passes that runs after NTI */ - public static void addEs6PassesAfterNTI(List passes) { + public static void addEs6LatePassesAfterNti(List passes) { passes.add(lateConvertEs6ToEs3); passes.add(rewriteGenerators); } diff --git a/test/com/google/javascript/jscomp/CompilerTestCase.java b/test/com/google/javascript/jscomp/CompilerTestCase.java index be31b7be412..14ce9479cd0 100644 --- a/test/com/google/javascript/jscomp/CompilerTestCase.java +++ b/test/com/google/javascript/jscomp/CompilerTestCase.java @@ -1786,7 +1786,8 @@ private static void transpileToEs5(AbstractCompiler compiler, Node externsRoot, TranspilationPasses.addEs2017Passes(factories); TranspilationPasses.addEs2016Passes(factories); TranspilationPasses.addEs6EarlyPasses(factories); - TranspilationPasses.addEs6LatePasses(factories); + TranspilationPasses.addEs6LatePassesBeforeNti(factories); + TranspilationPasses.addEs6LatePassesAfterNti(factories); TranspilationPasses.addRewritePolyfillPass(factories); for (PassFactory factory : factories) { factory.create(compiler).process(externsRoot, codeRoot); diff --git a/test/com/google/javascript/jscomp/NewTypeInferenceTestBase.java b/test/com/google/javascript/jscomp/NewTypeInferenceTestBase.java index c333a20807e..97180d19570 100644 --- a/test/com/google/javascript/jscomp/NewTypeInferenceTestBase.java +++ b/test/com/google/javascript/jscomp/NewTypeInferenceTestBase.java @@ -254,9 +254,9 @@ private void parseAndTypeCheck(String externs, String js) { TranspilationPasses.addEs2017Passes(passes); TranspilationPasses.addEs2016Passes(passes); TranspilationPasses.addEs6EarlyPasses(passes); - TranspilationPasses.addEs6PassesBeforeNTI(passes); + TranspilationPasses.addEs6LatePassesBeforeNti(passes); if (!compilerOptions.getTypeCheckEs6Natively()) { - TranspilationPasses.addEs6PassesAfterNTI(passes); + TranspilationPasses.addEs6LatePassesAfterNti(passes); TranspilationPasses.addRewritePolyfillPass(passes); } } @@ -264,7 +264,7 @@ private void parseAndTypeCheck(String externs, String js) { passes.add(makePassFactory("NewTypeInference", new NewTypeInference(compiler))); if (compilerOptions.needsTranspilationFrom(FeatureSet.ES6) && compilerOptions.getTypeCheckEs6Natively()) { - TranspilationPasses.addEs6PassesAfterNTI(passes); + TranspilationPasses.addEs6LatePassesAfterNti(passes); TranspilationPasses.addRewritePolyfillPass(passes); } diff --git a/test/com/google/javascript/jscomp/TypeCheckTest.java b/test/com/google/javascript/jscomp/TypeCheckTest.java index 9395f537196..200b82718c9 100644 --- a/test/com/google/javascript/jscomp/TypeCheckTest.java +++ b/test/com/google/javascript/jscomp/TypeCheckTest.java @@ -17997,7 +17997,8 @@ private TypeCheckResult parseAndTypeCheckWithScope(String externs, String js) { TranspilationPasses.addEs2017Passes(passes); TranspilationPasses.addEs2016Passes(passes); TranspilationPasses.addEs6EarlyPasses(passes); - TranspilationPasses.addEs6LatePasses(passes); + TranspilationPasses.addEs6LatePassesBeforeNti(passes); + TranspilationPasses.addEs6LatePassesAfterNti(passes); TranspilationPasses.addRewritePolyfillPass(passes); PhaseOptimizer phaseopt = new PhaseOptimizer(compiler, null); phaseopt.consume(passes);