Don't print trailing commas for object destructuring and rest (#512)

Fixes #507
master
Christopher Chedeau 2017-01-30 07:07:03 -08:00 committed by James Long
parent 8d786e5352
commit 9cfc645659
3 changed files with 13 additions and 1 deletions

View File

@ -582,6 +582,10 @@ function genericPrintNoParens(path, options, print) {
);
});
const lastElem = util.getLast(n.properties);
const canHaveTrailingComma = !(lastElem &&
lastElem.type === "RestProperty");
if (props.length === 0) {
return concat([
"{",
@ -599,7 +603,7 @@ function genericPrintNoParens(path, options, print) {
join(concat([separator, line]), props)
])
),
ifBreak(options.trailingComma ? "," : ""),
ifBreak(canHaveTrailingComma && options.trailingComma ? "," : ""),
options.bracketSpacing ? line : softline,
rightBrace,
path.call(print, "typeAnnotation")

View File

@ -16,6 +16,8 @@ declare class C { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSu
[superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,,];
[veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong, ...a] = [];
var {veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong, ...a} = {};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
declare class C {
f(
@ -44,5 +46,9 @@ declare class C {
veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong,
...a
] = [];
var {
veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong,
...a
} = {};
"
`;

View File

@ -15,3 +15,5 @@ declare class C { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSu
[superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,,];
[veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong, ...a] = [];
var {veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong, ...a} = {};