From b25c03560eabfff1b55a6e360453cc6ba568b811 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 13 Jul 2019 12:57:25 +1200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20refactor=20`errors`=20to?= =?UTF-8?q?=20be=20compatible=20w/=20`strictNullChecks`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/internal/errors.ts | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/internal/errors.ts b/src/internal/errors.ts index b305c2971..f5e7074a7 100644 --- a/src/internal/errors.ts +++ b/src/internal/errors.ts @@ -4,13 +4,12 @@ // value statically and permanently identifies the error. While the error // message may change, the code should not. +import * as assert from 'assert'; +import * as util from 'util'; + const kCode = typeof Symbol === 'undefined' ? '_kCode' : (Symbol as any)('code'); const messages = {}; // new Map(); -// Lazily loaded -let assert = null; -let util = null; - function makeNodeError(Base) { return class NodeError extends Base { constructor(key, ...args) { @@ -37,9 +36,6 @@ class AssertionError extends global.Error { if (options.message) { super(options.message); } else { - if (util === null) { - util = require('util'); - } super( `${util.inspect(options.actual).slice(0, 128)} ` + `${options.operator} ${util.inspect(options.expected).slice(0, 128)}`, @@ -57,9 +53,6 @@ class AssertionError extends global.Error { } function message(key, args) { - if (assert === null) { - assert = require('assert'); - } assert.strictEqual(typeof key, 'string'); // const msg = messages.get(key); const msg = messages[key]; @@ -68,9 +61,6 @@ function message(key, args) { if (typeof msg === 'function') { fmt = msg; } else { - if (util === null) { - util = require('util'); - } fmt = util.format; if (args === undefined || args.length === 0) return msg; args.unshift(msg);