mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(transformer/typescript): remove typescript ast nodes (#3559)
According to Babel tests feedback, remove some known ts AST nodes. There are still many TS AST nodes that need to be deleted
This commit is contained in:
parent
37cdc13030
commit
e8a20f8d50
5 changed files with 35 additions and 14 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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>,
|
||||
|
|
|
|||
|
|
@ -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>) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue