[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master fae5776 01/22: Check that the let declaration comes before
From: |
Dmitry Gutov |
Subject: |
[elpa] master fae5776 01/22: Check that the let declaration comes before the reference |
Date: |
Fri, 24 Apr 2015 02:57:07 +0000 |
branch: master
commit fae57760064e25fd1b307a8f6b117c41eae45320
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Check that the let declaration comes before the reference
Implementing, more or less, the ES6 "temporal dead zone" for let.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let
https://bugzilla.mozilla.org/show_bug.cgi?id=1001090
---
js2-mode.el | 18 ++++++++++++------
1 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 8133903..bef5e61 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -2313,19 +2313,25 @@ Returns nil if there is no enclosing scope node."
(setq parent (js2-node-parent parent)))
parent))
-(defun js2-get-defining-scope (scope name)
+(defun js2-get-defining-scope (scope name &optional point)
"Search up scope chain from SCOPE looking for NAME, a string or symbol.
-Returns `js2-scope' in which NAME is defined, or nil if not found."
+Returns `js2-scope' in which NAME is defined, or nil if not found.
+
+If POINT is non-nil, and if the found declaration type is
+`js2-LET', also check that the declaration node is before POINT."
(let ((sym (if (symbolp name)
name
(intern name)))
- table
result
(continue t))
(while (and scope continue)
(if (or
- (and (setq table (js2-scope-symbol-table scope))
- (assq sym table))
+ (let ((entry (cdr (assq sym (js2-scope-symbol-table scope)))))
+ (and entry
+ (or (not point)
+ (not (eq js2-LET (js2-symbol-decl-type entry)))
+ (>= point
+ (js2-node-abs-pos (js2-symbol-ast-node entry))))))
(and (eq sym 'arguments)
(js2-function-node-p scope)))
(setq continue nil
@@ -7034,7 +7040,7 @@ it is considered declared."
(unless (or (member name js2-global-externs)
(member name js2-default-externs)
(member name js2-additional-externs)
- (js2-get-defining-scope scope name))
+ (js2-get-defining-scope scope name pos))
(js2-report-warning "msg.undeclared.variable" name pos (- end pos)
'js2-external-variable))))
(setq js2-recorded-identifiers nil)))
- [elpa] master updated (c10ba4b -> 54df259), Dmitry Gutov, 2015/04/23
- [elpa] master fae5776 01/22: Check that the let declaration comes before the reference,
Dmitry Gutov <=
- [elpa] master dd2106b 02/22: Merge branch 'let-temporal-dz', Dmitry Gutov, 2015/04/23
- [elpa] master 28853c9 03/22: do auto semicolon insert on function exports, Dmitry Gutov, 2015/04/23
- [elpa] master dfad0d5 04/22: Merge pull request #211 from cowboyd/no-semicolon-warning-on-function-export, Dmitry Gutov, 2015/04/23
- [elpa] master 02fea21 06/22: Merge pull request #213 from lelit/typos, Dmitry Gutov, 2015/04/23
- [elpa] master bf454ef 05/22: Fix typos in comments and docstrings, Dmitry Gutov, 2015/04/23
- [elpa] master 7bf479a 08/22: Fix js2-paren-node length, Dmitry Gutov, 2015/04/23
- [elpa] master 4d8ec67 07/22: Rely on bogus scopes less, Dmitry Gutov, 2015/04/23
- [elpa] master 4a1b4e8 09/22: Parse without error first method in a class with keyword name, Dmitry Gutov, 2015/04/23
- [elpa] master 90a9056 10/22: ...or any following one, Dmitry Gutov, 2015/04/23
- [elpa] master bc61ce0 11/22: Fix off-by-one error for comment node length, Dmitry Gutov, 2015/04/23