Skip to content

Commit bec27f0

Browse files
committed
test(tsfmt): add test for decorations refs #13
1 parent 39c41a2 commit bec27f0

File tree

3 files changed

+158
-0
lines changed

3 files changed

+158
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"IndentSize": 4,
3+
"TabSize": 4,
4+
"NewLineCharacter": "\r\n",
5+
"ConvertTabsToSpaces": true,
6+
"InsertSpaceAfterCommaDelimiter": true,
7+
"InsertSpaceAfterSemicolonInForStatements": true,
8+
"InsertSpaceBeforeAndAfterBinaryOperators": true,
9+
"InsertSpaceAfterKeywordsInControlFlowStatements": true,
10+
"InsertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
11+
"InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
12+
"PlaceOpenBraceOnNewLineForFunctions": false,
13+
"PlaceOpenBraceOnNewLineForControlBlocks": false
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"use strict";
2+
3+
@classDecorator
4+
class Sample {
5+
a(): string {
6+
return "";
7+
}
8+
9+
@methodDecorator
10+
b(): string {
11+
return "";
12+
}
13+
14+
@staticMethodDecorator
15+
static c(): string {
16+
return "";
17+
}
18+
19+
@propertyDecorator
20+
d = "";
21+
22+
23+
@accessorDecorator
24+
get e(): string {
25+
return "";
26+
}
27+
28+
f( @parameterDecorator str: string): string {
29+
return `Hello, ${str}`;
30+
}
31+
}
32+
33+
console.log("------");
34+
35+
let obj = new Sample();
36+
console.log(obj.a());
37+
console.log(obj.b());
38+
console.log(Sample.c());
39+
console.log(obj.d);
40+
console.log(obj.e);
41+
console.log(obj.f("parameter"));
42+
43+
function classDecorator(sampleClazz: typeof Sample): typeof Sample {
44+
console.log("classDecorator", arguments);
45+
sampleClazz.prototype.a = function() {
46+
return "Hello from classDecorator!";
47+
}
48+
return null;
49+
}
50+
51+
function methodDecorator(prototypeOfSample: any, key: string, propertyDescription: PropertyDescriptor): PropertyDescriptor {
52+
console.log("methodDecorator", arguments);
53+
return null;
54+
}
55+
56+
function staticMethodDecorator(sampleClazz: typeof Sample, key: string, propertyDescription: PropertyDescriptor): PropertyDescriptor {
57+
console.log("staticMethodDecorator", arguments);
58+
return null;
59+
}
60+
61+
function propertyDecorator(prototypeOfSample: any, key: string): void {
62+
console.log("propertyDecorator", arguments);
63+
}
64+
65+
function accessorDecorator(prototypeOfSample: any, key: string, propertyDescription: PropertyDescriptor): PropertyDescriptor {
66+
console.log("accessorDecorator", arguments);
67+
return null;
68+
}
69+
70+
function parameterDecorator(prototypeOfSample: any, methodName: string, parameterIndex: number): void {
71+
console.log("parameterDecorator", arguments);
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"use strict";
2+
3+
@classDecorator
4+
class Sample {
5+
a(): string {
6+
return "";
7+
}
8+
9+
@methodDecorator
10+
b(): string {
11+
return "";
12+
}
13+
14+
@staticMethodDecorator
15+
static c(): string {
16+
return "";
17+
}
18+
19+
@propertyDecorator
20+
d = "";
21+
22+
23+
@accessorDecorator
24+
get e(): string {
25+
return "";
26+
}
27+
28+
f( @parameterDecorator str: string): string {
29+
return `Hello, ${str}`;
30+
}
31+
}
32+
33+
console.log("------");
34+
35+
let obj = new Sample();
36+
console.log(obj.a());
37+
console.log(obj.b());
38+
console.log(Sample.c());
39+
console.log(obj.d);
40+
console.log(obj.e);
41+
console.log(obj.f("parameter"));
42+
43+
function classDecorator(sampleClazz: typeof Sample): typeof Sample {
44+
console.log("classDecorator", arguments);
45+
sampleClazz.prototype.a = function() {
46+
return "Hello from classDecorator!";
47+
}
48+
return null;
49+
}
50+
51+
function methodDecorator(prototypeOfSample: any, key: string, propertyDescription: PropertyDescriptor): PropertyDescriptor {
52+
console.log("methodDecorator", arguments);
53+
return null;
54+
}
55+
56+
function staticMethodDecorator(sampleClazz: typeof Sample, key: string, propertyDescription: PropertyDescriptor): PropertyDescriptor {
57+
console.log("staticMethodDecorator", arguments);
58+
return null;
59+
}
60+
61+
function propertyDecorator(prototypeOfSample: any, key: string): void {
62+
console.log("propertyDecorator", arguments);
63+
}
64+
65+
function accessorDecorator(prototypeOfSample: any, key: string, propertyDescription: PropertyDescriptor): PropertyDescriptor {
66+
console.log("accessorDecorator", arguments);
67+
return null;
68+
}
69+
70+
function parameterDecorator(prototypeOfSample: any, methodName: string, parameterIndex: number): void {
71+
console.log("parameterDecorator", arguments);
72+
}

0 commit comments

Comments
 (0)