Preserve blank line between export specifiers (#12746)

* Preserve blank line between export specifiers

* Add changelog

* rename
This commit is contained in:
Sosuke Suzuki authored and GitHub committed 2022-04-29 17:42:42 +09:00
1 parent e23b89b8c7
commit 504d751036
4 files changed
+172 -6

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
#### Preserve blank line between export specifiers (#12746 by @sosukesuzuki)
<!-- prettier-ignore -->
```jsx
// Input
export {
// a
foo1,
// b
bar1,
baz1,
} from "mod";
// Prettier stable
export {
// a
foo1,
// b
bar1,
baz1,
} from "mod";
// Prettier main
export {
// a
foo1,
// b
bar1,
baz1,
} from "mod";
```
+9 -6
View File
@@ -65,7 +65,7 @@ function handleOwnLineComment(context) {
handleForComments,
handleUnionTypeComments,
handleOnlyComments,
handleImportDeclarationComments,
handleModuleSpecifiersComments,
handleAssignmentPatternComments,
handleMethodNameComments,
handleLabeledStatementComments,
@@ -787,17 +787,20 @@ function handleForComments({ comment, enclosingNode }) {
return false;
}
function handleImportDeclarationComments({
function handleModuleSpecifiersComments({
comment,
precedingNode,
enclosingNode,
text,
}) {
const isImportDeclaration =
precedingNode?.type === "ImportSpecifier" &&
enclosingNode?.type === "ImportDeclaration";
const isExportDeclaration =
precedingNode?.type === "ExportSpecifier" &&
enclosingNode?.type === "ExportNamedDeclaration";
if (
precedingNode &&
precedingNode.type === "ImportSpecifier" &&
enclosingNode &&
enclosingNode.type === "ImportDeclaration" &&
(isImportDeclaration || isExportDeclaration) &&
hasNewline(text, locEnd(comment))
) {
addTrailingComment(precedingNode, comment);
@@ -1,5 +1,114 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`blank-line-between-specifiers.js - {"bracketSpacing":false} format 1`] = `
====================================options=====================================
bracketSpacing: false
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
export {
// a
foo1,
// b
bar1,
baz1,
} from "mod";
const foo2 = 1;
const bar2 = 1;
const baz2 = 1;
export {
// a
foo2,
// b
bar2,
baz2,
};
=====================================output=====================================
export {
// a
foo1,
// b
bar1,
baz1,
} from "mod";
const foo2 = 1;
const bar2 = 1;
const baz2 = 1;
export {
// a
foo2,
// b
bar2,
baz2,
};
================================================================================
`;
exports[`blank-line-between-specifiers.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
export {
// a
foo1,
// b
bar1,
baz1,
} from "mod";
const foo2 = 1;
const bar2 = 1;
const baz2 = 1;
export {
// a
foo2,
// b
bar2,
baz2,
};
=====================================output=====================================
export {
// a
foo1,
// b
bar1,
baz1,
} from "mod";
const foo2 = 1;
const bar2 = 1;
const baz2 = 1;
export {
// a
foo2,
// b
bar2,
baz2,
};
================================================================================
`;
exports[`bracket.js - {"bracketSpacing":false} format 1`] = `
====================================options=====================================
bracketSpacing: false
@@ -0,0 +1,21 @@
export {
// a
foo1,
// b
bar1,
baz1,
} from "mod";
const foo2 = 1;
const bar2 = 1;
const baz2 = 1;
export {
// a
foo2,
// b
bar2,
baz2,
};