diff --git a/crates/mako/src/ast/file.rs b/crates/mako/src/ast/file.rs index 981a39826..75dfc300b 100644 --- a/crates/mako/src/ast/file.rs +++ b/crates/mako/src/ast/file.rs @@ -416,10 +416,10 @@ mod tests { #[test] fn test_has_hash_without_dot() { - assert_eq!(has_hash_without_dot("foo.ts#world"), true); - assert_eq!(has_hash_without_dot("foo#bar.ts"), false); - assert_eq!(has_hash_without_dot("#no_dot"), true); - assert_eq!(has_hash_without_dot("no_hash"), false); - assert_eq!(has_hash_without_dot("#.dot_after_hash"), false); + assert!(has_hash_without_dot("foo.ts#world")); + assert!(!has_hash_without_dot("foo#bar.ts")); + assert!(has_hash_without_dot("#no_dot")); + assert!(!has_hash_without_dot("no_hash")); + assert!(!has_hash_without_dot("#.dot_after_hash")); } } diff --git a/crates/mako/src/visitors/env_replacer.rs b/crates/mako/src/visitors/env_replacer.rs index c32134fd0..37f691c32 100644 --- a/crates/mako/src/visitors/env_replacer.rs +++ b/crates/mako/src/visitors/env_replacer.rs @@ -94,10 +94,14 @@ impl VisitMut for EnvReplacer { current_member_obj = obj.as_mut(); } - if let Expr::Ident(Ident { sym, .. }) = current_member_obj { + if let Expr::Ident(Ident { sym, span, .. }) = current_member_obj { + if span.ctxt.outer() != self.unresolved_mark { + return; + } member_visit_path.push('.'); member_visit_path.push_str(sym.as_ref()); } + let member_visit_path = member_visit_path .split('.') .rev() @@ -403,7 +407,7 @@ mod tests { } #[test] - fn test_complited_computed_as_member_key() { + fn test_complicated_computed_as_member_key() { assert_eq!( run( r#"log(A[v.v])"#, @@ -441,6 +445,20 @@ mod tests { ); } + #[test] + fn test_should_not_replace_existed_as_member_prop() { + assert_eq!( + run( + r#"let A = {};log(A.v, A[X.Y])"#, + hashmap! { + "A".to_string() => json!(r#"{"v": 1}"#), + "X.Y".to_string() => json!(r#""xy""#) + } + ), + r#"let A = {};log(A.v, A["xy"]);"# + ); + } + #[test] fn test_should_not_replace_not_defined() { assert_eq!(