Skip to content

Commit f7cb2a2

Browse files
tomblindPerryvw
authored andcommitted
fixed crashes from recursive base constraints (#681)
fixes #680
1 parent d2fad97 commit f7cb2a2

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/TSHelper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export function isStaticNode(node: ts.Node): boolean {
135135
export function isStringType(type: ts.Type, checker: ts.TypeChecker, program: ts.Program): boolean {
136136
if (type.symbol) {
137137
const baseConstraint = checker.getBaseConstraintOfType(type);
138-
if (baseConstraint) {
138+
if (baseConstraint && baseConstraint !== type) {
139139
return isStringType(baseConstraint, checker, program);
140140
}
141141
}
@@ -166,7 +166,7 @@ export function isNumberType(type: ts.Type): boolean {
166166
export function isExplicitArrayType(type: ts.Type, checker: ts.TypeChecker, program: ts.Program): boolean {
167167
if (type.symbol) {
168168
const baseConstraint = checker.getBaseConstraintOfType(type);
169-
if (baseConstraint) {
169+
if (baseConstraint && baseConstraint !== type) {
170170
return isExplicitArrayType(baseConstraint, checker, program);
171171
}
172172
}

test/unit/enum.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,27 @@ test("Const enum index identifier chain", () => {
172172

173173
expect(result).toBe(4);
174174
});
175+
176+
test("enum toString", () => {
177+
const code = `
178+
enum TestEnum {
179+
A,
180+
B,
181+
C,
182+
}
183+
let test = TestEnum.A;
184+
return test.toString();`;
185+
expect(util.transpileAndExecute(code)).toBe(0);
186+
});
187+
188+
test("enum concat", () => {
189+
const code = `
190+
enum TestEnum {
191+
A,
192+
B,
193+
C,
194+
}
195+
let test = TestEnum.A;
196+
return test + "_foobar";`;
197+
expect(util.transpileAndExecute(code)).toBe("0_foobar");
198+
});

0 commit comments

Comments
 (0)