Skip to content

Commit 8237782

Browse files
authored
fix(46406): add Template Literal types to decorator metadata serialization (#46913)
1 parent 461fb65 commit 8237782

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

Diff for: src/compiler/transformers/ts.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,7 @@ namespace ts {
15111511
case SyntaxKind.BooleanKeyword:
15121512
return factory.createIdentifier("Boolean");
15131513

1514+
case SyntaxKind.TemplateLiteralType:
15141515
case SyntaxKind.StringKeyword:
15151516
return factory.createIdentifier("String");
15161517

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [decoratorOnClassProperty12.ts]
2+
declare function dec(): <T>(target: any, propertyKey: string) => void;
3+
4+
class A {
5+
@dec()
6+
foo: `${string}`
7+
}
8+
9+
10+
//// [decoratorOnClassProperty12.js]
11+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
12+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
14+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
15+
return c > 3 && r && Object.defineProperty(target, key, r), r;
16+
};
17+
var __metadata = (this && this.__metadata) || function (k, v) {
18+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
19+
};
20+
var A = /** @class */ (function () {
21+
function A() {
22+
}
23+
__decorate([
24+
dec(),
25+
__metadata("design:type", String)
26+
], A.prototype, "foo", void 0);
27+
return A;
28+
}());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty12.ts ===
2+
declare function dec(): <T>(target: any, propertyKey: string) => void;
3+
>dec : Symbol(dec, Decl(decoratorOnClassProperty12.ts, 0, 0))
4+
>T : Symbol(T, Decl(decoratorOnClassProperty12.ts, 0, 25))
5+
>target : Symbol(target, Decl(decoratorOnClassProperty12.ts, 0, 28))
6+
>propertyKey : Symbol(propertyKey, Decl(decoratorOnClassProperty12.ts, 0, 40))
7+
8+
class A {
9+
>A : Symbol(A, Decl(decoratorOnClassProperty12.ts, 0, 70))
10+
11+
@dec()
12+
>dec : Symbol(dec, Decl(decoratorOnClassProperty12.ts, 0, 0))
13+
14+
foo: `${string}`
15+
>foo : Symbol(A.foo, Decl(decoratorOnClassProperty12.ts, 2, 9))
16+
}
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty12.ts ===
2+
declare function dec(): <T>(target: any, propertyKey: string) => void;
3+
>dec : () => <T>(target: any, propertyKey: string) => void
4+
>target : any
5+
>propertyKey : string
6+
7+
class A {
8+
>A : A
9+
10+
@dec()
11+
>dec() : <T>(target: any, propertyKey: string) => void
12+
>dec : () => <T>(target: any, propertyKey: string) => void
13+
14+
foo: `${string}`
15+
>foo : string
16+
}
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @target: es5
2+
// @experimentaldecorators: true
3+
// @emitdecoratormetadata: true
4+
declare function dec(): <T>(target: any, propertyKey: string) => void;
5+
6+
class A {
7+
@dec()
8+
foo: `${string}`
9+
}

0 commit comments

Comments
 (0)