Skip to content

Incorrect arguments formatting when the call is nested and its root call is an initialization of a variable declarator. #18388

@Dunqing

Description

@Dunqing

Prettier 3.7.3
Playground link

--parser babel-ts

Input:

// Correct
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx()((
  props: xxxxxxxxxxxxx,
) => {
  //
});

// Correct
const x = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx((
  props: xxxxxxxxxxxxx,
) => {
  //
});

// Incorrect, weird group breaking
const x = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx()((
  props: xxxxxxxxxxxxx,
) => {
  //
});

Output:

// Correct
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx()(
  (props: xxxxxxxxxxxxx) => {
    //
  },
);

// Correct
const x = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
  (props: xxxxxxxxxxxxx) => {
    //
  },
);

// Incorrect, weird group breaking
const x = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx()((
  props: xxxxxxxxxxxxx,
) => {
  //
});

Expected output:

// Correct
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx()(
  (props: xxxxxxxxxxxxx) => {
    //
  },
);

// Correct
const x = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
  (props: xxxxxxxxxxxxx) => {
    //
  },
);

// Incorrect, weird group breaking
const x = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx()(
  (props: xxxxxxxxxxxxx) => {
    //
  },
);

Why?

Original issue in oxc-project/oxc#16255.

The incorrect example's output is weird; it should be the same as other similar cases, because the argument has no changes in these three cases.

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