diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 407cae74feb62..7f824995dbd30 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -353,7 +353,7 @@ impl<'a> Expression<'a> { matches!(self, Expression::Identifier(_)) } - pub fn get_identifier_reference(&self) -> Option<&IdentifierReference> { + pub fn get_identifier_reference(&self) -> Option<&IdentifierReference<'a>> { match self.get_inner_expression() { Expression::Identifier(ident) => Some(ident), _ => None, diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index 0a05975a2f7fe..2766fbab42326 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -157,6 +157,14 @@ impl<'a> Traverse<'a> for Transformer<'a> { self.x3_es2015.transform_expression_on_exit(expr); } + fn enter_simple_assignment_target( + &mut self, + node: &mut SimpleAssignmentTarget<'a>, + _ctx: &mut TraverseCtx<'a>, + ) { + self.x0_typescript.transform_simple_assignment_target(node); + } + fn enter_formal_parameter( &mut self, param: &mut FormalParameter<'a>, diff --git a/crates/oxc_transformer/src/typescript/annotations.rs b/crates/oxc_transformer/src/typescript/annotations.rs index 90d0e1163b2da..3b9057ee95cb0 100644 --- a/crates/oxc_transformer/src/typescript/annotations.rs +++ b/crates/oxc_transformer/src/typescript/annotations.rs @@ -122,6 +122,9 @@ impl<'a> TypeScriptAnnotations<'a> { ModuleDeclaration::ExportAllDeclaration(decl) => { return !decl.export_kind.is_type() } + ModuleDeclaration::ExportDefaultDeclaration(decl) => { + return !decl.is_typescript_syntax() + } ModuleDeclaration::ImportDeclaration(decl) => { let is_type = decl.import_kind.is_type(); @@ -228,7 +231,7 @@ impl<'a> TypeScriptAnnotations<'a> { body.body.retain(|elem| match elem { ClassElement::MethodDefinition(method) => { matches!(method.r#type, MethodDefinitionType::MethodDefinition) - || !method.value.is_typescript_syntax() + && !method.value.is_typescript_syntax() } ClassElement::PropertyDefinition(prop) => { if prop.value.as_ref().is_some_and(Expression::is_typescript_syntax) @@ -239,13 +242,27 @@ impl<'a> TypeScriptAnnotations<'a> { matches!(prop.r#type, PropertyDefinitionType::PropertyDefinition) } } + ClassElement::AccessorProperty(prop) => { + matches!(prop.r#type, AccessorPropertyType::AccessorProperty) + } ClassElement::TSIndexSignature(_) => false, - _ => true, + ClassElement::StaticBlock(_) => true, }); } pub fn transform_expression(&mut self, expr: &mut Expression<'a>) { - *expr = self.ctx.ast.copy(expr.get_inner_expression()); + if expr.is_typescript_syntax() { + *expr = self.ctx.ast.copy(expr.get_inner_expression()); + } + } + + pub fn transform_simple_assignment_target(&mut self, target: &mut SimpleAssignmentTarget<'a>) { + if let Some(expr) = target.get_expression() { + if let Some(ident) = expr.get_inner_expression().get_identifier_reference() { + let ident = self.ctx.ast.alloc(self.ctx.ast.copy(ident)); + *target = SimpleAssignmentTarget::AssignmentTargetIdentifier(ident); + } + } } pub fn transform_formal_parameter(&mut self, param: &mut FormalParameter<'a>) { diff --git a/crates/oxc_transformer/src/typescript/mod.rs b/crates/oxc_transformer/src/typescript/mod.rs index b0065e02155f8..7bc67783bc78b 100644 --- a/crates/oxc_transformer/src/typescript/mod.rs +++ b/crates/oxc_transformer/src/typescript/mod.rs @@ -109,6 +109,10 @@ impl<'a> TypeScript<'a> { self.annotations.transform_expression(expr); } + pub fn transform_simple_assignment_target(&mut self, target: &mut SimpleAssignmentTarget<'a>) { + self.annotations.transform_simple_assignment_target(target); + } + pub fn transform_formal_parameter(&mut self, param: &mut FormalParameter<'a>) { self.annotations.transform_formal_parameter(param); } diff --git a/tasks/transform_conformance/babel.snap.md b/tasks/transform_conformance/babel.snap.md index 0438710ff93f1..41d11fabac1d1 100644 --- a/tasks/transform_conformance/babel.snap.md +++ b/tasks/transform_conformance/babel.snap.md @@ -1,6 +1,6 @@ commit: 4bd1b2c2 -Passed: 469/926 +Passed: 477/926 # All Passed: * babel-preset-react @@ -445,20 +445,12 @@ Passed: 469/926 * opts/optimizeConstEnums/input.ts * opts/rewriteImportExtensions/input.ts -# babel-plugin-transform-typescript (125/150) -* cast/multiple-assert-and-assign/input.ts -* class/accessor-allowDeclareFields-false/input.ts -* class/accessor-allowDeclareFields-true/input.ts -* class/methods/input.ts -* class/private-method-override/input.ts +# babel-plugin-transform-typescript (133/150) * enum/mix-references/input.ts * enum/ts5.0-const-foldable/input.ts * exports/declared-types/input.ts -* exports/default-function/input.ts * exports/interface/input.ts * imports/type-only-export-specifier-2/input.ts -* lvalues/as-expression/input.ts -* lvalues/type-assertion/input.ts * optimize-const-enums/custom-values/input.ts * optimize-const-enums/custom-values-exported/input.ts * optimize-const-enums/declare/input.ts