Skip to content

Commit a196459

Browse files
authored
chore(traverse): fix some internal typescript types (#14821)
1 parent 8d17ae6 commit a196459

2 files changed

Lines changed: 33 additions & 11 deletions

File tree

packages/babel-traverse/src/path/family.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -498,17 +498,26 @@ function getOuterBindingIdentifiers(
498498

499499
export { getOuterBindingIdentifiers };
500500

501+
function getBindingIdentifierPaths(
502+
duplicates: true,
503+
outerOnly?: boolean,
504+
): Record<string, NodePath<t.Identifier>[]>;
505+
function getBindingIdentifierPaths(
506+
duplicates: false,
507+
outerOnly?: boolean,
508+
): Record<string, NodePath<t.Identifier>>;
509+
function getBindingIdentifierPaths(
510+
duplicates?: boolean,
511+
outerOnly?: boolean,
512+
): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]>;
513+
501514
// original source - https://github.com/babel/babel/blob/main/packages/babel-types/src/retrievers/getBindingIdentifiers.js
502-
// path.getBindingIdentifiers returns nodes where the following re-implementation
503-
// returns paths
504-
export function getBindingIdentifierPaths(
515+
// path.getBindingIdentifiers returns nodes where the following re-implementation returns paths
516+
function getBindingIdentifierPaths(
505517
this: NodePath,
506518
duplicates: boolean = false,
507519
outerOnly: boolean = false,
508-
): {
509-
// todo: returns NodePath<t.Identifier>[] when duplicates is true
510-
[x: string]: NodePath<t.Identifier>;
511-
} {
520+
): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]> {
512521
const path = this;
513522
const search = [path];
514523
const ids = Object.create(null);
@@ -563,13 +572,26 @@ export function getBindingIdentifierPaths(
563572
}
564573
}
565574

566-
// $FlowIssue Object.create() is object type
567575
return ids;
568576
}
569577

570-
export function getOuterBindingIdentifierPaths(
571-
this: NodePath,
578+
export { getBindingIdentifierPaths };
579+
580+
function getOuterBindingIdentifierPaths(
581+
duplicates: true,
582+
): Record<string, NodePath<t.Identifier>[]>;
583+
function getOuterBindingIdentifierPaths(
584+
duplicates?: false,
585+
): Record<string, NodePath<t.Identifier>>;
586+
function getOuterBindingIdentifierPaths(
572587
duplicates?: boolean,
588+
): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]>;
589+
590+
function getOuterBindingIdentifierPaths(
591+
this: NodePath,
592+
duplicates: boolean = false,
573593
) {
574594
return this.getBindingIdentifierPaths(duplicates, true);
575595
}
596+
597+
export { getOuterBindingIdentifierPaths };

packages/babel-traverse/src/scope/binding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default class Binding {
7979
* Register a constant violation with the provided `path`.
8080
*/
8181

82-
reassign(path: any) {
82+
reassign(path: NodePath) {
8383
this.constant = false;
8484
if (this.constantViolations.indexOf(path) !== -1) {
8585
return;

0 commit comments

Comments
 (0)