Fix crash in decorator metadata calculation when serializing template literal type nodes (#39481)

This commit is contained in:
Wesley Wigham 2020-07-07 15:29:52 -07:00 committed by GitHub
parent 62b4377acf
commit 4f375552b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 0 deletions

View File

@ -1531,6 +1531,7 @@ namespace ts {
case SyntaxKind.LiteralType:
switch ((<LiteralTypeNode>node).literal.kind) {
case SyntaxKind.StringLiteral:
case SyntaxKind.NoSubstitutionTemplateLiteral:
return factory.createIdentifier("String");
case SyntaxKind.PrefixUnaryExpression:

View File

@ -0,0 +1,31 @@
//// [templateLiteralsAndDecoratorMetadata.ts]
declare var format: any;
export class Greeter {
@format("Hello, %s")
greeting: `boss` | `employee` = `employee`; //template literals on this line cause the issue
}
//// [templateLiteralsAndDecoratorMetadata.js]
"use strict";
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);
};
exports.__esModule = true;
exports.Greeter = void 0;
var Greeter = /** @class */ (function () {
function Greeter() {
this.greeting = "employee"; //template literals on this line cause the issue
}
__decorate([
format("Hello, %s"),
__metadata("design:type", String)
], Greeter.prototype, "greeting");
return Greeter;
}());
exports.Greeter = Greeter;

View File

@ -0,0 +1,13 @@
=== tests/cases/compiler/templateLiteralsAndDecoratorMetadata.ts ===
declare var format: any;
>format : Symbol(format, Decl(templateLiteralsAndDecoratorMetadata.ts, 0, 11))
export class Greeter {
>Greeter : Symbol(Greeter, Decl(templateLiteralsAndDecoratorMetadata.ts, 0, 24))
@format("Hello, %s")
>format : Symbol(format, Decl(templateLiteralsAndDecoratorMetadata.ts, 0, 11))
greeting: `boss` | `employee` = `employee`; //template literals on this line cause the issue
>greeting : Symbol(Greeter.greeting, Decl(templateLiteralsAndDecoratorMetadata.ts, 1, 22))
}

View File

@ -0,0 +1,16 @@
=== tests/cases/compiler/templateLiteralsAndDecoratorMetadata.ts ===
declare var format: any;
>format : any
export class Greeter {
>Greeter : Greeter
@format("Hello, %s")
>format("Hello, %s") : any
>format : any
>"Hello, %s" : "Hello, %s"
greeting: `boss` | `employee` = `employee`; //template literals on this line cause the issue
>greeting : "boss" | "employee"
>`employee` : "employee"
}

View File

@ -0,0 +1,7 @@
// @experimentalDecorators: true
// @emitDecoratorMetadata: true
declare var format: any;
export class Greeter {
@format("Hello, %s")
greeting: `boss` | `employee` = `employee`; //template literals on this line cause the issue
}