mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(semantic): apply ImportSpecifier's binder and remove ModuleDeclaration's binder (#2307)
Added in #2230, But i forgot to call.
This commit is contained in:
parent
bb9cf484e9
commit
f3035f1bbe
3 changed files with 19 additions and 33 deletions
|
|
@ -2,8 +2,7 @@ use std::borrow::Cow;
|
||||||
|
|
||||||
use oxc_ast::{
|
use oxc_ast::{
|
||||||
ast::{
|
ast::{
|
||||||
CallExpression, Expression, ImportDeclaration, ImportDeclarationSpecifier,
|
CallExpression, Expression, ImportDeclaration, ImportDeclarationSpecifier, TemplateLiteral,
|
||||||
ModuleDeclaration, TemplateLiteral,
|
|
||||||
},
|
},
|
||||||
AstKind,
|
AstKind,
|
||||||
};
|
};
|
||||||
|
|
@ -201,11 +200,8 @@ fn collect_ids_referenced_to_import<'a, 'b>(
|
||||||
.filter_map(|(symbol_id, reference_ids)| {
|
.filter_map(|(symbol_id, reference_ids)| {
|
||||||
if ctx.symbols().get_flag(symbol_id).is_import_binding() {
|
if ctx.symbols().get_flag(symbol_id).is_import_binding() {
|
||||||
let id = ctx.symbols().get_declaration(symbol_id);
|
let id = ctx.symbols().get_declaration(symbol_id);
|
||||||
let node = ctx.nodes().get_node(id);
|
let Some(AstKind::ImportDeclaration(import_decl)) = ctx.nodes().parent_kind(id)
|
||||||
let AstKind::ModuleDeclaration(module_decl) = node.kind() else {
|
else {
|
||||||
return None;
|
|
||||||
};
|
|
||||||
let ModuleDeclaration::ImportDeclaration(import_decl) = module_decl else {
|
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
let name = ctx.symbols().get_name(symbol_id);
|
let name = ctx.symbols().get_name(symbol_id);
|
||||||
|
|
|
||||||
|
|
@ -274,25 +274,11 @@ impl<'a> Binder for CatchClause<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Binder for ModuleDeclaration<'a> {
|
|
||||||
fn bind(&self, builder: &mut SemanticBuilder) {
|
|
||||||
self.bound_names(&mut |ident| {
|
|
||||||
let symbol_id = builder.declare_symbol(
|
|
||||||
ident.span,
|
|
||||||
&ident.name,
|
|
||||||
SymbolFlags::ImportBinding,
|
|
||||||
SymbolFlags::ImportBindingExcludes,
|
|
||||||
);
|
|
||||||
ident.symbol_id.set(Some(symbol_id));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn declare_symbol_for_import_specifier(ident: &BindingIdentifier, builder: &mut SemanticBuilder) {
|
fn declare_symbol_for_import_specifier(ident: &BindingIdentifier, builder: &mut SemanticBuilder) {
|
||||||
let symbol_id = builder.declare_symbol(
|
let symbol_id = builder.declare_symbol(
|
||||||
ident.span,
|
ident.span,
|
||||||
&ident.name,
|
&ident.name,
|
||||||
SymbolFlags::ImportBinding,
|
SymbolFlags::Import | SymbolFlags::ImportBinding,
|
||||||
SymbolFlags::ImportBindingExcludes,
|
SymbolFlags::ImportBindingExcludes,
|
||||||
);
|
);
|
||||||
ident.symbol_id.set(Some(symbol_id));
|
ident.symbol_id.set(Some(symbol_id));
|
||||||
|
|
|
||||||
|
|
@ -1642,8 +1642,18 @@ impl<'a> SemanticBuilder<'a> {
|
||||||
fn enter_kind(&mut self, kind: AstKind<'a>) {
|
fn enter_kind(&mut self, kind: AstKind<'a>) {
|
||||||
match kind {
|
match kind {
|
||||||
AstKind::ModuleDeclaration(decl) => {
|
AstKind::ModuleDeclaration(decl) => {
|
||||||
self.current_symbol_flags |= Self::symbol_flag_from_module_declaration(decl);
|
if !matches!(decl, ModuleDeclaration::ImportDeclaration(_)) {
|
||||||
decl.bind(self);
|
self.current_symbol_flags |= SymbolFlags::Export;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AstKind::ImportSpecifier(specifier) => {
|
||||||
|
specifier.bind(self);
|
||||||
|
}
|
||||||
|
AstKind::ImportDefaultSpecifier(specifier) => {
|
||||||
|
specifier.bind(self);
|
||||||
|
}
|
||||||
|
AstKind::ImportNamespaceSpecifier(specifier) => {
|
||||||
|
specifier.bind(self);
|
||||||
}
|
}
|
||||||
AstKind::VariableDeclarator(decl) => {
|
AstKind::VariableDeclarator(decl) => {
|
||||||
decl.bind(self);
|
decl.bind(self);
|
||||||
|
|
@ -1750,7 +1760,9 @@ impl<'a> SemanticBuilder<'a> {
|
||||||
self.class_table_builder.pop_class();
|
self.class_table_builder.pop_class();
|
||||||
}
|
}
|
||||||
AstKind::ModuleDeclaration(decl) => {
|
AstKind::ModuleDeclaration(decl) => {
|
||||||
self.current_symbol_flags -= Self::symbol_flag_from_module_declaration(decl);
|
if !matches!(decl, ModuleDeclaration::ImportDeclaration(_)) {
|
||||||
|
self.current_symbol_flags -= SymbolFlags::Export;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
AstKind::LabeledStatement(_) => self.label_builder.leave(),
|
AstKind::LabeledStatement(_) => self.label_builder.leave(),
|
||||||
AstKind::StaticBlock(_) | AstKind::Function(_) => {
|
AstKind::StaticBlock(_) | AstKind::Function(_) => {
|
||||||
|
|
@ -1886,12 +1898,4 @@ impl<'a> SemanticBuilder<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn symbol_flag_from_module_declaration(module: &ModuleDeclaration) -> SymbolFlags {
|
|
||||||
if matches!(module, ModuleDeclaration::ImportDeclaration(_)) {
|
|
||||||
SymbolFlags::Import
|
|
||||||
} else {
|
|
||||||
SymbolFlags::Export
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue