update packages
This commit is contained in:
@@ -35,6 +35,10 @@
|
||||
(require 'cl-lib)
|
||||
(require 'js2-mode)
|
||||
|
||||
(eval-when-compile
|
||||
(when (<= emacs-major-version 26)
|
||||
(require 'subr-x)))
|
||||
|
||||
(defvar js2-imenu-extension-styles
|
||||
`((:framework jquery
|
||||
:call-re "\\_<\\(?:jQuery\\|\\$\\|_\\)\\.extend\\s-*("
|
||||
@@ -60,6 +64,14 @@
|
||||
:call-re "\\_<React\\.createClass\\s-*("
|
||||
:recorder js2-imenu-record-react-class)
|
||||
|
||||
(:framework mocha
|
||||
:call-re ,(rx line-start
|
||||
(* (syntax whitespace))
|
||||
(or "describe" "fdescribe" "describe.only")
|
||||
(* (syntax whitespace))
|
||||
"(")
|
||||
:recorder js2-imenu-record-mocha-describe)
|
||||
|
||||
(:framework sencha
|
||||
:call-re "^\\s-*Ext\\.define\\s-*("
|
||||
:recorder js2-imenu-record-sencha-class))
|
||||
@@ -112,6 +124,21 @@ Currently used for jQuery widgets, Dojo and Enyo declarations."
|
||||
:type 'boolean
|
||||
:group 'js2-imenu)
|
||||
|
||||
(defcustom js2-imenu-mocha-describe-node-names '("describe" "describe.only" "fdescribe")
|
||||
"List of strings starting a describe() node."
|
||||
:type '(repeat string)
|
||||
:group 'js2-imenu)
|
||||
|
||||
(defcustom js2-imenu-mocha-it-node-names '("it" "it.only" "fit")
|
||||
"List of strings starting a it() node."
|
||||
:type '(repeat string)
|
||||
:group 'js2-imenu)
|
||||
|
||||
(defcustom js2-imenu-mocha-hook-node-names '("beforeEach" "afterEach" "beforeAll" "afterAll")
|
||||
"List of strings starting a hook node (e.g., before and after hooks)."
|
||||
:type '(repeat string)
|
||||
:group 'js2-imenu)
|
||||
|
||||
;;;###autoload
|
||||
(defun js2-imenu-extras-setup ()
|
||||
(when js2-imenu-enabled-frameworks
|
||||
@@ -221,6 +248,151 @@ Currently used for jQuery widgets, Dojo and Enyo declarations."
|
||||
(list name-value))
|
||||
(js2-node-abs-pos methods))))))
|
||||
|
||||
(defun js2-imenu-record-mocha-describe ()
|
||||
"Populate `js2-imenu-recorder' with mocha-like describe/it/beforeEach/… nodes."
|
||||
(let ((node (js2-node-at-point (1- (point)))))
|
||||
(when (js2-imenu-extras--mocha-top-level-describe-p node)
|
||||
(js2-imenu-extras--mocha-visit-node node (list)))))
|
||||
|
||||
(defun js2-imenu-extras--mocha-visit-node (node qname)
|
||||
"Search NODE and its children for mocha test blocks.
|
||||
|
||||
If mocha test blocks are found (e.g., a describe() or it() block)
|
||||
they are added to `js2-imenu-recorder' with QNAME as prefix.
|
||||
|
||||
QNAME is a list of nodes representing the qualified name of
|
||||
NODE's parent. If NODE has no parent, QNAME is the empty list.
|
||||
The last item of QNAME is NODE's parent name while the item
|
||||
before that is NODE's grandparent name etc."
|
||||
(js2-visit-ast
|
||||
node
|
||||
(lambda (child end-p)
|
||||
(when (not end-p)
|
||||
(js2-imenu-extras--mocha-check-unknown-node child qname)))))
|
||||
|
||||
(defun js2-imenu-extras--mocha-check-unknown-node (node qname)
|
||||
"If NODE is a mocha test block, populate `js2-imenu-recorder'.
|
||||
|
||||
QNAME is the same as described in
|
||||
`js2-imenu-extras--mocha-visit-node'."
|
||||
(cond
|
||||
((js2-imenu-extras--mocha-describe-node-p node)
|
||||
(progn
|
||||
(js2-imenu-extras--mocha-visit-describe-node node qname)
|
||||
nil))
|
||||
((js2-imenu-extras--mocha-it-node-p node)
|
||||
(progn
|
||||
(js2-imenu-extras--mocha-visit-it-node node qname)
|
||||
nil))
|
||||
((js2-imenu-extras--mocha-before-after-node-p node)
|
||||
(progn
|
||||
(js2-imenu-extras--mocha-visit-before-after-node node qname)
|
||||
nil))
|
||||
((js2-imenu-extras--mocha-named-function-node-p node)
|
||||
(progn
|
||||
(js2-imenu-extras--mocha-visit-named-function-node node qname)
|
||||
nil))
|
||||
(t t)))
|
||||
|
||||
(defun js2-imenu-extras--mocha-top-level-describe-p (node)
|
||||
"Return non-nil if NODE is a top-level mocha describe() block.
|
||||
|
||||
A top-level block is one which isn't included in another mocha
|
||||
describe() block."
|
||||
(and (js2-imenu-extras--mocha-describe-node-p node)
|
||||
(not (js2-imenu-extras--mocha-is-or-within-describe-block-p (js2-node-parent node)))))
|
||||
|
||||
(defun js2-imenu-extras--mocha-within-describe-block-p (node)
|
||||
"Return non-nil if NODE is within a mocha describe() block."
|
||||
(js2-imenu-extras--mocha-is-or-within-describe-block-p (js2-node-parent node)))
|
||||
|
||||
(defun js2-imenu-extras--mocha-is-or-within-describe-block-p (node)
|
||||
"Return non-nil if NODE is a or within a mocha describe() block."
|
||||
(when node
|
||||
(or (js2-imenu-extras--mocha-describe-node-p node)
|
||||
(js2-imenu-extras--mocha-within-describe-block-p node))))
|
||||
|
||||
(defun js2-imenu-extras--mocha-describe-node-p (node)
|
||||
"Return non-nil if NODE is a mocha describe() block."
|
||||
(when-let ((name (js2-imenu-extras--call-target-name node)))
|
||||
(member name js2-imenu-mocha-describe-node-names)))
|
||||
|
||||
(defun js2-imenu-extras--mocha-it-node-p (node)
|
||||
"Return non-nil if NODE is a mocha it() block."
|
||||
(when-let ((name (js2-imenu-extras--call-target-name node)))
|
||||
(member name js2-imenu-mocha-it-node-names)))
|
||||
|
||||
(defun js2-imenu-extras--mocha-before-after-node-p (node)
|
||||
"Return non-nil if NODE is a `{before,after}{Each,All}' block."
|
||||
(when-let ((name (js2-imenu-extras--call-target-name node)))
|
||||
(member name js2-imenu-mocha-hook-node-names)))
|
||||
|
||||
(defun js2-imenu-extras--mocha-named-function-node-p (node)
|
||||
"Return non-nil if NODE is a function definition."
|
||||
(and (js2-function-node-p node)
|
||||
(js2-function-name node)))
|
||||
|
||||
(defun js2-imenu-extras--mocha-visit-describe-node (node qname)
|
||||
"Record NODE, a mocha describe() block, in imenu.
|
||||
Also search and record other mocha blocks within NODE's body.
|
||||
|
||||
QNAME is the same as described in
|
||||
`js2-imenu-extras--mocha-visit-node'."
|
||||
(let* ((args (js2-call-node-args node))
|
||||
(name (cl-first args))
|
||||
(qname (append qname (list name)))
|
||||
(body (car (last args)))
|
||||
(position (js2-node-abs-pos node)))
|
||||
(js2-record-imenu-entry body qname position)
|
||||
(js2-imenu-extras--mocha-visit-node body qname)))
|
||||
|
||||
(defun js2-imenu-extras--mocha-visit-it-node (node qname)
|
||||
"Record NODE, a mocha it() block, in imenu.
|
||||
|
||||
QNAME is the same as described in
|
||||
`js2-imenu-extras--mocha-visit-node'."
|
||||
(let* ((args (js2-call-node-args node))
|
||||
(name (cl-first args))
|
||||
(qname (append qname (list name)))
|
||||
(body (car (last args)))
|
||||
(position (js2-node-abs-pos node)))
|
||||
(js2-record-imenu-entry body qname position)))
|
||||
|
||||
(defun js2-imenu-extras--mocha-visit-before-after-node (node qname)
|
||||
"Record NODE, a mocha {before,after}{Each,All}() block, in imenu.
|
||||
|
||||
QNAME is the same as described in
|
||||
`js2-imenu-extras--mocha-visit-node'."
|
||||
(let* ((args (js2-call-node-args node))
|
||||
(qname (append qname (list (js2-imenu-extras--call-target-name node))))
|
||||
(body (car (last args)))
|
||||
(position (js2-node-abs-pos node)))
|
||||
(js2-record-imenu-entry body qname position)))
|
||||
|
||||
(defun js2-imenu-extras--mocha-visit-named-function-node (node qname)
|
||||
"Record NODE, a function declaration, in imenu.
|
||||
|
||||
QNAME is the same as described in
|
||||
`js2-imenu-extras--mocha-visit-node'."
|
||||
(let* ((qname (append qname (list (js2-function-name node))))
|
||||
(position (js2-node-abs-pos node)))
|
||||
(js2-record-imenu-entry node qname position)))
|
||||
|
||||
(defun js2-imenu-extras--call-target-name (node)
|
||||
"Return the function name, as string, called by NODE.
|
||||
If node is not a function call, return nil."
|
||||
(when (js2-call-node-p node)
|
||||
(js2-imenu-extras--string-content (js2-call-node-target node))))
|
||||
|
||||
(defun js2-imenu-extras--string-content (node)
|
||||
"Return a string representing the value of NODE."
|
||||
(if (js2-string-node-p node)
|
||||
(js2-string-node-value node)
|
||||
(let ((start (js2-node-abs-pos node)))
|
||||
(buffer-substring-no-properties
|
||||
start
|
||||
(+ start (js2-node-len node))))))
|
||||
|
||||
(defun js2-imenu-walk-ast ()
|
||||
(js2-visit-ast
|
||||
js2-mode-ast
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
(define-package "js2-mode" "20201220.1718" "Improved JavaScript editing mode"
|
||||
(define-package "js2-mode" "20211229.135" "Improved JavaScript editing mode"
|
||||
'((emacs "24.1")
|
||||
(cl-lib "0.5"))
|
||||
:commit "29979e5f3301796ba606759e39ee0b1b6a2a24f3" :authors
|
||||
:commit "997cac4c80a03062145b541b006c51cc91ee0c24" :authors
|
||||
'(("Steve Yegge" . "steve.yegge@gmail.com")
|
||||
("mooz" . "stillpedant@gmail.com")
|
||||
("Dmitry Gutov" . "dgutov@yandex.ru"))
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
;;; js2-mode.el --- Improved JavaScript editing mode -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2009, 2011-2020 Free Software Foundation, Inc.
|
||||
;; Copyright (C) 2009, 2011-2021 Free Software Foundation, Inc.
|
||||
|
||||
;; Author: Steve Yegge <steve.yegge@gmail.com>
|
||||
;; mooz <stillpedant@gmail.com>
|
||||
;; Dmitry Gutov <dgutov@yandex.ru>
|
||||
;; URL: https://github.com/mooz/js2-mode/
|
||||
;; http://code.google.com/p/js2-mode/
|
||||
;; Version: 20201220
|
||||
;; Version: 20211229
|
||||
;; Keywords: languages, javascript
|
||||
;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
|
||||
|
||||
@@ -657,7 +657,9 @@ which doesn't seem particularly useful, but Rhino permits it."
|
||||
(defvar js2-EXPON 175)
|
||||
(defvar js2-NULLISH-COALESCING 176) ; nullish coalescing (obj.value ?? obj.defaultValue ?? 0))
|
||||
|
||||
(defconst js2-num-tokens (1+ js2-NULLISH-COALESCING))
|
||||
(defvar js2-PRIVATE_NAME 177) ; this.#bar();
|
||||
|
||||
(defconst js2-num-tokens (1+ js2-PRIVATE_NAME))
|
||||
|
||||
(defconst js2-debug-print-trees nil)
|
||||
|
||||
@@ -2651,14 +2653,17 @@ so many of its properties will be nil.
|
||||
object
|
||||
in-pos
|
||||
each-pos
|
||||
foreach-p forof-p
|
||||
await-pos
|
||||
foreach-p forof-p forawait-p
|
||||
lp rp)))
|
||||
"AST node for a for..in loop."
|
||||
iterator ; [var] foo in ...
|
||||
object ; object over which we're iterating
|
||||
in-pos ; buffer position of 'in' keyword
|
||||
each-pos ; buffer position of 'each' keyword, if foreach-p
|
||||
await-pos ; buffer position of 'await' keyword, if forawait-p
|
||||
foreach-p ; t if it's a for-each loop
|
||||
forawait-p ; t if it's a for-await loop
|
||||
forof-p) ; t if it's a for-of loop
|
||||
|
||||
(js2--struct-put 'js2-for-in-node 'js2-visitor 'js2-visit-for-in-node)
|
||||
@@ -2672,10 +2677,13 @@ so many of its properties will be nil.
|
||||
(defun js2-print-for-in-node (n i)
|
||||
(let ((pad (js2-make-pad i))
|
||||
(foreach (js2-for-in-node-foreach-p n))
|
||||
(forawait (js2-for-in-node-forawait-p n))
|
||||
(forof (js2-for-in-node-forof-p n)))
|
||||
(insert pad "for ")
|
||||
(if foreach
|
||||
(insert "each "))
|
||||
(if forawait
|
||||
(insert "await "))
|
||||
(insert "(")
|
||||
(js2-print-ast (js2-for-in-node-iterator n) 0)
|
||||
(insert (if forof " of " " in "))
|
||||
@@ -3009,12 +3017,15 @@ modules metadata itself."
|
||||
(let ((pad (js2-make-pad i))
|
||||
(guard-kwd (js2-catch-node-guard-kwd n))
|
||||
(guard-expr (js2-catch-node-guard-expr n)))
|
||||
(insert " catch (")
|
||||
(js2-print-ast (js2-catch-node-param n) 0)
|
||||
(when guard-kwd
|
||||
(insert " if ")
|
||||
(js2-print-ast guard-expr 0))
|
||||
(insert ") {\n")
|
||||
(insert " catch ")
|
||||
(when (js2-catch-node-lp n)
|
||||
(insert "(")
|
||||
(js2-print-ast (js2-catch-node-param n) 0)
|
||||
(when guard-kwd
|
||||
(insert " if ")
|
||||
(js2-print-ast guard-expr 0))
|
||||
(insert ") "))
|
||||
(insert "{\n")
|
||||
(js2-print-body n (1+ i))
|
||||
(insert pad "}")))
|
||||
|
||||
@@ -5892,6 +5903,7 @@ the token is flagged as such."
|
||||
During operation, creates an instance of `js2-token' struct, sets
|
||||
its relevant fields and puts it into `js2-ti-tokens'."
|
||||
(let (identifier-start
|
||||
identifier-private
|
||||
is-unicode-escape-start c
|
||||
contains-escape escape-val str result base
|
||||
look-for-slash continue tt legacy-octal
|
||||
@@ -5937,7 +5949,10 @@ its relevant fields and puts it into `js2-ti-tokens'."
|
||||
(js2-unget-char)
|
||||
(setq c ?\\)))
|
||||
(t
|
||||
(when (setq identifier-start (js2-identifier-start-p c))
|
||||
(when (setq identifier-start (or (js2-identifier-start-p c)
|
||||
(and
|
||||
(eq c ?#)
|
||||
(setq identifier-private t))))
|
||||
(setq js2-ts-string-buffer nil)
|
||||
(js2-add-to-string c))))
|
||||
(when identifier-start
|
||||
@@ -5997,7 +6012,11 @@ its relevant fields and puts it into `js2-ti-tokens'."
|
||||
(throw 'return (js2-tt-code result))))
|
||||
;; If we want to intern these as Rhino does, just use (intern str)
|
||||
(setf (js2-token-string token) str)
|
||||
(throw 'return js2-NAME)) ; end identifier/kwd check
|
||||
(throw 'return
|
||||
(if identifier-private
|
||||
js2-PRIVATE_NAME
|
||||
js2-NAME)
|
||||
)) ; end identifier/kwd check
|
||||
;; is it a number?
|
||||
(when (or (js2-digit-p c)
|
||||
(and (eq c ?.) (js2-digit-p (js2-peek-char))))
|
||||
@@ -8015,7 +8034,7 @@ string is NAME. Returns nil and keeps current token otherwise."
|
||||
"Consume token and return t if next token is a valid property name.
|
||||
If `js2-language-version' is >= 180, a keyword or reserved word
|
||||
is considered valid name as well."
|
||||
(if (eq js2-NAME (js2-get-prop-name-token))
|
||||
(if (memq (js2-get-prop-name-token) `(,js2-NAME ,js2-PRIVATE_NAME))
|
||||
t
|
||||
(js2-unget-token)
|
||||
nil))
|
||||
@@ -8606,7 +8625,7 @@ node are given relative start positions and correct lengths."
|
||||
(aset parsers js2-FOR #'js2-parse-for)
|
||||
(aset parsers js2-FUNCTION #'js2-parse-function-stmt)
|
||||
(aset parsers js2-IF #'js2-parse-if)
|
||||
(aset parsers js2-IMPORT #'js2-parse-import)
|
||||
(aset parsers js2-IMPORT #'js2-parse-import-declaration-or-expr)
|
||||
(aset parsers js2-LC #'js2-parse-block)
|
||||
(aset parsers js2-LET #'js2-parse-let-stmt)
|
||||
(aset parsers js2-NAME #'js2-parse-name-or-label)
|
||||
@@ -8736,6 +8755,11 @@ Return value is a list (EXPR LP RP), with absolute paren positions."
|
||||
(js2-node-add-children pn (car cond) if-true if-false)
|
||||
pn))
|
||||
|
||||
(defun js2-parse-import-declaration-or-expr ()
|
||||
(if (memq (js2-peek-token) `(,js2-LP ,js2-DOT))
|
||||
(js2-parse-expr-stmt)
|
||||
(js2-parse-import)))
|
||||
|
||||
(defun js2-parse-import ()
|
||||
"Parse import statement. The current token must be js2-IMPORT."
|
||||
(unless (js2-ast-root-p js2-current-scope)
|
||||
@@ -9133,24 +9157,31 @@ invalid export statements."
|
||||
node)))
|
||||
|
||||
(defun js2-parse-for ()
|
||||
"Parse a for, for-in or for each-in statement.
|
||||
"Parse a for, for-in, for each-in or for await-in statement.
|
||||
Last matched token must be js2-FOR."
|
||||
(let ((for-pos (js2-current-token-beg))
|
||||
(tmp-scope (make-js2-scope))
|
||||
pn is-for-each is-for-in-or-of is-for-of
|
||||
in-pos each-pos tmp-pos
|
||||
pn is-for-each is-for-in-or-of is-for-of is-for-await
|
||||
in-pos each-pos tmp-pos await-pos
|
||||
init ; Node init is also foo in 'foo in object'.
|
||||
cond ; Node cond is also object in 'foo in object'.
|
||||
incr ; 3rd section of for-loop initializer.
|
||||
body tt lp rp)
|
||||
;; See if this is a for each () instead of just a for ()
|
||||
(when (js2-match-token js2-NAME)
|
||||
(if (string= "each" (js2-current-token-string))
|
||||
(progn
|
||||
(setq is-for-each t
|
||||
each-pos (- (js2-current-token-beg) for-pos)) ; relative
|
||||
(js2-record-face 'font-lock-keyword-face))
|
||||
(js2-report-error "msg.no.paren.for")))
|
||||
(cond
|
||||
;; See if this is a for each () instead of just a for ()
|
||||
((string= "each" (js2-current-token-string))
|
||||
(progn
|
||||
(setq is-for-each t
|
||||
each-pos (- (js2-current-token-beg) for-pos)) ; relative
|
||||
(js2-record-face 'font-lock-keyword-face)))
|
||||
;; See if this is a for await () instead of just a for ()
|
||||
((string= "await" (js2-current-token-string))
|
||||
(progn
|
||||
(setq is-for-await t
|
||||
await-pos (- (js2-current-token-beg) for-pos)) ; relative
|
||||
(js2-record-face 'font-lock-keyword-face)))
|
||||
(t (js2-report-error "msg.no.paren.for"))))
|
||||
(if (js2-must-match js2-LP "msg.no.paren.for")
|
||||
(setq lp (- (js2-current-token-beg) for-pos)))
|
||||
(setq tt (js2-get-token))
|
||||
@@ -9212,6 +9243,8 @@ Last matched token must be js2-FOR."
|
||||
:in-pos in-pos
|
||||
:foreach-p is-for-each
|
||||
:each-pos each-pos
|
||||
:forawait-p is-for-await
|
||||
:await-pos await-pos
|
||||
:forof-p is-for-of
|
||||
:lp lp
|
||||
:rp rp)))
|
||||
@@ -9258,30 +9291,30 @@ Last matched token must be js2-FOR."
|
||||
lp rp)
|
||||
(if saw-default-catch
|
||||
(js2-report-error "msg.catch.unreachable"))
|
||||
(if (js2-must-match js2-LP "msg.no.paren.catch")
|
||||
(setq lp (- (js2-current-token-beg) catch-pos)))
|
||||
(js2-push-scope catch-node)
|
||||
(let ((tt (js2-peek-token)))
|
||||
(cond
|
||||
;; Destructuring pattern:
|
||||
;; catch ({ message, file }) { ... }
|
||||
((or (= tt js2-LB) (= tt js2-LC))
|
||||
(js2-get-token)
|
||||
(setq param (js2-parse-destruct-primary-expr))
|
||||
(js2-define-destruct-symbols param js2-LET nil))
|
||||
;; Simple name.
|
||||
(t
|
||||
(js2-must-match-name "msg.bad.catchcond")
|
||||
(setq param (js2-create-name-node))
|
||||
(js2-define-symbol js2-LET (js2-current-token-string) param)
|
||||
(js2-check-strict-identifier param))))
|
||||
;; Catch condition.
|
||||
(if (js2-match-token js2-IF)
|
||||
(setq guard-kwd (- (js2-current-token-beg) catch-pos)
|
||||
catch-cond (js2-parse-expr))
|
||||
(setq saw-default-catch t))
|
||||
(if (js2-must-match js2-RP "msg.bad.catchcond")
|
||||
(setq rp (- (js2-current-token-beg) catch-pos)))
|
||||
(when (js2-match-token js2-LP)
|
||||
(setq lp (- (js2-current-token-beg) catch-pos))
|
||||
(let ((tt (js2-peek-token)))
|
||||
(cond
|
||||
;; Destructuring pattern:
|
||||
;; catch ({ message, file }) { ... }
|
||||
((or (= tt js2-LB) (= tt js2-LC))
|
||||
(js2-get-token)
|
||||
(setq param (js2-parse-destruct-primary-expr))
|
||||
(js2-define-destruct-symbols param js2-LET nil))
|
||||
;; Simple name.
|
||||
(t
|
||||
(js2-must-match-name "msg.bad.catchcond")
|
||||
(setq param (js2-create-name-node))
|
||||
(js2-define-symbol js2-LET (js2-current-token-string) param)
|
||||
(js2-check-strict-identifier param))))
|
||||
;; Catch condition.
|
||||
(if (js2-match-token js2-IF)
|
||||
(setq guard-kwd (- (js2-current-token-beg) catch-pos)
|
||||
catch-cond (js2-parse-expr))
|
||||
(setq saw-default-catch t))
|
||||
(if (js2-must-match js2-RP "msg.bad.catchcond")
|
||||
(setq rp (- (js2-current-token-beg) catch-pos))))
|
||||
(js2-must-match js2-LC "msg.no.brace.catchblock")
|
||||
(js2-parse-statements catch-node)
|
||||
(if (js2-must-match js2-RC "msg.no.brace.after.body")
|
||||
@@ -9877,15 +9910,20 @@ If NODE is non-nil, it is the AST node associated with the symbol."
|
||||
(while (and (not oneshot)
|
||||
(js2-match-token js2-COMMA))
|
||||
(setq op-pos (- (js2-current-token-beg) pos)) ; relative
|
||||
(setq right (js2-parse-assign-expr)
|
||||
left pn
|
||||
pn (make-js2-infix-node :type js2-COMMA
|
||||
:pos pos
|
||||
:len (- js2-ts-cursor pos)
|
||||
:op-pos op-pos
|
||||
:left left
|
||||
:right right))
|
||||
(js2-node-add-children pn left right))
|
||||
(if (eq (js2-peek-token) js2-RP)
|
||||
;; Stop the parser from scanning too far: it's actually
|
||||
;; valid syntax in arrow fun arguments, and we don't want
|
||||
;; the RP token to get consumed.
|
||||
(js2-report-error "msg.syntax")
|
||||
(setq right (js2-parse-assign-expr)
|
||||
left pn
|
||||
pn (make-js2-infix-node :type js2-COMMA
|
||||
:pos pos
|
||||
:len (- js2-ts-cursor pos)
|
||||
:op-pos op-pos
|
||||
:left left
|
||||
:right right))
|
||||
(js2-node-add-children pn left right)))
|
||||
pn))
|
||||
|
||||
(defun js2-parse-assign-expr ()
|
||||
@@ -10489,7 +10527,7 @@ Last token parsed must be `js2-RB'."
|
||||
tt (js2-get-prop-name-token))
|
||||
(cond
|
||||
;; handles: name, ns::name, ns::*, ns::[expr]
|
||||
((= tt js2-NAME)
|
||||
((or (= tt js2-NAME) (= tt js2-PRIVATE_NAME))
|
||||
(setq ref (js2-parse-property-name -1 nil member-type-flags)))
|
||||
;; handles: *, *::name, *::*, *::[expr]
|
||||
((= tt js2-MUL)
|
||||
@@ -10631,6 +10669,8 @@ array-literals, array comprehensions and regular expressions."
|
||||
(js2-parse-attribute-access))
|
||||
((= tt js2-NAME)
|
||||
(js2-parse-name tt))
|
||||
((= tt js2-IMPORT)
|
||||
(js2-create-name-node nil nil "import"))
|
||||
((= tt js2-NUMBER)
|
||||
(setq node (make-js2-number-node))
|
||||
(when (and js2-in-use-strict-directive
|
||||
@@ -11034,8 +11074,8 @@ expression)."
|
||||
(when (and (>= js2-language-version 200)
|
||||
(= js2-NAME tt)
|
||||
(member prop '("get" "set" "async"))
|
||||
(member (js2-peek-token 'KEYWORD_IS_NAME)
|
||||
(list js2-NAME js2-STRING js2-NUMBER js2-LB)))
|
||||
(memq (js2-peek-token 'KEYWORD_IS_NAME)
|
||||
`(,js2-NAME ,js2-PRIVATE_NAME ,js2-STRING ,js2-NUMBER ,js2-LB)))
|
||||
(setq previous-token (js2-current-token)
|
||||
tt (js2-get-prop-name-token))))
|
||||
(cond
|
||||
@@ -11046,7 +11086,7 @@ expression)."
|
||||
(setq after-comma nil
|
||||
elem (js2-make-unary nil js2-TRIPLEDOT 'js2-parse-assign-expr)))
|
||||
;; Found a key/value property (of any sort)
|
||||
((member tt (list js2-NAME js2-STRING js2-NUMBER js2-LB))
|
||||
((memq tt `(,js2-NAME ,js2-PRIVATE_NAME ,js2-STRING ,js2-NUMBER ,js2-LB))
|
||||
(setq after-comma nil
|
||||
elem (js2-parse-named-prop tt previous-token class-p))
|
||||
(if (and (null elem)
|
||||
@@ -11110,7 +11150,7 @@ expression)."
|
||||
(defun js2-parse-named-prop (tt previous-token &optional class-p)
|
||||
"Parse a name, string, or getter/setter object property.
|
||||
When `js2-is-in-destructuring' is t, forms like {a, b, c} will be permitted."
|
||||
(let ((key (js2-parse-prop-name tt))
|
||||
(let ((key (js2-parse-prop-name tt class-p))
|
||||
(prop (and previous-token (js2-token-string previous-token)))
|
||||
(property-type (when previous-token
|
||||
(if (= (js2-token-type previous-token) js2-MUL)
|
||||
@@ -11162,7 +11202,7 @@ When `js2-is-in-destructuring' is t, forms like {a, b, c} will be permitted."
|
||||
(when (js2-match-token js2-ASSIGN)
|
||||
(js2-make-binary js2-ASSIGN name 'js2-parse-assign-expr t)))
|
||||
|
||||
(defun js2-parse-prop-name (tt)
|
||||
(defun js2-parse-prop-name (tt allow-private)
|
||||
(cond
|
||||
;; Literal string keys: {'foo': 'bar'}
|
||||
((= tt js2-STRING)
|
||||
@@ -11180,6 +11220,9 @@ When `js2-is-in-destructuring' is t, forms like {a, b, c} will be permitted."
|
||||
;; Unquoted names: {foo: 12}
|
||||
((= tt js2-NAME)
|
||||
(js2-create-name-node))
|
||||
((and allow-private
|
||||
(= tt js2-PRIVATE_NAME))
|
||||
(js2-create-name-node))
|
||||
;; Anything else is an error
|
||||
(t (js2-report-error "msg.bad.prop"))))
|
||||
|
||||
@@ -11195,9 +11238,9 @@ string or expression."
|
||||
((and (>= js2-language-version 200)
|
||||
(if class-p
|
||||
(and (setq tt (js2-peek-token-or-eol))
|
||||
(member tt (list js2-EOL js2-RC js2-SEMI)))
|
||||
(memq tt `(,js2-EOL ,js2-RC ,js2-SEMI)))
|
||||
(and (setq tt (js2-peek-token))
|
||||
(member tt (list js2-COMMA js2-RC))
|
||||
(memq tt `(,js2-COMMA ,js2-RC))
|
||||
(js2-name-node-p prop))))
|
||||
(setq result (make-js2-object-prop-node
|
||||
:pos pos
|
||||
@@ -11269,7 +11312,7 @@ And, if CHECK-ACTIVATION-P is non-nil, use the value of TOKEN."
|
||||
(let* ((beg (js2-current-token-beg))
|
||||
(tt (js2-current-token-type))
|
||||
(s (or string
|
||||
(if (= js2-NAME tt)
|
||||
(if (or (= js2-NAME tt) (= js2-PRIVATE_NAME tt))
|
||||
(js2-current-token-string)
|
||||
(js2-tt-name tt))))
|
||||
name)
|
||||
@@ -12569,7 +12612,7 @@ move backward across N balanced expressions."
|
||||
(setq pos (js2-node-abs-pos child)))
|
||||
;; Before both parens.
|
||||
(setq pos lp)))
|
||||
(let ((state (parse-partial-sexp start pos)))
|
||||
(let ((state (parse-partial-sexp pos start)))
|
||||
(goto-char (if (not (zerop (car state)))
|
||||
;; Stumble at the unbalanced paren if < 0, or
|
||||
;; jump a bit further if > 0.
|
||||
@@ -12910,7 +12953,7 @@ it marks the next defun after the ones already marked."
|
||||
(cl-assert (js2-object-node-p node))
|
||||
;; Only support name-node and nodes for the time being
|
||||
(cl-loop for elem in (js2-object-node-elems node)
|
||||
for left = (js2-object-prop-node-left elem)
|
||||
for left = (js2-infix-node-left elem)
|
||||
if (or (and (js2-name-node-p left)
|
||||
(equal (js2-name-node-name name-node)
|
||||
(js2-name-node-name left)))
|
||||
@@ -12930,28 +12973,43 @@ i.e. (\\='name\\=' \\='value\\=') = {name : { value: 3}}"
|
||||
(while (and temp names (js2-object-node-p temp-object))
|
||||
(setq temp (js2-search-object temp-object (pop names)))
|
||||
(and (setq node temp)
|
||||
(setq temp-object (js2-object-prop-node-right temp))))
|
||||
(setq temp-object (js2-infix-node-right temp))))
|
||||
(unless names node)))
|
||||
|
||||
(defun js2-search-scope (node names)
|
||||
"Searches NODE scope for jump location matching NAMES.
|
||||
NAMES is a list of property values to search for. For functions
|
||||
and variables NAMES will contain one element."
|
||||
(let (node-init
|
||||
(val (js2-name-node-name (car names))))
|
||||
(setq node-init (js2-get-symbol-declaration node val))
|
||||
(let (node-init val)
|
||||
(cond
|
||||
((js2-name-node-p (car names))
|
||||
(setq val (js2-name-node-name (car names)))
|
||||
(setq node-init (js2-get-symbol-declaration node val)))
|
||||
((and (js2-keyword-node-p (car names))
|
||||
(equal (js2-keyword-node-type (car names))
|
||||
js2-THIS))
|
||||
(let* ((scope (js2-node-get-enclosing-scope node))
|
||||
(parent (js2-node-parent scope)))
|
||||
(when (or (js2-method-node-p parent)
|
||||
(js2-object-prop-node-p parent))
|
||||
;; class or object
|
||||
(setq node-init (js2-node-parent parent))))))
|
||||
|
||||
(when (> (length names) 1)
|
||||
|
||||
;; Check var declarations
|
||||
(when (and node-init (string= val (js2-name-node-name node-init)))
|
||||
(let ((parent (js2-node-parent node-init))
|
||||
(temp-names names))
|
||||
(pop temp-names) ;; First element is var name
|
||||
(setq node-init (when (js2-var-init-node-p parent)
|
||||
(js2-search-object-for-prop
|
||||
(js2-var-init-node-initializer parent)
|
||||
temp-names)))))
|
||||
(when node-init
|
||||
(cond
|
||||
((js2-name-node-p (car names))
|
||||
;; Check var declarations
|
||||
(when (string= val (js2-name-node-name node-init))
|
||||
(let ((parent (js2-node-parent node-init)))
|
||||
(setq node-init (when (js2-var-init-node-p parent)
|
||||
(js2-search-object-for-prop
|
||||
(js2-var-init-node-initializer parent)
|
||||
(cdr names)))))))
|
||||
((js2-object-node-p node-init)
|
||||
(setq node-init (js2-search-object-for-prop
|
||||
node-init
|
||||
(cdr names))))))
|
||||
|
||||
;; Check all assign nodes
|
||||
(js2-visit-ast
|
||||
@@ -12964,11 +13022,17 @@ and variables NAMES will contain one element."
|
||||
(temp-names names))
|
||||
(when (js2-prop-get-node-p left)
|
||||
(let* ((prop-list (js2-compute-nested-prop-get left))
|
||||
(found (cl-loop for prop in prop-list
|
||||
until (not (string= (js2-name-node-name
|
||||
(pop temp-names))
|
||||
(js2-name-node-name prop)))
|
||||
if (not temp-names) return prop))
|
||||
;; 'this' or 'super'
|
||||
(target-is-keyword (js2-keyword-node-p (car temp-names)))
|
||||
(_ (when target-is-keyword
|
||||
(pop temp-names)))
|
||||
(found (unless target-is-keyword
|
||||
(cl-loop for prop in prop-list
|
||||
until (not (string= (js2-name-node-name
|
||||
(pop temp-names))
|
||||
(and (js2-name-node-p prop)
|
||||
(js2-name-node-name prop))))
|
||||
if (not temp-names) return prop)))
|
||||
(found-node (or found
|
||||
(when (js2-object-node-p right)
|
||||
(js2-search-object-for-prop right
|
||||
|
||||
Reference in New Issue
Block a user