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

improve SourceLocation typing #15776

Merged
merged 2 commits into from
Jul 13, 2023
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
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