Skip to content

Commit

Permalink
chore(traverse): fix some internal typescript types (#14821)
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Aug 3, 2022
1 parent 8d17ae6 commit a196459
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
42 changes: 32 additions & 10 deletions packages/babel-traverse/src/path/family.ts
Expand Up @@ -498,17 +498,26 @@ function getOuterBindingIdentifiers(

export { getOuterBindingIdentifiers };

function getBindingIdentifierPaths(
duplicates: true,
outerOnly?: boolean,
): Record<string, NodePath<t.Identifier>[]>;
function getBindingIdentifierPaths(
duplicates: false,
outerOnly?: boolean,
): Record<string, NodePath<t.Identifier>>;
function getBindingIdentifierPaths(
duplicates?: boolean,
outerOnly?: boolean,
): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]>;

// 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<t.Identifier>[] when duplicates is true
[x: string]: NodePath<t.Identifier>;
} {
): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]> {
const path = this;
const search = [path];
const ids = Object.create(null);
Expand Down Expand Up @@ -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<string, NodePath<t.Identifier>[]>;
function getOuterBindingIdentifierPaths(
duplicates?: false,
): Record<string, NodePath<t.Identifier>>;
function getOuterBindingIdentifierPaths(
duplicates?: boolean,
): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]>;

function getOuterBindingIdentifierPaths(
this: NodePath,
duplicates: boolean = false,
) {
return this.getBindingIdentifierPaths(duplicates, true);
}

export { getOuterBindingIdentifierPaths };
2 changes: 1 addition & 1 deletion packages/babel-traverse/src/scope/binding.ts
Expand Up @@ -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;
Expand Down

0 comments on commit a196459

Please sign in to comment.