File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,13 @@ const messages = new Map();
14
14
const { defineProperty } = Object ;
15
15
16
16
// Lazily loaded
17
- var util = null ;
17
+ var util_ = null ;
18
+ function lazyUtil ( ) {
19
+ if ( ! util_ ) {
20
+ util_ = require ( 'util' ) ;
21
+ }
22
+ return util_ ;
23
+ }
18
24
19
25
function makeNodeError ( Base ) {
20
26
return class NodeError extends Base {
@@ -65,11 +71,11 @@ class AssertionError extends Error {
65
71
if ( message ) {
66
72
super ( message ) ;
67
73
} else {
74
+ const util = lazyUtil ( ) ;
68
75
if ( actual && actual . stack && actual instanceof Error )
69
76
actual = `${ actual . name } : ${ actual . message } ` ;
70
77
if ( expected && expected . stack && expected instanceof Error )
71
78
expected = `${ expected . name } : ${ expected . message } ` ;
72
- if ( util === null ) util = require ( 'util' ) ;
73
79
super ( `${ util . inspect ( actual ) . slice ( 0 , 128 ) } ` +
74
80
`${ operator } ${ util . inspect ( expected ) . slice ( 0 , 128 ) } ` ) ;
75
81
}
@@ -104,7 +110,7 @@ function message(key, args) {
104
110
if ( typeof msg === 'function' ) {
105
111
fmt = msg ;
106
112
} else {
107
- if ( util === null ) util = require ( 'util' ) ;
113
+ const util = lazyUtil ( ) ;
108
114
fmt = util . format ;
109
115
if ( args === undefined || args . length === 0 )
110
116
return msg ;
You can’t perform that action at this time.
0 commit comments