From: Dmitry Gutov Date: Mon, 4 Aug 2014 03:31:02 +0000 (+0400) Subject: Allow 'in' operator inside 'for' init when unambiguous X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/aef2c811ac24750ea8a923708eddf82a1f34bd26 Allow 'in' operator inside 'for' init when unambiguous Fixes #155 --- diff --git a/js2-mode.el b/js2-mode.el index e93925820..62a9da4f6 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 2e492a2fe..389d686d6 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