mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
fix(transformer): JSX source: add var _jsxFileName statement (#5894)
Fix JSX source transform when run alone without main JSX transform. The added test case is same as one of Babel's exec test cases, but the exec test fails due to `transformAsync` not being present.
This commit is contained in:
1 parent
bd7a6535f6
commit
9758c1a5cc
6 files changed
+20
-1
No files matched your search
@@ -59,6 +59,12 @@ impl<'a> ReactJsxSource<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Traverse<'a> for ReactJsxSource<'a> {
|
||||
fn exit_program(&mut self, program: &mut Program<'a>, _ctx: &mut TraverseCtx<'a>) {
|
||||
if let Some(stmt) = self.get_var_file_name_statement() {
|
||||
program.body.insert(0, stmt);
|
||||
}
|
||||
}
|
||||
|
||||
fn enter_jsx_opening_element(
|
||||
&mut self,
|
||||
elem: &mut JSXOpeningElement<'a>,
|
||||
|
||||
@@ -84,6 +84,8 @@ impl<'a> Traverse<'a> for React<'a> {
|
||||
}
|
||||
if self.jsx_plugin {
|
||||
self.jsx.exit_program(program, ctx);
|
||||
} else if self.jsx_source_plugin {
|
||||
self.jsx.jsx_source.exit_program(program, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
commit: 3bcfee23
|
||||
|
||||
Passed: 46/56
|
||||
Passed: 47/57
|
||||
|
||||
# All Passed:
|
||||
* babel-plugin-transform-nullish-coalescing-operator
|
||||
* babel-plugin-transform-optional-catch-binding
|
||||
* babel-plugin-transform-arrow-functions
|
||||
* babel-preset-typescript
|
||||
* babel-plugin-transform-react-jsx-source
|
||||
* regexp
|
||||
|
||||
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
var x = <sometag />;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
var _jsxFileName = "<CWD>/tests/babel-plugin-transform-react-jsx-source/test/fixtures/react-source/basic-sample/input.jsx";
|
||||
var x = <sometag __source={{
|
||||
fileName: _jsxFileName,
|
||||
lineNumber: 1,
|
||||
columnNumber: 9
|
||||
}} />;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["syntax-jsx", "transform-react-jsx-source"]
|
||||
}
|
||||
Reference in new issue
Block a user