diff --git a/packages/babel-generator/src/printer.ts b/packages/babel-generator/src/printer.ts index 354f15ff9658..5832e1dfa96b 100644 --- a/packages/babel-generator/src/printer.ts +++ b/packages/babel-generator/src/printer.ts @@ -7,6 +7,7 @@ import { isStatement, isClassBody, isTSInterfaceBody, + isTSEnumDeclaration, } from "@babel/types"; import type { RecordAndTuplePluginOptions, @@ -1103,7 +1104,8 @@ class Printer { singleLine && !isStatement(node) && !isClassBody(parent) && - !isTSInterfaceBody(parent); + !isTSInterfaceBody(parent) && + !isTSEnumDeclaration(parent); if (type === COMMENT_TYPE.LEADING) { this._printComment( diff --git a/packages/babel-generator/test/index.js b/packages/babel-generator/test/index.js index a5493e1ee858..e107e969f2aa 100644 --- a/packages/babel-generator/test/index.js +++ b/packages/babel-generator/test/index.js @@ -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( `