Skip to content

Commit 03e49f9

Browse files
shicksblickly
authored andcommitted
[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=173489405
1 parent b412db9 commit 03e49f9

File tree

5 files changed

+14
-22
lines changed

5 files changed

+14
-22
lines changed

src/com/google/javascript/jscomp/DefaultPassConfig.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ protected List<PassFactory> getTranspileOnlyPasses() {
183183
// can be removed.
184184
if (options.needsTranspilationFrom(ES6) || options.needsTranspilationFrom(ES7)) {
185185
TranspilationPasses.addEs6EarlyPasses(passes);
186-
TranspilationPasses.addEs6LatePasses(passes);
186+
TranspilationPasses.addEs6LatePassesBeforeNti(passes);
187+
TranspilationPasses.addEs6LatePassesAfterNti(passes);
187188
TranspilationPasses.addPostCheckPasses(passes);
188189
if (options.rewritePolyfills) {
189190
TranspilationPasses.addRewritePolyfillPass(passes);
@@ -381,10 +382,9 @@ protected List<PassFactory> getChecks() {
381382
}
382383

383384
if (options.needsTranspilationFrom(ES6)) {
384-
if (options.getTypeCheckEs6Natively()) {
385-
TranspilationPasses.addEs6PassesBeforeNTI(checks);
386-
} else {
387-
TranspilationPasses.addEs6LatePasses(checks);
385+
TranspilationPasses.addEs6LatePassesBeforeNti(checks);
386+
if (!options.getTypeCheckEs6Natively()) {
387+
TranspilationPasses.addEs6LatePassesAfterNti(checks);
388388
}
389389
}
390390

@@ -424,7 +424,7 @@ protected List<PassFactory> getChecks() {
424424
}
425425

426426
if (options.needsTranspilationFrom(ES6)) {
427-
TranspilationPasses.addEs6PassesAfterNTI(checks);
427+
TranspilationPasses.addEs6LatePassesAfterNti(checks);
428428
checks.add(setFeatureSet(options.getLanguageOut().toFeatureSet()));
429429
}
430430
}

src/com/google/javascript/jscomp/TranspilationPasses.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,6 @@ public static void addEs6EarlyPasses(List<PassFactory> passes) {
5959
passes.add(es6RewriteArrowFunction);
6060
}
6161

62-
/** Adds all the late ES6 transpilation passes, which go after the Dart pass */
63-
public static void addEs6LatePasses(List<PassFactory> passes) {
64-
// TODO(b/64811685): Delete this method and use addEs6PassesBeforeNTI and addEs6PassesAfterNTI.
65-
passes.add(es6ExtractClasses);
66-
passes.add(es6RewriteClass);
67-
passes.add(earlyConvertEs6ToEs3);
68-
passes.add(lateConvertEs6ToEs3);
69-
passes.add(rewriteBlockScopedDeclaration);
70-
passes.add(rewriteGenerators);
71-
}
72-
7362
/**
7463
* Adds all the late ES6 transpilation passes, which go after the Dart pass
7564
* and go before TypeChecking
@@ -79,15 +68,15 @@ public static void addEs6LatePasses(List<PassFactory> passes) {
7968
* transpilation later in the compilation, and eventually only transpiling
8069
* when the output is lower than ES6.
8170
*/
82-
public static void addEs6PassesBeforeNTI(List<PassFactory> passes) {
71+
public static void addEs6LatePassesBeforeNti(List<PassFactory> passes) {
8372
passes.add(es6ExtractClasses);
8473
passes.add(es6RewriteClass);
8574
passes.add(earlyConvertEs6ToEs3);
8675
passes.add(rewriteBlockScopedDeclaration);
8776
}
8877

8978
/** Adds all transpilation passes that runs after NTI */
90-
public static void addEs6PassesAfterNTI(List<PassFactory> passes) {
79+
public static void addEs6LatePassesAfterNti(List<PassFactory> passes) {
9180
passes.add(lateConvertEs6ToEs3);
9281
passes.add(rewriteGenerators);
9382
}

test/com/google/javascript/jscomp/CompilerTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,8 @@ private static void transpileToEs5(AbstractCompiler compiler, Node externsRoot,
16811681
TranspilationPasses.addEs2017Passes(factories);
16821682
TranspilationPasses.addEs2016Passes(factories);
16831683
TranspilationPasses.addEs6EarlyPasses(factories);
1684-
TranspilationPasses.addEs6LatePasses(factories);
1684+
TranspilationPasses.addEs6LatePassesBeforeNti(factories);
1685+
TranspilationPasses.addEs6LatePassesAfterNti(factories);
16851686
TranspilationPasses.addRewritePolyfillPass(factories);
16861687
for (PassFactory factory : factories) {
16871688
factory.create(compiler).process(externsRoot, codeRoot);

test/com/google/javascript/jscomp/NewTypeInferenceTestBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ private final void parseAndTypeCheck(String externs, String js) {
260260
TranspilationPasses.addEs2017Passes(passes);
261261
TranspilationPasses.addEs2016Passes(passes);
262262
TranspilationPasses.addEs6EarlyPasses(passes);
263-
TranspilationPasses.addEs6LatePasses(passes);
263+
TranspilationPasses.addEs6LatePassesBeforeNti(passes);
264+
TranspilationPasses.addEs6LatePassesAfterNti(passes);
264265
TranspilationPasses.addRewritePolyfillPass(passes);
265266
}
266267
passes.add(makePassFactory("GlobalTypeInfo", new GlobalTypeInfoCollector(compiler)));

test/com/google/javascript/jscomp/TypeCheckTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17953,7 +17953,8 @@ private TypeCheckResult parseAndTypeCheckWithScope(String externs, String js) {
1795317953
TranspilationPasses.addEs2017Passes(passes);
1795417954
TranspilationPasses.addEs2016Passes(passes);
1795517955
TranspilationPasses.addEs6EarlyPasses(passes);
17956-
TranspilationPasses.addEs6LatePasses(passes);
17956+
TranspilationPasses.addEs6LatePassesBeforeNti(passes);
17957+
TranspilationPasses.addEs6LatePassesAfterNti(passes);
1795717958
TranspilationPasses.addRewritePolyfillPass(passes);
1795817959
PhaseOptimizer phaseopt = new PhaseOptimizer(compiler, null);
1795917960
phaseopt.consume(passes);

0 commit comments

Comments
 (0)