diff --git a/changelog_unreleased/typescript/16133.md b/changelog_unreleased/typescript/16133.md new file mode 100644 index 000000000..9c2b90f26 --- /dev/null +++ b/changelog_unreleased/typescript/16133.md @@ -0,0 +1,22 @@ +#### Respect `--no-semi` for readonly class field (#16133 by @sxzz) + + +```tsx +// Input +class A { + field + readonly [expr] = true +} + +// Prettier stable +class A { + field; + readonly [expr] = true +} + +// Prettier main +class A { + field + readonly [expr] = true +} +``` diff --git a/src/language-js/print/class.js b/src/language-js/print/class.js index 518340460..bbcb24670 100644 --- a/src/language-js/print/class.js +++ b/src/language-js/print/class.js @@ -323,7 +323,8 @@ function shouldPrintSemicolonAfterClassProperty(node, nextNode) { if ( nextNode.static || - nextNode.accessibility // TypeScript + nextNode.accessibility || // TypeScript + nextNode.readonly // TypeScript ) { return false; } diff --git a/tests/format/typescript/no-semi/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/no-semi/__snapshots__/jsfmt.spec.js.snap index 4e9ca3903..36ef55ac7 100644 --- a/tests/format/typescript/no-semi/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/no-semi/__snapshots__/jsfmt.spec.js.snap @@ -16,6 +16,7 @@ class A { bar: A; private [baz] + readonly [qux] } =====================================output===================================== @@ -28,6 +29,7 @@ class A { bar: A private [baz] + readonly [qux] } ================================================================================ @@ -48,6 +50,7 @@ class A { bar: A; private [baz] + readonly [qux] } =====================================output===================================== @@ -60,6 +63,7 @@ class A { bar: A; private [baz]; + readonly [qux]; } ================================================================================ diff --git a/tests/format/typescript/no-semi/no-semi.ts b/tests/format/typescript/no-semi/no-semi.ts index 19134b858..2ef89445a 100644 --- a/tests/format/typescript/no-semi/no-semi.ts +++ b/tests/format/typescript/no-semi/no-semi.ts @@ -7,4 +7,5 @@ class A { bar: A; private [baz] + readonly [qux] }