Skip to content

Commit 8a1f7da

Browse files
refactor: use module interface for empty module validation
Moved from AST checking to module interface, similar to what I did on publish.rs. Also, previously the code counted public definitions from the AST and checked if the definitions list was empty. Now it directly checks if both the values and types HashMaps in the module interface are empty, as suggested by @GearsDatapacks
1 parent cb6f368 commit 8a1f7da

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

compiler-core/src/build/package_compiler.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -571,16 +571,13 @@ fn analyse(
571571
let _ = module_types.insert(module.name.clone(), module.ast.type_info.clone());
572572

573573
// Check for empty modules and emit warning
574-
let public_definitions = module
575-
.ast
576-
.definitions
577-
.iter()
578-
.filter(|def| def.is_public())
579-
.count();
580-
581574
// Only emit the empty module warning if the module has no definitions at all.
582575
// Modules with only private definitions already emit their own warnings.
583-
if public_definitions == 0 && module.ast.definitions.is_empty() {
576+
if module_types
577+
.get(&module.name)
578+
.map(|interface| interface.values.is_empty() && interface.types.is_empty())
579+
.unwrap_or(false)
580+
{
584581
warnings.emit(crate::warning::Warning::EmptyModule {
585582
path: module.input_path.clone(),
586583
name: module.name.clone(),

0 commit comments

Comments
 (0)