Fix parsing regexp after unary-prefix operator
authorMihai Bazon <mihai@bazon.net>
Mon, 2 Sep 2013 06:56:27 +0000 (09:56 +0300)
committerMihai Bazon <mihai@bazon.net>
Mon, 2 Sep 2013 06:56:27 +0000 (09:56 +0300)
++/x/.y

Fix #284

lib/parse.js

index 48ab216..cc80a93 100644 (file)
@@ -688,12 +688,16 @@ function parse($TEXT, options) {
         };
     };
 
-    var statement = embed_tokens(function() {
-        var tmp;
+    function handle_regexp() {
         if (is("operator", "/") || is("operator", "/=")) {
             S.peeked = null;
             S.token = S.input(S.token.value.substr(1)); // force regexp
         }
+    };
+
+    var statement = embed_tokens(function() {
+        var tmp;
+        handle_regexp();
         switch (S.token.type) {
           case "string":
             var dir = S.in_directives, stat = simple_statement();
@@ -1279,6 +1283,7 @@ function parse($TEXT, options) {
         var start = S.token;
         if (is("operator") && UNARY_PREFIX(start.value)) {
             next();
+            handle_regexp();
             var ex = make_unary(AST_UnaryPrefix, start.value, maybe_unary(allow_calls));
             ex.start = start;
             ex.end = prev();