diff --git a/src/printer.js b/src/printer.js index a0a53d9c..d1e6b976 100644 --- a/src/printer.js +++ b/src/printer.js @@ -556,6 +556,9 @@ function genericPrintNoParens(path, options, print, args) { (args && args.expandLastArg) || path.getParentNode().type === "JSXExpressionContainer"; + const printTrailingComma = + args && args.expandLastArg && shouldPrintComma(options, "all"); + // In order to avoid confusion between // a => a ? a : a // a <= a ? a : a @@ -580,10 +583,7 @@ function genericPrintNoParens(path, options, print, args) { ]) ), shouldAddSoftLine - ? concat([ - ifBreak(shouldPrintComma(options, "all") ? "," : ""), - softline - ]) + ? concat([ifBreak(printTrailingComma ? "," : ""), softline]) : "" ]) ) diff --git a/tests/trailing_comma/__snapshots__/jsfmt.spec.js.snap b/tests/trailing_comma/__snapshots__/jsfmt.spec.js.snap index 73d6d260..8649f223 100644 --- a/tests/trailing_comma/__snapshots__/jsfmt.spec.js.snap +++ b/tests/trailing_comma/__snapshots__/jsfmt.spec.js.snap @@ -210,6 +210,63 @@ a( `; +exports[`jsx.js 1`] = ` +