diff --git a/crates/oxc_transformer_plugins/src/replace_global_defines.rs b/crates/oxc_transformer_plugins/src/replace_global_defines.rs index 1ff900c8d62a6..e131165ed6739 100644 --- a/crates/oxc_transformer_plugins/src/replace_global_defines.rs +++ b/crates/oxc_transformer_plugins/src/replace_global_defines.rs @@ -545,7 +545,7 @@ impl<'a> ReplaceGlobalDefines<'a> { // `import.meta.env` should not match `import.meta.env.*` return has_matched_part && !is_full_match; } - return true; + return i == 0; } Expression::Identifier(_) => { return false; diff --git a/crates/oxc_transformer_plugins/tests/integrations/replace_global_defines.rs b/crates/oxc_transformer_plugins/tests/integrations/replace_global_defines.rs index 06a387fb1ebd9..e181287f638f7 100644 --- a/crates/oxc_transformer_plugins/tests/integrations/replace_global_defines.rs +++ b/crates/oxc_transformer_plugins/tests/integrations/replace_global_defines.rs @@ -80,6 +80,14 @@ fn dot() { test("foo(process['env'].NODE_ENV)", "foo(production)", &config); } +#[test] +fn dot_with_partial_overlap() { + let config = config(&[("import.meta.foo.bar", "1")]); + test("console.log(import.meta.bar)", "console.log(import.meta.bar)", &config); + test("console.log(import.meta.foo)", "console.log(import.meta.foo)", &config); + test("console.log(import.meta.foo.bar)", "console.log(1)", &config); +} + #[test] fn dot_with_overlap() { let config =