Skip to content

fix(46406): Template literal types with decorator crashes in emit #46913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,7 @@ namespace ts {
case SyntaxKind.BooleanKeyword:
return factory.createIdentifier("Boolean");

case SyntaxKind.TemplateLiteralType:
case SyntaxKind.StringKeyword:
return factory.createIdentifier("String");

Expand Down
28 changes: 28 additions & 0 deletions tests/baselines/reference/decoratorOnClassProperty12.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//// [decoratorOnClassProperty12.ts]
declare function dec(): <T>(target: any, propertyKey: string) => void;

class A {
@dec()
foo: `${string}`
}


//// [decoratorOnClassProperty12.js]
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var A = /** @class */ (function () {
function A() {
}
__decorate([
dec(),
__metadata("design:type", String)
], A.prototype, "foo", void 0);
return A;
}());
17 changes: 17 additions & 0 deletions tests/baselines/reference/decoratorOnClassProperty12.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty12.ts ===
declare function dec(): <T>(target: any, propertyKey: string) => void;
>dec : Symbol(dec, Decl(decoratorOnClassProperty12.ts, 0, 0))
>T : Symbol(T, Decl(decoratorOnClassProperty12.ts, 0, 25))
>target : Symbol(target, Decl(decoratorOnClassProperty12.ts, 0, 28))
>propertyKey : Symbol(propertyKey, Decl(decoratorOnClassProperty12.ts, 0, 40))

class A {
>A : Symbol(A, Decl(decoratorOnClassProperty12.ts, 0, 70))

@dec()
>dec : Symbol(dec, Decl(decoratorOnClassProperty12.ts, 0, 0))

foo: `${string}`
>foo : Symbol(A.foo, Decl(decoratorOnClassProperty12.ts, 2, 9))
}

17 changes: 17 additions & 0 deletions tests/baselines/reference/decoratorOnClassProperty12.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty12.ts ===
declare function dec(): <T>(target: any, propertyKey: string) => void;
>dec : () => <T>(target: any, propertyKey: string) => void
>target : any
>propertyKey : string

class A {
>A : A

@dec()
>dec() : <T>(target: any, propertyKey: string) => void
>dec : () => <T>(target: any, propertyKey: string) => void

foo: `${string}`
>foo : string
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @target: es5
// @experimentaldecorators: true
// @emitdecoratormetadata: true
declare function dec(): <T>(target: any, propertyKey: string) => void;

class A {
@dec()
foo: `${string}`
}