diff --git a/src/printer.js b/src/printer.js index 3e5b5f5c..06ada672 100644 --- a/src/printer.js +++ b/src/printer.js @@ -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": diff --git a/tests/typescript_index_signature/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_index_signature/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..76878611 --- /dev/null +++ b/tests/typescript_index_signature/__snapshots__/jsfmt.spec.js.snap @@ -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; +} + +`; diff --git a/tests/typescript_index_signature/index-signature.ts b/tests/typescript_index_signature/index-signature.ts new file mode 100644 index 00000000..ebe06818 --- /dev/null +++ b/tests/typescript_index_signature/index-signature.ts @@ -0,0 +1,4 @@ +class LocalStorage implements Storage { + [index: number]: string; + [key: string]: any; +} diff --git a/tests/typescript_index_signature/jsfmt.spec.js b/tests/typescript_index_signature/jsfmt.spec.js new file mode 100644 index 00000000..bc085c48 --- /dev/null +++ b/tests/typescript_index_signature/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, { parser: "typescript" }); diff --git a/tests/typescript_nosemi/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_nosemi/__snapshots__/jsfmt.spec.js.snap index 6db6d27e..5c73500c 100644 --- a/tests/typescript_nosemi/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_nosemi/__snapshots__/jsfmt.spec.js.snap @@ -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 } diff --git a/tests/typescript_nosemi/index-signature.ts b/tests/typescript_nosemi/index-signature.ts new file mode 100644 index 00000000..ebe06818 --- /dev/null +++ b/tests/typescript_nosemi/index-signature.ts @@ -0,0 +1,4 @@ +class LocalStorage implements Storage { + [index: number]: string; + [key: string]: any; +}