branch: master
commit f1edac7db39c7ef433f9d597c71014a90fd61488
Author: Jackson Ray Hamilton <[email protected]>
Commit: Jackson Ray Hamilton <[email protected]>
Don't treat a block-scoped const as redeclaration
---
js2-mode.el | 8 ++++++--
tests/parser.el | 8 +++++---
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 18cda80..5745dc5 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -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))))
diff --git a/tests/parser.el b/tests/parser.el
index 93c47ab..b9c9c68 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -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