fix code generator for this case:
authorMihai Bazon <mihai@bazon.net>
Tue, 28 Aug 2012 12:29:58 +0000 (15:29 +0300)
committerMihai Bazon <mihai@bazon.net>
Tue, 28 Aug 2012 12:29:58 +0000 (15:29 +0300)
if (foo) {
  with (bar)
    if (baz)
      x();
} else y();

(the compressor removes the brackets since the consequent consists of a
single statement, but the codegen must include the brackets because
otherwise the `else` would refer to the inner `if`)

lib/ast.js
lib/output.js

index ee57f80..a4a87a2 100644 (file)
@@ -149,6 +149,9 @@ var AST_EmptyStatement = DEFNODE("EmptyStatement", null, {
     }
 }, AST_Statement);
 
+var AST_StatementWithBody = DEFNODE("StatementWithBody", null, {
+}, AST_Statement);
+
 var AST_DWLoop = DEFNODE("DWLoop", "condition", {
     $documentation: "Base class for do/while statements.",
     _walk: function(visitor) {
@@ -157,7 +160,7 @@ var AST_DWLoop = DEFNODE("DWLoop", "condition", {
             this.body._walk(visitor);
         });
     }
-}, AST_Statement);
+}, AST_StatementWithBody);
 
 var AST_Do = DEFNODE("Do", null, {
     $documentation: "A `do` statement"
@@ -177,7 +180,7 @@ var AST_For = DEFNODE("For", "init condition step", {
             this.body._walk(visitor);
         });
     }
-}, AST_Statement);
+}, AST_StatementWithBody);
 
 var AST_ForIn = DEFNODE("ForIn", "init name object", {
     $documentation: "A `for ... in` statement",
@@ -188,7 +191,7 @@ var AST_ForIn = DEFNODE("ForIn", "init name object", {
             this.body._walk(visitor);
         });
     }
-}, AST_Statement);
+}, AST_StatementWithBody);
 
 var AST_With = DEFNODE("With", "expression", {
     $documentation: "A `with` statement",
@@ -198,7 +201,7 @@ var AST_With = DEFNODE("With", "expression", {
             this.body._walk(visitor);
         });
     }
-}, AST_Statement);
+}, AST_StatementWithBody);
 
 /* -----[ scope and functions ]----- */
 
index 1d9e501..7cd3e3c 100644 (file)
@@ -611,10 +611,7 @@ function OutputStream(options) {
                 }
                 b = b.alternative;
             }
-            else if (b instanceof AST_While
-                     || b instanceof AST_Do
-                     || b instanceof AST_For
-                     || b instanceof AST_ForIn) {
+            else if (b instanceof AST_StatementWithBody) {
                 b = b.body;
             }
             else break;