Skip to content

Add support for objects with custom toString#116

Open
sjh9714 wants to merge 1 commit into
lukeed:masterfrom
sjh9714:regression-proof/to-string-object
Open

Add support for objects with custom toString#116
sjh9714 wants to merge 1 commit into
lukeed:masterfrom
sjh9714:regression-proof/to-string-object

Conversation

@sjh9714
Copy link
Copy Markdown

@sjh9714 sjh9714 commented May 20, 2026

Hi, this is a small follow-up for #52.

This adds support for objects/classes that provide a custom toString() method, matching the shape discussed in the issue. Normal object maps still use the existing key/value handling when the object has the default Object.prototype.toString.

I know this may not be the right tradeoff for clsx. In my local build, the output changed from 239 -> 277 B for dist/clsx.mjs, 245 -> 281 B for dist/clsx.js, and 305 -> 340 B for dist/clsx.min.js. If that size/perf tradeoff is not desirable, please feel free to close this PR.

I used Node 20.20.2 for tests and bench. On my local Node 22.22.0 setup, the existing uvu -r esm test command fails before reaching this change.

Testing

  • npx -y node@20.20.2 node_modules/.bin/uvu -r esm test
  • npm run build
  • npx -y node@20.20.2 bench

Refs #52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant