mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +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:
parent
bd7a6535f6
commit
9758c1a5cc
6 changed files with 20 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
var x = <sometag />;
|
||||
|
|
@ -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
|
||||
}} />;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"plugins": ["syntax-jsx", "transform-react-jsx-source"]
|
||||
}
|
||||
Loading…
Reference in a new issue