]> code.delx.au - gnu-emacs-elpa/blobdiff - tests/parser.el
Include function's AST node in parent scope's symbol table entry
[gnu-emacs-elpa] / tests / parser.el
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