From e24e2ffe5971d2d1ef667c910a12b94ca41f1b52 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Thu, 8 Aug 2024 04:47:12 +0800 Subject: [PATCH] fix(es/typescript): Enable Injector to process JSX (#9395) - Closes https://github.com/swc-project/swc/issues/9394 --- .changeset/wet-pets-check.md | 5 +++++ crates/swc/tests/fixture/issues-9xxx/9394/input/.swcrc | 9 +++++++++ .../swc/tests/fixture/issues-9xxx/9394/input/index.tsx | 5 +++++ .../swc/tests/fixture/issues-9xxx/9394/output/index.tsx | 7 +++++++ crates/swc_ecma_utils/src/constructor.rs | 6 ++---- 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 .changeset/wet-pets-check.md create mode 100644 crates/swc/tests/fixture/issues-9xxx/9394/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-9xxx/9394/input/index.tsx create mode 100644 crates/swc/tests/fixture/issues-9xxx/9394/output/index.tsx diff --git a/.changeset/wet-pets-check.md b/.changeset/wet-pets-check.md new file mode 100644 index 000000000000..5eb1e535e46f --- /dev/null +++ b/.changeset/wet-pets-check.md @@ -0,0 +1,5 @@ +--- +swc_ecma_utils: patch +--- + +fix(es/typescript): Enable Injector to process JSX diff --git a/crates/swc/tests/fixture/issues-9xxx/9394/input/.swcrc b/crates/swc/tests/fixture/issues-9xxx/9394/input/.swcrc new file mode 100644 index 000000000000..d74d87e56029 --- /dev/null +++ b/crates/swc/tests/fixture/issues-9xxx/9394/input/.swcrc @@ -0,0 +1,9 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript", + "tsx": true + }, + "target": "es2022" + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-9xxx/9394/input/index.tsx b/crates/swc/tests/fixture/issues-9xxx/9394/input/index.tsx new file mode 100644 index 000000000000..84897f9f591d --- /dev/null +++ b/crates/swc/tests/fixture/issues-9xxx/9394/input/index.tsx @@ -0,0 +1,5 @@ +class MyClass { + constructor(private readonly myNumber: number) { + const component = ; + } +} diff --git a/crates/swc/tests/fixture/issues-9xxx/9394/output/index.tsx b/crates/swc/tests/fixture/issues-9xxx/9394/output/index.tsx new file mode 100644 index 000000000000..83c1d6f88a0b --- /dev/null +++ b/crates/swc/tests/fixture/issues-9xxx/9394/output/index.tsx @@ -0,0 +1,7 @@ +class MyClass { + myNumber; + constructor(myNumber){ + this.myNumber = myNumber; + const component = /*#__PURE__*/ React.createElement(MyComponent, null); + } +} diff --git a/crates/swc_ecma_utils/src/constructor.rs b/crates/swc_ecma_utils/src/constructor.rs index 6c988bc79ea1..22b5bf922dc9 100644 --- a/crates/swc_ecma_utils/src/constructor.rs +++ b/crates/swc_ecma_utils/src/constructor.rs @@ -2,9 +2,7 @@ use std::iter; use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; -use swc_ecma_visit::{ - noop_visit_mut_type, standard_only_fold, Fold, FoldWith, VisitMut, VisitMutWith, -}; +use swc_ecma_visit::{noop_fold_type, noop_visit_mut_type, Fold, FoldWith, VisitMut, VisitMutWith}; use crate::{prepend_stmts, ExprFactory}; @@ -36,7 +34,7 @@ struct Injector<'a> { } impl<'a> Fold for Injector<'a> { - standard_only_fold!(); + noop_fold_type!(); fn fold_class(&mut self, c: Class) -> Class { c