refactor(transformer): move TSImportEqualsDeclaration transform code (#3764)

Pure refactor. Move all code related to `TSImportEqualsDeclaration` transform into `module.rs`.
This commit is contained in:
overlookmotel 2024-06-19 12:48:44 +00:00
parent cd56aa9dd8
commit 22c56d73c3
2 changed files with 37 additions and 37 deletions

View file

@ -178,17 +178,6 @@ impl<'a> TypeScript<'a> {
self.annotations.transform_tagged_template_expression(expr);
}
pub fn transform_declaration(&mut self, decl: &mut Declaration<'a>, ctx: &mut TraverseCtx<'a>) {
match decl {
Declaration::TSImportEqualsDeclaration(ts_import_equals)
if ts_import_equals.import_kind.is_value() =>
{
*decl = self.transform_ts_import_equals(ts_import_equals, ctx);
}
_ => {}
}
}
pub fn transform_jsx_element(&mut self, elem: &mut JSXElement<'a>) {
self.annotations.transform_jsx_element(elem);
}

View file

@ -7,31 +7,6 @@ use oxc_traverse::TraverseCtx;
use super::TypeScript;
impl<'a> TypeScript<'a> {
fn transform_ts_type_name(
&self,
type_name: &mut TSTypeName<'a>,
ctx: &mut TraverseCtx<'a>,
) -> Expression<'a> {
match type_name {
TSTypeName::IdentifierReference(ident) => {
ident.reference_flag = ReferenceFlag::Read;
if let Some(reference_id) = ident.reference_id.get() {
let reference = ctx.symbols_mut().get_reference_mut(reference_id);
*reference.flag_mut() = ReferenceFlag::Read;
} else {
unreachable!()
}
self.ctx.ast.identifier_reference_expression(ctx.ast.copy(ident))
}
TSTypeName::QualifiedName(qualified_name) => self.ctx.ast.static_member_expression(
SPAN,
self.transform_ts_type_name(&mut qualified_name.left, ctx),
qualified_name.right.clone(),
false,
),
}
}
/// ```TypeScript
/// import b = babel;
/// import AliasModule = LongNameModule;
@ -40,7 +15,18 @@ impl<'a> TypeScript<'a> {
/// var b = babel;
/// var AliasModule = LongNameModule;
/// ```
pub fn transform_ts_import_equals(
pub fn transform_declaration(&mut self, decl: &mut Declaration<'a>, ctx: &mut TraverseCtx<'a>) {
match decl {
Declaration::TSImportEqualsDeclaration(ts_import_equals)
if ts_import_equals.import_kind.is_value() =>
{
*decl = self.transform_ts_import_equals(ts_import_equals, ctx);
}
_ => {}
}
}
fn transform_ts_import_equals(
&self,
decl: &mut Box<'a, TSImportEqualsDeclaration<'a>>,
ctx: &mut TraverseCtx<'a>,
@ -86,6 +72,31 @@ impl<'a> TypeScript<'a> {
Declaration::VariableDeclaration(variable_declaration)
}
fn transform_ts_type_name(
&self,
type_name: &mut TSTypeName<'a>,
ctx: &mut TraverseCtx<'a>,
) -> Expression<'a> {
match type_name {
TSTypeName::IdentifierReference(ident) => {
ident.reference_flag = ReferenceFlag::Read;
if let Some(reference_id) = ident.reference_id.get() {
let reference = ctx.symbols_mut().get_reference_mut(reference_id);
*reference.flag_mut() = ReferenceFlag::Read;
} else {
unreachable!()
}
self.ctx.ast.identifier_reference_expression(ctx.ast.copy(ident))
}
TSTypeName::QualifiedName(qualified_name) => self.ctx.ast.static_member_expression(
SPAN,
self.transform_ts_type_name(&mut qualified_name.left, ctx),
qualified_name.right.clone(),
false,
),
}
}
pub fn transform_ts_export_assignment(
&mut self,
export_assignment: &mut TSExportAssignment<'a>,