]> code.delx.au - gnu-emacs-elpa/commitdiff
Allow 'in' operator inside 'for' init when unambiguous
authorDmitry Gutov <dgutov@yandex.ru>
Mon, 4 Aug 2014 03:31:02 +0000 (07:31 +0400)
committerDmitry Gutov <dgutov@yandex.ru>
Mon, 4 Aug 2014 03:31:02 +0000 (07:31 +0400)
Fixes #155

js2-mode.el
tests/parser.el

index e93925820378e26bc32e5111ff2b8cda910a433f..62a9da4f63b9b6384ab6fc41586d951f97266bac 100644 (file)
@@ -8535,7 +8535,8 @@ If NODE is non-nil, it is the AST node associated with the symbol."
     (if (and (>= js2-language-version 200)
              (js2-match-token js2-FOR))
         (js2-parse-generator-comp px-pos)
-      (let* ((expr (js2-parse-expr))
+      (let* ((js2-in-for-init nil)
+             (expr (js2-parse-expr))
              (pn (make-js2-paren-node :pos px-pos
                                       :expr expr
                                       :len (- (js2-current-token-end)
@@ -8617,7 +8618,7 @@ If NODE is non-nil, it is the AST node associated with the symbol."
         c-pos)
     (when (js2-match-token js2-HOOK)
       (setq q-pos (- (js2-current-token-beg) pos)
-            if-true (js2-parse-assign-expr))
+            if-true (let (js2-in-for-init) (js2-parse-assign-expr)))
       (js2-must-match js2-COLON "msg.no.colon.cond")
       (setq c-pos (- (js2-current-token-beg) pos)
             if-false (js2-parse-assign-expr)
index 2e492a2fe19e86a89f3ca72524c1dd383958f66b..389d686d6f110c972b69f322c77ec13da271af97 100644 (file)
@@ -115,6 +115,12 @@ the test."
 (js2-deftest-parse parenthesized-expression
   "(1 + 2);")
 
+(js2-deftest-parse for-with-in-operator-in-parens
+  "for (var y = (0 in []) in {}) {\n}")
+
+(js2-deftest-parse for-with-in-operator-in-cond
+  "for (var y = 1 ? 0 in [] : false in {}) {\n}")
+
 ;;; Callers of `js2-valid-prop-name-token'
 
 (js2-deftest-parse parse-property-access-when-not-keyword