Revert "Workaround flow bug around trailing comma" (#429)

This commit is contained in:
Christopher Chedeau authored and GitHub committed 2017-01-22 20:52:30 -08:00
1 parent d7a44bae10
commit d9d704fd00
4 files changed
+2 -90

No files matched your search

+2 -15
View File
@@ -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":
@@ -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,
],
) {
}
}
"
`;
-2
View File
@@ -1,2 +0,0 @@
run_spec(__dirname, {printWidth: 1, trailingComma: true});
run_spec(__dirname, {printWidth: 1, trailingComma: true, parser: 'babylon'});
@@ -1,4 +0,0 @@
f = ([s=1]) => 1;
function f([s=1]){};
f = function([s=1]){};
class c {a([s=1]){}}