(defvar js2-ARROW 162) ; function arrow (=>)
(defvar js2-CLASS 163)
(defvar js2-EXTENDS 164)
-(defvar js2-STATIC 165)
-(defvar js2-SUPER 166)
-(defvar js2-TEMPLATE_HEAD 167) ; part of template literal before substitution
-(defvar js2-NO_SUBS_TEMPLATE 168) ; template literal without substitutions
-(defvar js2-TAGGED_TEMPLATE 169) ; tagged template literal
+(defvar js2-SUPER 165)
+(defvar js2-TEMPLATE_HEAD 166) ; part of template literal before substitution
+(defvar js2-NO_SUBS_TEMPLATE 167) ; template literal without substitutions
+(defvar js2-TAGGED_TEMPLATE 168) ; tagged template literal
- (defconst js2-num-tokens (1+ js2-TAGGED_TEMPLATE))
-(defvar js2-AWAIT 170) ; await (pseudo keyword)
++(defvar js2-AWAIT 169) ; await (pseudo keyword)
+
+ (defconst js2-num-tokens (1+ js2-AWAIT))
(defconst js2-debug-print-trees nil)
(rest-p (js2-function-node-rest-p n))
(body (js2-function-node-body n))
(expr (not (eq (js2-function-node-form n) 'FUNCTION_STATEMENT))))
- (unless (or method arrow)
- (insert pad "function")
- (unless getter
- (insert pad))
- (when (js2-function-node-async n)
- (insert "async "))
- (unless (or getter arrow)
- (insert "function")
++ (unless method
++ (insert pad)
++ (when (js2-function-node-async n) (insert "async "))
++ (unless arrow (insert "function"))
(when (eq (js2-function-node-generator-type n) 'STAR)
(insert "*")))
(when name
(when (js2-match-token js2-NAME)
(setq name (js2-create-name-node t)))
(js2-must-match js2-LP "msg.no.paren.parms")
- (js2-parse-function 'FUNCTION_EXPRESSION pos star-p name)))
+ (js2-parse-function 'FUNCTION_EXPRESSION pos star-p async-p name)))
- (defun js2-parse-function-internal (function-type pos star-p &optional name)
-(defun js2-parse-function (function-type pos star-p async-p &optional name)
- "Function parser. FUNCTION-TYPE is a symbol, POS is the
-beginning of the first token (function keyword, unless it's an
-arrow function), NAME is js2-name-node."
++(defun js2-parse-function-internal (function-type pos star-p &optional async-p name)
(let (fn-node lp)
(if (= (js2-current-token-type) js2-LP) ; eventually matched LP?
(setq lp (js2-current-token-beg)))
(setf (js2-scope-parent-scope fn-node) js2-current-scope)
fn-node))
- (defun js2-parse-function (function-type pos star-p &optional name)
++(defun js2-parse-function (function-type pos star-p &optional async-p name)
+ "Function parser. FUNCTION-TYPE is a symbol, POS is the
+beginning of the first token (function keyword, unless it's an
+arrow function), NAME is js2-name-node."
+ (let ((continue t)
+ ts-state
+ fn-node
+ ;; Preserve strict state outside this function.
+ (js2-in-use-strict-directive js2-in-use-strict-directive))
+ ;; Parse multiple times if a new strict mode directive is discovered in the
+ ;; function body, as new rules will be retroactively applied to the legality
+ ;; of function names and parameters.
+ (while continue
+ (setq ts-state (make-js2-ts-state))
+ (setq continue (catch 'reparse
+ (setq fn-node (js2-parse-function-internal
- function-type pos star-p name))
++ function-type pos star-p async-p name))
+ ;; Don't continue.
+ nil))
+ (when continue
+ (js2-ts-seek ts-state)))
+ fn-node))
+
(defun js2-parse-statements (&optional parent)
"Parse a statement list. Last token consumed must be js2-LC.