emacs-elpa-diffs
[Top][All Lists]
Advanced

[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))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]