Add semi for functions without body (#2025)

We don't need to be overly restrictive and should add the semi if there's no body

Fixes #2003
master
Christopher Chedeau 2017-06-07 11:51:17 -07:00 committed by GitHub
parent 57b3fe8a50
commit 5ba0b0ec87
5 changed files with 17 additions and 8 deletions

View File

@ -395,7 +395,7 @@ function genericPrintNoParens(path, options, print, args) {
parts.push("declare ");
}
parts.push(printFunctionDeclaration(path, print, options));
if (n.type === "TSNamespaceFunctionDeclaration" && !n.body) {
if (!n.body) {
parts.push(semi);
}
return concat(parts);

View File

@ -507,7 +507,7 @@ function f(x: string): void {
return;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function f(x: string): number
function f(x: string): number;
function f(x: string): void {
return;
}
@ -520,7 +520,7 @@ function f(x: string): number {
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function f(x: string): void
function f(x: string): void;
function f(x: string): number {
return 0;
}
@ -533,7 +533,7 @@ function f(x: string): void {
return;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function f(x: string): void
function f(x: string): void;
function f(x: string): void {
return;
}
@ -553,14 +553,14 @@ function fn5(x: string, ...y: any[], z: string);
function fn5() { }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Function overload signature with optional parameter followed by non-optional parameter
function fn4a(x?: number, y: string)
function fn4a(x?: number, y: string);
function fn4a() {}
function fn4b(n: string, x?: number, y: string)
function fn4b(n: string, x?: number, y: string);
function fn4b() {}
//Function overload signature with rest param followed by non-optional parameter
function fn5(x: string, ...y: any[], z: string)
function fn5(x: string, ...y: any[], z: string);
function fn5() {}
`;

View File

@ -4,7 +4,7 @@ exports[`comment.js 1`] = `
export function match(): string /* the matching pattern */
a
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export function match(): string /* the matching pattern */
export function match(): string; /* the matching pattern */
a;
`;

View File

@ -5,12 +5,18 @@ declare module 'foo' {
function foo(namespace: string): void;
function bar(namespace: string): void;
}
function pickCard(x: {suit: string; card: number; }[]): number;
function pickCard(x: number): {suit: string; card: number; };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
declare module "foo" {
function foo(namespace: string): void;
function bar(namespace: string): void;
}
function pickCard(x: { suit: string; card: number }[]): number;
function pickCard(x: number): { suit: string; card: number };
`;
exports[`type_literal_optional_method.ts 1`] = `

View File

@ -2,3 +2,6 @@ declare module 'foo' {
function foo(namespace: string): void;
function bar(namespace: string): void;
}
function pickCard(x: {suit: string; card: number; }[]): number;
function pickCard(x: number): {suit: string; card: number; };