Skip to content

Commit db7ed63

Browse files
rishipalcopybara-github
authored andcommitted
Move reportUntranspilableFeatures pass inside addEarlyOptimizationTranspilation method
The `CompilerTestCase.transpileToEs5` method creates its own PassListBuilder to create and invoke custom transpiler passes. In doing that, it only includes select passes from outside `addEarlyOptimizationTranspilation`. This change ensures that the `reportUntranspilableFeatures` gets included and executes in that code path also. PiperOrigin-RevId: 551316236
1 parent bb04061 commit db7ed63

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ public DefaultPassConfig(CompilerOptions options) {
123123
protected PassListBuilder getTranspileOnlyPasses() {
124124
PassListBuilder passes = new PassListBuilder(options);
125125

126-
passes.maybeAdd(reportUntranspilableFeatures);
127-
128126
// Certain errors in block-scoped variable declarations will prevent correct transpilation
129127
passes.maybeAdd(checkVariableReferences);
130128
passes.maybeAdd(checkVars);
@@ -166,6 +164,9 @@ protected PassListBuilder getTranspileOnlyPasses() {
166164

167165
passes.maybeAdd(injectRuntimeLibraries);
168166

167+
// NOTE: Any new transpiler passes added outside of
168+
// {@code addEarlyOptimizationTranspilationPasses} also need to update
169+
// {@code CompilerTestCase.transpileToEs5}
169170
TranspilationPasses.addEarlyOptimizationTranspilationPasses(passes, options);
170171

171172
// Passes below this point may rely on normalization and must maintain normalization.
@@ -507,7 +508,6 @@ protected PassListBuilder getChecks() {
507508
protected PassListBuilder getOptimizations() {
508509
PassListBuilder passes = new PassListBuilder(options);
509510
if (options.isPropertyRenamingOnlyCompilationMode()) {
510-
passes.maybeAdd(reportUntranspilableFeatures);
511511
TranspilationPasses.addTranspilationRuntimeLibraries(passes);
512512
passes.maybeAdd(closureProvidesRequires);
513513
passes.maybeAdd(processDefinesOptimize);
@@ -551,8 +551,6 @@ protected PassListBuilder getOptimizations() {
551551
passes.maybeAdd(j2clPass);
552552
}
553553

554-
passes.maybeAdd(reportUntranspilableFeatures);
555-
556554
TranspilationPasses.addTranspilationRuntimeLibraries(passes);
557555

558556
if (options.rewritePolyfills || options.getIsolatePolyfills()) {
@@ -1535,14 +1533,6 @@ compiler, new GoogleJsMessageIdGenerator(options.tcProjectId)
15351533
compiler, ImmutableSet.copyOf(compiler.getOptions().forceLibraryInjection)))
15361534
.build();
15371535

1538-
private final PassFactory reportUntranspilableFeatures =
1539-
PassFactory.builder()
1540-
.setName("reportUntranspilableFeatures")
1541-
.setInternalFactory(
1542-
(compiler) ->
1543-
new ReportUntranspilableFeatures(compiler, options.getOutputFeatureSet()))
1544-
.build();
1545-
15461536
private final PassFactory removeWeakSources =
15471537
PassFactory.builder()
15481538
.setName("removeWeakSources")

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public static void addEs6RewriteImportPathPass(PassListBuilder passes) {
6464
public static void addEarlyOptimizationTranspilationPasses(
6565
PassListBuilder passes, CompilerOptions options) {
6666

67+
passes.maybeAdd(reportUntranspilableFeatures);
68+
6769
// Note that we detect feature by feature rather than by yearly languages
6870
// in order to handle FeatureSet.BROWSER_2020, which is ES2019 without the new RegExp features.
6971
// However, RegExp features are not transpiled, and this does not imply that we allow arbitrary
@@ -416,6 +418,15 @@ static final PassFactory getEs6RewriteDestructuring(ObjectDestructuringRewriteMo
416418
.setInternalFactory(RewriteNullishCoalesceOperator::new)
417419
.build();
418420

421+
static final PassFactory reportUntranspilableFeatures =
422+
PassFactory.builder()
423+
.setName("reportUntranspilableFeatures")
424+
.setInternalFactory(
425+
(compiler) ->
426+
new ReportUntranspilableFeatures(
427+
compiler, compiler.getOptions().getOutputFeatureSet()))
428+
.build();
429+
419430
/**
420431
* @param script The SCRIPT node representing a JS file
421432
* @return If the file has any features not in {@code supportedFeatures}

0 commit comments

Comments
 (0)