mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
feat(oxc_transformer): support jsx pragma that are long member expressions (#7538)
related tests:
d34e79e2a9/internal/bundler_tests/bundler_default_test.go (L6188-L6236)
This commit is contained in:
parent
f0e7acc68b
commit
a784a82f4f
5 changed files with 34 additions and 19 deletions
|
|
@ -315,7 +315,7 @@ fn get_import_source(jsx_runtime_importer: &str, react_importer_len: u32) -> Ato
|
||||||
/// Pragma used in classic mode
|
/// Pragma used in classic mode
|
||||||
struct Pragma<'a> {
|
struct Pragma<'a> {
|
||||||
object: Atom<'a>,
|
object: Atom<'a>,
|
||||||
property: Option<Atom<'a>>,
|
properties: Vec<Atom<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Pragma<'a> {
|
impl<'a> Pragma<'a> {
|
||||||
|
|
@ -335,19 +335,10 @@ impl<'a> Pragma<'a> {
|
||||||
if object_name.is_empty() {
|
if object_name.is_empty() {
|
||||||
return Self::invalid(default_property_name, ctx);
|
return Self::invalid(default_property_name, ctx);
|
||||||
}
|
}
|
||||||
|
let props = parts.map(|item| ast.atom(item)).collect();
|
||||||
let property = match parts.next() {
|
|
||||||
Some(property_name) => {
|
|
||||||
if property_name.is_empty() || parts.next().is_some() {
|
|
||||||
return Self::invalid(default_property_name, ctx);
|
|
||||||
}
|
|
||||||
Some(ast.atom(property_name))
|
|
||||||
}
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let object = ast.atom(object_name);
|
let object = ast.atom(object_name);
|
||||||
Self { object, property }
|
Self { object, properties: props }
|
||||||
} else {
|
} else {
|
||||||
Self::default(default_property_name)
|
Self::default(default_property_name)
|
||||||
}
|
}
|
||||||
|
|
@ -359,16 +350,27 @@ impl<'a> Pragma<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default(default_property_name: &'static str) -> Self {
|
fn default(default_property_name: &'static str) -> Self {
|
||||||
Self { object: Atom::from("React"), property: Some(Atom::from(default_property_name)) }
|
Self { object: Atom::from("React"), properties: vec![Atom::from(default_property_name)] }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_expression(&self, ctx: &mut TraverseCtx<'a>) -> Expression<'a> {
|
fn create_expression(&self, ctx: &mut TraverseCtx<'a>) -> Expression<'a> {
|
||||||
let object = get_read_identifier_reference(SPAN, self.object.clone(), ctx);
|
let object = get_read_identifier_reference(SPAN, self.object.clone(), ctx);
|
||||||
if let Some(property) = self.property.as_ref() {
|
Self::create_arbitrary_length_member_expr_or_ident(object, &self.properties, ctx)
|
||||||
create_static_member_expression(object, property.clone(), ctx)
|
}
|
||||||
} else {
|
|
||||||
Expression::Identifier(ctx.alloc(object))
|
/// create a static member expression without caring about the referenceId,
|
||||||
|
/// this function is always used to creat a tail part of a real member expression
|
||||||
|
fn create_arbitrary_length_member_expr_or_ident(
|
||||||
|
object: IdentifierReference<'a>,
|
||||||
|
list: &[Atom<'a>],
|
||||||
|
ctx: &mut TraverseCtx<'a>,
|
||||||
|
) -> Expression<'a> {
|
||||||
|
let mut expr = Expression::Identifier(ctx.alloc(object));
|
||||||
|
for item in list {
|
||||||
|
let name = ctx.ast.identifier_name(SPAN, item.clone());
|
||||||
|
expr = ctx.ast.member_expression_static(SPAN, expr, name, false).into();
|
||||||
}
|
}
|
||||||
|
expr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
commit: 54a8389f
|
commit: 54a8389f
|
||||||
|
|
||||||
Passed: 90/101
|
Passed: 91/102
|
||||||
|
|
||||||
# All Passed:
|
# All Passed:
|
||||||
* babel-plugin-transform-class-static-block
|
* babel-plugin-transform-class-static-block
|
||||||
|
|
@ -170,7 +170,7 @@ rebuilt : SymbolId(2): []
|
||||||
x Output mismatch
|
x Output mismatch
|
||||||
|
|
||||||
|
|
||||||
# babel-plugin-transform-react-jsx (31/34)
|
# babel-plugin-transform-react-jsx (32/35)
|
||||||
* refresh/does-not-transform-it-because-it-is-not-used-in-the-AST/input.jsx
|
* refresh/does-not-transform-it-because-it-is-not-used-in-the-AST/input.jsx
|
||||||
x Output mismatch
|
x Output mismatch
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
<test></test>
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"transform-react-jsx",
|
||||||
|
{
|
||||||
|
"runtime": "classic",
|
||||||
|
"pragma": "a.b.c"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
a.b.c("test", null);
|
||||||
Loading…
Reference in a new issue