fix(JavaScript): bug when arrow fn as function parameter with newline (#6301)
parent
d66c5f82da
commit
ce366f0834
|
@ -339,6 +339,35 @@ Previously, even if the line length is shorter than print-width is Prettier brea
|
||||||
</template>
|
</template>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### JavaScript: Fix breaks indentation and idempotency when an arrow function that args include object pattern is passed to a function as parameter. ([#6301] by [@sosukesuzuki])
|
||||||
|
|
||||||
|
Previously, Prettier collapses strangely, when an arrow function that args include object pattern is passed to a function as parameter. Also, it breaks idempotency. Please see [#6294](https://github.com/prettier/prettier/issues/6294) for detail.
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
```js
|
||||||
|
// Input
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Output (Prettier stable)
|
||||||
|
foo(({ a,
|
||||||
|
b }) => {});
|
||||||
|
|
||||||
|
// Output (Prettier master)
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
[#5910]: https://github.com/prettier/prettier/pull/5910
|
[#5910]: https://github.com/prettier/prettier/pull/5910
|
||||||
[#6186]: https://github.com/prettier/prettier/pull/6186
|
[#6186]: https://github.com/prettier/prettier/pull/6186
|
||||||
[#6206]: https://github.com/prettier/prettier/pull/6206
|
[#6206]: https://github.com/prettier/prettier/pull/6206
|
||||||
|
@ -350,6 +379,7 @@ Previously, even if the line length is shorter than print-width is Prettier brea
|
||||||
[#6289]: https://github.com/prettier/prettier/pull/6289
|
[#6289]: https://github.com/prettier/prettier/pull/6289
|
||||||
[#6332]: https://github.com/prettier/prettier/pull/6332
|
[#6332]: https://github.com/prettier/prettier/pull/6332
|
||||||
[#6284]: https://github.com/prettier/prettier/pull/6284
|
[#6284]: https://github.com/prettier/prettier/pull/6284
|
||||||
|
[#6301]: https://github.com/prettier/prettier/pull/6301
|
||||||
[@duailibe]: https://github.com/duailibe
|
[@duailibe]: https://github.com/duailibe
|
||||||
[@gavinjoyce]: https://github.com/gavinjoyce
|
[@gavinjoyce]: https://github.com/gavinjoyce
|
||||||
[@sosukesuzuki]: https://github.com/sosukesuzuki
|
[@sosukesuzuki]: https://github.com/sosukesuzuki
|
||||||
|
|
|
@ -4056,6 +4056,32 @@ function printArgumentsList(path, options, print) {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// func(
|
||||||
|
// ({
|
||||||
|
// a,
|
||||||
|
|
||||||
|
// b
|
||||||
|
// }) => {}
|
||||||
|
// );
|
||||||
|
function hasEmptyLineInObjectArgInArrowFunction(arg) {
|
||||||
|
return (
|
||||||
|
arg &&
|
||||||
|
arg.type === "ArrowFunctionExpression" &&
|
||||||
|
arg.params &&
|
||||||
|
arg.params.some(
|
||||||
|
param =>
|
||||||
|
param.type &&
|
||||||
|
param.type === "ObjectPattern" &&
|
||||||
|
param.properties &&
|
||||||
|
param.properties.some(
|
||||||
|
(property, i, properties) =>
|
||||||
|
i < properties.length - 1 &&
|
||||||
|
isNextLineEmpty(options.originalText, property, options)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let anyArgEmptyLine = false;
|
let anyArgEmptyLine = false;
|
||||||
let hasEmptyLineFollowingFirstArg = false;
|
let hasEmptyLineFollowingFirstArg = false;
|
||||||
const lastArgIndex = args.length - 1;
|
const lastArgIndex = args.length - 1;
|
||||||
|
@ -4076,6 +4102,8 @@ function printArgumentsList(path, options, print) {
|
||||||
parts.push(",", line);
|
parts.push(",", line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
anyArgEmptyLine = hasEmptyLineInObjectArgInArrowFunction(arg);
|
||||||
|
|
||||||
return concat(parts);
|
return concat(parts);
|
||||||
}, "arguments");
|
}, "arguments");
|
||||||
|
|
||||||
|
|
|
@ -286,6 +286,61 @@ fooooooooooooooooooooooooooooooooooooooooooooooooooo(action => next =>
|
||||||
dispatch(action),
|
dispatch(action),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
b
|
||||||
|
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
a,
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
)
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => a
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
b
|
||||||
|
}) => a
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
b
|
||||||
|
|
||||||
|
}) => a
|
||||||
|
);
|
||||||
|
|
||||||
=====================================output=====================================
|
=====================================output=====================================
|
||||||
Seq(typeDef.interface.groups).forEach(group =>
|
Seq(typeDef.interface.groups).forEach(group =>
|
||||||
Seq(group.members).forEach((member, memberName) =>
|
Seq(group.members).forEach((member, memberName) =>
|
||||||
|
@ -376,6 +431,39 @@ fooooooooooooooooooooooooooooooooooooooooooooooooooo(action => next =>
|
||||||
dispatch(action)
|
dispatch(action)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(({ a, b }) => {});
|
||||||
|
|
||||||
|
foo(({ a, b }) => {});
|
||||||
|
|
||||||
|
foo(
|
||||||
|
a,
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => a
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(({ a, b }) => a);
|
||||||
|
|
||||||
|
foo(({ a, b }) => a);
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -467,6 +555,61 @@ fooooooooooooooooooooooooooooooooooooooooooooooooooo(action => next =>
|
||||||
dispatch(action),
|
dispatch(action),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
b
|
||||||
|
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
a,
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
)
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => a
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
b
|
||||||
|
}) => a
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
b
|
||||||
|
|
||||||
|
}) => a
|
||||||
|
);
|
||||||
|
|
||||||
=====================================output=====================================
|
=====================================output=====================================
|
||||||
Seq(typeDef.interface.groups).forEach((group) =>
|
Seq(typeDef.interface.groups).forEach((group) =>
|
||||||
Seq(group.members).forEach((member, memberName) =>
|
Seq(group.members).forEach((member, memberName) =>
|
||||||
|
@ -557,6 +700,39 @@ fooooooooooooooooooooooooooooooooooooooooooooooooooo((action) => (next) =>
|
||||||
dispatch(action)
|
dispatch(action)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(({ a, b }) => {});
|
||||||
|
|
||||||
|
foo(({ a, b }) => {});
|
||||||
|
|
||||||
|
foo(
|
||||||
|
a,
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => a
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(({ a, b }) => a);
|
||||||
|
|
||||||
|
foo(({ a, b }) => a);
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
|
@ -78,3 +78,58 @@ jest.mock(
|
||||||
fooooooooooooooooooooooooooooooooooooooooooooooooooo(action => next =>
|
fooooooooooooooooooooooooooooooooooooooooooooooooooo(action => next =>
|
||||||
dispatch(action),
|
dispatch(action),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
b
|
||||||
|
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
a,
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => {}
|
||||||
|
)
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
|
||||||
|
b
|
||||||
|
}) => a
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
b
|
||||||
|
}) => a
|
||||||
|
);
|
||||||
|
|
||||||
|
foo(
|
||||||
|
({
|
||||||
|
a,
|
||||||
|
b
|
||||||
|
|
||||||
|
}) => a
|
||||||
|
);
|
||||||
|
|
Loading…
Reference in New Issue