]> code.delx.au - gnu-emacs-elpa/commitdiff
Include function's AST node in parent scope's symbol table entry
authorDmitry Gutov <dgutov@yandex.ru>
Sun, 13 Oct 2013 02:46:53 +0000 (05:46 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Sun, 13 Oct 2013 02:46:53 +0000 (05:46 +0300)
Reported by Sergey Mogzovoy

js2-mode.el
tests/parser.el

index 03be86b5048b582c9d242d8502a7f7be6af9f7e1..e6eace1b82fc582d93d17c86c26cc2eb331fe38f 100644 (file)
@@ -7426,16 +7426,16 @@ arrow function), NAME is js2-name-node."
   (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.
index b84265ebe4fcf1196182910e32d736df6d90f135..0176f935cabd7d1831fcef082bb040f72103c87e 100644 (file)
@@ -197,6 +197,28 @@ the test."
   (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