Include ModuleDecl::ExportNamed

This commit is contained in:
Andrew Morris
2023-03-24 12:47:28 +11:00
parent 5f5398b566
commit d3391028ba
2 changed files with 43 additions and 3 deletions

View File

@@ -410,10 +410,15 @@ impl ModuleCompiler {
}
None => match self.scope_analysis.lookup(&OwnerId::Module, &orig_name) {
Some(Value::Pointer(p)) => Some(p),
_ => {
lookup_result => {
self.diagnostics.push(Diagnostic {
level: DiagnosticLevel::InternalError,
message: format!("Definition for {} should have been in scope", orig_name),
message: format!(
"{} should have been a pointer, but it was {:?}, ref: {:?}",
orig_name,
lookup_result,
self.scope_analysis.refs.get(&orig_name.span)
),
span: named.orig.span(),
});

View File

@@ -299,7 +299,11 @@ impl ScopeAnalysis {
ModuleDecl::ExportDecl(ed) => {
self.decl(&scope, &ed.decl);
}
ModuleDecl::ExportNamed(_) => {}
ModuleDecl::ExportNamed(en) => {
for specifier in &en.specifiers {
self.export_specifier(&scope, specifier);
}
}
ModuleDecl::ExportDefaultDecl(edd) => {
self.default_decl(&scope, &edd.decl);
}
@@ -361,6 +365,37 @@ impl ScopeAnalysis {
}
}
fn export_specifier(&mut self, scope: &XScope, export_specifier: &swc_ecma_ast::ExportSpecifier) {
use swc_ecma_ast::ExportSpecifier::*;
use swc_ecma_ast::ModuleExportName;
match export_specifier {
Named(named_specifier) => {
if named_specifier.is_type_only {
return;
}
match &named_specifier.orig {
ModuleExportName::Ident(ident) => self.ident(scope, ident),
ModuleExportName::Str(_) => self.diagnostics.push(Diagnostic {
level: DiagnosticLevel::InternalError,
message: "TODO: ModuleExportName::Str".to_string(),
span: export_specifier.span(),
}),
}
}
Default(default_specifier) => self.ident(scope, &default_specifier.exported),
Namespace(namespace_specifier) => match &namespace_specifier.name {
ModuleExportName::Ident(ident) => self.ident(scope, ident),
ModuleExportName::Str(_) => self.diagnostics.push(Diagnostic {
level: DiagnosticLevel::InternalError,
message: "TODO: ModuleExportName::Str".to_string(),
span: export_specifier.span(),
}),
},
}
}
fn decl(&mut self, scope: &XScope, decl: &swc_ecma_ast::Decl) {
use swc_ecma_ast::Decl;