fix: mark Pattern in CatchClause as scope (#12119)

This commit is contained in:
Huáng Jùnliàng
2020-09-29 15:04:24 -04:00
committed by GitHub
parent afc03581cc
commit e0b2bfb78f
10 changed files with 54 additions and 17 deletions

View File

@@ -11,17 +11,15 @@ import {
* Check if the input `node` is a scope.
*/
export default function isScope(node: Object, parent: Object): boolean {
if (isBlockStatement(node) && isFunction(parent, { body: node })) {
return false;
}
if (isBlockStatement(node) && isCatchClause(parent, { body: node })) {
return false;
}
// If a Pattern is an immediate descendent of a Function, it must be in the params.
// If a BlockStatement is an immediate descendent of a Function/CatchClause, it must be in the body.
// Hence we skipped the parentKey === "params" check
if (isPattern(node) && isFunction(parent)) {
if (isBlockStatement(node) && (isFunction(parent) || isCatchClause(parent))) {
return false;
}
// If a Pattern is an immediate descendent of a Function/CatchClause, it must be in the params.
// Hence we skipped the parentKey === "params" check
if (isPattern(node) && (isFunction(parent) || isCatchClause(parent))) {
return true;
}