Reviewers: scottb,

Description:
This patch removes trailing parenthesis from Javascript 'new' operators
if there
are no constructor arguments.

new Foo() -> new Foo

Now with fixes based on Scott's review, as well as some inline comments
in case future archaeologists after the apocalypse discover this code
and want to know the motivation.


Please review this at http://gwt-code-reviews.appspot.com/47808

Affected files:
   dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java


Index: dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
===================================================================
--- dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java  
(revision 5638)
+++ dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java  
(working copy)
@@ -583,16 +583,19 @@
        _rparen();
      }

-    _lparen();
-    boolean sep = false;
-    for (Object element : x.getArguments()) {
-      JsExpression arg = (JsExpression) element;
-      sep = _sepCommaOptSpace(sep);
-      _parenPushIfCommaExpr(arg);
-      accept(arg);
-      _parenPopIfCommaExpr(arg);
+    // if an constructor call has no arguments, it may simply be
+    // replaced with "new Constructor" with no parenthesis
+    if (x.getArguments().size() > 0) {
+      _lparen();
+      boolean sep = false;
+      for (JsExpression arg : x.getArguments()) {
+        sep = _sepCommaOptSpace(sep);
+        _parenPushIfCommaExpr(arg);
+        accept(arg);
+        _parenPopIfCommaExpr(arg);
+      }
+      _rparen();
      }
-    _rparen();

      return false;
    }



--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to