dgutov pushed a commit to branch master
in repository elpa.
commit aef2c811ac24750ea8a923708eddf82a1f34bd26
Author: Dmitry Gutov <[email protected]>
Date: Mon Aug 4 07:31:02 2014 +0400
Allow 'in' operator inside 'for' init when unambiguous
Fixes #155
---
js2-mode.el | 5 +++--
tests/parser.el | 6 ++++++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index e939258..62a9da4 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -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)
diff --git a/tests/parser.el b/tests/parser.el
index 2e492a2..389d686 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -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