Fix crash for single rest on class declaration (#315)

I thought I didn't need to check the length but forgot that the rest argument is not in the list for class declaration. Now it doesn't crash anymore and there's a test...
master
Christopher Chedeau 2017-01-19 07:01:31 -08:00 committed by James Long
parent a7793a66ee
commit a6ec181566
3 changed files with 11 additions and 1 deletions

View File

@ -1741,7 +1741,7 @@ function printFunctionParams(path, print, options) {
}
const lastParam = util.getLast(path.getValue().params);
const canHaveTrailingComma = lastParam.type !== "RestElement" && !fun.rest;
const canHaveTrailingComma = !(lastParam && lastParam.type === "RestElement") && !fun.rest;
return concat([
"(",

View File

@ -10,6 +10,8 @@ function f(
superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,
...args
) {}
declare class C { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong): void; }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
declare class C {
f(
@ -23,5 +25,11 @@ function f(
...args
) {
}
declare class C {
f(
...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong
): void,
}
"
`;

View File

@ -9,3 +9,5 @@ function f(
superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,
...args
) {}
declare class C { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong): void; }