Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/utils/src/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ function baseFormat(args: unknown[], options: FormatOptions = {}): string {
if (typeof value === 'bigint') {
return `${value.toString()}n`
}
if (typeof value === 'symbol') {
return 'NaN'
}
Copy link
Copy Markdown
Contributor Author

@nami8824 nami8824 Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The %d case is also fixed. It's not in the original issue, but has the same root cause — Number(Symbol()) throws a TypeError.

return Number(value).toString()
}
case '%i': {
Expand Down Expand Up @@ -221,7 +224,7 @@ function baseFormat(args: unknown[], options: FormatOptions = {}): string {

for (let x = args[i]; i < len; x = args[++i]) {
if (x === null || typeof x !== 'object') {
str += ` ${x}`
str += ` ${typeof x === 'symbol' ? x.toString() : x}`
}
else {
str += ` ${formatArg(x)}`
Expand Down
8 changes: 8 additions & 0 deletions test/core/test/utils-display.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,39 @@ describe('format', () => {
}
})('string value'),
],
['%s', Symbol('test')],
['%d', 100],
['%d', 100n],
['%d', null],
['%d', {}],
['%d', {}, 'next'],
['%d', Symbol('test')],
['%i', 100],
['%i', 100n],
['%i', null],
['%i', {}],
['%i', {}, 'next'],
['%i', Symbol('test')],
['%f', 100],
['%f', 100n],
['%f', null],
['%f', {}],
['%f', {}, 'next'],
['%f', Symbol('test')],
['%o', 'string'],
['%o', 100],
['%o', 100n],
['%o', null],
['%o', {}],
['%o', {}, 'next'],
['%o', Symbol('test')],
['%O', 'string'],
['%O', 100],
['%O', 100n],
['%O', null],
['%O', {}],
['%O', {}, 'next'],
['%O', Symbol('test')],
['%c', 'css value'],
['%c', 'css value', 'some other value'],
['%c %f', 'css value', '100.00'],
Expand All @@ -64,7 +70,9 @@ describe('format', () => {
['%j', {}, 'next'],
['%j', { obj }],
['%j', { fn: () => {} }],
['%j', Symbol('test')],
['%%', 'string'],
['prefix', Symbol('test')],
])('format(%s)', (formatString, ...args) => {
expect(format(formatString, ...args), `failed ${formatString}`).toBe(util.format(formatString, ...args))
})
Expand Down
Loading