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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master c5cc951 22/22: Merge commit 'ed955e7f1608cfd2d2713129d65f5


From: Dmitry Gutov
Subject: [elpa] master c5cc951 22/22: Merge commit 'ed955e7f1608cfd2d2713129d65f5fd734842ae4' from js2-mode
Date: Tue, 19 Feb 2019 06:06:49 -0500 (EST)

branch: master
commit c5cc9510df3fe2d04902614f90c2a5ec946defbb
Merge: ddd6b22 ed955e7
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Merge commit 'ed955e7f1608cfd2d2713129d65f5fd734842ae4' from js2-mode
---
 packages/js2-mode/NEWS.md             |   4 +
 packages/js2-mode/README.md           |   2 +-
 packages/js2-mode/js2-mode.el         | 150 ++++++++++++++++++++--------------
 packages/js2-mode/tests/navigation.el |  60 ++++++++++++--
 packages/js2-mode/tests/parser.el     |  30 ++++++-
 5 files changed, 178 insertions(+), 68 deletions(-)

diff --git a/packages/js2-mode/NEWS.md b/packages/js2-mode/NEWS.md
index d66f25e..c120be7 100644
--- a/packages/js2-mode/NEWS.md
+++ b/packages/js2-mode/NEWS.md
@@ -1,5 +1,9 @@
 # History of user-visible changes
 
+## 2019-02-19
+
+* Changed the default of `js2-strict-trailing-comma-warning` to nil.
+
 ## 2018-03-01
 
 * Support single-line JSDocs.
