Skip to content

Commit

Permalink
fix(typescript): inline method decorators should stay inlined (#5444)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang authored Nov 14, 2018
1 parent 81a72cc commit 57b057c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/language-js/printer-estree.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class X {
@deco x() {
return this.count * 2;
}
@deco get x() {
return this.count * 2;
}
}

0 comments on commit 57b057c

Please sign in to comment.