From 09a81ce42d75b5377ff05fd5f769db0acf663f82 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Thu, 15 Aug 2024 12:19:12 -0400 Subject: [PATCH 1/2] Fix esbuild object sourcemap by overriding Object.prototype.toString --- 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..a9fe8011 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.hasOwn(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.hasOwn(map, 'toUrl')) { Object.defineProperty(map, 'toUrl', { enumerable: false, value: function toUrl() { From 505e6fa56c31b86392f57964bf15885f20214290 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Thu, 15 Aug 2024 12:40:11 -0400 Subject: [PATCH 2/2] 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 a9fe8011..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 (!Object.hasOwn(map, 'toString')) { + 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 (!Object.hasOwn(map, 'toUrl')) { + if (!Object.prototype.hasOwnProperty.call(map, 'toUrl')) { Object.defineProperty(map, 'toUrl', { enumerable: false, value: function toUrl() {