Skip to content

Commit

Permalink
refactor(transformer): rename ImportKind to Import
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Oct 14, 2024
1 parent 31860fd commit b9d7286
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions crates/oxc_transformer/src/common/module_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct NamedImport<'a> {
local: BoundIdentifier<'a>,
}

enum ImportKind<'a> {
enum Import<'a> {
Named(NamedImport<'a>),
Default(BoundIdentifier<'a>),
}
Expand All @@ -78,7 +78,7 @@ enum ImportKind<'a> {
/// to produce output that's the same as Babel's.
/// Substitute `FxHashMap` once we don't need to match Babel's output exactly.
pub struct ModuleImportsStore<'a> {
imports: RefCell<IndexMap<Atom<'a>, Vec<ImportKind<'a>>>>,
imports: RefCell<IndexMap<Atom<'a>, Vec<Import<'a>>>>,
}

// Public methods
Expand All @@ -97,7 +97,7 @@ impl<'a> ModuleImportsStore<'a> {
///
/// If `front` is `true`, `import`/`require` is added to front of the `import`s/`require`s.
pub fn add_default_import(&self, source: Atom<'a>, local: BoundIdentifier<'a>, front: bool) {
self.add_import(source, ImportKind::Default(local), front);
self.add_import(source, Import::Default(local), front);
}

/// Add named `import` to top of program.
Expand All @@ -114,7 +114,7 @@ impl<'a> ModuleImportsStore<'a> {
local: BoundIdentifier<'a>,
front: bool,
) {
self.add_import(source, ImportKind::Named(NamedImport { imported, local }), front);
self.add_import(source, Import::Named(NamedImport { imported, local }), front);
}

/// Returns `true` if no imports have been scheduled for insertion.
Expand All @@ -137,7 +137,7 @@ impl<'a> ModuleImportsStore<'a> {
/// If `front` is `true`, `import`/`require` is added to front of the `import`s/`require`s.
/// TODO(improve-on-babel): `front` option is only required to pass one of Babel's tests. Output
/// without it is still valid. Remove this once our output doesn't need to match Babel exactly.
fn add_import(&self, source: Atom<'a>, import: ImportKind<'a>, front: bool) {
fn add_import(&self, source: Atom<'a>, import: Import<'a>, front: bool) {
match self.imports.borrow_mut().entry(source) {
IndexMapEntry::Occupied(mut entry) => {
entry.get_mut().push(import);
Expand Down Expand Up @@ -194,19 +194,19 @@ impl<'a> ModuleImportsStore<'a> {

fn get_import(
source: Atom<'a>,
names: Vec<ImportKind<'a>>,
names: Vec<Import<'a>>,
ctx: &mut TraverseCtx<'a>,
) -> Statement<'a> {
let specifiers = ctx.ast.vec_from_iter(names.into_iter().map(|kind| match kind {
ImportKind::Named(named) => {
Import::Named(named) => {
ImportDeclarationSpecifier::ImportSpecifier(ctx.ast.alloc_import_specifier(
SPAN,
ModuleExportName::IdentifierName(IdentifierName::new(SPAN, named.imported)),
named.local.create_binding_identifier(),
ImportOrExportKind::Value,
))
}
ImportKind::Default(local) => ImportDeclarationSpecifier::ImportDefaultSpecifier(
Import::Default(local) => ImportDeclarationSpecifier::ImportDefaultSpecifier(
ctx.ast.alloc_import_default_specifier(SPAN, local.create_binding_identifier()),
),
}));
Expand All @@ -223,7 +223,7 @@ impl<'a> ModuleImportsStore<'a> {

fn get_require(
source: Atom<'a>,
names: std::vec::Vec<ImportKind<'a>>,
names: std::vec::Vec<Import<'a>>,
require_symbol_id: Option<SymbolId>,
ctx: &mut TraverseCtx<'a>,
) -> Statement<'a> {
Expand All @@ -240,7 +240,7 @@ impl<'a> ModuleImportsStore<'a> {
let arg = Argument::from(ctx.ast.expression_string_literal(SPAN, source));
ctx.ast.vec1(arg)
};
let Some(ImportKind::Default(local)) = names.into_iter().next() else { unreachable!() };
let Some(Import::Default(local)) = names.into_iter().next() else { unreachable!() };
let id = local.create_binding_pattern(ctx);
let decl = {
let init = ctx.ast.expression_call(SPAN, callee, NONE, args, false);
Expand Down

0 comments on commit b9d7286

Please sign in to comment.