Skip to content
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

fix(esbuild): object sourcemap by overriding Object.prototype.toString #399

Merged
merged 2 commits into from
Aug 15, 2024

Conversation

edemaine
Copy link
Contributor

Currently, if you:

  • use esbuild mode of an unplugin, and
  • return a map from a load handler, where the map is produced by JSON.parseing a JSON sourcemap (e.g. as returned by esbuild itself),

then unplugin ends up outputting a sourcemap of [object Object] (encoded in base64) because it overrides toUrl but not toString that's inherited from the Object prototype.

I believe the simple fix in this PR (use Object.hasOwn instead of in, to avoid checking prototypes) is what is intended, and it fixed the bug I was encountering.

Full (but not small) reproduction: https://github.com/DanielXMoore/Civet/tree/main/integration/unplugin-examples/esbuild with sourceMap: true added to options in esbuild.js, and v0.7.22 of @danielx/civet (I'm about to release a workaround).

Copy link

pkg-pr-new bot commented Aug 15, 2024

commit: 505e6fa

pnpm add https://pkg.pr.new/unjs/unplugin@399

Open in Stackblitz

@antfu antfu changed the title Fix esbuild object sourcemap by overriding Object.prototype.toString fix(esbuild): object sourcemap by overriding Object.prototype.toString Aug 15, 2024
@antfu antfu merged commit 5d91695 into unjs:main Aug 15, 2024
12 checks passed
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.

2 participants