Skip to content

inconsistent semicolon placement with trailing block comments on variable declarations #18832

@Dunqing

Description

@Dunqing

Prettier 3.8.1
Playground link

--parser babel

Input:

const fn = () => {
  return;
} /* foo */;

() => {
  return;
} /* foo */

const v = a || b /* bar */;

a || b /* bar */;

Output:

const fn = () => {
  return;
}; /* foo */

() => {
  return;
}; /* foo */

const v = a || b; /* bar */

a || b /* bar */;

Expected output:
Same as input

const fn = () => {
  return;
} /* foo */;

() => {
  return;
} /* foo */

const v = a || b /* bar */;

a || b /* bar */;

Why?

Semicolon placement is inconsistent: variable declarations move the semicolon before the comment (}; /* foo */), while expression statements keep it after (} /* foo */;).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions