emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master ab82544 23/45: Do not declare fn expression's name in the


From: Dmitry Gutov
Subject: [elpa] master ab82544 23/45: Do not declare fn expression's name in the enclosing scope
Date: Mon, 02 Feb 2015 03:18:42 +0000

branch: master
commit ab825444356826caf4d85ee60c452de2975eb5a2
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Do not declare fn expression's name in the enclosing scope
    
    Fixes #186
---
 js2-mode.el     |    3 ++-
 tests/parser.el |   10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/js2-mode.el b/js2-mode.el
index c3bb903..b80d60d 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -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))
diff --git a/tests/parser.el b/tests/parser.el
index dc210a5..00bd2cf 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]