Skip to content

Leading comments of sequence expressions were placed incorrectly #18169

@Dunqing

Description

@Dunqing

Prettier 3.6.2
Playground link

--parser acorn

Input:

func(() => // comment
(a , b , c))


func(
  () =>
    (
      // comment
      a, b, c
    ),
);

(
  // comment
  a, b, c
);

Output:

func(
  () =>
    // comment
    (a, b, c),
);

func(
  () =>
    // comment
    (a, b, c),
);

// comment
(a, b, c);

Expected output:

  1. Place comments inside the sequence expression
func(
  () =>
    (
      // comment
      a, b, c
    ),
);

func(
  () =>
    (
      // comment
      a, b, c
    ),
);

(
  // comment
  a, b, c
)
  1. Keep the comments place as-is
func(
  () =>
    // comment
    (a, b, c),
);

func(
  () =>
    (
      // comment
      a, b, c
    ),
);

(
  // comment
  a, b, c
)

Why?

I think the comment, if the sequence expression wraps it, then the output should keep it in the same place. However, it was placed before the sequence expression anyway.

Not sure which output is better, here are my thoughts on the two different results:

  1. The first one maintains consistency as long as the comments precede the first expression of the sequence.
  2. The second one keeps the comments in the same place as the input.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions