Skip to content

Commit d0aff9b

Browse files
authored
Fix crash (#29333)
1 parent 387be1f commit d0aff9b

5 files changed

+71
-0
lines changed

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,7 @@ namespace ts {
18981898
case SyntaxKind.StringLiteral:
18991899
return createIdentifier("String");
19001900

1901+
case SyntaxKind.PrefixUnaryExpression:
19011902
case SyntaxKind.NumericLiteral:
19021903
return createIdentifier("Number");
19031904

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [decoratorWithNegativeLiteralTypeNoCrash.ts]
2+
class A {
3+
@decorator
4+
public field1: -1 = -1;
5+
}
6+
function decorator(target: any, field: any) {}
7+
8+
//// [decoratorWithNegativeLiteralTypeNoCrash.js]
9+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
10+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
12+
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;
13+
return c > 3 && r && Object.defineProperty(target, key, r), r;
14+
};
15+
var __metadata = (this && this.__metadata) || function (k, v) {
16+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
17+
};
18+
var A = /** @class */ (function () {
19+
function A() {
20+
this.field1 = -1;
21+
}
22+
__decorate([
23+
decorator,
24+
__metadata("design:type", Number)
25+
], A.prototype, "field1", void 0);
26+
return A;
27+
}());
28+
function decorator(target, field) { }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/compiler/decoratorWithNegativeLiteralTypeNoCrash.ts ===
2+
class A {
3+
>A : Symbol(A, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 0, 0))
4+
5+
@decorator
6+
>decorator : Symbol(decorator, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 3, 1))
7+
8+
public field1: -1 = -1;
9+
>field1 : Symbol(A.field1, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 0, 9))
10+
}
11+
function decorator(target: any, field: any) {}
12+
>decorator : Symbol(decorator, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 3, 1))
13+
>target : Symbol(target, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 4, 19))
14+
>field : Symbol(field, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 4, 31))
15+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/compiler/decoratorWithNegativeLiteralTypeNoCrash.ts ===
2+
class A {
3+
>A : A
4+
5+
@decorator
6+
>decorator : (target: any, field: any) => void
7+
8+
public field1: -1 = -1;
9+
>field1 : -1
10+
>-1 : -1
11+
>1 : 1
12+
>-1 : -1
13+
>1 : 1
14+
}
15+
function decorator(target: any, field: any) {}
16+
>decorator : (target: any, field: any) => void
17+
>target : any
18+
>field : any
19+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: es5
2+
// @experimentalDecorators: true
3+
// @emitDecoratorMetadata: true
4+
class A {
5+
@decorator
6+
public field1: -1 = -1;
7+
}
8+
function decorator(target: any, field: any) {}

0 commit comments

Comments
 (0)