Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(transformer/jsx): Pragma::parse take a &str #7619

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions crates/oxc_transformer/src/jsx/jsx_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl<'a> Pragma<'a> {
///
/// If provided option is invalid, raise an error and use default.
fn parse(
pragma: Option<&String>,
pragma: Option<&str>,
default_property_name: &'static str,
ast: AstBuilder<'a>,
ctx: &TransformCtx<'a>,
Expand Down Expand Up @@ -386,8 +386,9 @@ impl<'a, 'ctx> JsxImpl<'a, 'ctx> {
if options.import_source.is_some() {
ctx.error(diagnostics::import_source_cannot_be_set());
}
let pragma = Pragma::parse(options.pragma.as_ref(), "createElement", ast, ctx);
let pragma_frag = Pragma::parse(options.pragma_frag.as_ref(), "Fragment", ast, ctx);
let pragma = Pragma::parse(options.pragma.as_deref(), "createElement", ast, ctx);
let pragma_frag =
Pragma::parse(options.pragma_frag.as_deref(), "Fragment", ast, ctx);
Bindings::Classic(ClassicBindings { pragma, pragma_frag })
}
JsxRuntime::Automatic => {
Expand Down Expand Up @@ -1098,12 +1099,8 @@ mod test {
fn this_expr_pragma() {
setup!(traverse_ctx, transform_ctx);

let pragma = Pragma::parse(
Some(&"this.a.b".to_string()),
"createElement",
traverse_ctx.ast,
&transform_ctx,
);
let pragma = Some("this.a.b");
let pragma = Pragma::parse(pragma, "createElement", traverse_ctx.ast, &transform_ctx);
let expr = pragma.create_expression(traverse_ctx);

let Expression::StaticMemberExpression(outer_member) = &expr else { panic!() };
Expand All @@ -1119,12 +1116,8 @@ mod test {
fn import_meta_pragma() {
setup!(traverse_ctx, transform_ctx);

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

let Expression::StaticMemberExpression(member) = &expr else { panic!() };
Expand Down
Loading