-
-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transformer): implement @babel/plugin-transform-react-jsx-self
- Loading branch information
1 parent
2c6bfa3
commit 005d12e
Showing
8 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function App() { | ||
return ( | ||
<sometag /> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::{context::TransformerCtx, ReactJsxOptions}; | ||
use oxc_ast::ast::*; | ||
use oxc_span::SPAN; | ||
|
||
/// @babel/plugin-transform-react-jsx-self | ||
/// | ||
/// References: | ||
/// * <https://babeljs.io/docs/babel-plugin-transform-react-jsx-self> | ||
/// * <https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-react-jsx-self> | ||
/// | ||
pub struct JsxSelf<'a> { | ||
ctx: TransformerCtx<'a>, | ||
options: ReactJsxOptions, | ||
} | ||
|
||
impl<'a> JsxSelf<'a> { | ||
pub fn new(ctx: TransformerCtx<'a>) -> Option<Self> { | ||
let jsx_options = ctx.options.react_jsx.clone()?; | ||
Some(Self { ctx, options: jsx_options }) | ||
} | ||
pub fn transform_jsx_opening_element(&mut self, elem: &mut JSXOpeningElement<'a>) { | ||
if self.options.development != Some(true) { | ||
return; | ||
} | ||
|
||
elem.attributes.push(JSXAttributeItem::Attribute(self.ctx.ast.jsx_attribute( | ||
SPAN, | ||
JSXAttributeName::Identifier(self.ctx.ast.jsx_identifier(SPAN, "__self".into())), | ||
Some(JSXAttributeValue::ExpressionContainer(self.ctx.ast.jsx_expression_container( | ||
SPAN, | ||
JSXExpression::Expression(self.ctx.ast.this_expression(SPAN)), | ||
))), | ||
))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters