From 6fab78ef13450211b733ed5b621b8615937b3cf2 Mon Sep 17 00:00:00 2001 From: fisker Date: Wed, 11 Mar 2020 15:10:58 +0800 Subject: [PATCH] Nested --- rules/consistent-function-scoping.js | 9 ++++++++- test/consistent-function-scoping.js | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/rules/consistent-function-scoping.js b/rules/consistent-function-scoping.js index fcb0ea350b..f78cd3c969 100644 --- a/rules/consistent-function-scoping.js +++ b/rules/consistent-function-scoping.js @@ -75,9 +75,16 @@ function checkReferences(scope, parent, scopeManager) { ); } +const isArrowFunctionWithThis = scope => + scope.type === 'function' && + scope.block && + scope.block.type === 'ArrowFunctionExpression' && + scope.thisFound + function checkNode(node, scopeManager) { const scope = scopeManager.acquire(node); - if (!scope || (node.type === 'ArrowFunctionExpression' && scope.thisFound)) { + + if (!scope || isArrowFunctionWithThis(scope) || scope.childScopes.some(scope => isArrowFunctionWithThis(scope))) { return true; } diff --git a/test/consistent-function-scoping.js b/test/consistent-function-scoping.js index 52d75d3cd3..3e73081816 100644 --- a/test/consistent-function-scoping.js +++ b/test/consistent-function-scoping.js @@ -198,6 +198,12 @@ ruleTester.run('consistent-function-scoping', rule, { return doBar(); }; `, + outdent` + function doFoo(Foo) { + const doBar = () => () => this; + return doBar(); + }; + `, // `arguments` outdent` function doFoo(Foo) {