@@ -138,14 +138,14 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
138138
139139 if ( groupIndentation !== undefined ) {
140140 validateInteger ( groupIndentation , 'groupIndentation' ,
141- 0 , kMaxGroupIndentation ) ;
141+ 0 , kMaxGroupIndentation ) ;
142142 }
143143
144144 if ( inspectOptions !== undefined ) {
145145 validateObject ( inspectOptions , 'options.inspectOptions' ) ;
146146
147147 if ( inspectOptions . colors !== undefined &&
148- options . colorMode !== undefined ) {
148+ options . colorMode !== undefined ) {
149149 throw new ERR_INCOMPATIBLE_OPTION_PAIR (
150150 'options.inspectOptions.color' , 'colorMode' ) ;
151151 }
@@ -273,7 +273,7 @@ ObjectDefineProperties(Console.prototype, {
273273 [ kWriteToConsole ] : {
274274 __proto__ : null ,
275275 ...consolePropAttributes ,
276- value : function ( streamSymbol , string ) {
276+ value : function ( streamSymbol , string , color ) {
277277 const ignoreErrors = this . _ignoreErrors ;
278278 const groupIndent = this [ kGroupIndent ] ;
279279
@@ -288,6 +288,11 @@ ObjectDefineProperties(Console.prototype, {
288288 }
289289 string = groupIndent + string ;
290290 }
291+
292+ if ( color && lazyUtilColors ( ) . hasColors ) {
293+ string = `${ color } ${ string } ${ lazyUtilColors ( ) . clear } ` ;
294+ }
295+
291296 string += '\n' ;
292297
293298 if ( ignoreErrors === false ) return stream . write ( string ) ;
@@ -381,9 +386,14 @@ const consoleMethods = {
381386
382387
383388 warn ( ...args ) {
384- this [ kWriteToConsole ] ( kUseStderr , this [ kFormatForStderr ] ( args ) ) ;
389+ const color = typeof args === 'string' ? lazyUtilColors ( ) . yellow : null ;
390+ this [ kWriteToConsole ] ( kUseStderr , this [ kFormatForStderr ] ( args ) , color ) ;
385391 } ,
386392
393+ error ( ...args ) {
394+ const color = typeof args === 'string' ? lazyUtilColors ( ) . red : null ;
395+ this [ kWriteToConsole ] ( kUseStderr , this [ kFormatForStderr ] ( args ) , color ) ;
396+ } ,
387397
388398 dir ( object , options ) {
389399 this [ kWriteToConsole ] ( kUseStdout , inspect ( object , {
@@ -515,9 +525,9 @@ const consoleMethods = {
515525
516526 const _inspect = ( v ) => {
517527 const depth = v !== null &&
518- typeof v === 'object' &&
519- ! isArray ( v ) &&
520- ObjectKeys ( v ) . length > 2 ? - 1 : 0 ;
528+ typeof v === 'object' &&
529+ ! isArray ( v ) &&
530+ ObjectKeys ( v ) . length > 2 ? - 1 : 0 ;
521531 const opt = {
522532 depth,
523533 maxArrayLength : 3 ,
@@ -587,7 +597,7 @@ const consoleMethods = {
587597 for ( ; i < indexKeyArray . length ; i ++ ) {
588598 const item = tabularData [ indexKeyArray [ i ] ] ;
589599 const primitive = item === null ||
590- ( typeof item !== 'function' && typeof item !== 'object' ) ;
600+ ( typeof item !== 'function' && typeof item !== 'object' ) ;
591601 if ( properties === undefined && primitive ) {
592602 hasPrimitives = true ;
593603 valuesKeyArray [ i ] = _inspect ( item ) ;
@@ -596,7 +606,7 @@ const consoleMethods = {
596606 for ( const key of keys ) {
597607 map [ key ] ??= [ ] ;
598608 if ( ( primitive && properties ) ||
599- ! ObjectPrototypeHasOwnProperty ( item , key ) )
609+ ! ObjectPrototypeHasOwnProperty ( item , key ) )
600610 map [ key ] [ i ] = '' ;
601611 else
602612 map [ key ] [ i ] = _inspect ( item [ key ] ) ;
@@ -689,7 +699,6 @@ for (const method of ReflectOwnKeys(consoleMethods))
689699Console . prototype . debug = Console . prototype . log ;
690700Console . prototype . info = Console . prototype . log ;
691701Console . prototype . dirxml = Console . prototype . log ;
692- Console . prototype . error = Console . prototype . warn ;
693702Console . prototype . groupCollapsed = Console . prototype . group ;
694703
695704function initializeGlobalConsole ( globalConsole ) {
0 commit comments