Skip to content

Commit

Permalink
feat(transformer/typescript): remove verbatim_module_syntax option (#…
Browse files Browse the repository at this point in the history
…2796)

Remove `verbatim_module_syntax` option, Because Babel's
[onlyRemoveTypeImports](https://babeljs.io/docs/babel-plugin-transform-typescript#onlyremovetypeimports)
option same behavior with `verbatim_module_syntax` , You can see
babel/babel#15493 (comment)
  • Loading branch information
Dunqing committed Mar 24, 2024
1 parent b6e493b commit 398a034
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
3 changes: 1 addition & 2 deletions crates/oxc_transformer/src/lib.rs
Expand Up @@ -104,8 +104,7 @@ impl<'a> Transformer<'a> {
Self {
ctx: ctx.clone(),
decorators: Decorators::new(Rc::clone(&ast), ctx.clone(), &options),
// TODO: pass verbatim_module_syntax from user config
typescript: source_type.is_typescript().then(|| TypeScript::new(Rc::clone(&ast), ctx.clone(), false, &options)),
typescript: source_type.is_typescript().then(|| TypeScript::new(Rc::clone(&ast), ctx.clone(), &options)),
regexp_flags: RegexpFlags::new(Rc::clone(&ast), &options),
// es2022
es2022_class_static_block: es2022::ClassStaticBlock::new(Rc::clone(&ast), &options),
Expand Down
17 changes: 3 additions & 14 deletions crates/oxc_transformer/src/typescript/mod.rs
Expand Up @@ -23,7 +23,6 @@ use crate::{context::TransformerCtx, utils::is_valid_identifier, TransformOption
pub struct TypeScript<'a> {
ast: Rc<AstBuilder<'a>>,
ctx: TransformerCtx<'a>,
verbatim_module_syntax: bool,
export_name_set: FxHashSet<Atom<'a>>,
options: TypescriptOptions,
namespace_arg_names: FxHashMap<Atom<'a>, usize>,
Expand All @@ -33,13 +32,11 @@ impl<'a> TypeScript<'a> {
pub fn new(
ast: Rc<AstBuilder<'a>>,
ctx: TransformerCtx<'a>,
verbatim_module_syntax: bool,
options: &TransformOptions,
) -> Self {
Self {
ast,
ctx,
verbatim_module_syntax,
export_name_set: FxHashSet::default(),
options: options.typescript.clone().unwrap_or_default(),
namespace_arg_names: FxHashMap::default(),
Expand Down Expand Up @@ -140,7 +137,6 @@ impl<'a> TypeScript<'a> {
});

if decl.export_kind.is_type()
|| self.verbatim_module_syntax
|| ((decl.declaration.is_none()
|| decl.declaration.as_ref().is_some_and(|d| {
d.modifiers().is_some_and(|modifiers| {
Expand Down Expand Up @@ -170,9 +166,7 @@ impl<'a> TypeScript<'a> {
return false;
}

if self.verbatim_module_syntax
|| self.options.only_remove_type_imports
{
if self.options.only_remove_type_imports {
return true;
}

Expand All @@ -182,9 +176,7 @@ impl<'a> TypeScript<'a> {

self.has_value_references(&s.local.name)
}
ImportDeclarationSpecifier::ImportDefaultSpecifier(s)
if !self.verbatim_module_syntax =>
{
ImportDeclarationSpecifier::ImportDefaultSpecifier(s) => {
if is_type {
import_type_names.insert(s.local.name.clone());
return false;
Expand All @@ -195,9 +187,7 @@ impl<'a> TypeScript<'a> {
}
self.has_value_references(&s.local.name)
}
ImportDeclarationSpecifier::ImportNamespaceSpecifier(s)
if !self.verbatim_module_syntax =>
{
ImportDeclarationSpecifier::ImportNamespaceSpecifier(s) => {
if is_type {
import_type_names.insert(s.local.name.clone());
}
Expand All @@ -208,7 +198,6 @@ impl<'a> TypeScript<'a> {

self.has_value_references(&s.local.name)
}
_ => true,
});
}

Expand Down

0 comments on commit 398a034

Please sign in to comment.