Fix formatting for tagged template decorators (#11717)
* Fix formatting for tagged template decorators * Add changelog
This commit is contained in:
1 parent
d3163259c7
commit
6f602d1126
8 files changed
+88
No files matched your search
@@ -0,0 +1,22 @@
|
||||
#### Fix formatting for tagged template decorators (#11717 by @sosukesuzuki)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```tsx
|
||||
// Input
|
||||
class Test {
|
||||
@foo`bar`
|
||||
test: string = "test"
|
||||
}
|
||||
|
||||
// Prettier stable
|
||||
class Test {
|
||||
@(foo`bar`)
|
||||
test: string = "test"
|
||||
}
|
||||
|
||||
// Prettier main
|
||||
class Test {
|
||||
@foo`bar`
|
||||
test: string = "test"
|
||||
}
|
||||
```
|
||||
@@ -140,6 +140,10 @@ function needsParens(path, options) {
|
||||
break;
|
||||
case "Identifier":
|
||||
return false;
|
||||
case "TaggedTemplateExpression":
|
||||
// babel-parser cannot parse
|
||||
// @foo`bar`
|
||||
return options.parser !== "typescript";
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,16 @@ exports[`multiline-declaration-type.ts [babel-ts] format 1`] = `
|
||||
3 |"
|
||||
`;
|
||||
|
||||
exports[`parenthesized-decorators-tagged-template.ts [babel-ts] format 1`] = `
|
||||
"Unexpected token (2:7)
|
||||
1 | class Test {
|
||||
> 2 | @foo\`bar\`
|
||||
| ^
|
||||
3 | text: string = \\"text\\"
|
||||
4 | }
|
||||
5 |"
|
||||
`;
|
||||
|
||||
exports[`type-annotation-expr-statement.ts [babel-ts] format 1`] = `
|
||||
"Did not expect a type annotation here. (1:3)
|
||||
> 1 | (a: T);
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
class Test {
|
||||
@foo`bar`
|
||||
text: string = "text"
|
||||
}
|
||||
@@ -60,6 +60,26 @@ class Bar {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`parenthesized-decorators-tagged-template.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel-ts"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
class Test {
|
||||
@(foo\`bar\`)
|
||||
text: string = "text"
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
class Test {
|
||||
@(foo\`bar\`)
|
||||
text: string = "text";
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`prettier-ignore-nested-unions.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel-ts"]
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
class Test {
|
||||
@(foo`bar`)
|
||||
text: string = "text"
|
||||
}
|
||||
@@ -93,6 +93,26 @@ class Bar {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`parenthesized-decorators-tagged-template.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
class Test {
|
||||
@foo\`bar\`
|
||||
text: string = "text"
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
class Test {
|
||||
@foo\`bar\`
|
||||
text: string = "text";
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`prettier-ignore-parenthesized-type.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
class Test {
|
||||
@foo`bar`
|
||||
text: string = "text"
|
||||
}
|
||||
Reference in new issue
Block a user