Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not add excess empty lines between object properties #1262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions lib/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,6 @@ function genericPrintNoParens(path: any, options: any, print: any) {
? ";"
: ",";
const fields = [];
let allowBreak = false;

if (isTypeAnnotation) {
fields.push("indexers", "callProperties");
Expand Down Expand Up @@ -743,19 +742,9 @@ function genericPrintNoParens(path: any, options: any, print: any) {
lines = lines.indent(options.tabWidth);
}

const multiLine = !isTypeAnnotation && lines.length > 1;
if (multiLine && allowBreak) {
// Similar to the logic for BlockStatement.
parts.push("\n");
}

parts.push(lines);

if (i < len - 1) {
// Add an extra line break if the previous object property
// had a multi-line value.
parts.push(separator + (multiLine ? "\n\n" : "\n"));
allowBreak = !multiLine;
parts.push(separator + "\n");
} else if (len !== 1 && isTypeAnnotation) {
parts.push(separator);
} else if (
Expand Down
4 changes: 0 additions & 4 deletions test/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,15 @@ describe("Babel", function () {
" async *a() {", // ObjectMethod
" b;",
" },",
"",
" get a() {",
" return 1;",
" },",
"",
" set a(b) {",
" return 1;",
" },",
"",
" async *[d](c) {",
" return 1;",
" },",
"",
" a: 3,",
" [a]: 3,",
" 1: 3,",
Expand Down
4 changes: 0 additions & 4 deletions test/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,16 @@ function runTestsForParser(parserId: any) {
" // Important for instanceof",
" // to work in all browsers.",
" constructor: Foo,",
"",
" // Just in case we need it.",
' bar: "baz",',
"",
" // There was an object literal...",
" // ... and here I am continuing this comment.",
" qux: {",
" // Here is an object literal.",
" // Put more properties here when you think of them.",
" zxcv: 42,",
"",
" asdf: 43",
" },",
"",
' extra: "property"',
"};",
];
Expand Down
1 change: 0 additions & 1 deletion test/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2493,7 +2493,6 @@ describe("printer", function () {
" a: #{",
" b: 1234",
" },",
"",
" c: #{",
' d: "dee"',
" }",
Expand Down