fix(es/typescript): Enable Injector to process JSX (#9395)

- Closes https://github.com/swc-project/swc/issues/9394
This commit is contained in:
magic-akari 2024-08-08 04:47:12 +08:00 committed by GitHub
parent 8e49c904d8
commit e24e2ffe59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 28 additions and 4 deletions

View File

@ -0,0 +1,5 @@
---
swc_ecma_utils: patch
---
fix(es/typescript): Enable Injector to process JSX

View File

@ -0,0 +1,9 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
},
"target": "es2022"
}
}

View File

@ -0,0 +1,5 @@
class MyClass {
constructor(private readonly myNumber: number) {
const component = <MyComponent />;
}
}

View File

@ -0,0 +1,7 @@
class MyClass {
myNumber;
constructor(myNumber){
this.myNumber = myNumber;
const component = /*#__PURE__*/ React.createElement(MyComponent, null);
}
}

View File

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