From 5d91695e32fd0734cbdcc0b2206c36a4b043020c Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Thu, 15 Aug 2024 16:48:31 -0400 Subject: [PATCH] fix(esbuild): object sourcemap by overriding Object.prototype.toString (#399) * Fix esbuild object sourcemap by overriding Object.prototype.toString * Switch from Object.hasOwn to Object.prototype.hasOwnProperty --- src/esbuild/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/esbuild/utils.ts b/src/esbuild/utils.ts index 6bc4d6f3..d5a3d6ba 100644 --- a/src/esbuild/utils.ts +++ b/src/esbuild/utils.ts @@ -46,7 +46,7 @@ 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() { @@ -54,7 +54,7 @@ export function fixSourceMap(map: EncodedSourceMap): SourceMap { }, }) } - if (!('toUrl' in map)) { + if (!Object.prototype.hasOwnProperty.call(map, 'toUrl')) { Object.defineProperty(map, 'toUrl', { enumerable: false, value: function toUrl() {