Repository: google/closure-compiler (java)

Issue:
Turning on the typed-based optimizations by default
This seems to come up a lot. Unless you are well versed in the compiler project, the expectation is that type information would be used for renaming.

* http://stackoverflow.com/q/28318862/1211524
* http://stackoverflow.com/q/28196051/1211524
* http://stackoverflow.com/q/12671041/1211524

Is it time to turn on the type based optimizations by default?

Pull request:
Enable the use_types_for_optmization flag by default
Enables type optimizations by default. Fixes #812.

Based off of the discussion at https://groups.google.com/forum/#!topic/closure-compiler-discuss/JPzrMiD_6dk

Question: Should we have a temporary warning or banner for the compiler when this would take effect?

I plan to update the FAQ and any other documentation pieces about this. There are also a few stackoverflow posts I'll edit. Someone should probably change the web service options to match as well (after release).

Patch:
diff --git a/externs/w3c_dom2.js b/externs/w3c_dom2.js
index d6642074c..5ddefd04f 100644
--- a/externs/w3c_dom2.js
+++ b/externs/w3c_dom2.js
@@ -728,7 +728,7 @@ HTMLSelectElement.prototype.length;
 HTMLSelectElement.prototype.form;
 
 /**
- * @type {!HTMLOptionsCollection}
+ * @type {HTMLOptionsCollection}
  * @see http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/html.html#ID-30606413
  */
 HTMLSelectElement.prototype.options;
diff --git a/src/com/google/javascript/jscomp/CommandLineRunner.java b/src/com/google/javascript/jscomp/CommandLineRunner.java
index b505d7496..5515bfbe0 100644
--- a/src/com/google/javascript/jscomp/CommandLineRunner.java
+++ b/src/com/google/javascript/jscomp/CommandLineRunner.java
@@ -361,10 +361,11 @@ public class CommandLineRunner extends
 
     @Option(name = "--use_types_for_optimization",
         hidden = true,
-        usage = "Experimental: perform additional optimizations " +
-        "based on available information. Inaccurate type annotations " +
+        handler = BooleanOptionHandler.class,
+        usage = "Enable or disable the optimizations " +
+        "based on available type information. Inaccurate type annotations " +
         "may result in incorrect results.")
-    private boolean useTypesForOptimization = false;
+    private boolean useTypesForOptimization = true;
 
     @Option(name = "--warning_level",
         aliases = {"-W"},


Test patch:
diff --git a/test/com/google/javascript/jscomp/CommandLineRunnerTest.java b/test/com/google/javascript/jscomp/CommandLineRunnerTest.java
index c35695d4b..e160814d6 100644
--- a/test/com/google/javascript/jscomp/CommandLineRunnerTest.java
+++ b/test/com/google/javascript/jscomp/CommandLineRunnerTest.java
@@ -247,7 +247,6 @@ public class CommandLineRunnerTest extends TestCase {
 
   public void testTypedAdvanced() {
     args.add("--compilation_level=ADVANCED_OPTIMIZATIONS");
-    args.add("--use_types_for_optimization");
     test(
         "/** @constructor */\n" +
         "function Foo() {}\n" +
@@ -260,6 +259,26 @@ public class CommandLineRunnerTest extends TestCase {
         "alert(2)");
   }
 
+  public void testTypedDisabledAdvanced() {
+    args.add("--compilation_level=ADVANCED_OPTIMIZATIONS");
+    args.add("--use_types_for_optimization=false");
+    test(
+        "/** @constructor */\n"
+        + "function Foo() {}\n"
+        +"Foo.prototype.handle1 = function(x, y) { alert(y); };\n"
+        + "/** @constructor */\n"
+        + "function Bar() {}\n"
+        + "Bar.prototype.handle1 = function(x, y) {};\n"
+        + "new Foo().handle1(1, 2);\n"
+        + "new Bar().handle1(1, 2);\n",
+        "function a() {}\n"
+        + "a.prototype.a = function(d, c) { alert(c); };\n"
+        + "function b() {}\n"
+        + "b.prototype.a = function() {};\n"
+        + "(new a).a(1, 2);\n"
+        + "(new b).a(1, 2);");
+  }
+
   public void testTypeCheckingOnWithVerbose() {
     args.add("--warning_level=VERBOSE");
     test("function f(x) { return x; } f();", TypeCheck.WRONG_ARGUMENT_COUNT);