Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(traverse): fix some internal typescript types #14821

Merged
merged 1 commit into from Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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