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

fix: Print newlines for leading Comments of TSEnumMember #15216

Merged
merged 1 commit into from Nov 29, 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
4 changes: 3 additions & 1 deletion packages/babel-generator/src/printer.ts
Expand Up @@ -7,6 +7,7 @@ import {
isStatement,
isClassBody,
isTSInterfaceBody,
isTSEnumDeclaration,
} from "@babel/types";
import type {
RecordAndTuplePluginOptions,
Expand Down Expand Up @@ -1089,7 +1090,8 @@ class Printer {
singleLine &&
!isStatement(node) &&
!isClassBody(parent) &&
!isTSInterfaceBody(parent);
!isTSInterfaceBody(parent) &&
!isTSEnumDeclaration(parent);

if (type === COMMENT_TYPE.LEADING) {
this._printComment(
Expand Down
31 changes: 31 additions & 0 deletions packages/babel-generator/test/index.js
Expand Up @@ -634,6 +634,37 @@ describe("generation", function () {
`);
});

it("comments without loc3", () => {
const ast = parse(
`
/** This describes how the endpoint is implemented when the lease is deployed */
export enum Endpoint_Kind {
/** SHARED_HTTP - Describes an endpoint that becomes a Kubernetes Ingress */
SHARED_HTTP = 0,
/** RANDOM_PORT - Describes an endpoint that becomes a Kubernetes NodePort */
RANDOM_PORT = 1,
UNRECOGNIZED = -1,
}
`,
{ sourceType: "module", plugins: ["typescript"] },
);

for (const comment of ast.comments) {
comment.loc = undefined;
}

expect(generate(ast).code).toMatchInlineSnapshot(`
"/** This describes how the endpoint is implemented when the lease is deployed */
export enum Endpoint_Kind {
/** SHARED_HTTP - Describes an endpoint that becomes a Kubernetes Ingress */
SHARED_HTTP = 0,
/** RANDOM_PORT - Describes an endpoint that becomes a Kubernetes NodePort */
RANDOM_PORT = 1,
UNRECOGNIZED = -1,
}"
`);
});

it("comments without node.loc", () => {
const ast = parse(
`
Expand Down