Skip to content

Commit 1ca28b7

Browse files
committed
Merge pull request #4402 from Microsoft/metadataTypeName
Instead of writing text from source file use text property to write t…
2 parents 15fb496 + 060dbd2 commit 1ca28b7

5 files changed

+148
-1
lines changed

src/compiler/emitter.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
15191519
return;
15201520
}
15211521
}
1522-
writeTextOfNode(currentSourceFile, node);
1522+
1523+
if (nodeIsSynthesized(node)) {
1524+
write(node.text);
1525+
}
1526+
else {
1527+
writeTextOfNode(currentSourceFile, node);
1528+
}
15231529
}
15241530

15251531
function isNameOfNestedRedeclaration(node: Identifier) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//// [decoratorMetadataWithConstructorType.ts]
2+
3+
declare var console: {
4+
log(msg: string): void;
5+
};
6+
7+
class A {
8+
constructor() { console.log('new A'); }
9+
}
10+
11+
function decorator(target: Object, propertyKey: string) {
12+
}
13+
14+
export class B {
15+
@decorator
16+
x: A = new A();
17+
}
18+
19+
20+
//// [decoratorMetadataWithConstructorType.js]
21+
var A = (function () {
22+
function A() {
23+
console.log('new A');
24+
}
25+
return A;
26+
})();
27+
function decorator(target, propertyKey) {
28+
}
29+
var B = (function () {
30+
function B() {
31+
this.x = new A();
32+
}
33+
__decorate([
34+
decorator,
35+
__metadata('design:type', A)
36+
], B.prototype, "x");
37+
return B;
38+
})();
39+
exports.B = B;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
=== tests/cases/compiler/decoratorMetadataWithConstructorType.ts ===
2+
3+
declare var console: {
4+
>console : Symbol(console, Decl(decoratorMetadataWithConstructorType.ts, 1, 11))
5+
6+
log(msg: string): void;
7+
>log : Symbol(log, Decl(decoratorMetadataWithConstructorType.ts, 1, 22))
8+
>msg : Symbol(msg, Decl(decoratorMetadataWithConstructorType.ts, 2, 8))
9+
10+
};
11+
12+
class A {
13+
>A : Symbol(A, Decl(decoratorMetadataWithConstructorType.ts, 3, 2))
14+
15+
constructor() { console.log('new A'); }
16+
>console.log : Symbol(log, Decl(decoratorMetadataWithConstructorType.ts, 1, 22))
17+
>console : Symbol(console, Decl(decoratorMetadataWithConstructorType.ts, 1, 11))
18+
>log : Symbol(log, Decl(decoratorMetadataWithConstructorType.ts, 1, 22))
19+
}
20+
21+
function decorator(target: Object, propertyKey: string) {
22+
>decorator : Symbol(decorator, Decl(decoratorMetadataWithConstructorType.ts, 7, 1))
23+
>target : Symbol(target, Decl(decoratorMetadataWithConstructorType.ts, 9, 19))
24+
>Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11))
25+
>propertyKey : Symbol(propertyKey, Decl(decoratorMetadataWithConstructorType.ts, 9, 34))
26+
}
27+
28+
export class B {
29+
>B : Symbol(B, Decl(decoratorMetadataWithConstructorType.ts, 10, 1))
30+
31+
@decorator
32+
>decorator : Symbol(decorator, Decl(decoratorMetadataWithConstructorType.ts, 7, 1))
33+
34+
x: A = new A();
35+
>x : Symbol(x, Decl(decoratorMetadataWithConstructorType.ts, 12, 16))
36+
>A : Symbol(A, Decl(decoratorMetadataWithConstructorType.ts, 3, 2))
37+
>A : Symbol(A, Decl(decoratorMetadataWithConstructorType.ts, 3, 2))
38+
}
39+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
=== tests/cases/compiler/decoratorMetadataWithConstructorType.ts ===
2+
3+
declare var console: {
4+
>console : { log(msg: string): void; }
5+
6+
log(msg: string): void;
7+
>log : (msg: string) => void
8+
>msg : string
9+
10+
};
11+
12+
class A {
13+
>A : A
14+
15+
constructor() { console.log('new A'); }
16+
>console.log('new A') : void
17+
>console.log : (msg: string) => void
18+
>console : { log(msg: string): void; }
19+
>log : (msg: string) => void
20+
>'new A' : string
21+
}
22+
23+
function decorator(target: Object, propertyKey: string) {
24+
>decorator : (target: Object, propertyKey: string) => void
25+
>target : Object
26+
>Object : Object
27+
>propertyKey : string
28+
}
29+
30+
export class B {
31+
>B : B
32+
33+
@decorator
34+
>decorator : (target: Object, propertyKey: string) => void
35+
36+
x: A = new A();
37+
>x : A
38+
>A : A
39+
>new A() : A
40+
>A : typeof A
41+
}
42+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @noemithelpers: true
2+
// @experimentaldecorators: true
3+
// @emitdecoratormetadata: true
4+
// @target: es5
5+
// @module: commonjs
6+
7+
declare var console: {
8+
log(msg: string): void;
9+
};
10+
11+
class A {
12+
constructor() { console.log('new A'); }
13+
}
14+
15+
function decorator(target: Object, propertyKey: string) {
16+
}
17+
18+
export class B {
19+
@decorator
20+
x: A = new A();
21+
}

0 commit comments

Comments
 (0)