| 1 |
import { |
| 2 |
isFunction, |
| 3 |
isCatchClause, |
| 4 |
isBlockStatement, |
| 5 |
isScopable, |
| 6 |
isPattern, |
| 7 |
} from "./generated"; |
| 8 |
import type * as t from ".."; |
| 9 |
|
| 10 |
/** |
| 11 |
* Check if the input `node` is a scope. |
| 12 |
*/ |
| 13 |
export default function isScope(node: t.Node, parent: t.Node): boolean { |
| 14 |
// If a BlockStatement is an immediate descendent of a Function/CatchClause, it must be in the body. |
| 15 |
// Hence we skipped the parentKey === "params" check |
| 16 |
if (isBlockStatement(node) && (isFunction(parent) || isCatchClause(parent))) { |
| 17 |
return false; |
| 18 |
} |
| 19 |
|
| 20 |
// If a Pattern is an immediate descendent of a Function/CatchClause, it must be in the params. |
| 21 |
// Hence we skipped the parentKey === "params" check |
| 22 |
if (isPattern(node) && (isFunction(parent) || isCatchClause(parent))) { |
| 23 |
return true; |
| 24 |
} |
| 25 |
|
| 26 |
return isScopable(node); |
| 27 |
} |