diff --git a/src/printer.js b/src/printer.js index 6cc228b2..753e1436 100644 --- a/src/printer.js +++ b/src/printer.js @@ -637,7 +637,7 @@ function genericPrintNoParens(path, options, print) { ]) ), needsForcedTrailingComma ? "," : "", - ifBreak(options.trailingComma ? "," : ""), + ifBreak(!needsForcedTrailingComma && options.trailingComma ? "," : ""), options.bracketSpacing ? line : softline, "]" ]) diff --git a/tests/rest/__snapshots__/jsfmt.spec.js.snap b/tests/rest/__snapshots__/jsfmt.spec.js.snap index 79cff5aa..aaf012af 100644 --- a/tests/rest/__snapshots__/jsfmt.spec.js.snap +++ b/tests/rest/__snapshots__/jsfmt.spec.js.snap @@ -12,6 +12,8 @@ function f( ) {} declare class C { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong): void; } + +[superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,,] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ declare class C { f( @@ -31,5 +33,10 @@ declare class C { ...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong ): void, } + +[ + superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong, + , +]; " `; diff --git a/tests/rest/trailing-commas.js b/tests/rest/trailing-commas.js index 65a05498..8fabb726 100644 --- a/tests/rest/trailing-commas.js +++ b/tests/rest/trailing-commas.js @@ -11,3 +11,5 @@ function f( ) {} declare class C { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong): void; } + +[superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,,]