From 3bcf3b0a24fe7d6b1c38ff1c552ba160e6721018 Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Wed, 12 Oct 2022 10:21:01 +0800 Subject: [PATCH] review --- packages/babel-generator/src/printer.ts | 15 +++++++++++++-- .../fixtures/flow-comments/type-cast/output.js | 4 +--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/babel-generator/src/printer.ts b/packages/babel-generator/src/printer.ts index f55ec31cfb93..614390e9878a 100644 --- a/packages/babel-generator/src/printer.ts +++ b/packages/babel-generator/src/printer.ts @@ -2,7 +2,13 @@ import Buffer from "./buffer"; import type { Loc } from "./buffer"; import * as n from "./node"; import type * as t from "@babel/types"; -import { isProperty, isFunction, isStatement, isLVal } from "@babel/types"; +import { + isProperty, + isFunction, + isStatement, + isClassBody, + isTSInterfaceBody, +} from "@babel/types"; import type { RecordAndTuplePluginOptions, PipelineOperatorPluginOptions, @@ -1020,7 +1026,12 @@ class Printer { ? COMMENT_SKIP_NEWLINE.SKIP_ALL : COMMENT_SKIP_NEWLINE.DEFAULT, ); - } else if (type === COMMENT_TYPE.TRAILING && isLVal(node)) { + } else if ( + type === COMMENT_TYPE.TRAILING && + !isStatement(node) && + !isClassBody(parent) && + !isTSInterfaceBody(parent) + ) { this._printComment(comment, COMMENT_SKIP_NEWLINE.SKIP_ALL); } else { this._printComment(comment, COMMENT_SKIP_NEWLINE.DEFAULT); diff --git a/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/type-cast/output.js b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/type-cast/output.js index adfbff51872f..1b2c5f2b1fca 100644 --- a/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/type-cast/output.js +++ b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/type-cast/output.js @@ -1,4 +1,2 @@ var a = (y /*: any*/); -var a = ((y /*: foo*/) -/*: any*/ -); +var a = ((y /*: foo*/) /*: any*/);