]> code.delx.au - gnu-emacs-elpa/commitdiff
Don't treat a block-scoped const as redeclaration
authorJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Mon, 8 Jun 2015 08:25:58 +0000 (01:25 -0700)
committerJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Mon, 8 Jun 2015 08:25:58 +0000 (01:25 -0700)
js2-mode.el
tests/parser.el

index 18cda80ce13d726ce7600792c61213d8d691d105..5745dc5dfb81c7b9d212460b5de5486f5ab0590c 100644 (file)
@@ -9559,8 +9559,12 @@ If NODE is non-nil, it is the AST node associated with the symbol."
          (len (if node (js2-node-len node))))
     (cond
      ((and symbol ; already defined
-           (or (= sdt js2-CONST) ; old version is const
-               (= decl-type js2-CONST) ; new version is const
+           (or (if js2-in-use-strict-directive
+                   ;; two const-bound vars in this block have same name
+                   (and (= sdt js2-CONST)
+                        (eq defining-scope js2-current-scope))
+                 (or (= sdt js2-CONST)          ; old version is const
+                     (= decl-type js2-CONST)))  ; new version is const
                ;; two let-bound vars in this block have same name
                (and (= sdt js2-LET)
                     (eq defining-scope js2-current-scope))))
index 93c47abe9503c3210728e1a6ba512f6edd91f82f..b9c9c689267a611f185e50c38646706a99b57aa9 100644 (file)
@@ -247,7 +247,7 @@ the test."
 (js2-deftest-parse function-with-rest-after-default-parameter
   "function foo(a = 1, ...rest) {\n}")
 
-;;; Strict identifiers
+;;; Strict mode errors
 
 (js2-deftest-parse function-bad-strict-parameters
   "'use strict';\nfunction foo(eval, {arguments}, bar) {\n}"
@@ -281,8 +281,6 @@ the test."
   "'use strict';\narguments = 'fufufu';"
   :syntax-error "arguments" :errors-count 1)
 
-;;; Strict syntax errors
-
 (js2-deftest-parse function-strict-with
   "'use strict';\nwith ({}) {}"
   :syntax-error "with" :errors-count 1)
@@ -295,6 +293,10 @@ the test."
   "'use strict';\nvar object = {a: 1, a: 2, 'a': 3, ['a']: 4, 1: 5, '1': 6, [1 + 1]: 7};"
   :syntax-error "a" :errors-count 4) ; "a" has 3 dupes, "1" has 1 dupe.
 
+;; errors... or lackthereof.
+(js2-deftest-parse function-strict-const-scope
+  "'use strict';\nconst a;\nif (1) {\n  const a;\n}")
+
 ;;; Spread operator
 
 (js2-deftest-parse spread-in-array-literal