Skip to content

Commit

Permalink
improve SourceLocation typing (#15776)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jul 13, 2023
1 parent 900f6de commit 52244bf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
4 changes: 1 addition & 3 deletions packages/babel-generator/src/generators/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ function _getFuncIdName(
if (id.type === "Identifier") {
nameInfo = {
pos: id.loc?.start,
name:
// @ts-expect-error Undocumented property identifierName
id.loc?.identifierName || id.name,
name: id.loc?.identifierName || id.name,
};
} else if (id.type === "PrivateName") {
nameInfo = {
Expand Down
5 changes: 1 addition & 4 deletions packages/babel-generator/src/generators/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import type * as t from "@babel/types";
import jsesc from "jsesc";

export function Identifier(this: Printer, node: t.Identifier) {
this.sourceIdentifierName(
// @ts-expect-error Undocumented property identifierName
node.loc?.identifierName || node.name,
);
this.sourceIdentifierName(node.loc?.identifierName || node.name);
this.word(node.name);
}

Expand Down
19 changes: 10 additions & 9 deletions packages/babel-types/scripts/generators/ast-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ interface BaseComment {
type: "CommentBlock" | "CommentLine";
}
interface Position {
line: number;
column: number;
index: number;
}
export interface CommentBlock extends BaseComment {
type: "CommentBlock";
}
Expand All @@ -59,15 +65,10 @@ export interface CommentLine extends BaseComment {
export type Comment = CommentBlock | CommentLine;
export interface SourceLocation {
start: {
line: number;
column: number;
};
end: {
line: number;
column: number;
};
start: Position;
end: Position;
filename: string;
identifierName: string | undefined | null;
}
interface BaseNode {
Expand Down
19 changes: 10 additions & 9 deletions packages/babel-types/src/ast-types/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ interface BaseComment {
type: "CommentBlock" | "CommentLine";
}

interface Position {
line: number;
column: number;
index: number;
}

export interface CommentBlock extends BaseComment {
type: "CommentBlock";
}
Expand All @@ -22,15 +28,10 @@ export interface CommentLine extends BaseComment {
export type Comment = CommentBlock | CommentLine;

export interface SourceLocation {
start: {
line: number;
column: number;
};

end: {
line: number;
column: number;
};
start: Position;
end: Position;
filename: string;
identifierName: string | undefined | null;
}

interface BaseNode {
Expand Down

0 comments on commit 52244bf

Please sign in to comment.