Skip to content

Commit

Permalink
refactor(transformer): move TSImportEqualsDeclaration transform code (#…
Browse files Browse the repository at this point in the history
…3764)

Pure refactor. Move all code related to `TSImportEqualsDeclaration` transform into `module.rs`.
  • Loading branch information
overlookmotel committed Jun 19, 2024
1 parent cd56aa9 commit 22c56d7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
11 changes: 0 additions & 11 deletions crates/oxc_transformer/src/typescript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
63 changes: 37 additions & 26 deletions crates/oxc_transformer/src/typescript/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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>,
Expand Down Expand Up @@ -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>,
Expand Down

0 comments on commit 22c56d7

Please sign in to comment.