Skip to content

Commit be2aea7

Browse files
committed
fix(46406): add Template Literal types to decorator metadata serialization
1 parent 0163a62 commit be2aea7

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 0 deletions
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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [decoratorOnClassProperty12.ts]
2+
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
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+
}());
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty12.ts ===
2+
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
3+
>dec : Symbol(dec, Decl(decoratorOnClassProperty12.ts, 0, 0))
4+
>T : Symbol(T, Decl(decoratorOnClassProperty12.ts, 0, 21))
5+
>target : Symbol(target, Decl(decoratorOnClassProperty12.ts, 0, 24))
6+
>propertyKey : Symbol(propertyKey, Decl(decoratorOnClassProperty12.ts, 0, 36))
7+
>descriptor : Symbol(descriptor, Decl(decoratorOnClassProperty12.ts, 0, 57))
8+
>TypedPropertyDescriptor : Symbol(TypedPropertyDescriptor, Decl(lib.es5.d.ts, --, --))
9+
>T : Symbol(T, Decl(decoratorOnClassProperty12.ts, 0, 21))
10+
>TypedPropertyDescriptor : Symbol(TypedPropertyDescriptor, Decl(lib.es5.d.ts, --, --))
11+
>T : Symbol(T, Decl(decoratorOnClassProperty12.ts, 0, 21))
12+
13+
class A {
14+
>A : Symbol(A, Decl(decoratorOnClassProperty12.ts, 0, 126))
15+
16+
@dec
17+
>dec : Symbol(dec, Decl(decoratorOnClassProperty12.ts, 0, 0))
18+
19+
foo: `${string}`
20+
>foo : Symbol(A.foo, Decl(decoratorOnClassProperty12.ts, 2, 9))
21+
}
22+
Lines changed: 17 additions & 0 deletions
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, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
3+
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
4+
>target : any
5+
>propertyKey : string
6+
>descriptor : TypedPropertyDescriptor<T>
7+
8+
class A {
9+
>A : A
10+
11+
@dec
12+
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
13+
14+
foo: `${string}`
15+
>foo : string
16+
}
17+
Lines changed: 9 additions & 0 deletions
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)