Print as instead of : for babel-ts parser (#12706)

Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
HosokawaRandfisker Cheung authored and GitHub committed 2022-04-27 17:56:38 +08:00
1 parent d1332b4c63
commit 9fbdcda5b1
4 files changed
+33

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
#### Print `as` instead of `:` for `babel-ts` parser (#12706 by @HosokawaR)
<!-- prettier-ignore -->
```tsx
// Input
[x as any] = x;
// Prettier stable
[x: any] = x;
// Prettier main
[x as any] = x;
```
+5
View File
@@ -55,6 +55,11 @@ function printTypeAnnotation(path, options, print) {
const parentNode = path.getParentNode();
// Workaround for https://github.com/babel/babel/issues/14498
if (parentNode.type === "ArrayPattern" && options.parser === "babel-ts") {
return [" as ", print("typeAnnotation")];
}
const isFunctionDeclarationIdentifier =
parentNode.type === "DeclareFunction" && parentNode.id === node;
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`array-pattern.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
[x as any] = x;
=====================================output=====================================
[x as any] = x;
================================================================================
`;
exports[`as.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
@@ -0,0 +1 @@
[x as any] = x;