From ab825444356826caf4d85ee60c452de2975eb5a2 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sun, 7 Dec 2014 07:47:52 +0200 Subject: [PATCH] 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 deletion(-) diff --git a/js2-mode.el b/js2-mode.el index c3bb90341..b80d60d1e 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 dc210a5a8..00bd2cff9 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 -- 2.39.2