Handle removal of unused polyfills in RemoveUnusedCode instead of custom RemoveUnusedPolyfills pass.
@@ -629,18 +629,6 @@ public final class DefaultPassConfig extends PassConfig {
passes.add(removeUnusedCodeOnce);
}
- // RewritePolyfills is overly generous in the polyfills it adds. After type
- // checking and early smart name removal, we can use the new type information
- // to figure out which polyfilled prototype methods are actually called, and
- // which were "false alarms" (i.e. calling a method of the same name on a
- // user-provided class). We also remove any polyfills added by code that
- // was smart-name-removed. This is a one-time pass, since it does not work
- // after inlining - we do not attempt to aggressively remove polyfills used
- // by code that is only flow-sensitively dead.
- if (options.rewritePolyfills) {
- passes.add(removeUnusedPolyfills);
- }
-
// Property disambiguation should only run once and needs to be done
// soon after type checking, both so that it can make use of type
// information and so that other passes can take advantage of the renamed
@@ -951,7 +939,8 @@ public final class DefaultPassConfig extends PassConfig {
|| options.removeUnusedLocalVars
|| options.removeUnusedPrototypeProperties
|| options.isRemoveUnusedClassProperties()
- || options.isRemoveUnusedConstructorProperties();
+ || options.isRemoveUnusedConstructorProperties()
+ || options.rewritePolyfills;
}
private final HotSwapPassFactory checkSideEffects =
@@ -2594,20 +2583,6 @@ public final class DefaultPassConfig extends PassConfig {
}
};
- /** Use data flow analysis to remove dead branches. */
- private final PassFactory removeUnusedPolyfills =
- new PassFactory("removeUnusedPolyfills", true) {
- @Override
- protected CompilerPass create(AbstractCompiler compiler) {
- return new RemoveUnusedPolyfills(compiler);
- }
-
- @Override
- protected FeatureSet featureSet() {
- return ES2019_MODULES;
- }
- };
-
/** Inlines simple methods, like getters */
private final PassFactory inlineSimpleMethods =
new PassFactory("inlineSimpleMethods", false) {
@@ -2703,6 +2678,7 @@ public final class DefaultPassConfig extends PassConfig {
.removeUnusedThisProperties(options.isRemoveUnusedClassProperties())
.removeUnusedObjectDefinePropertiesDefinitions(options.isRemoveUnusedClassProperties())
.removeUnusedConstructorProperties(options.isRemoveUnusedConstructorProperties())
+ .removeUnusedPolyfills(options.rewritePolyfills)
.build();
}
