From f2c6b94ee76b858667b9091c3f487ac4500e887f Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Tue, 29 Oct 2019 15:17:29 +0900 Subject: [PATCH] =?UTF-8?q?TypeScript:=20Keep=20semi=20for=20a=20class=20p?= =?UTF-8?q?roperty=20before=20index=20signatu=E2=80=A6=20(#6728)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Modify to add semi to prop before TSIndexSignature Co-Authored-By: Simon Lydell --- CHANGELOG.unreleased.md | 26 +++++++++++++++++++ src/language-js/utils.js | 3 ++- .../__snapshots__/jsfmt.spec.js.snap | 10 +++++++ tests/typescript_semi/no-semi.ts | 5 ++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 94da1ddc..f2d831d0 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -1269,6 +1269,31 @@ new Map([ ]); ``` +#### TypeScript: Keep semi for a class property before index signature when no-semi is enabled ([#6728] by [@sosukesuzuki]) + +Attempting to format Prettier’s output again used to result in a syntax error. + + +```ts +// Input +export class User { + id: number = 2; + [key: string]: any +} + +// Output (Prettier stable) +export class User { + id: number = 2 + [key: string]: any +} + +// Output (Prettier master) +export class User { + id: number = 2; + [key: string]: any +} +``` + [#5682]: https://github.com/prettier/prettier/pull/5682 [#6657]: https://github.com/prettier/prettier/pull/6657 [#5910]: https://github.com/prettier/prettier/pull/5910 @@ -1311,6 +1336,7 @@ new Map([ [#6673]: https://github.com/prettier/prettier/pull/6673 [#6695]: https://github.com/prettier/prettier/pull/6695 [#6694]: https://github.com/prettier/prettier/pull/6694 +[#6728]: https://github.com/prettier/prettier/pull/6728 [@brainkim]: https://github.com/brainkim [@duailibe]: https://github.com/duailibe [@gavinjoyce]: https://github.com/gavinjoyce diff --git a/src/language-js/utils.js b/src/language-js/utils.js index 8666b6eb..245f84dd 100644 --- a/src/language-js/utils.js +++ b/src/language-js/utils.js @@ -536,7 +536,8 @@ function classChildNeedsASIProtection(node) { } return false; } - + case "TSIndexSignature": + return true; default: /* istanbul ignore next */ return false; diff --git a/tests/typescript_semi/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_semi/__snapshots__/jsfmt.spec.js.snap index 728ce512..71ffa419 100644 --- a/tests/typescript_semi/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_semi/__snapshots__/jsfmt.spec.js.snap @@ -12,11 +12,21 @@ export class Mutation { private delete: NQuad[]; } +class Foo { + prop1 = 0; + [key: string]: any; +} + =====================================output===================================== export class Mutation { private set: NQuad[] private delete: NQuad[] } +class Foo { + prop1 = 0; + [key: string]: any +} + ================================================================================ `; diff --git a/tests/typescript_semi/no-semi.ts b/tests/typescript_semi/no-semi.ts index 4960b150..8a32ed49 100644 --- a/tests/typescript_semi/no-semi.ts +++ b/tests/typescript_semi/no-semi.ts @@ -2,3 +2,8 @@ export class Mutation { private set: NQuad[]; private delete: NQuad[]; } + +class Foo { + prop1 = 0; + [key: string]: any; +}