[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master fbe58dc 18/49: Compute externs on demand
From: |
Dmitry Gutov |
Subject: |
[elpa] master fbe58dc 18/49: Compute externs on demand |
Date: |
Mon, 16 Jan 2017 15:35:47 +0000 (UTC) |
branch: master
commit fbe58dc1b3ac2629d5921b712d5a8514635e3af8
Author: Julian Kniephoff <address@hidden>
Commit: Julian Kniephoff <address@hidden>
Compute externs on demand
Instead of only taking into account the `js2-include-?-externs`
variables when initializing the mode, compute what was
`js2-default-externs` before every time we highlight undeclared
identifiers.
Closes #375
---
js2-mode.el | 67 +++++++++++++++++++++++------------------------------------
1 file changed, 26 insertions(+), 41 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 3f18bc1..08f4101 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -115,7 +115,7 @@
decodeURI decodeURIComponent encodeURI
encodeURIComponent escape eval isFinite isNaN
parseFloat parseInt undefined unescape))
-"Ecma-262 externs. Included in `js2-externs' by default.")
+"Ecma-262 externs. Never highlighted by `js2-highlight-undeclared-vars'.")
(defvar js2-browser-externs
(mapcar 'symbol-name
@@ -789,28 +789,10 @@ Will only be used when we finish implementing the
interpreter.")
(defcustom js2-global-externs nil
"A list of any extern names you'd like to consider always declared.
This list is global and is used by all `js2-mode' files.
-You can create buffer-local externs list using `js2-additional-externs'.
-
-There is also a buffer-local variable `js2-default-externs',
-which is initialized by default to include the Ecma-262 externs
-and the standard browser externs. The three lists are all
-checked during highlighting."
+You can create buffer-local externs list using `js2-additional-externs'."
:type 'list
:group 'js2-mode)
-(js2-deflocal js2-default-externs nil
- "Default external declarations.
-
-These are currently only used for highlighting undeclared variables,
-which only worries about top-level (unqualified) references.
-As js2-mode's processing improves, we will flesh out this list.
-
-The initial value is set to `js2-ecma-262-externs', unless some
-of the `js2-include-?-externs' variables are set to t, in which
-case the browser, Rhino and/or Node.js externs are also included.
-
-See `js2-additional-externs' for more information.")
-
(defcustom js2-include-browser-externs t
"Non-nil to include browser externs in the master externs list.
If you work on JavaScript files that are not intended for browsers,
@@ -834,7 +816,7 @@ See `js2-additional-externs' for more information about
externs."
(js2-deflocal js2-additional-externs nil
"A buffer-local list of additional external declarations.
It is used to decide whether variables are considered undeclared
-for purposes of highlighting.
+for purposes of highlighting. See `js2-highlight-undeclared-vars'.
Each entry is a Lisp string. The string should be the fully qualified
name of an external entity. All externs should be added to this list,
@@ -7092,14 +7074,33 @@ later. NODE must be a name node."
We have to wait until entire buffer is parsed, since JavaScript permits var
decls to occur after they're used.
-If any undeclared var name is in `js2-externs' or `js2-additional-externs',
-it is considered declared."
- (let (name)
+Some identifiers may be assumed to be externally defined.
+These externs are not highlighted, even if there is no declaration
+for them in the source code.
+The list of externs consists of the following:
+- the list `js2-ecma262-externs' for basic names from the ECMAScript language
standard
+- depending on the buffer-local variables `js2-include-?-externs'
+ the corresponding `js2-?-externs' to add names for certain environments
+ like the browser or node/rhino
+- two user-customizable lists `js2-global-externs' and `js2-additional-externs'
+ of which the latter is a buffer-local variable
+
+See especially `js2-additional-externs' for further details about externs."
+ (let ((default-externs
+ (append js2-ecma-262-externs
+ (if js2-include-browser-externs js2-browser-externs)
+ (if (and js2-include-browser-externs
+ (>= js2-language-version 200)) js2-harmony-externs)
+ (if js2-include-rhino-externs js2-rhino-externs)
+ (if js2-include-node-externs js2-node-externs)
+ (if (or js2-include-browser-externs js2-include-node-externs)
+ js2-typed-array-externs)))
+ name)
(dolist (entry js2-recorded-identifiers)
(cl-destructuring-bind (name-node scope pos end) entry
(setq name (js2-name-node-name name-node))
(unless (or (member name js2-global-externs)
- (member name js2-default-externs)
+ (member name default-externs)
(member name js2-additional-externs)
(js2-get-defining-scope scope name pos))
(js2-report-warning "msg.undeclared.variable" name pos (- end pos)
@@ -7259,19 +7260,6 @@ are ignored."
(remove-hook 'js2-post-parse-callbacks
#'js2-highlight-unused-variables t)))
-(defun js2-set-default-externs ()
- "Set the value of `js2-default-externs' based on the various
-`js2-include-?-externs' variables."
- (setq js2-default-externs
- (append js2-ecma-262-externs
- (if js2-include-browser-externs js2-browser-externs)
- (if (and js2-include-browser-externs
- (>= js2-language-version 200)) js2-harmony-externs)
- (if js2-include-rhino-externs js2-rhino-externs)
- (if js2-include-node-externs js2-node-externs)
- (if (or js2-include-browser-externs js2-include-node-externs)
- js2-typed-array-externs))))
-
(defun js2-apply-jslint-globals ()
(setq js2-additional-externs
(nconc (js2-get-jslint-globals)
@@ -11421,7 +11409,6 @@ highlighting features of `js2-mode'."
(set (make-local-variable 'max-lisp-eval-depth)
(max max-lisp-eval-depth 3000))
(setq next-error-function #'js2-next-error)
- (js2-set-default-externs)
;; Experiment: make reparse-delay longer for longer files.
(if (cl-plusp js2-dynamic-idle-timer-adjust)
(setq js2-idle-timer-delay
@@ -11600,8 +11587,6 @@ Selecting an error will jump it to the corresponding
source-buffer error.
js2-mode-buffer-dirty-p t
js2-mode-parsing nil)
- (js2-set-default-externs)
-
(when js2-include-jslint-globals
(add-hook 'js2-post-parse-callbacks 'js2-apply-jslint-globals nil t))
- [elpa] master a91e357 40/49: Create a separate scope for switch statements, (continued)
- [elpa] master a91e357 40/49: Create a separate scope for switch statements, Dmitry Gutov, 2017/01/16
- [elpa] master 4d35da5 30/49: Fix the fix (error detection), Dmitry Gutov, 2017/01/16
- [elpa] master 31a2399 44/49: Mostly cosmetic, split js2--classify-variables in three simpler functions, Dmitry Gutov, 2017/01/16
- [elpa] master 3725fcf 35/49: Handle other cases of destructuring assignments/initializations, Dmitry Gutov, 2017/01/16
- [elpa] master dad7d09 32/49: feat: add js2-comments-between func, Dmitry Gutov, 2017/01/16
- [elpa] master 523b3cb 38/49: Add a STRICT parameter to js2--collect-declared-symbols, Dmitry Gutov, 2017/01/16
- [elpa] master 1f12517 10/49: Merge pull request #353 from kaushalmodi/js2-jsx-mode-docstring-fix, Dmitry Gutov, 2017/01/16
- [elpa] master 454b242 20/49: Update NEWS.md, Dmitry Gutov, 2017/01/16
- [elpa] master 2d0dc5e 43/49: Cosmetic, reformat to stay within the preferred 80 columns limit, Dmitry Gutov, 2017/01/16
- [elpa] master ff072bf 49/49: Merge commit '03c679eb9914d58d7d9b7afc2036c482a9a01236' from js2-mode, Dmitry Gutov, 2017/01/16
- [elpa] master fbe58dc 18/49: Compute externs on demand,
Dmitry Gutov <=
- [elpa] master d3dd406 46/49: fix: copyright year of tests/comsume.el, Dmitry Gutov, 2017/01/16
- [elpa] master cdbdca4 39/49: Rewrite js2--classify-variables, focusing only on name nodes, Dmitry Gutov, 2017/01/16
- [elpa] master 82bbd97 25/49: Move it up, Dmitry Gutov, 2017/01/16
- [elpa] master c303773 21/49: Fix dead link in the documentation, Dmitry Gutov, 2017/01/16
- [elpa] master 5855a45 22/49: Merge pull request #380 from JulianKniephoff/fix-dead-doc-link-js2-include-jslint-globals, Dmitry Gutov, 2017/01/16
- [elpa] master 94b2721 31/49: Merge pull request #385 from mishoo/master, Dmitry Gutov, 2017/01/16
- [elpa] master 91e722a 27/49: Merge pull request #381 from mgiles/template-pos, Dmitry Gutov, 2017/01/16
- [elpa] master 3106e3c 37/49: Fix arrow expression function's length, Dmitry Gutov, 2017/01/16
- [elpa] master 6f2d51b 41/49: Fix the breakage from the previous commit, Dmitry Gutov, 2017/01/16
- [elpa] master 03c679e 48/49: Bump the version, Dmitry Gutov, 2017/01/16