[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master d307285 039/110: Move method type handling to property MET
From: |
Dmitry Gutov |
Subject: |
[elpa] master d307285 039/110: Move method type handling to property METHOD_TYPE |
Date: |
Thu, 23 Jun 2016 01:12:55 +0000 (UTC) |
branch: master
commit d307285f4b47096c973d4a33d1427df311bab1b8
Author: Carl Lei <address@hidden>
Commit: Carl Lei <address@hidden>
Move method type handling to property METHOD_TYPE
Relying on js2-node-type requires a token number for each type of
method, but we did not define a js2-ASYNC for the coming async methods.
Only getter and setter are moved, generator is not.
---
js2-mode.el | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 1f11218..cc26f97 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -3958,13 +3958,12 @@ both fields have the same value.")
(cl-defstruct (js2-method-node
(:include js2-infix-node)
(:constructor nil)
- (:constructor make-js2-method-node (&key type ; GET, SET, or
FUNCTION
- (pos js2-ts-cursor)
+ (:constructor make-js2-method-node (&key (pos js2-ts-cursor)
len left right)))
"AST node for a method in an object literal or a class body.
The `left' field is the `js2-name-node' naming the method.
The `right' field is always an anonymous `js2-function-node' with a node
-property `METHOD_TYPE' set to js2-GET, js2-SET, or js2-FUNCTION. ")
+property `METHOD_TYPE' set to 'GET or 'SET. ")
(put 'cl-struct-js2-method-node 'js2-visitor 'js2-visit-infix-node)
(put 'cl-struct-js2-method-node 'js2-printer 'js2-print-method)
@@ -3972,10 +3971,13 @@ property `METHOD_TYPE' set to js2-GET, js2-SET, or
js2-FUNCTION. ")
(defun js2-print-method (n i)
(let* ((pad (js2-make-pad i))
(left (js2-method-node-left n))
- (right (js2-method-node-right n)))
+ (right (js2-method-node-right n))
+ (type (js2-node-get-prop right 'METHOD_TYPE)))
(insert pad)
- (if (/= (js2-node-type n) js2-FUNCTION)
- (insert (if (= (js2-node-type n) js2-GET) "get " "set ")))
+ (when type
+ (insert (cdr (assoc type '((GET . "get ")
+ (SET . "set ")
+ (FUNCTION . ""))))))
(when (and (js2-function-node-p right)
(eq 'STAR (js2-function-node-generator-type right)))
(insert "*"))
@@ -10778,8 +10780,11 @@ expression)."
;; But make an exception for getter / setter pairs.
(not (and (js2-method-node-p elem)
(js2-method-node-p previous-elem)
- (/= (js2-method-node-type elem)
- (js2-method-node-type
previous-elem))))))
+ (let ((type (js2-node-get-prop
(js2-method-node-right elem) 'METHOD_TYPE))
+ (previous-type (js2-node-get-prop
(js2-method-node-right previous-elem) 'METHOD_TYPE)))
+ (and (member type '(GET SET))
+ (member previous-type '(GET SET))
+ (not (eq type previous-type))))))))
elems))
(js2-report-error "msg.dup.obj.lit.prop.strict"
elem-key-string
@@ -10917,10 +10922,9 @@ and expression closure style is also supported
POS is the start position of the `get' or `set' keyword.
PROP is the `js2-name-node' representing the property name.
TYPE-STRING is a string `get', `set', `*', or nil, indicating a found keyword."
- (let ((type (cond
- ((string= "get" type-string) js2-GET)
- ((string= "set" type-string) js2-SET)
- (t js2-FUNCTION)))
+ (let ((type (or (cdr (assoc type-string '(("get" . GET)
+ ("set" . SET))))
+ 'FUNCTION))
result end
(fn (js2-parse-function-expr)))
;; it has to be an anonymous function, as we already parsed the name
@@ -10932,8 +10936,7 @@ TYPE-STRING is a string `get', `set', `*', or nil,
indicating a found keyword."
(when (string= type-string "*")
(setf (js2-function-node-generator-type fn) 'STAR))
(setq end (js2-node-end fn)
- result (make-js2-method-node :type type
- :pos pos
+ result (make-js2-method-node :pos pos
:len (- end pos)
:left prop
:right fn))
- [elpa] master c0e0309 022/110: Allow semicolons in a class body, (continued)
- [elpa] master c0e0309 022/110: Allow semicolons in a class body, Dmitry Gutov, 2016/06/22
- [elpa] master df3f97f 030/110: Add js2-jsx-mode, Dmitry Gutov, 2016/06/22
- [elpa] master 6aba571 021/110: Merge pull request #276 from XeCycle/methods, Dmitry Gutov, 2016/06/22
- [elpa] master 221282a 028/110: Merge pull request #280 from XeCycle/binding-pattern-initializer, Dmitry Gutov, 2016/06/22
- [elpa] master 2e7fdb3 012/110: Also highlight property lookups with the same face, Dmitry Gutov, 2016/06/22
- [elpa] master b1234ca 013/110: Don't misindent generator methods, Dmitry Gutov, 2016/06/22
- [elpa] master d82a58d 019/110: Refactor: rename getter-setter-node to method-node, Dmitry Gutov, 2016/06/22
- [elpa] master 263852b 026/110: Add melpa badges, Dmitry Gutov, 2016/06/22
- [elpa] master 98433fb 036/110: `js2-print-json-path' added, Dmitry Gutov, 2016/06/22
- [elpa] master f9d28d3 052/110: Adjust js2-print-export-node, Dmitry Gutov, 2016/06/22
- [elpa] master d307285 039/110: Move method type handling to property METHOD_TYPE,
Dmitry Gutov <=
- [elpa] master f652d17 044/110: Add setImmediate and clearImmediate to js2-node-externs, Dmitry Gutov, 2016/06/22
- [elpa] master e0972fb 048/110: s/will/would, Dmitry Gutov, 2016/06/22
- [elpa] master d201a30 027/110: Merge pull request #281 from robbyoconnor/patch-1, Dmitry Gutov, 2016/06/22
- [elpa] master 667d320 034/110: Merge pull request #282 from jacksonrayhamilton/js2-jsx-mode, Dmitry Gutov, 2016/06/22
- [elpa] master 29f74b1 040/110: Allow 0o octals in strict mode, Dmitry Gutov, 2016/06/22
- [elpa] master 2a22635 035/110: Support .jsx file extension too in the example, Dmitry Gutov, 2016/06/22
- [elpa] master 4955584 037/110: Merge pull request #278 from redguardtoo/master, Dmitry Gutov, 2016/06/22
- [elpa] master 7c12f2c 031/110: Copy JSX indentation logic to js2-old-indent.el, Dmitry Gutov, 2016/06/22
- [elpa] master d0e4323 046/110: Add NEWS entry for async/await, Dmitry Gutov, 2016/06/22
- [elpa] master 0b1704b 041/110: Merge pull request #284 from XeCycle/0o-octals, Dmitry Gutov, 2016/06/22