[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 3c4367f 25/45: Make catch-node inherit from scope
From: |
Dmitry Gutov |
Subject: |
[elpa] master 3c4367f 25/45: Make catch-node inherit from scope |
Date: |
Mon, 02 Feb 2015 03:18:43 +0000 |
branch: master
commit 3c4367ff81d442d63f9d75f54ad8501f9193e96f
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Make catch-node inherit from scope
Fixes #190
---
js2-mode.el | 152 ++++++++++++++++++++++++++--------------------------------
1 files changed, 68 insertions(+), 84 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index d8e8f21..2704edb 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -2688,7 +2688,7 @@ NAME can be a Lisp symbol or string. SYMBOL is a
`js2-symbol'."
(insert "\n"))))
(defstruct (js2-catch-node
- (:include js2-node)
+ (:include js2-scope)
(:constructor nil)
(:constructor make-js2-catch-node (&key (type js2-CATCH)
(pos js2-ts-cursor)
@@ -2696,13 +2696,11 @@ NAME can be a Lisp symbol or string. SYMBOL is a
`js2-symbol'."
param
guard-kwd
guard-expr
- block lp
- rp)))
+ lp rp)))
"AST node for a catch clause."
param ; destructuring form or simple name node
guard-kwd ; relative buffer position of "if" in "catch (x if ...)"
guard-expr ; catch condition, a `js2-node'
- block ; statements, a `js2-block-node'
lp ; buffer position of left-paren, nil if omitted
rp) ; buffer position of right-paren, nil if omitted
@@ -2713,7 +2711,7 @@ NAME can be a Lisp symbol or string. SYMBOL is a
`js2-symbol'."
(js2-visit-ast (js2-catch-node-param n) v)
(when (js2-catch-node-guard-kwd n)
(js2-visit-ast (js2-catch-node-guard-expr n) v))
- (js2-visit-ast (js2-catch-node-block n) v))
+ (js2-visit-block n v))
(defun js2-print-catch-node (n i)
(let ((pad (js2-make-pad i))
@@ -2725,7 +2723,7 @@ NAME can be a Lisp symbol or string. SYMBOL is a
`js2-symbol'."
(insert " if ")
(js2-print-ast guard-expr 0))
(insert ") {\n")
- (js2-print-body (js2-catch-node-block n) (1+ i))
+ (js2-print-body n (1+ i))
(insert pad "}")))
(defstruct (js2-finally-node
@@ -5034,7 +5032,7 @@ Returns logical OR of END_* flags."
(js2-set-flag rv (js2-end-check (js2-try-node-try-block node)))
;; check each catch block
(dolist (cb (js2-try-node-catch-clauses node))
- (js2-set-flag rv (js2-end-check (js2-catch-node-block cb)))))
+ (js2-set-flag rv (js2-end-check cb))))
rv))
(defun js2-end-check-loop (node)
@@ -7728,7 +7726,6 @@ up to be relative to the parent node. All children of
this block
node are given relative start positions and correct lengths."
(let ((pn (or parent (make-js2-block-node)))
tt)
- (setf (js2-node-pos pn) (js2-current-token-beg))
(while (and (> (setq tt (js2-peek-token)) js2-EOF)
(/= tt js2-RC))
(js2-block-node-push pn (js2-parse-statement)))
@@ -8089,24 +8086,14 @@ Parses for, for-in, and for each-in statements."
pn))
(defun js2-parse-try ()
- "Parser for try-statement. Last matched token must be js2-TRY."
+ "Parse a try statement. Last matched token must be js2-TRY."
(let ((try-pos (js2-current-token-beg))
try-end
try-block
catch-blocks
finally-block
saw-default-catch
- peek
- param
- catch-cond
- catch-node
- guard-kwd
- catch-pos
- finally-pos
- pn
- block
- lp
- rp)
+ peek)
(if (/= (js2-peek-token) js2-LC)
(js2-report-error "msg.no.brace.try"))
(setq try-block (js2-parse-statement)
@@ -8115,76 +8102,73 @@ Parses for, for-in, and for each-in statements."
(cond
((= peek js2-CATCH)
(while (js2-match-token js2-CATCH)
- (setq catch-pos (js2-current-token-beg)
- guard-kwd nil
- catch-cond nil
- lp nil
- rp nil)
- (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 (make-js2-scope))
- (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))))
- ;; pattern guard
- (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")
- (setq block (js2-parse-statements)
- try-end (js2-node-end block)
- catch-node (make-js2-catch-node :pos catch-pos
- :param param
- :guard-expr catch-cond
- :guard-kwd guard-kwd
- :block block
- :lp lp
- :rp rp))
- (js2-pop-scope)
- (if (js2-must-match js2-RC "msg.no.brace.after.body")
- (setq try-end (js2-current-token-beg)))
- (setf (js2-node-len block) (- try-end (js2-node-pos block))
- (js2-node-len catch-node) (- try-end catch-pos))
- (js2-node-add-children catch-node param catch-cond block)
- (push catch-node catch-blocks)))
+ (let* ((catch-pos (js2-current-token-beg))
+ (catch-node (make-js2-catch-node :pos catch-pos))
+ param
+ guard-kwd
+ catch-cond
+ 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))))
+ ;; 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")
+ (setq try-end (js2-current-token-end)))
+ (js2-pop-scope)
+ (setf (js2-node-len catch-node) (- try-end catch-pos)
+ (js2-catch-node-param catch-node) param
+ (js2-catch-node-guard-expr catch-node) catch-cond
+ (js2-catch-node-guard-kwd catch-node) guard-kwd
+ (js2-catch-node-lp catch-node) lp
+ (js2-catch-node-rp catch-node) rp)
+ (js2-node-add-children catch-node param catch-cond)
+ (push catch-node catch-blocks))))
((/= peek js2-FINALLY)
(js2-must-match js2-FINALLY "msg.try.no.catchfinally"
(js2-node-pos try-block)
(- (setq try-end (js2-node-end try-block))
(js2-node-pos try-block)))))
(when (js2-match-token js2-FINALLY)
- (setq finally-pos (js2-current-token-beg)
- block (js2-parse-statement)
- try-end (js2-node-end block)
- finally-block (make-js2-finally-node :pos finally-pos
- :len (- try-end finally-pos)
- :body block))
- (js2-node-add-children finally-block block))
- (setq pn (make-js2-try-node :pos try-pos
- :len (- try-end try-pos)
- :try-block try-block
- :finally-block finally-block))
- (js2-node-add-children pn try-block finally-block)
- ;; push them onto the try-node, which reverses and corrects their order
- (dolist (cb catch-blocks)
- (js2-node-add-children pn cb)
- (push cb (js2-try-node-catch-clauses pn)))
- pn))
+ (let ((finally-pos (js2-current-token-beg))
+ (block (js2-parse-statement)))
+ (setq try-end (js2-node-end block)
+ finally-block (make-js2-finally-node :pos finally-pos
+ :len (- try-end finally-pos)
+ :body block))
+ (js2-node-add-children finally-block block)))
+ (let ((pn (make-js2-try-node :pos try-pos
+ :len (- try-end try-pos)
+ :try-block try-block
+ :finally-block finally-block)))
+ (js2-node-add-children pn try-block finally-block)
+ ;; Push them onto the try-node, which reverses and corrects their order.
+ (dolist (cb catch-blocks)
+ (js2-node-add-children pn cb)
+ (push cb (js2-try-node-catch-clauses pn)))
+ pn)))
(defun js2-parse-throw ()
"Parser for throw-statement. Last matched token must be js2-THROW."
- [elpa] master c910d1b 19/45: Parse tagged templates, (continued)
- [elpa] master c910d1b 19/45: Parse tagged templates, Dmitry Gutov, 2015/02/01
- [elpa] master 8df508e 16/45: Handle template substitutions, Dmitry Gutov, 2015/02/01
- [elpa] master 92063fe 22/45: Fix js2-visit-tagged-template, Dmitry Gutov, 2015/02/01
- [elpa] master 94c2ec9 20/45: Drop `js2-allow-keywords-as-property-names' and `js2-valid-prop-name-token', Dmitry Gutov, 2015/02/01
- [elpa] master ab82544 23/45: Do not declare fn expression's name in the enclosing scope, Dmitry Gutov, 2015/02/01
- [elpa] master e6dc986 24/45: Limit the scope of `with-silent-modifications', Dmitry Gutov, 2015/02/01
- [elpa] master 6a4e84b 26/45: js2-parse-for: Reword docstring and comments, Dmitry Gutov, 2015/02/01
- [elpa] master 8088e75 21/45: Add js2-language-version check for template literals, Dmitry Gutov, 2015/02/01
- [elpa] master 395d4ae 29/45: Highlight methods with font-lock-function-name-face, Dmitry Gutov, 2015/02/01
- [elpa] master a117465 32/45: Handle "arguments" specially, Dmitry Gutov, 2015/02/01
- [elpa] master 3c4367f 25/45: Make catch-node inherit from scope,
Dmitry Gutov <=
- [elpa] master 65bd910 35/45: `js2-time' remove unused variable., Dmitry Gutov, 2015/02/01
- [elpa] master e109213 36/45: Merge pull request #203 from cheunghy/master, Dmitry Gutov, 2015/02/01
- [elpa] master b0ea681 33/45: Add animationFrame functions, Dmitry Gutov, 2015/02/01
- [elpa] master 590db34 37/45: js2-parse-class-stmt: Define the class in the current scope, Dmitry Gutov, 2015/02/01
- [elpa] master ba564b7 38/45: Handle arrowfun empty-args in js2-parse-paren-expr-or-generator-comp, Dmitry Gutov, 2015/02/01
- [elpa] master 874cf77 31/45: js2-get-token-internal-1: Reindent, Dmitry Gutov, 2015/02/01
- [elpa] master 58c6636 27/45: Support ES6 module syntax, Dmitry Gutov, 2015/02/01
- [elpa] master b91f874 34/45: Merge pull request #202 from brianloveswords/add-browser-externs, Dmitry Gutov, 2015/02/01
- [elpa] master f0935fa 42/45: Add top-level heading, Dmitry Gutov, 2015/02/01
- [elpa] master 7558a96 44/45: Bump the version and update NEWS, Dmitry Gutov, 2015/02/01