[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master df06798 23/49: Merge pull request #378 from JulianKniephof
From: |
Dmitry Gutov |
Subject: |
[elpa] master df06798 23/49: Merge pull request #378 from JulianKniephoff/include-externs-locally |
Date: |
Mon, 16 Jan 2017 15:35:48 +0000 (UTC) |
branch: master
commit df06798579b36b8ef0b793a4cd6733aa09763d18
Merge: 5855a45 454b242
Author: Dmitry Gutov <address@hidden>
Commit: GitHub <address@hidden>
Merge pull request #378 from JulianKniephoff/include-externs-locally
Compute externs on demand
---
NEWS.md | 3 +++
js2-mode.el | 67 +++++++++++++++++++++++------------------------------------
2 files changed, 29 insertions(+), 41 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index 0d69ca8..d309168 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -3,6 +3,9 @@
## Next
* Support for ES7 exponentiation operator.
+* The `js2-include-?-externs` are now evaluated on demand.
+ In particular, they can now effectively be used
+ as file- or directory-local variables.
## 2016-06-23
diff --git a/js2-mode.el b/js2-mode.el
index 55275a6..518fd26 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 (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)
+ (if js2-include-browser-externs js2-browser-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 49f9761 08/49: js2-jsdoc-arg-tag-regexp: Recognize @module, (continued)
- [elpa] master 49f9761 08/49: js2-jsdoc-arg-tag-regexp: Recognize @module, Dmitry Gutov, 2017/01/16
- [elpa] master e45206b 11/49: js2-parse-class: Convert positions to relative for NAME and EXTENDS, too, Dmitry Gutov, 2017/01/16
- [elpa] master bea6942 13/49: Unbind js2-mode-show-node, Dmitry Gutov, 2017/01/16
- [elpa] master c0801b2 12/49: Propertize regexp literals like js-mode does, Dmitry Gutov, 2017/01/16
- [elpa] master 9a8aaa9 28/49: Fix length of name in namespace-import nodes, Dmitry Gutov, 2017/01/16
- [elpa] master 44c289f 24/49: Copy edits, Dmitry Gutov, 2017/01/16
- [elpa] master b6d9301 17/49: Merge pull request #377 from XeCycle/memfn-delete, Dmitry Gutov, 2017/01/16
- [elpa] master 64ec0a2 14/49: Allow newline in globals declaration, Dmitry Gutov, 2017/01/16
- [elpa] master 2801681 26/49: Fix "pos" argument in template node constructors, Dmitry Gutov, 2017/01/16
- [elpa] master 712dfb0 29/49: Merge pull request #384 from mishoo/master, Dmitry Gutov, 2017/01/16
- [elpa] master df06798 23/49: Merge pull request #378 from JulianKniephoff/include-externs-locally,
Dmitry Gutov <=
- [elpa] master 2a79649 33/49: Fix indentation after regexp in js2-old-indent.el, Dmitry Gutov, 2017/01/16
- [elpa] master f450de0 34/49: Handle destructuring assignments when classifying variables, Dmitry Gutov, 2017/01/16
- [elpa] master 90e37cd 45/49: Merge pull request #397 from lelit/issue393, Dmitry Gutov, 2017/01/16
- [elpa] master 9b63a13 16/49: Special methods should allow keywords as names, Dmitry Gutov, 2017/01/16
- [elpa] master 672e2da 07/49: js2-parse-mul-expr: Parse the right operand as exponentiation too, Dmitry Gutov, 2017/01/16
- [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