mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(transformer/react-jsx): support pragmaFrag option (#1181)
This commit is contained in:
parent
4ed0813f9b
commit
3cb7c0b199
3 changed files with 16 additions and 6 deletions
|
|
@ -366,9 +366,13 @@ impl<'a> ReactJsx<'a> {
|
|||
fn get_fragment(&mut self) -> Expression<'a> {
|
||||
match self.options.runtime {
|
||||
ReactJsxRuntime::Classic => {
|
||||
let object = self.get_react_references();
|
||||
let property = IdentifierName::new(SPAN, "Fragment".into());
|
||||
self.ast.static_member_expression(SPAN, object, property, false)
|
||||
if self.options.pragma_frag == "React.Fragment" {
|
||||
let object = self.get_react_references();
|
||||
let property = IdentifierName::new(SPAN, "Fragment".into());
|
||||
return self.ast.static_member_expression(SPAN, object, property, false);
|
||||
}
|
||||
|
||||
self.get_call_expression_callee(self.options.pragma_frag.as_ref())
|
||||
}
|
||||
ReactJsxRuntime::Automatic => {
|
||||
let ident = IdentifierReference::new(SPAN, "_Fragment".into());
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ pub struct ReactJsxOptions {
|
|||
/// Note that the @jsx React.DOM pragma has been deprecated as of React v0.12
|
||||
#[serde(default = "default_pragma")]
|
||||
pub pragma: Cow<'static, str>,
|
||||
/// Replace the component used when compiling JSX fragments. It should be a valid JSX tag name. default to `React.Fragment`
|
||||
#[serde(default = "default_pragma_frag")]
|
||||
pub pragma_frag: Cow<'static, str>,
|
||||
}
|
||||
|
||||
fn default_import_source() -> Cow<'static, str> {
|
||||
|
|
@ -31,6 +34,10 @@ fn default_pragma() -> Cow<'static, str> {
|
|||
Cow::Borrowed("React.createElement")
|
||||
}
|
||||
|
||||
fn default_pragma_frag() -> Cow<'static, str> {
|
||||
Cow::Borrowed("React.Fragment")
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ReactJsxRuntime {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Passed: 262/1113
|
||||
Passed: 263/1113
|
||||
|
||||
# All Passed:
|
||||
* babel-plugin-transform-numeric-separator
|
||||
|
|
@ -825,7 +825,7 @@ Passed: 262/1113
|
|||
* regression/11061/input.mjs
|
||||
* variable-declaration/non-null-in-optional-chain/input.ts
|
||||
|
||||
# babel-plugin-transform-react-jsx (100/170)
|
||||
# babel-plugin-transform-react-jsx (101/170)
|
||||
* autoImport/after-polyfills-compiled-to-cjs/input.mjs
|
||||
* autoImport/after-polyfills-script-not-supported/input.js
|
||||
* autoImport/auto-import-react-source-type-module/input.js
|
||||
|
|
@ -884,7 +884,6 @@ Passed: 262/1113
|
|||
* react-automatic/should-warn-when-pragma-or-pragmaFrag-is-set/input.js
|
||||
* regression/issue-12478-automatic/input.js
|
||||
* regression/issue-12478-classic/input.js
|
||||
* regression/issue-15353-classic/input.js
|
||||
* regression/pragma-frag-set-default-classic-runtime/input.js
|
||||
* removed-options/invalid-use-builtins-false/input.js
|
||||
* removed-options/invalid-use-builtins-true/input.js
|
||||
|
|
|
|||
Loading…
Reference in a new issue