Do not output trailing commas with rest arguments (#283)
It turns out that this is not valid by the spec!master
parent
c2d1b49b62
commit
a8eb09553a
|
@ -1760,13 +1760,16 @@ function printFunctionParams(path, print, options) {
|
|||
return "()";
|
||||
}
|
||||
|
||||
const lastParam = util.getLast(path.getValue().params);
|
||||
const canHaveTrailingComma = lastParam.type !== "RestElement" && !fun.rest;
|
||||
|
||||
return concat([
|
||||
"(",
|
||||
indent(
|
||||
options.tabWidth,
|
||||
concat([ softline, join(concat([ ",", line ]), printed) ])
|
||||
),
|
||||
ifBreak(options.trailingComma ? "," : ""),
|
||||
ifBreak(canHaveTrailingComma && options.trailingComma ? "," : ""),
|
||||
softline,
|
||||
")"
|
||||
]);
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
exports[`test trailing-commas.js 1`] = `
|
||||
"declare class C {
|
||||
f(
|
||||
superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,
|
||||
...args
|
||||
): void,
|
||||
}
|
||||
|
||||
function f(
|
||||
superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,
|
||||
...args
|
||||
) {}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
declare class C {
|
||||
f(
|
||||
superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,
|
||||
...args
|
||||
): void,
|
||||
}
|
||||
|
||||
function f(
|
||||
superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,
|
||||
...args
|
||||
) {
|
||||
}
|
||||
"
|
||||
`;
|
|
@ -0,0 +1 @@
|
|||
run_spec(__dirname, {trailingComma: true});
|
|
@ -0,0 +1,11 @@
|
|||
declare class C {
|
||||
f(
|
||||
superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,
|
||||
...args
|
||||
): void,
|
||||
}
|
||||
|
||||
function f(
|
||||
superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,
|
||||
...args
|
||||
) {}
|
Loading…
Reference in New Issue