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

master
Ika 2018-11-14 10:13:35 +08:00 committed by GitHub
parent 81a72cc2d6
commit 57b057cfa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -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 (
@ -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 + " ");
}

View File

@ -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()

View File

@ -0,0 +1,8 @@
class X {
@deco x() {
return this.count * 2;
}
@deco get x() {
return this.count * 2;
}
}