use command: Don't create a variable with empty record if it doesn't define any constants (#14051)

# Description
Fixes: #13967

The key changes lays in `nu-protocol/src/module.rs`, when resolving
import pattern, nushell only needs to bring `$module` with a record
value if it defines any constants.

# User-Facing Changes
```nushell
module spam {}
use spam
```
Will no longer create a `$spam` variable with an empty record.

# Tests + Formatting
Adjusted some tests and added some tests.
This commit is contained in:
Wind
2024-10-17 10:25:45 +08:00
committed by GitHub
parent 2eef42c6b9
commit 71b49c3374
3 changed files with 49 additions and 26 deletions

View File

@ -120,6 +120,11 @@ fn export_consts() -> TestResult {
)
}
#[test]
fn dont_export_module_name_as_a_variable() -> TestResult {
fail_test(r#"module spam { }; use spam; $spam"#, "variable not found")
}
#[test]
fn func_use_consts() -> TestResult {
run_test(