From cf07d428a1c8890a53834ef6594a22174eb93fe6 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sun, 26 Jan 2020 11:01:41 -0800 Subject: [PATCH] refactor(ivy): make assert conditions more readable (#34938) PR Close #34938 --- packages/core/src/util/assert.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/core/src/util/assert.ts b/packages/core/src/util/assert.ts index fc9ddc8412..448940010d 100644 --- a/packages/core/src/util/assert.ts +++ b/packages/core/src/util/assert.ts @@ -13,59 +13,65 @@ import {stringify} from './stringify'; export function assertNumber(actual: any, msg: string) { - if (typeof actual != 'number') { + if (!(typeof actual === 'number')) { throwError(msg, typeof actual, 'number', '==='); } } export function assertString(actual: any, msg: string) { - if (typeof actual != 'string') { + if (!(typeof actual === 'string')) { throwError(msg, actual === null ? 'null' : typeof actual, 'string', '==='); } } export function assertEqual(actual: T, expected: T, msg: string) { - if (actual != expected) { + if (!(actual == expected)) { throwError(msg, actual, expected, '=='); } } export function assertNotEqual(actual: T, expected: T, msg: string) { - if (actual == expected) { + if (!(actual != expected)) { throwError(msg, actual, expected, '!='); } } export function assertSame(actual: T, expected: T, msg: string) { - if (actual !== expected) { + if (!(actual === expected)) { throwError(msg, actual, expected, '==='); } } export function assertNotSame(actual: T, expected: T, msg: string) { - if (actual === expected) { + if (!(actual !== expected)) { throwError(msg, actual, expected, '!=='); } } export function assertLessThan(actual: T, expected: T, msg: string) { - if (actual >= expected) { + if (!(actual < expected)) { throwError(msg, actual, expected, '<'); } } export function assertLessThanOrEqual(actual: T, expected: T, msg: string) { - if (actual > expected) { + if (!(actual <= expected)) { throwError(msg, actual, expected, '<='); } } export function assertGreaterThan(actual: T, expected: T, msg: string) { - if (actual <= expected) { + if (!(actual > expected)) { throwError(msg, actual, expected, '>'); } } +export function assertGreaterThanOrEqual(actual: T, expected: T, msg: string) { + if (!(actual >= expected)) { + throwError(msg, actual, expected, '>='); + } +} + export function assertNotDefined(actual: T, msg: string) { if (actual != null) { throwError(msg, actual, null, '==');