TypeScript: Keep semi for a class property before index signatu… (#6728)

* Modify to add semi to prop before TSIndexSignature

Co-Authored-By: Simon Lydell <simon.lydell@gmail.com>
master
Sosuke Suzuki 2019-10-29 15:17:29 +09:00 committed by Simon Lydell
parent b4f28a5b65
commit f2c6b94ee7
4 changed files with 43 additions and 1 deletions

View File

@ -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 Prettiers output again used to result in a syntax error.
<!-- prettier-ignore -->
```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

View File

@ -536,7 +536,8 @@ function classChildNeedsASIProtection(node) {
}
return false;
}
case "TSIndexSignature":
return true;
default:
/* istanbul ignore next */
return false;

View File

@ -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
}
================================================================================
`;

View File

@ -2,3 +2,8 @@ export class Mutation {
private set: NQuad[];
private delete: NQuad[];
}
class Foo {
prop1 = 0;
[key: string]: any;
}