mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
feat(transformer/typescript): support for transform TSImportEqualsDeclaration (#2998)
This commit is contained in:
parent
6732e8b9af
commit
afb1dd4b24
3 changed files with 72 additions and 5 deletions
|
|
@ -1,6 +1,7 @@
|
|||
mod annotations;
|
||||
mod collector;
|
||||
mod r#enum;
|
||||
mod module;
|
||||
mod namespace;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
|
@ -155,8 +156,7 @@ impl<'a> TypeScript<'a> {
|
|||
Declaration::TSImportEqualsDeclaration(ts_import_equals)
|
||||
if ts_import_equals.import_kind.is_value() =>
|
||||
{
|
||||
// TODO: support for transform_ts_import_equals function
|
||||
// *decl = self.transform_ts_import_equals(ts_import_equals);
|
||||
*decl = self.transform_ts_import_equals(ts_import_equals);
|
||||
}
|
||||
Declaration::TSEnumDeclaration(ts_enum_declaration) => {
|
||||
if let Some(expr) = self.transform_ts_enum(ts_enum_declaration) {
|
||||
|
|
|
|||
68
crates/oxc_transformer/src/typescript/module.rs
Normal file
68
crates/oxc_transformer/src/typescript/module.rs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
use oxc_allocator::Box;
|
||||
use oxc_ast::ast::*;
|
||||
use oxc_span::SPAN;
|
||||
|
||||
use super::TypeScript;
|
||||
|
||||
impl<'a> TypeScript<'a> {
|
||||
fn transform_ts_type_name(&self, type_name: &mut TSTypeName<'a>) -> Expression<'a> {
|
||||
match type_name {
|
||||
TSTypeName::IdentifierReference(reference) => {
|
||||
self.ctx.ast.identifier_reference_expression(IdentifierReference::new(
|
||||
SPAN,
|
||||
reference.name.clone(),
|
||||
))
|
||||
}
|
||||
TSTypeName::QualifiedName(qualified_name) => self.ctx.ast.static_member_expression(
|
||||
SPAN,
|
||||
self.transform_ts_type_name(&mut qualified_name.left),
|
||||
qualified_name.right.clone(),
|
||||
false,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// ```TypeScript
|
||||
/// import b = babel;
|
||||
/// import AliasModule = LongNameModule;
|
||||
///
|
||||
/// ```JavaScript
|
||||
/// var b = babel;
|
||||
/// var AliasModule = LongNameModule;
|
||||
/// ```
|
||||
pub fn transform_ts_import_equals(
|
||||
&self,
|
||||
decl: &mut Box<'a, TSImportEqualsDeclaration<'a>>,
|
||||
) -> Declaration<'a> {
|
||||
let kind = VariableDeclarationKind::Var;
|
||||
let decls = {
|
||||
let binding_identifier = BindingIdentifier::new(SPAN, decl.id.name.clone());
|
||||
let binding_pattern_kind = self.ctx.ast.binding_pattern_identifier(binding_identifier);
|
||||
let binding = self.ctx.ast.binding_pattern(binding_pattern_kind, None, false);
|
||||
|
||||
let init = match &mut *decl.module_reference {
|
||||
TSModuleReference::TypeName(type_name) => self.transform_ts_type_name(type_name),
|
||||
TSModuleReference::ExternalModuleReference(reference) => {
|
||||
let callee = self.ctx.ast.identifier_reference_expression(
|
||||
IdentifierReference::new(SPAN, "require".into()),
|
||||
);
|
||||
let arguments = self.ctx.ast.new_vec_single(Argument::Expression(
|
||||
self.ctx.ast.literal_string_expression(reference.expression.clone()),
|
||||
));
|
||||
self.ctx.ast.call_expression(SPAN, callee, arguments, false, None)
|
||||
}
|
||||
};
|
||||
self.ctx.ast.new_vec_single(self.ctx.ast.variable_declarator(
|
||||
SPAN,
|
||||
kind,
|
||||
binding,
|
||||
Some(init),
|
||||
false,
|
||||
))
|
||||
};
|
||||
let variable_declaration =
|
||||
self.ctx.ast.variable_declaration(SPAN, kind, decls, Modifiers::empty());
|
||||
|
||||
Declaration::VariableDeclaration(variable_declaration)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
Passed: 125/227
|
||||
Passed: 126/227
|
||||
|
||||
# All Passed:
|
||||
* babel-plugin-transform-react-jsx-source
|
||||
|
|
@ -24,7 +24,7 @@ Passed: 125/227
|
|||
* opts/optimizeConstEnums/input.ts
|
||||
* opts/rewriteImportExtensions/input.ts
|
||||
|
||||
# babel-plugin-transform-typescript (79/147)
|
||||
# babel-plugin-transform-typescript (80/147)
|
||||
* class/abstract-allowDeclareFields-false/input.ts
|
||||
* class/abstract-allowDeclareFields-true/input.ts
|
||||
* class/abstract-class-decorated/input.ts
|
||||
|
|
@ -47,7 +47,6 @@ Passed: 125/227
|
|||
* exports/export-type-star-from/input.ts
|
||||
* exports/export=/input.ts
|
||||
* function/overloads-exports/input.mjs
|
||||
* imports/elide-type-referenced-in-imports-equal-no/input.ts
|
||||
* imports/enum-id/input.ts
|
||||
* imports/enum-value/input.ts
|
||||
* imports/import=-module/input.ts
|
||||
|
|
|
|||
Loading…
Reference in a new issue