From 3d95e8317b04bcf2859a40cd63ce1a1d72c109a3 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sun, 22 Jan 2017 12:34:35 -0800 Subject: [PATCH] Fix forced trailing comma (#382) We shouldn't output trailing commas when there is a forced one when we break. Fixes #380 --- src/printer.js | 2 +- tests/rest/__snapshots__/jsfmt.spec.js.snap | 7 +++++++ tests/rest/trailing-commas.js | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/printer.js b/src/printer.js index 6cc228b22..753e1436d 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 79cff5aa0..aaf012afd 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 65a05498a..8fabb7268 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,,]