Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary parentheses for decorators #11849

Merged
merged 3 commits into from Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions changelog_unreleased/typescript/11717.md
@@ -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";
}
```
2 changes: 1 addition & 1 deletion src/language-js/needs-parens.js
Expand Up @@ -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;
Expand Down
Expand Up @@ -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"]
Expand Down
@@ -0,0 +1,2 @@
@(test().x("global").y())
class X {}
16 changes: 16 additions & 0 deletions tests/format/misc/typescript-only/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -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"]
Expand Down
@@ -0,0 +1,2 @@
@(test().x("global").y())
class X {}