Skip to content

Commit 47733a9

Browse files
authoredNov 2, 2023
fix(es/react): Visit children nodes in jsx-src pass (#8212)
**Related issue:** - Closes #8210
1 parent 2b35e6c commit 47733a9

File tree

4 files changed

+46
-1
lines changed
  • crates
    • swc/tests/fixture/issues-8xxx/8210
    • swc_ecma_transforms_react/src/jsx_src

4 files changed

+46
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "ecmascript",
5+
"jsx": true
6+
},
7+
"target": "es2022",
8+
"loose": false,
9+
"minify": {
10+
"compress": false,
11+
"mangle": false
12+
},
13+
"transform": {
14+
"react": {
15+
"development": true,
16+
"runtime": "automatic"
17+
}
18+
}
19+
},
20+
"module": {
21+
"type": "es6"
22+
},
23+
"minify": false,
24+
"isModule": true
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const Component = () => {
2+
return (<p thing={<a />}>Hello</p>)
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
2+
const Component = ()=>{
3+
return /*#__PURE__*/ _jsxDEV("p", {
4+
thing: /*#__PURE__*/ _jsxDEV("a", {}, void 0, false, {
5+
fileName: "$DIR/tests/fixture/issues-8xxx/8210/input/1.js",
6+
lineNumber: 2,
7+
columnNumber: 23
8+
}, void 0),
9+
children: "Hello"
10+
}, void 0, false, {
11+
fileName: "$DIR/tests/fixture/issues-8xxx/8210/input/1.js",
12+
lineNumber: 2,
13+
columnNumber: 13
14+
}, this);
15+
};

‎crates/swc_ecma_transforms_react/src/jsx_src/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use swc_common::{sync::Lrc, SourceMap, DUMMY_SP};
22
use swc_ecma_ast::*;
33
use swc_ecma_transforms_base::perf::Parallel;
44
use swc_ecma_utils::quote_ident;
5-
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut};
5+
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
66

77
#[cfg(test)]
88
mod tests;
@@ -34,6 +34,8 @@ impl VisitMut for JsxSrc {
3434
return;
3535
}
3636

37+
e.visit_mut_children_with(self);
38+
3739
let loc = self.cm.lookup_char_pos(e.span.lo);
3840
let file_name = loc.file.name.to_string();
3941

0 commit comments

Comments
 (0)
Please sign in to comment.