@@ -69,7 +69,10 @@ export function effect<Name extends string | symbol, Resumable extends boolean =
6969 } ;
7070 } ) ;
7171 if ( options && ( options as any ) . _overrideFunctionName === false ) return result as never ;
72- return renameFunction ( result , typeof name === "string" ? name : name . description || "" ) as never ;
72+ return renameFunction (
73+ result ,
74+ typeof name === "string" ? name : name . toString ( ) . slice ( 7 , - 1 ) || "" ,
75+ ) as never ;
7376}
7477
7578/**
@@ -220,7 +223,7 @@ export class Effected<out E extends Effect, out R> implements Iterable<E, R, unk
220223
221224 private constructor ( fn : ( ) => Iterator < E , R , unknown > , magicWords ?: string ) {
222225 if ( magicWords !== "Yes, I’m sure I want to call the constructor of Effected directly." )
223- console . warn (
226+ logger . warn (
224227 "You should not call the constructor of `Effected` directly. Use `effected` instead." ,
225228 ) ;
226229
@@ -364,7 +367,7 @@ export class Effected<out E extends Effect, out R> implements Iterable<E, R, unk
364367 if ( terminated === "with-value" ) message += ` with ${ stringify ( terminatedValue ) } ` ;
365368 }
366369 message += "). Only the first handler will be used." ;
367- console . warn ( message ) ;
370+ logger . warn ( message ) ;
368371 } ;
369372 const resume = ( ...args : [ ] | [ R ] ) => {
370373 if ( resumed || terminated ) {
@@ -1198,7 +1201,7 @@ const stringify = (x: unknown, space: number = 0): string => {
11981201 const indent = ( level : number ) : string => ( space > 0 ? " " . repeat ( level * space ) : "" ) ;
11991202
12001203 const serialize = ( value : unknown , level : number ) : string => {
1201- if ( typeof value === "bigint" ) return `${ value } n` ;
1204+ if ( typeof value === "bigint" ) return `${ value as any } n` ;
12021205 if ( typeof value === "function" )
12031206 return value . name ? `[Function: ${ value . name } ]` : "[Function (anonymous)]" ;
12041207 if ( typeof value === "symbol" ) return value . toString ( ) ;
@@ -1219,7 +1222,7 @@ const stringify = (x: unknown, space: number = 0): string => {
12191222 . map ( ( item ) => serialize ( item , nextLevel ) )
12201223 . join ( space > 0 ? `,\n${ indent ( nextLevel ) } ` : ", " ) ;
12211224 let result = `[${ space > 0 ? "\n" + indent ( nextLevel ) : "" } ${ arrayItems } ${ space > 0 ? "\n" + indent ( level ) : "" } ]` ;
1222- if ( className !== "Array " ) result = `${ className . trimEnd ( ) } (${ value . length } ) ${ result } ` ;
1225+ if ( className !== "Array " ) result = `${ className . trim ( ) } (${ value . length } ) ${ result } ` ;
12231226 return result ;
12241227 }
12251228
@@ -1242,3 +1245,24 @@ const stringify = (x: unknown, space: number = 0): string => {
12421245
12431246 return serialize ( x , 0 ) ;
12441247} ;
1248+
1249+ // `console` is not standard in JavaScript. Though rare, it is possible that `console` is not
1250+ // available in some environments. We use a proxy to handle this case and ignore errors if `console`
1251+ // is not available.
1252+ const logger : {
1253+ debug ( ...data : unknown [ ] ) : void ;
1254+ error ( ...data : unknown [ ] ) : void ;
1255+ log ( ...data : unknown [ ] ) : void ;
1256+ warn ( ...data : unknown [ ] ) : void ;
1257+ } = new Proxy ( { } as never , {
1258+ get :
1259+ ( _ , prop ) =>
1260+ ( ...args : unknown [ ] ) => {
1261+ try {
1262+ // @ts -expect-error - Cannot find name 'console'
1263+ console [ prop ] ( ...args ) ;
1264+ } catch {
1265+ // Ignore
1266+ }
1267+ } ,
1268+ } ) ;
0 commit comments