Print as instead of : for babel-ts parser (#12706)
Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
1 parent
d1332b4c63
commit
9fbdcda5b1
4 files changed
+33
No files matched your search
@@ -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;
|
||||||
|
```
|
||||||
@@ -55,6 +55,11 @@ function printTypeAnnotation(path, options, print) {
|
|||||||
|
|
||||||
const parentNode = path.getParentNode();
|
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 =
|
const isFunctionDeclarationIdentifier =
|
||||||
parentNode.type === "DeclareFunction" && parentNode.id === node;
|
parentNode.type === "DeclareFunction" && parentNode.id === node;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,19 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// 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`] = `
|
exports[`as.ts format 1`] = `
|
||||||
====================================options=====================================
|
====================================options=====================================
|
||||||
parsers: ["typescript"]
|
parsers: ["typescript"]
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
[x as any] = x;
|
||||||
Reference in new issue
Block a user