Skip to content

Commit 4d6d163

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 daca0cc commit 4d6d163

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
@@ -552,16 +552,13 @@ fn analyse(
552552
let _ = module_types.insert(module.name.clone(), module.ast.type_info.clone());
553553

554554
// Check for empty modules and emit warning
555-
let public_definitions = module
556-
.ast
557-
.definitions
558-
.iter()
559-
.filter(|def| def.is_public())
560-
.count();
561-
562555
// Only emit the empty module warning if the module has no definitions at all.
563556
// Modules with only private definitions already emit their own warnings.
564-
if public_definitions == 0 && module.ast.definitions.is_empty() {
557+
if module_types
558+
.get(&module.name)
559+
.map(|interface| interface.values.is_empty() && interface.types.is_empty())
560+
.unwrap_or(false)
561+
{
565562
warnings.emit(crate::warning::Warning::EmptyModule {
566563
path: module.input_path.clone(),
567564
name: module.name.clone(),

0 commit comments

Comments
 (0)