Skip to content

Commit

Permalink
fix(esbuild): object sourcemap by overriding Object.prototype.toString (
Browse files Browse the repository at this point in the history
#399)

* Fix esbuild object sourcemap by overriding Object.prototype.toString

* Switch from Object.hasOwn to Object.prototype.hasOwnProperty
  • Loading branch information
edemaine authored Aug 15, 2024
1 parent c28d727 commit 5d91695
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/esbuild/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ export function unwrapLoader(
// `load` and `transform` may return a sourcemap without toString and toUrl,
// but esbuild needs them, we fix the two methods
export function fixSourceMap(map: EncodedSourceMap): SourceMap {
if (!('toString' in map)) {
if (!Object.prototype.hasOwnProperty.call(map, 'toString')) {
Object.defineProperty(map, 'toString', {
enumerable: false,
value: function toString() {
return JSON.stringify(this)
},
})
}
if (!('toUrl' in map)) {
if (!Object.prototype.hasOwnProperty.call(map, 'toUrl')) {
Object.defineProperty(map, 'toUrl', {
enumerable: false,
value: function toUrl() {
Expand Down

0 comments on commit 5d91695

Please sign in to comment.