-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
perf(es/minifier): Remove needless JSON conversion #10628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
if (bindings) { | ||
return bindings.minify(toBuffer(src), toBuffer(opts ?? {}), extras ?? {}); | ||
return bindings.minify(Buffer.from(typeof src === 'object' ? JSON.stringify(src) : src), toBuffer(opts ?? {}), typeof src === 'object', extras ?? {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kdy1
You widened the allowed type of src
to include Buffer
, in which case typeof src === 'object'
, which means if a caller passes a Buffer
it will get stringified, which is going to make a mess. If you want to include Buffer
in the allowed input types you'll want to handle it explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah you are right
Thank you!
### What? Remove unnecessary JSON operations. ### Why? - swc-project/swc#10628 - swc-project/swc#10610
Description:
Related issue: