fix(es/react): Visit children nodes in jsx-src pass (#8212)

**Related issue:**

 - Closes #8210
This commit is contained in:
Donny/강동윤 2023-11-03 08:29:16 +09:00 committed by GitHub
parent 2b35e6c159
commit 47733a951c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 1 deletions

View File

@ -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
}

View File

@ -0,0 +1,3 @@
const Component = () => {
return (<p thing={<a />}>Hello</p>)
}

View File

@ -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);
};

View File

@ -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;
@ -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();