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

fix(typescript): inline method decorators should stay inlined #5444

Merged
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
7 changes: 6 additions & 1 deletion src/language-js/printer-estree.js
Expand Up @@ -102,7 +102,9 @@ function genericPrint(path, options, printPath, args) {
node.type === "ClassMethod" ||
node.type === "ClassProperty" ||
node.type === "TSAbstractClassProperty" ||
node.type === "ClassPrivateProperty"
node.type === "ClassPrivateProperty" ||
node.type === "MethodDefinition" ||
node.type === "TSAbstractMethodDefinition"
) {
// their decorators are handled themselves
} else if (
Expand Down Expand Up @@ -875,6 +877,9 @@ function printPathNoParens(path, options, print, args) {
}
case "MethodDefinition":
case "TSAbstractMethodDefinition":
if (n.decorators && n.decorators.length !== 0) {
parts.push(printDecorators(path, options, print));
}
if (n.accessibility) {
parts.push(n.accessibility + " ");
}
Expand Down
21 changes: 21 additions & 0 deletions tests/decorators-ts/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -116,6 +116,27 @@ class Greeter {

`;

exports[`mobx.ts - typescript-verify 1`] = `
class X {
@deco x() {
return this.count * 2;
}
@deco get x() {
return this.count * 2;
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class X {
@deco x() {
return this.count * 2;
}
@deco get x() {
return this.count * 2;
}
}

`;

exports[`multiple.ts - typescript-verify 1`] = `
class C {
@f()
Expand Down
8 changes: 8 additions & 0 deletions tests/decorators-ts/mobx.ts
@@ -0,0 +1,8 @@
class X {
@deco x() {
return this.count * 2;
}
@deco get x() {
return this.count * 2;
}
}