(let (fn-node lp)
(if (= (js2-current-token-type) js2-LP) ; eventually matched LP?
(setq lp (js2-current-token-beg)))
+ (setf fn-node (make-js2-function-node :pos pos
+ :name name
+ :form function-type
+ :lp (if lp (- lp pos))))
(when name
(js2-set-face (js2-node-pos name) (js2-node-end name)
'font-lock-function-name-face 'record)
(when (plusp (js2-name-node-length name))
;; Function statements define a symbol in the enclosing scope
(js2-define-symbol js2-FUNCTION (js2-name-node-name name) fn-node)))
- (setf fn-node (make-js2-function-node :pos pos
- :name name
- :form function-type
- :lp (if lp (- lp pos))))
(if (or (js2-inside-function) (plusp js2-nesting-of-with))
;; 1. Nested functions are not affected by the dynamic scope flag
;; as dynamic scope is already a parent of their scope.
(let ((assignment (js2-expr-stmt-node-expr (car (js2-scope-kids js2-mode-ast)))))\r
(should (js2-name-node-p (js2-assign-node-right assignment)))))\r
\r
+;;; Scopes\r
+\r
+(js2-deftest ast-symbol-table-includes-fn-node "function foo() {}"\r
+ (js2-mode)\r
+ (let ((entry (js2-scope-get-symbol js2-mode-ast 'foo)))\r
+ (should (= (js2-symbol-decl-type entry) js2-FUNCTION))\r
+ (should (equal (js2-symbol-name entry) "foo"))\r
+ (should (js2-function-node-p (js2-symbol-ast-node entry)))))\r
+\r
+(js2-deftest fn-symbol-table-includes-nested-fn "function foo() {\r
+ function bar() {}\r
+ var x;\r
+}"\r
+ (js2-mode)\r
+ (let* ((scope (js2-node-at-point (point-min)))\r
+ (fn-entry (js2-scope-get-symbol scope 'bar))\r
+ (var-entry (js2-scope-get-symbol scope 'x)))\r
+ (should (= (js2-symbol-decl-type fn-entry) js2-FUNCTION))\r
+ (should (js2-function-node-p (js2-symbol-ast-node fn-entry)))\r
+ (should (= (js2-symbol-decl-type var-entry) js2-VAR))\r
+ (should (js2-name-node-p (js2-symbol-ast-node var-entry)))))\r
+\r
;;; Tokenizer\r
\r
(js2-deftest get-token "(1+1)"\r