From d9d704fd00939d808b97ef9021c758477b1b64f6 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sun, 22 Jan 2017 20:52:30 -0800 Subject: [PATCH] Revert "Workaround flow bug around trailing comma" (#429) --- src/printer.js | 17 +---- .../__snapshots__/jsfmt.spec.js.snap | 69 ------------------- tests/array_trailing_comma/jsfmt.spec.js | 2 - tests/array_trailing_comma/trailing_comma.js | 4 -- 4 files changed, 2 insertions(+), 90 deletions(-) delete mode 100644 tests/array_trailing_comma/__snapshots__/jsfmt.spec.js.snap delete mode 100644 tests/array_trailing_comma/jsfmt.spec.js delete mode 100644 tests/array_trailing_comma/trailing_comma.js diff --git a/src/printer.js b/src/printer.js index cae7878ae..c7c2873ef 100644 --- a/src/printer.js +++ b/src/printer.js @@ -609,24 +609,12 @@ function genericPrintNoParens(path, options, print) { case "Decorator": return concat([ "@", path.call(print, "expression") ]); case "ArrayExpression": - case "ArrayPattern": { + case "ArrayPattern": if (n.elements.length === 0) { parts.push("[]"); } else { const lastElem = util.getLast(n.elements); - let canHaveTrailingComma = !(lastElem && lastElem.type === "RestElement"); - - // There's a bug with flow 0.38 where trailing commas are triggering - // parse errors for array patterns in arguments of a function - const parent = path.getParentNode(0); - if (options.parser === 'flow' && - n.type === "ArrayPattern" && - parent && ( - parent.type === 'FunctionExpression' || - parent.type === 'FunctionDeclaration' || - parent.type === 'ArrowFunctionExpression')) { - canHaveTrailingComma = false; - } + const canHaveTrailingComma = !(lastElem && lastElem.type === "RestElement"); // JavaScript allows you to have empty elements in an array which // changes its length based on the number of commas. The algorithm @@ -667,7 +655,6 @@ function genericPrintNoParens(path, options, print) { if (n.typeAnnotation) parts.push(path.call(print, "typeAnnotation")); return concat(parts); - } case "SequenceExpression": return join(", ", path.map(print, "expressions")); case "ThisExpression": diff --git a/tests/array_trailing_comma/__snapshots__/jsfmt.spec.js.snap b/tests/array_trailing_comma/__snapshots__/jsfmt.spec.js.snap deleted file mode 100644 index 5171c2359..000000000 --- a/tests/array_trailing_comma/__snapshots__/jsfmt.spec.js.snap +++ /dev/null @@ -1,69 +0,0 @@ -exports[`test trailing_comma.js 1`] = ` -"f = ([s=1]) => 1; -function f([s=1]){}; -f = function([s=1]){}; -class c {a([s=1]){}} -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -f = ( - [ - s = 1 - ], -) => - 1; -function f( - [ - s = 1 - ], -) { -} -f = function( - [ - s = 1 - ], -) { -}; -class c { - a( - [ - s = 1 - ], - ) { - } -} -" -`; - -exports[`test trailing_comma.js 2`] = ` -"f = ([s=1]) => 1; -function f([s=1]){}; -f = function([s=1]){}; -class c {a([s=1]){}} -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -f = ( - [ - s = 1, - ], -) => - 1; -function f( - [ - s = 1, - ], -) { -} -f = function( - [ - s = 1, - ], -) { -}; -class c { - a( - [ - s = 1, - ], - ) { - } -} -" -`; diff --git a/tests/array_trailing_comma/jsfmt.spec.js b/tests/array_trailing_comma/jsfmt.spec.js deleted file mode 100644 index cfda4f52c..000000000 --- a/tests/array_trailing_comma/jsfmt.spec.js +++ /dev/null @@ -1,2 +0,0 @@ -run_spec(__dirname, {printWidth: 1, trailingComma: true}); -run_spec(__dirname, {printWidth: 1, trailingComma: true, parser: 'babylon'}); diff --git a/tests/array_trailing_comma/trailing_comma.js b/tests/array_trailing_comma/trailing_comma.js deleted file mode 100644 index 5b953b32f..000000000 --- a/tests/array_trailing_comma/trailing_comma.js +++ /dev/null @@ -1,4 +0,0 @@ -f = ([s=1]) => 1; -function f([s=1]){}; -f = function([s=1]){}; -class c {a([s=1]){}}