Remove unnecessary parentheses for decorators (#11849)
* Remove unnecesary parans for typescript parser * Add tests * Update changelog
This commit is contained in:
1 parent
c9b3518ec7
commit
7acdac30db
6 files changed
+48
-3
No files matched your search
@@ -1,22 +1,31 @@
|
||||
#### Fix formatting for tagged template decorators (#11717 by @sosukesuzuki)
|
||||
#### Remove unnecessary parentheses for decorators (#11717, #11849 by @sosukesuzuki)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```tsx
|
||||
// Input
|
||||
class Test {
|
||||
@foo`bar`
|
||||
test: string = "test"
|
||||
test1: string = "test"
|
||||
|
||||
@test().x("global").y()
|
||||
test2: string = "test";
|
||||
}
|
||||
|
||||
// Prettier stable
|
||||
class Test {
|
||||
@(foo`bar`)
|
||||
test: string = "test"
|
||||
|
||||
@(test().x("global").y())
|
||||
test2: string = "test";
|
||||
}
|
||||
|
||||
// Prettier main
|
||||
class Test {
|
||||
@foo`bar`
|
||||
test: string = "test"
|
||||
|
||||
@test().x("global").y()
|
||||
test2: string = "test";
|
||||
}
|
||||
```
|
||||
@@ -133,7 +133,7 @@ function needsParens(path, options) {
|
||||
/** @(x().y) */ hasMemberExpression ||
|
||||
/** @(x().y()) */ hasCallExpression
|
||||
) {
|
||||
return true;
|
||||
return options.parser !== "typescript";
|
||||
}
|
||||
hasCallExpression = true;
|
||||
current = current.callee;
|
||||
|
||||
@@ -60,6 +60,22 @@ class Bar {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`parenthesized-decorators-call-expression.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel-ts"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@(test().x("global").y())
|
||||
class X {}
|
||||
|
||||
=====================================output=====================================
|
||||
@(test().x("global").y())
|
||||
class X {}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`parenthesized-decorators-tagged-template.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel-ts"]
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
@(test().x("global").y())
|
||||
class X {}
|
||||
@@ -93,6 +93,22 @@ class Bar {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`parenthesized-decorators-call-expression.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@(test().x("global").y())
|
||||
class X {}
|
||||
|
||||
=====================================output=====================================
|
||||
@test().x("global").y()
|
||||
class X {}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`parenthesized-decorators-tagged-template.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
@(test().x("global").y())
|
||||
class X {}
|
||||
Reference in new issue
Block a user