From 5f1594cb5542fd1e31dad439bda5cd45c445d1cd Mon Sep 17 00:00:00 2001 From: austaras Date: Wed, 22 Nov 2023 03:00:38 +0800 Subject: [PATCH] fix(es/base): Allow `globalThis` to be shadowed --- crates/swc_ecma_transforms_base/src/resolver/mod.rs | 7 +++---- .../tests/resolver/global/globalThis/input.js | 2 ++ .../tests/resolver/global/globalThis/output.js | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 crates/swc_ecma_transforms_base/tests/resolver/global/globalThis/input.js create mode 100644 crates/swc_ecma_transforms_base/tests/resolver/global/globalThis/output.js diff --git a/crates/swc_ecma_transforms_base/src/resolver/mod.rs b/crates/swc_ecma_transforms_base/src/resolver/mod.rs index 4342c7b83bfa..ac97304e335e 100644 --- a/crates/swc_ecma_transforms_base/src/resolver/mod.rs +++ b/crates/swc_ecma_transforms_base/src/resolver/mod.rs @@ -304,10 +304,9 @@ impl<'a> Resolver<'a> { } return match &**sym { - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects#value_properties - "undefined" | "NaN" | "Infinity" | "globalThis" - if mark == self.config.top_level_mark => - { + // https://tc39.es/ecma262/multipage/global-object.html#sec-value-properties-of-the-global-object-infinity + // non configurable global value + "undefined" | "NaN" | "Infinity" if mark == self.config.top_level_mark => { Some(self.config.unresolved_mark) } _ => Some(mark), diff --git a/crates/swc_ecma_transforms_base/tests/resolver/global/globalThis/input.js b/crates/swc_ecma_transforms_base/tests/resolver/global/globalThis/input.js new file mode 100644 index 000000000000..0290601da4ce --- /dev/null +++ b/crates/swc_ecma_transforms_base/tests/resolver/global/globalThis/input.js @@ -0,0 +1,2 @@ +var globalThis = {}; +console.log(globalThis); diff --git a/crates/swc_ecma_transforms_base/tests/resolver/global/globalThis/output.js b/crates/swc_ecma_transforms_base/tests/resolver/global/globalThis/output.js new file mode 100644 index 000000000000..91adce272ad8 --- /dev/null +++ b/crates/swc_ecma_transforms_base/tests/resolver/global/globalThis/output.js @@ -0,0 +1,2 @@ +var globalThis__2 = {}; +console.log(globalThis__2);