fix(typescript): print semi in class index signatures, fixes #1960 (#1961)

master
Lucas Azzola 2017-06-05 00:21:33 +10:00 committed by Christopher Chedeau
parent 41688901f2
commit 642ac7e230
6 changed files with 39 additions and 1 deletions

View File

@ -2300,6 +2300,7 @@ function genericPrintNoParens(path, options, print, args) {
case "TSParenthesizedType":
return concat(["(", path.call(print, "typeAnnotation"), ")"]);
case "TSIndexSignature": {
const parent = path.getParentNode();
let printedParams = [];
if (n.params) {
printedParams = path.map(print, "params");
@ -2319,7 +2320,8 @@ function genericPrintNoParens(path, options, print, args) {
// it using parseDelimitedList that uses commas as delimiter.
join(", ", printedParams),
"]: ",
path.call(print, "typeAnnotation")
path.call(print, "typeAnnotation"),
parent.type === "ClassBody" ? semi : ""
]);
}
case "TSTypePredicate":

View File

@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`index-signature.ts 1`] = `
class LocalStorage implements Storage {
[index: number]: string;
[key: string]: any;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LocalStorage implements Storage {
[index: number]: string;
[key: string]: any;
}
`;

View File

@ -0,0 +1,4 @@
class LocalStorage implements Storage {
[index: number]: string;
[key: string]: any;
}

View File

@ -0,0 +1 @@
run_spec(__dirname, { parser: "typescript" });

View File

@ -1,5 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`index-signature.ts 1`] = `
class LocalStorage implements Storage {
[index: number]: string;
[key: string]: any;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LocalStorage implements Storage {
[index: number]: string
[key: string]: any
}
`;
exports[`interface.ts 1`] = `
interface Inline { x: string }

View File

@ -0,0 +1,4 @@
class LocalStorage implements Storage {
[index: number]: string;
[key: string]: any;
}