Skip to content

Commit

Permalink
fix(es/react): Visit children nodes in jsx-src pass (#8212)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8210
  • Loading branch information
kdy1 authored Nov 2, 2023
1 parent 2b35e6c commit 47733a9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
25 changes: 25 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8210/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": true
},
"target": "es2022",
"loose": false,
"minify": {
"compress": false,
"mangle": false
},
"transform": {
"react": {
"development": true,
"runtime": "automatic"
}
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}
3 changes: 3 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8210/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const Component = () => {
return (<p thing={<a />}>Hello</p>)
}
15 changes: 15 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8210/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
const Component = ()=>{
return /*#__PURE__*/ _jsxDEV("p", {
thing: /*#__PURE__*/ _jsxDEV("a", {}, void 0, false, {
fileName: "$DIR/tests/fixture/issues-8xxx/8210/input/1.js",
lineNumber: 2,
columnNumber: 23
}, void 0),
children: "Hello"
}, void 0, false, {
fileName: "$DIR/tests/fixture/issues-8xxx/8210/input/1.js",
lineNumber: 2,
columnNumber: 13
}, this);
};
4 changes: 3 additions & 1 deletion crates/swc_ecma_transforms_react/src/jsx_src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use swc_common::{sync::Lrc, SourceMap, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_transforms_base::perf::Parallel;
use swc_ecma_utils::quote_ident;
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut};
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -34,6 +34,8 @@ impl VisitMut for JsxSrc {
return;
}

e.visit_mut_children_with(self);

let loc = self.cm.lookup_char_pos(e.span.lo);
let file_name = loc.file.name.to_string();

Expand Down

0 comments on commit 47733a9

Please sign in to comment.