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:
1 parent
35a7f3027b
commit
2d3b846607
5 files changed
+94
No files matched your search
@@ -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
|
||||
```
|
||||
@@ -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 = !(
|
||||
|
||||
@@ -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;
|
||||
Reference in new issue
Block a user