Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Oct 11, 2022
1 parent dcb88d0 commit c54417e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
24 changes: 15 additions & 9 deletions packages/babel-generator/src/printer.ts
Expand Up @@ -2,7 +2,7 @@ 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 } from "@babel/types";
import { isProperty, isFunction, isStatement, isLVal } from "@babel/types";
import type {
RecordAndTuplePluginOptions,
PipelineOperatorPluginOptions,
Expand Down Expand Up @@ -1011,14 +1011,20 @@ class Printer {
} else {
hasLoc = false;

if (len === 1 && type === COMMENT_TYPE.LEADING) {
this._printComment(
comment,
(!isStatement(node) && !isProperty(node)) ||
isFunction(parent, { body: node })
? COMMENT_SKIP_NEWLINE.SKIP_ALL
: COMMENT_SKIP_NEWLINE.DEFAULT,
);
if (len === 1) {
if (type === COMMENT_TYPE.LEADING) {
this._printComment(
comment,
(!isStatement(node) && !isProperty(node)) ||
isFunction(parent, { body: node })
? COMMENT_SKIP_NEWLINE.SKIP_ALL
: COMMENT_SKIP_NEWLINE.DEFAULT,
);
} else if (type === COMMENT_TYPE.TRAILING && isLVal(node)) {
this._printComment(comment, COMMENT_SKIP_NEWLINE.SKIP_ALL);
} else {
this._printComment(comment, COMMENT_SKIP_NEWLINE.DEFAULT);
}
} else if (
type === COMMENT_TYPE.INNER &&
!(node.type === "ObjectExpression" && node.properties.length > 1) &&
Expand Down
@@ -1,4 +1,5 @@
class X {
foo = 2;
bar /*: number*/ = 3; /*:: baz: ?string*/
bar /*: number*/ = 3;
/*:: baz: ?string*/
}
@@ -1,2 +1,4 @@
var a = (y /*: any*/);
var a = ((y /*: foo*/) /*: any*/);
var a = ((y /*: foo*/)
/*: any*/
);

0 comments on commit c54417e

Please sign in to comment.