Print semicolon before type assertion (#18738)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
fisker Cheungandautofix-ci[bot] authored and GitHub committed 2026-01-24 17:50:44 +08:00
1 parent 35a7f3027b
commit 2d3b846607
5 files changed
+94

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
#### Print semicolon before type assertion in `no-semi` mode (#18738 by @fisker)
<!-- prettier-ignore -->
```tsx
// Input
a;
<b>c;
// Prettier stable (First format, --no-semi)
a
<b>c
// Prettier stable (Second format, --no-semi)
a < b > c
// Prettier main
a
;<b>c
```
+3
View File
@@ -7,6 +7,9 @@ import {
} from "../../document/index.js";
import { isArrayExpression, isObjectExpression } from "../utilities/index.js";
/*
- `TSTypeAssertion` (TypeScript)
*/
function printTypeAssertion(path, options, print) {
const { node } = path;
const shouldBreakAfterCast = !(
+2
View File
@@ -39,12 +39,14 @@ function expressionNeedsASIProtection(path, options) {
switch (node.type) {
case "ParenthesizedExpression":
case "TypeCastExpression":
case "TSTypeAssertion":
case "ArrayExpression":
case "ArrayPattern":
case "TemplateLiteral":
case "TemplateElement":
case "RegExpLiteral":
return true;
case "ArrowFunctionExpression":
if (!shouldPrintParamsWithoutParens(path, options)) {
return true;
@@ -105,3 +105,64 @@ const el = ReactDOM.findDOMNode(ref);
================================================================================
`;
exports[`type-assertion.ts - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
semi: false
| printWidth
=====================================input======================================
// #14039
a;
<b>c;
a;
(<b>c).foo();
a;
<b>c + 1;
=====================================output=====================================
// #14039
a
;<b>c
a
;(<b>c).foo()
a
;<b>c + 1
================================================================================
`;
exports[`type-assertion.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
// #14039
a;
<b>c;
a;
(<b>c).foo();
a;
<b>c + 1;
=====================================output=====================================
// #14039
a;
<b>c;
a;
(<b>c).foo();
a;
<b>c + 1;
================================================================================
`;
@@ -0,0 +1,9 @@
// #14039
a;
<b>c;
a;
(<b>c).foo();
a;
<b>c + 1;