From 4d9edec4e1e2dffb5d5d8f6bfd0c3b02d181bdbd Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Thu, 13 Apr 2017 09:10:08 -0500 Subject: [PATCH] Fix trailing comma for rest element in Babylon (#1230) --- src/printer.js | 7 +++++-- tests/rest/jsfmt.spec.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/printer.js b/src/printer.js index d286ca5c..f1da58fc 100644 --- a/src/printer.js +++ b/src/printer.js @@ -706,8 +706,11 @@ function genericPrintNoParens(path, options, print, args) { }); const lastElem = util.getLast(n[propertiesField]); - const canHaveTrailingComma = !(lastElem && - lastElem.type === "RestProperty"); + + const canHaveTrailingComma = !( + lastElem && + (lastElem.type === "RestProperty" || lastElem.type === "RestElement") + ); const shouldBreak = n.type !== "ObjectPattern" && diff --git a/tests/rest/jsfmt.spec.js b/tests/rest/jsfmt.spec.js index a4f98d3f..1f7d49d1 100644 --- a/tests/rest/jsfmt.spec.js +++ b/tests/rest/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, { trailingComma: "all" }); +run_spec(__dirname, { trailingComma: "all" }, ["babylon"]);