]> code.delx.au - gnu-emacs-elpa/commitdiff
Do not declare fn expression's name in the enclosing scope
authorDmitry Gutov <dgutov@yandex.ru>
Sun, 7 Dec 2014 05:47:52 +0000 (07:47 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Sun, 7 Dec 2014 05:47:52 +0000 (07:47 +0200)
Fixes #186

js2-mode.el
tests/parser.el

index c3bb903419a6b1eccf3d713844f90fd1d13e10c0..b80d60d1edb0238dfa2ae781b4f1ab0f194f9c0d 100644 (file)
@@ -7664,7 +7664,8 @@ arrow function), NAME is js2-name-node."
     (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))
+      (when (and (eq function-type 'FUNCTION_STATEMENT)
+                 (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)))
     (if (or (js2-inside-function) (plusp js2-nesting-of-with))
index dc210a5a89561f5e53e9ba34786751a9d7497a2e..00bd2cff9b35dbeb29a64551b590c653f75c09d6 100644 (file)
@@ -199,6 +199,16 @@ the test."
 (js2-deftest-parse object-literal-computed-keys
   "var x = {[Symbol.iterator]: function() {}};")
 
+;;; Function definition
+
+(js2-deftest function-redeclaring-var "var gen = 3; function gen() {};"
+  (js2-mode)
+  (should (= (length (js2-ast-root-warnings js2-mode-ast)) 1)))
+
+(js2-deftest function-expression-var-same-name "var gen = function gen() {};"
+  (js2-mode)
+  (should (null (js2-ast-root-warnings js2-mode-ast))))
+
 ;;; Function parameters
 
 (js2-deftest-parse function-with-default-parameters