Skip to content

Commit

Permalink
Make tests more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Dec 3, 2024
1 parent 7fa8d9e commit 62fbc1e
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions crates/oxc_transformer/src/jsx/jsx_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,37 +1090,37 @@ mod test {
let mut traverse_ctx = unsafe {
ReusableTraverseCtx::new(ScopeTree::default(), SymbolTable::default(), &alloc).unwrap()
};
let pragma = Pragma::parse(Some(&"this.a.b".to_string()), "createElement", ast, &ctx);

let pragma = Pragma::parse(Some(&"this.a.b".to_string()), "createElement", ast, &ctx);
let expr = pragma.create_expression(&mut traverse_ctx);
let member_expr = expr.as_member_expression().unwrap();
assert_eq!(member_expr.static_property_name(), Some("b"));
let object = member_expr.object().as_member_expression().unwrap();
assert_eq!(object.static_property_name(), Some("a"));
match object.object() {
Expression::ThisExpression(_) => {}
_ => panic!("Expected ThisExpression"),
}

let Expression::StaticMemberExpression(outer_member) = &expr else { panic!() };
let Expression::StaticMemberExpression(inner_member) = &outer_member.object else {
panic!()
};
assert!(matches!(&inner_member.object, Expression::ThisExpression(_)));
assert_eq!(inner_member.property.name, "a");
assert_eq!(outer_member.property.name, "b");
}

#[test]
fn import_meta() {
fn import_meta_pragma() {
let alloc = Allocator::default();
let ast = AstBuilder::new(&alloc);
let ctx = TransformCtx::new(Path::new("test.jsx"), &TransformOptions::default());
// SAFETY: constructed to avoid unsoundness
let mut traverse_ctx = unsafe {
ReusableTraverseCtx::new(ScopeTree::default(), SymbolTable::default(), &alloc).unwrap()
};

let pragma =
Pragma::parse(Some(&"import.meta.prop".to_string()), "createElement", ast, &ctx);

let expr = pragma.create_expression(&mut traverse_ctx);
let member_expr = expr.as_member_expression().unwrap();
assert_eq!(member_expr.static_property_name(), Some("prop"));
match member_expr.object() {
Expression::MetaProperty(_) => {}
_ => panic!("Expected MetaProperty"),
}

let Expression::StaticMemberExpression(member) = &expr else { panic!() };
let Expression::MetaProperty(meta_prop) = &member.object else { panic!() };
assert_eq!(&meta_prop.meta.name, "import");
assert_eq!(&meta_prop.property.name, "meta");
assert_eq!(member.property.name, "prop");
}
}

0 comments on commit 62fbc1e

Please sign in to comment.