diff --git a/packages/babel-traverse/src/path/family.ts b/packages/babel-traverse/src/path/family.ts index 9ad0f6dbef06..14c81d48acb4 100644 --- a/packages/babel-traverse/src/path/family.ts +++ b/packages/babel-traverse/src/path/family.ts @@ -498,17 +498,26 @@ function getOuterBindingIdentifiers( export { getOuterBindingIdentifiers }; +function getBindingIdentifierPaths( + duplicates: true, + outerOnly?: boolean, +): Record[]>; +function getBindingIdentifierPaths( + duplicates: false, + outerOnly?: boolean, +): Record>; +function getBindingIdentifierPaths( + duplicates?: boolean, + outerOnly?: boolean, +): Record | NodePath[]>; + // original source - https://github.com/babel/babel/blob/main/packages/babel-types/src/retrievers/getBindingIdentifiers.js -// path.getBindingIdentifiers returns nodes where the following re-implementation -// returns paths -export function getBindingIdentifierPaths( +// path.getBindingIdentifiers returns nodes where the following re-implementation returns paths +function getBindingIdentifierPaths( this: NodePath, duplicates: boolean = false, outerOnly: boolean = false, -): { - // todo: returns NodePath[] when duplicates is true - [x: string]: NodePath; -} { +): Record | NodePath[]> { const path = this; const search = [path]; const ids = Object.create(null); @@ -563,13 +572,26 @@ export function getBindingIdentifierPaths( } } - // $FlowIssue Object.create() is object type return ids; } -export function getOuterBindingIdentifierPaths( - this: NodePath, +export { getBindingIdentifierPaths }; + +function getOuterBindingIdentifierPaths( + duplicates: true, +): Record[]>; +function getOuterBindingIdentifierPaths( + duplicates?: false, +): Record>; +function getOuterBindingIdentifierPaths( duplicates?: boolean, +): Record | NodePath[]>; + +function getOuterBindingIdentifierPaths( + this: NodePath, + duplicates: boolean = false, ) { return this.getBindingIdentifierPaths(duplicates, true); } + +export { getOuterBindingIdentifierPaths }; diff --git a/packages/babel-traverse/src/scope/binding.ts b/packages/babel-traverse/src/scope/binding.ts index 48f15692f813..8ca4cd2c0e2d 100644 --- a/packages/babel-traverse/src/scope/binding.ts +++ b/packages/babel-traverse/src/scope/binding.ts @@ -79,7 +79,7 @@ export default class Binding { * Register a constant violation with the provided `path`. */ - reassign(path: any) { + reassign(path: NodePath) { this.constant = false; if (this.constantViolations.indexOf(path) !== -1) { return;