feat(decorators): inline more types of decorators (#1864)

This commit is contained in:
Lucas Azzola authored and Christopher Chedeau committed 2017-06-02 07:38:44 -07:00
1 parent 9ed94c77ab
commit 8511e798dc
4 files changed
+154 -2

No files matched your search

+9 -1
View File
@@ -92,10 +92,18 @@ function genericPrint(path, options, printPath, args) {
prefix = "";
}
// #1817
if (
node.decorators.length === 1 &&
node.type !== "ClassDeclaration" &&
node.type !== "MethodDefinition" &&
(decorator.type === "Identifier" ||
decorator.type === "MemberExpression")
decorator.type === "MemberExpression" ||
(decorator.type === "CallExpression" &&
decorator.arguments.length === 1 &&
(isStringLiteral(decorator.arguments[0]) ||
decorator.arguments[0].type === "Identifier" ||
decorator.arguments[0].type === "MemberExpression")))
) {
separator = " ";
}
@@ -45,7 +45,8 @@ import {observable} from "mobx";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import { observable } from "mobx";
@observer class OrderLine {
@observer
class OrderLine {
@observable price: number = 0;
@observable amount: number = 1;
@@ -20,3 +20,101 @@ export class TestTextFileService {
export class TabCompletionController {}
`;
exports[`inline-decorators.ts 1`] = `
@d1
@d2(foo)
@d3.bar
@d4.baz()
class Class1 {}
class Class2 {
@d1
@d2(foo)
@d3.bar
@d4.baz()
method1() {}
@d1
method2() {}
@d2(foo)
method3() {}
@d3.bar
method4() {}
}
class Class3 {
@d1 fieldA;
@d2(foo) fieldB;
@d3.bar fieldC;
@d4.baz() fieldD;
constructor (
@d1 private x: number,
@d2(foo) private y: number,
@d3('foo') private z: number,
@d4({
x: string
}) private a: string,
) {}
}
@decorated class Foo {}
class Bar {
@decorated method() {}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@d1
@d2(foo)
@d3.bar
@d4.baz()
class Class1 {}
class Class2 {
@d1
@d2(foo)
@d3.bar
@d4.baz()
method1() {}
@d1
method2() {}
@d2(foo)
method3() {}
@d3.bar
method4() {}
}
class Class3 {
@d1 fieldA;
@d2(foo) fieldB;
@d3.bar fieldC;
@d4.baz()
fieldD;
constructor(
@d1 private x: number,
@d2(foo) private y: number,
@d3("foo") private z: number,
@d4({
x: string
})
private a: string
) {}
}
@decorated
class Foo {}
class Bar {
@decorated
method() {}
}
`;
@@ -0,0 +1,45 @@
@d1
@d2(foo)
@d3.bar
@d4.baz()
class Class1 {}
class Class2 {
@d1
@d2(foo)
@d3.bar
@d4.baz()
method1() {}
@d1
method2() {}
@d2(foo)
method3() {}
@d3.bar
method4() {}
}
class Class3 {
@d1 fieldA;
@d2(foo) fieldB;
@d3.bar fieldC;
@d4.baz() fieldD;
constructor (
@d1 private x: number,
@d2(foo) private y: number,
@d3('foo') private z: number,
@d4({
x: string
}) private a: string,
) {}
}
@decorated class Foo {}
class Bar {
@decorated method() {}
}