JavaScript: Fix formatting on long named exports (#6446)
* Modify to put specific export inline * Add tests * Fix tests * Modify to support default exports * Update CHANGELOG.unreleased.md * Modify to refactor * Add pr link * Modify to rename "content" -> "printed" * Modify to define canBreak helpter * Fix from linter * Update CHANGELOG.unreleased.md * Add testsmaster
parent
9f5bd298db
commit
3f89bba231
|
@ -581,6 +581,23 @@ Previously, Prettier formatted parens wrap binary expressions within call expres
|
||||||
)();
|
)();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### JavaScript: Fix formatting on long named exports ([#6446] by [@sosukesuzuki])
|
||||||
|
|
||||||
|
Previously, Prettier formatted long named exports differently than named imports.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Input
|
||||||
|
export { fooooooooooooooooooooooooooooooooooooooooooooooooo } from "fooooooooooooooooooooooooooooo";
|
||||||
|
|
||||||
|
// Prettier (stable)
|
||||||
|
export {
|
||||||
|
fooooooooooooooooooooooooooooooooooooooooooooooooo
|
||||||
|
} from "fooooooooooooooooooooooooooooo";
|
||||||
|
|
||||||
|
// Prettier (master)
|
||||||
|
export { fooooooooooooooooooooooooooooooooooooooooooooooooo } from "fooooooooooooooooooooooooooooo";
|
||||||
|
```
|
||||||
|
|
||||||
[#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
|
||||||
|
@ -601,6 +618,7 @@ Previously, Prettier formatted parens wrap binary expressions within call expres
|
||||||
[#6411]: https://github.com/prettier/prettier/pull/6411
|
[#6411]: https://github.com/prettier/prettier/pull/6411
|
||||||
[#6438]: https://github.com/prettier/prettier/pull/6411
|
[#6438]: https://github.com/prettier/prettier/pull/6411
|
||||||
[#6441]: https://github.com/prettier/prettier/pull/6441
|
[#6441]: https://github.com/prettier/prettier/pull/6441
|
||||||
|
[#6446]: https://github.com/prettier/prettier/pull/6446
|
||||||
[@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
|
||||||
|
|
|
@ -4598,14 +4598,15 @@ function printExportDeclaration(path, options, print) {
|
||||||
defaultSpecifiers.length !== 0 &&
|
defaultSpecifiers.length !== 0 &&
|
||||||
(namespaceSpecifiers.length !== 0 || specifiers.length !== 0);
|
(namespaceSpecifiers.length !== 0 || specifiers.length !== 0);
|
||||||
|
|
||||||
parts.push(
|
const canBreak =
|
||||||
decl.exportKind === "type" ? "type " : "",
|
specifiers.length > 1 ||
|
||||||
concat(defaultSpecifiers),
|
defaultSpecifiers.length > 0 ||
|
||||||
concat([isDefaultFollowed ? ", " : ""]),
|
(decl.specifiers && decl.specifiers.some(node => node.comments));
|
||||||
concat(namespaceSpecifiers),
|
|
||||||
concat([isNamespaceFollowed ? ", " : ""]),
|
let printed = "";
|
||||||
specifiers.length !== 0
|
if (specifiers.length !== 0) {
|
||||||
? group(
|
if (canBreak) {
|
||||||
|
printed = group(
|
||||||
concat([
|
concat([
|
||||||
"{",
|
"{",
|
||||||
indent(
|
indent(
|
||||||
|
@ -4618,8 +4619,25 @@ function printExportDeclaration(path, options, print) {
|
||||||
options.bracketSpacing ? line : softline,
|
options.bracketSpacing ? line : softline,
|
||||||
"}"
|
"}"
|
||||||
])
|
])
|
||||||
)
|
);
|
||||||
: ""
|
} else {
|
||||||
|
printed = concat([
|
||||||
|
"{",
|
||||||
|
options.bracketSpacing ? " " : "",
|
||||||
|
concat(specifiers),
|
||||||
|
options.bracketSpacing ? " " : "",
|
||||||
|
"}"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parts.push(
|
||||||
|
decl.exportKind === "type" ? "type " : "",
|
||||||
|
concat(defaultSpecifiers),
|
||||||
|
concat([isDefaultFollowed ? ", " : ""]),
|
||||||
|
concat(namespaceSpecifiers),
|
||||||
|
concat([isNamespaceFollowed ? ", " : ""]),
|
||||||
|
printed
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
parts.push("{}");
|
parts.push("{}");
|
||||||
|
|
|
@ -11,6 +11,9 @@ export v from 'mod';
|
||||||
export a, * as b from 'mod';
|
export a, * as b from 'mod';
|
||||||
export c, { foo } from 'mod';
|
export c, { foo } from 'mod';
|
||||||
export * as d, { bar } from 'mod';
|
export * as d, { bar } from 'mod';
|
||||||
|
export { fooooooooooooooooooooooooooooooooooooooooooooooooo } from "fooooooooooooooooooooooooooooo";
|
||||||
|
export Bar, { barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr } from "barrrrrrrrrrrrrrrrrrrrrrrrrrrr";
|
||||||
|
export { foooooooooooooooooooooooooooooooooooooooooooooo, fooooooooooooooooooooooooooooooooooooooooooooooo } from "fooooooooooooooooooooooooooooo";
|
||||||
|
|
||||||
=====================================output=====================================
|
=====================================output=====================================
|
||||||
export * as ns from "mod";
|
export * as ns from "mod";
|
||||||
|
@ -18,6 +21,14 @@ export v from "mod";
|
||||||
export a, * as b from "mod";
|
export a, * as b from "mod";
|
||||||
export c, { foo } from "mod";
|
export c, { foo } from "mod";
|
||||||
export * as d, { bar } from "mod";
|
export * as d, { bar } from "mod";
|
||||||
|
export { fooooooooooooooooooooooooooooooooooooooooooooooooo } from "fooooooooooooooooooooooooooooo";
|
||||||
|
export Bar, {
|
||||||
|
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
|
||||||
|
} from "barrrrrrrrrrrrrrrrrrrrrrrrrrrr";
|
||||||
|
export {
|
||||||
|
foooooooooooooooooooooooooooooooooooooooooooooo,
|
||||||
|
fooooooooooooooooooooooooooooooooooooooooooooooo
|
||||||
|
} from "fooooooooooooooooooooooooooooo";
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -3,3 +3,6 @@ export v from 'mod';
|
||||||
export a, * as b from 'mod';
|
export a, * as b from 'mod';
|
||||||
export c, { foo } from 'mod';
|
export c, { foo } from 'mod';
|
||||||
export * as d, { bar } from 'mod';
|
export * as d, { bar } from 'mod';
|
||||||
|
export { fooooooooooooooooooooooooooooooooooooooooooooooooo } from "fooooooooooooooooooooooooooooo";
|
||||||
|
export Bar, { barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr } from "barrrrrrrrrrrrrrrrrrrrrrrrrrrr";
|
||||||
|
export { foooooooooooooooooooooooooooooooooooooooooooooo, fooooooooooooooooooooooooooooooooooooooooooooooo } from "fooooooooooooooooooooooooooooo";
|
||||||
|
|
Loading…
Reference in New Issue