Rollback "Switch RemoveUnusedPolyfills to RemoveUnusedCode"
The change caused a project breakage within Google.
@@ -612,6 +612,18 @@ 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
@@ -937,8 +949,7 @@ public final class DefaultPassConfig extends PassConfig {
|| options.removeUnusedLocalVars
|| options.removeUnusedPrototypeProperties
|| options.isRemoveUnusedClassProperties()
- || options.isRemoveUnusedConstructorProperties()
- || options.rewritePolyfills;
+ || options.isRemoveUnusedConstructorProperties();
}
private final HotSwapPassFactory checkSideEffects =
@@ -2527,6 +2538,22 @@ 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 ES8_MODULES;
+ }
+ };
+
/** Inlines simple methods, like getters */
private final PassFactory inlineSimpleMethods =
new PassFactory("inlineSimpleMethods", false) {
@@ -2622,7 +2649,6 @@ public final class DefaultPassConfig extends PassConfig {
.removeUnusedThisProperties(options.isRemoveUnusedClassProperties())
.removeUnusedObjectDefinePropertiesDefinitions(options.isRemoveUnusedClassProperties())
.removeUnusedConstructorProperties(options.isRemoveUnusedConstructorProperties())
- .removeUnusedPolyfills(options.rewritePolyfills)
.build();
}
@@ -2631,6 +2657,7 @@ public final class DefaultPassConfig extends PassConfig {
return ES8_MODULES;
}
};
+
}
/** Move global symbols to a deeper common module */
