Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions crates/oxc_isolated_declarations/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use oxc_ast::ast::*;

use oxc_allocator::Box;
use oxc_ast::Visit;
use oxc_span::{GetSpan, SPAN};
use oxc_span::{Atom, GetSpan, SPAN};

use crate::{diagnostics::default_export_inferred, IsolatedDeclarations};

Expand All @@ -24,6 +24,16 @@ impl<'a> IsolatedDeclarations<'a> {
})
}

pub fn create_unique_name(&mut self, name: &str) -> Atom<'a> {
let mut binding = self.ast.new_atom(name);
let mut i = 1;
while self.scope.has_reference(&binding) {
binding = self.ast.new_atom(format!("{name}_{i}").as_str());
i += 1;
}
binding
}

pub fn transform_export_default_declaration(
&mut self,
decl: &ExportDefaultDeclaration<'a>,
Expand All @@ -46,8 +56,7 @@ impl<'a> IsolatedDeclarations<'a> {
} else {
// declare const _default: Type
let kind = VariableDeclarationKind::Const;
// TODO: create unique name for this
let name = self.ast.new_atom("_default");
let name = self.create_unique_name("_default");
let id = self
.ast
.binding_pattern_identifier(BindingIdentifier::new(SPAN, name.clone()));
Expand Down