Skip to content

Commit

Permalink
fix(transformer): JSX source: add var _jsxFileName statement
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Sep 19, 2024
1 parent 66b4688 commit 418c0be
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions crates/oxc_transformer/src/react/jsx_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_transformer/src/react/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion tasks/transform_conformance/oxc.snap.md
Original file line number Diff line number Diff line change
@@ -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


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var x = <sometag />;
Original file line number Diff line number Diff line change
@@ -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
}} />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["syntax-jsx", "transform-react-jsx-source"]
}

0 comments on commit 418c0be

Please sign in to comment.