hint that brackets may be required in AST_BlockStatement
authorMihai Bazon <mihai@bazon.net>
Tue, 21 Aug 2012 13:27:57 +0000 (16:27 +0300)
committerMihai Bazon <mihai@bazon.net>
Tue, 21 Aug 2012 16:16:05 +0000 (19:16 +0300)
lib/ast.js
lib/compress.js
lib/parse.js
lib/scope.js

index 1b75bd6..3fd197e 100644 (file)
@@ -86,7 +86,7 @@ var AST_SimpleStatement = DEFNODE("SimpleStatement", null, {
     $documentation: "A statement consisting of an expression, i.e. a = 1 + 2."
 }, AST_Statement);
 
-var AST_BlockStatement = DEFNODE("BlockStatement", null, {
+var AST_BlockStatement = DEFNODE("BlockStatement", "required", {
     $documentation: "A block statement.",
     _walk: function(visitor) {
         return visitor._visit(this, function(){
index 025c262..c28aacc 100644 (file)
@@ -35,10 +35,6 @@ function Compressor(options) {
         return this;
     });
 
-    AST_Token.DEFMETHOD("squeeze", function(){
-        return this;
-    });
-
     function SQUEEZE(nodetype, squeeze) {
         nodetype.DEFMETHOD("squeeze", function(compressor){
             compressor.push_node(this);
index 7f14429..a30ec5a 100644 (file)
@@ -746,7 +746,7 @@ function parse($TEXT, exigent_mode) {
           case "punc":
             switch (S.token.value) {
               case "{":
-                return block_();
+                return block_(false);
               case "[":
               case "(":
                 return simple_statement();
@@ -938,7 +938,7 @@ function parse($TEXT, exigent_mode) {
                 S.in_directives = true;
                 S.in_loop = 0;
                 S.labels = [];
-                var a = block_();
+                var a = block_(true);
                 --S.in_function;
                 S.in_loop = loop;
                 S.labels = labels;
@@ -960,7 +960,7 @@ function parse($TEXT, exigent_mode) {
         });
     };
 
-    function block_() {
+    function block_(required) {
         var start = S.token;
         expect("{");
         var a = [];
@@ -971,9 +971,10 @@ function parse($TEXT, exigent_mode) {
         var end = S.token;
         next();
         return new AST_BlockStatement({
-            start : start,
-            body  : a,
-            end   : end
+            required : required,
+            start    : start,
+            body     : a,
+            end      : end
         });
     };
 
@@ -1011,14 +1012,15 @@ function parse($TEXT, exigent_mode) {
         var end = S.token;
         next();
         return new AST_SwitchBlock({
-            start : start,
-            body  : a,
-            end   : end
+            required : true,
+            start    : start,
+            body     : a,
+            end      : end
         });
     }));
 
     function try_() {
-        var body = block_(), bcatch = null, bfinally = null;
+        var body = block_(true), bcatch = null, bfinally = null;
         if (is("keyword", "catch")) {
             var start = S.token;
             next();
@@ -1028,7 +1030,7 @@ function parse($TEXT, exigent_mode) {
             bcatch = new AST_Catch({
                 start   : start,
                 argname : name,
-                body    : block_(),
+                body    : block_(true),
                 end     : prev()
             });
         }
@@ -1037,7 +1039,7 @@ function parse($TEXT, exigent_mode) {
             next();
             bfinally = new AST_Finally({
                 start : start,
-                body  : block_(),
+                body  : block_(true),
                 end   : prev()
             });
         }
index 05585fe..a017056 100644 (file)
@@ -7,7 +7,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
     // times on the same tree.
 
     // pass 1: setup scope chaining and handle definitions
-    var scope = null;
+    var scope = this.parent_scope;
     var labels = {};
     var tw = new TreeWalker(function(node, descend){
         if (node instanceof AST_Scope) {