From dde79edccd6e6ec18dcf18e35647ee1f5b7b3abe Mon Sep 17 00:00:00 2001 From: Tom <26638278+tomblind@users.noreply.github.com> Date: Tue, 23 Jul 2019 07:08:29 -0600 Subject: [PATCH] fixed crashes from recursive base constraints fixes #680 --- src/TSHelper.ts | 4 ++-- test/unit/enum.spec.ts | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/TSHelper.ts b/src/TSHelper.ts index 6a9dc5a32..c8d749d8a 100644 --- a/src/TSHelper.ts +++ b/src/TSHelper.ts @@ -135,7 +135,7 @@ export function isStaticNode(node: ts.Node): boolean { export function isStringType(type: ts.Type, checker: ts.TypeChecker, program: ts.Program): boolean { if (type.symbol) { const baseConstraint = checker.getBaseConstraintOfType(type); - if (baseConstraint) { + if (baseConstraint && baseConstraint !== type) { return isStringType(baseConstraint, checker, program); } } @@ -158,7 +158,7 @@ export function isNumberType(type: ts.Type): boolean { export function isExplicitArrayType(type: ts.Type, checker: ts.TypeChecker, program: ts.Program): boolean { if (type.symbol) { const baseConstraint = checker.getBaseConstraintOfType(type); - if (baseConstraint) { + if (baseConstraint && baseConstraint !== type) { return isExplicitArrayType(baseConstraint, checker, program); } } diff --git a/test/unit/enum.spec.ts b/test/unit/enum.spec.ts index 383d9708f..bd40f2619 100644 --- a/test/unit/enum.spec.ts +++ b/test/unit/enum.spec.ts @@ -172,3 +172,27 @@ test("Const enum index identifier chain", () => { expect(result).toBe(4); }); + +test("enum toString", () => { + const code = ` + enum TestEnum { + A, + B, + C, + } + let test = TestEnum.A; + return test.toString();`; + expect(util.transpileAndExecute(code)).toBe(0); +}); + +test("enum concat", () => { + const code = ` + enum TestEnum { + A, + B, + C, + } + let test = TestEnum.A; + return test + "_foobar";`; + expect(util.transpileAndExecute(code)).toBe("0_foobar"); +});