mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 12:35:59 +02:00
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:
@ -161,20 +161,25 @@ impl Module {
|
||||
}
|
||||
|
||||
let span = self.span.unwrap_or(backup_span);
|
||||
let const_record = Value::record(
|
||||
const_rows
|
||||
.into_iter()
|
||||
.map(|(name, val)| (String::from_utf8_lossy(&name).to_string(), val))
|
||||
.collect(),
|
||||
span,
|
||||
);
|
||||
|
||||
// only needs to bring `$module` with a record value if it defines any constants.
|
||||
let constants = if const_rows.is_empty() {
|
||||
vec![]
|
||||
} else {
|
||||
vec![(
|
||||
final_name.clone(),
|
||||
Value::record(
|
||||
const_rows
|
||||
.into_iter()
|
||||
.map(|(name, val)| (String::from_utf8_lossy(&name).to_string(), val))
|
||||
.collect(),
|
||||
span,
|
||||
),
|
||||
)]
|
||||
};
|
||||
|
||||
return (
|
||||
ResolvedImportPattern::new(
|
||||
decls,
|
||||
vec![(final_name.clone(), self_id)],
|
||||
vec![(final_name, const_record)],
|
||||
),
|
||||
ResolvedImportPattern::new(decls, vec![(final_name.clone(), self_id)], constants),
|
||||
errors,
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user