From 47733a951c14bc22c2a60acb420b597ddab7d306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 3 Nov 2023 08:29:16 +0900 Subject: [PATCH] fix(es/react): Visit children nodes in `jsx-src` pass (#8212) **Related issue:** - Closes #8210 --- .../fixture/issues-8xxx/8210/input/.swcrc | 25 +++++++++++++++++++ .../tests/fixture/issues-8xxx/8210/input/1.js | 3 +++ .../fixture/issues-8xxx/8210/output/1.js | 15 +++++++++++ .../src/jsx_src/mod.rs | 4 ++- 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 crates/swc/tests/fixture/issues-8xxx/8210/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-8xxx/8210/input/1.js create mode 100644 crates/swc/tests/fixture/issues-8xxx/8210/output/1.js diff --git a/crates/swc/tests/fixture/issues-8xxx/8210/input/.swcrc b/crates/swc/tests/fixture/issues-8xxx/8210/input/.swcrc new file mode 100644 index 000000000000..53722f9ac21b --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8210/input/.swcrc @@ -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 +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-8xxx/8210/input/1.js b/crates/swc/tests/fixture/issues-8xxx/8210/input/1.js new file mode 100644 index 000000000000..9b7ae893f885 --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8210/input/1.js @@ -0,0 +1,3 @@ +const Component = () => { + return (

}>Hello

) +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-8xxx/8210/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8210/output/1.js new file mode 100644 index 000000000000..7c1f2f74b0e7 --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8210/output/1.js @@ -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); +}; diff --git a/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs b/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs index 5c99b697149f..cb8a1c2498ba 100644 --- a/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs +++ b/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs @@ -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();