diff --git a/packages/js2-mode/README.md b/packages/js2-mode/README.md
index 506c2d4..755a818 100644
--- a/packages/js2-mode/README.md
+++ b/packages/js2-mode/README.md
@@ -3,7 +3,7 @@ About [![Build 
Status](https://travis-ci.org/mooz/js2-mode.svg?branch=master)](h
 
 Improved JavaScript editing mode for GNU Emacs ([description 
here](http://elpa.gnu.org/packages/js2-mode.html)).
 
-For some of the latest changes, see [latest user-visible 
changes](https://github.com/mooz/js2-mode/wiki/Latest-user-visible-changes).
+For some of the latest changes, see [latest user-visible 
changes](https://github.com/mooz/js2-mode/blob/master/NEWS.md).
 
 Installation
 ======
diff --git a/packages/js2-mode/js2-mode.el b/packages/js2-mode/js2-mode.el
index 8def8f2..3f789fa 100644
--- a/packages/js2-mode/js2-mode.el
+++ b/packages/js2-mode/js2-mode.el
@@ -7,7 +7,7 @@
 ;;         Dmitry Gutov <address@hidden>
 ;; URL:  https://github.com/mooz/js2-mode/
 ;;       http://code.google.com/p/js2-mode/
-;; Version: 20180301
+;; Version: 20190219
 ;; Keywords: languages, javascript
 ;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
 
@@ -290,7 +290,7 @@ even if this flag is non-nil."
   :type 'boolean
   :group 'js2-mode)
 
-(defcustom js2-strict-trailing-comma-warning t
+(defcustom js2-strict-trailing-comma-warning nil
   "Non-nil to warn about trailing commas in array literals.
 Ecma-262-5.1 allows them, but older versions of IE raise an error."
   :type 'boolean
@@ -853,6 +853,9 @@ Your post-parse callback may of course also use the simpler 
and
 faster (but perhaps less robust) approach of simply scanning the
 buffer text for your imports, using regular expressions.")
 
+(put 'js2-additional-externs 'safe-local-variable
+     (lambda (val) (cl-every #'stringp val)))
+
 ;; SKIP:  decompiler
 ;; SKIP:  encoded-source
 
@@ -4548,8 +4551,11 @@ If N has no parent pointer, returns N."
 
 (defsubst js2-node-short-name (n)
   "Return the short name of node N as a string, e.g. `js2-if-node'."
-  (substring (symbol-name (aref n 0))
-             (length "cl-struct-")))
+  (let ((name (symbol-name (aref n 0))))
+    (if (string-prefix-p "cl-struct-" name)
+        (substring (symbol-name (aref n 0))
+                   (length "cl-struct-"))
+      name)))
 
 (defun js2-node-child-list (node)
   "Return the child list for NODE, a Lisp list of nodes.
@@ -7192,58 +7198,71 @@ key of a literal object."
         (let ((left (js2-prop-get-node-left parent)))
           (when (js2-name-node-p left)
             (js2--add-or-update-symbol left nil t vars)))
-      (let ((granparent parent)
-            var-init-node
-            assign-node
-            object-key         ; is name actually an object prop key?
-            declared           ; is it declared in narrowest scope?
-            assigned           ; does it get assigned or initialized?
-            (used (null function-param)))
-        ;; Determine the closest var-init-node and assign-node: this
-        ;; is needed because the name may be within a "destructured"
-        ;; declaration/assignment, so we cannot just take its parent
-        (while (and granparent (not (js2-scope-p granparent)))
-          (cond
-           ((js2-var-init-node-p granparent)
-            (when (null var-init-node)
-              (setq var-init-node granparent)))
-           ((js2-assign-node-p granparent)
-            (when (null assign-node)
-              (setq assign-node granparent))))
-          (setq granparent (js2-node-parent granparent)))
-
-        ;; If we are within a var-init-node, determine if the name is
-        ;; declared and initialized
-        (when var-init-node
-          (let ((result (js2--examine-variable parent node var-init-node)))
-            (setq declared (car result)
-                  assigned (cadr result)
-                  object-key (car (cddr result)))))
-
-        ;; Ignore literal object keys, which are not really variables
-        (unless object-key
-          (when function-param
-            (setq assigned ?P))
-
-          (when (null assigned)
+      ;; If the node is the external name of an export-binding-node, and
+      ;; it is different from the local name, ignore it
+      (when (or (not (js2-export-binding-node-p parent))
+                (not (and (eq (js2-export-binding-node-extern-name parent) 
node)
+                          (not (eq (js2-export-binding-node-local-name parent) 
node)))))
+        (let ((granparent parent)
+              var-init-node
+              assign-node
+              object-key         ; is name actually an object prop key?
+              declared           ; is it declared in narrowest scope?
+              assigned           ; does it get assigned or initialized?
+              (used (null function-param)))
+          ;; Determine the closest var-init-node and assign-node: this
+          ;; is needed because the name may be within a "destructured"
+          ;; declaration/assignment, so we cannot just take its parent
+          (while (and granparent (not (js2-scope-p granparent)))
             (cond
-             ((js2-for-in-node-p parent)
-              (setq assigned (eq node (js2-for-in-node-iterator parent))
-                    used (not assigned)))
-             ((js2-function-node-p parent)
-              (setq assigned t
-                    used (js2-wrapper-function-p parent)))
-             (assign-node
-              (setq assigned (memq node
-                                   (js2--collect-target-symbols
-                                    (js2-assign-node-left assign-node)
-                                    nil))
-                    used (not assigned)))))
-
-          (when declared
-            (setq used nil))
-
-          (js2--add-or-update-symbol node assigned used vars))))))
+             ((js2-var-init-node-p granparent)
+              (when (null var-init-node)
+                (setq var-init-node granparent)))
+             ((js2-assign-node-p granparent)
+              (when (null assign-node)
+                (setq assign-node granparent))))
+            (setq granparent (js2-node-parent granparent)))
+
+          ;; If we are within a var-init-node, determine if the name is
+          ;; declared and initialized
+          (when var-init-node
+            (let ((result (js2--examine-variable parent node var-init-node)))
+              (setq declared (car result)
+                    assigned (cadr result)
+                    object-key (car (cddr result)))))
+
+          ;; Ignore literal object keys, which are not really variables
+          (unless object-key
+            (when function-param
+              (setq assigned ?P))
+
+            (when (null assigned)
+              (cond
+               ((js2-for-in-node-p parent)
+                (setq assigned (eq node (js2-for-in-node-iterator parent))
+                      used (not assigned)))
+               ((js2-function-node-p parent)
+                (setq assigned t
+                      used (js2-wrapper-function-p parent)))
+               ((js2-export-binding-node-p parent)
+                (if (js2-import-clause-node-p (js2-node-parent parent))
+                    (setq declared t
+                          assigned t)
+                  (setq used t)))
+               ((js2-namespace-import-node-p parent)
+                (setq assigned t
+                      used nil))
+               (assign-node
+                (setq assigned (memq node
+                                     (js2--collect-target-symbols
+                                      (js2-assign-node-left assign-node)
+                                      nil))
+                      used (not assigned)))))
+
+            (when declared
+              (setq used nil))
+
+            (js2--add-or-update-symbol node assigned used vars)))))))
 
 (defun js2--classify-variables ()
   "Collect and classify variables declared or used within js2-mode-ast.
@@ -7620,7 +7639,7 @@ For instance, processing a nested scope requires a parent 
function node."
   (let (result fn parent-qname p elem)
     (dolist (entry js2-imenu-recorder)
       ;; function node goes first
-      (cl-destructuring-bind (current-fn &rest (&whole chain head &rest _)) 
entry
+      (cl-destructuring-bind (current-fn &rest (&whole chain head &rest)) entry
         ;; Examine head's defining scope:
         ;; Pre-processed chain, or top-level/external, keep as-is.
         (if (or (stringp head) (js2-node-top-level-decl-p head))
@@ -10571,7 +10590,9 @@ array-literals, array comprehensions and regular 
expressions."
     (setq node (if js2-compiler-xml-available
                    (js2-parse-property-name nil name 0)
                  (js2-create-name-node 'check-activation nil name)))
-    (if js2-highlight-external-variables
+    (if (and js2-highlight-external-variables
+             ;; FIXME: What's TRT for `js2-xml-ref-node'?
+             (js2-name-node-p node))
         (js2-record-name-node node))
     node))
 
@@ -12388,6 +12409,8 @@ move backward across N balanced expressions."
     (let (forward-sexp-function
           node (start (point)) pos lp rp child)
       (cond
+       ((js2-string-node-p (js2-node-at-point))
+        (forward-sexp arg))
        ;; backward-sexp
        ;; could probably make this better for some cases:
        ;;  - if in statement block (e.g. function body), go to parent
@@ -12555,8 +12578,11 @@ destroying the region selection."
         (goto-char (cl-cadadr e))))))
 
 (defun js2-mode-create-imenu-index ()
-  "Return an alist for `imenu--index-alist'."
-  ;; This is built up in `js2-parse-record-imenu' during parsing.
+  "Returns an alist for `imenu--index-alist'. Returns nil on first
+scan if buffer size > `imenu-auto-rescan-maxout'."
+  (when (and (not js2-mode-ast)
+             (<= (buffer-size) imenu-auto-rescan-maxout))
+      (js2-reparse))
   (when js2-mode-ast
     ;; if we have an ast but no recorder, they're requesting a rescan
     (unless js2-imenu-recorder
@@ -12716,8 +12742,10 @@ it marks the next defun after the ones already marked."
       (error "Node is not a supported jump node"))
     (push (or (and names (pop names))
               (unless (and (js2-object-prop-node-p parent)
-                           (eq node (js2-object-prop-node-left parent)))
-                node)) names)
+                           (eq node (js2-object-prop-node-left parent))
+                           (not (js2-node-get-prop parent 'SHORTHAND)))
+                node)
+              (error "Node is not a supported jump node")) names)
     (setq node-init (js2-search-scope node names))
 
     ;; todo: display list of results in buffer
diff --git a/packages/js2-mode/tests/navigation.el 
b/packages/js2-mode/tests/navigation.el
index d7a8314..26431da 100644
--- a/packages/js2-mode/tests/navigation.el
+++ b/packages/js2-mode/tests/navigation.el
@@ -22,15 +22,20 @@
 (require 'ert)
 (require 'js2-mode)
 
-(cl-defun js2-navigation-helper (buffer-content &optional expected-point 
(point-offset 1))
+(cl-defun js2-navigation-helper (buffer-content &optional expected-point 
(point-offset 1) expected-error-msg)
   (with-temp-buffer
     (insert buffer-content)
-    (let ((start-point (or (- (point) point-offset))))
+    (let ((start-point (or (- (point) point-offset)))
+          actual-error-msg)
       (js2-mode)
       (goto-char start-point)
-      (ignore-errors (js2-jump-to-definition))
+      (if expected-error-msg
+          (setq actual-error-msg
+                (cadr (should-error (js2-jump-to-definition) :type 'error)))
+        (js2-jump-to-definition))
       (print (format "%d %d" (point) start-point))
-      (should (= (point) (or expected-point start-point))))))
+      (should (= (point) (or expected-point start-point)))
+      (should (string= actual-error-msg expected-error-msg)))))
 
 (ert-deftest js2-jump-to-var ()
   (js2-navigation-helper "var soup = 2; soup" 5))
@@ -45,7 +50,8 @@
   (js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"}; 
aObject.prop1" 16))
 
 (ert-deftest js2-no-jump-to-object-property ()
-  (js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"}; 
anotherObject.prop1"))
+  (js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"}; 
anotherObject.prop1"
+                         61 1 "No jump location found"))
 
 (ert-deftest js2-jump-to-nested-property ()
   (js2-navigation-helper "var aObject = {prop1: {prop2: { prop3: 4}}}; 
aObject.prop1.prop2.prop3" 33))
@@ -58,3 +64,47 @@
 
 (ert-deftest js2-jump-to-property-object-property ()
   (js2-navigation-helper "aObject.value = {prop:1};aObject.value.prop" 18))
+
+(ert-deftest js2-jump-to-function-definition-inside-object-value ()
+  (js2-navigation-helper
+   "function aFunction(p1, p2) {return p1+p2}; module.exports = 
{aFunction:aFunction};" 1 6))
+
+(ert-deftest js2-no-jump-to-function-definition-object-property ()
+  (js2-navigation-helper
+   "function aFunction(p1, p2) {return p1+p2}; module.exports = 
{aFunction:aFunction};"
+   67 16 "Node is not a supported jump node"))
+
+(ert-deftest js2-jump-to-function-inside-property-value-syntax ()
+  (js2-navigation-helper "function aFunction(p1, p2) {return p1+p2}; 
module.exports = {aFunction};" 1 6))
+
+
+;; forward-sexp
+
+(defun js2-test-forward-sexp (pre-point skipped after-sexp)
+  "Test `js2-mode-forward-sexp'.
+The test buffer's contents are set to the concatenation of
+PRE-POINT, SKIPPED, and AFTER-SEXP.  Point is placed after
+PRE-POINT, and `forward-sexp' is called.  Then point should be
+after SKIPPED."
+  (with-temp-buffer
+    (insert pre-point skipped after-sexp)
+    (js2-mode)
+    (goto-char (1+ (length pre-point)))
+    (forward-sexp)
+    (should (= (point) (+ 1 (length pre-point) (length skipped))))))
+
+(ert-deftest js2-forward-sexp-skip-semi ()
+  "Ensure expr-stmt-nodes' semicolons are skipped over."
+  (js2-test-forward-sexp "" "const s = 123;" ""))
+
+(ert-deftest js2-forward-sexp-inside-string ()
+  "Test forward sexp inside a string."
+  (js2-test-forward-sexp "const s = 'some " "(string contents)" " xyz';"))
+
+(ert-deftest js2-backward-sexp-inside-string ()
+  "Test backward sexp inside a string."
+  (with-temp-buffer
+    (insert "const s = 'some (string contents) ")
+    (save-excursion (insert "xyz';"))
+    (backward-sexp)
+    (should (= (point) 17))))
diff --git a/packages/js2-mode/tests/parser.el 
b/packages/js2-mode/tests/parser.el
index 1853f03..9137940 100644
--- a/packages/js2-mode/tests/parser.el
+++ b/packages/js2-mode/tests/parser.el
@@ -635,7 +635,7 @@ the test."
       (should name)
       (should (equal "default" (js2-name-node-name name))))))
 
-(js2-deftest parse-namepsace-import "* as lib;"
+(js2-deftest parse-namespace-import "* as lib;"
   (js2-init-scanner)
   (should (js2-match-token js2-MUL))
   (let ((namespace-import (js2-parse-namespace-import)))
@@ -1358,6 +1358,34 @@ the test."
   "function foo() { let {foo: missing = 10} = {}; }"
   '("address@hidden:U" "address@hidden:U"))
 
+(js2-deftest-classify-variables import-unused
+  "import foo from 'module';"
+  '("address@hidden:U"))
+
+(js2-deftest-classify-variables named-import-unused
+  "import foo as bar from 'module';"
+  '("address@hidden:U"))
+
+(js2-deftest-classify-variables import-unused-many
+  "import {a,b} from 'module';"
+  '("address@hidden:U" "address@hidden:U"))
+
+(js2-deftest-classify-variables named-import-unused-many
+  "import {a as b, c as d} from 'module';"
+  '("address@hidden:U" "address@hidden:U"))
+
+(js2-deftest-classify-variables import-export
+  "import foo from 'module'; export {foo}"
+  '("address@hidden:I" 35))
+
+(js2-deftest-classify-variables import-namespace-unused
+  "import * as foo from 'module';"
+  '("address@hidden:U"))
+
+(js2-deftest-classify-variables import-namespace-used
+  "import * as foo from 'module'; function bar() { return foo.x; }"
+  '("address@hidden:I" 56 "address@hidden:U"))
+
 ;; Side effects
 
 (js2-deftest no-side-effects-at-top-level



reply via email to

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