allow export alias in repl (#15054)

# Description
Fixes: #15048
The issue is happened while `parse_export_in_block`, it makes a call to
`parse_internal_call`, which may be an error.
But in reality, these errors are not useful, all useful errors will be
generated by `parse_xxx` at the end of the function.

# User-Facing Changes
The following code should no longer raise error:
```
export alias a = overlay use
```

# Tests + Formatting
Added 1 test.

# After Submitting
NaN
This commit is contained in:
Wind 2025-02-10 15:32:05 +08:00 committed by GitHub
parent 6e88b3f8d6
commit d4675d9138
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View File

@ -163,3 +163,9 @@ fn alias_default_help() {
let first_help_line = actual.out.lines().next().unwrap();
assert!(first_help_line.starts_with("Alias for `echo 'I am a beautiful teapot'`"));
}
#[test]
fn export_alias_with_overlay_use_works() {
let actual = nu!("export alias teapot = overlay use");
assert!(actual.err.is_empty())
}

View File

@ -1147,6 +1147,7 @@ pub fn parse_export_in_block(
}
if let Some(decl_id) = working_set.find_decl(full_name.as_bytes()) {
let starting_error_count = working_set.parse_errors.len();
let ParsedInternalCall { call, output, .. } = parse_internal_call(
working_set,
if full_name == "export" {
@ -1161,12 +1162,12 @@ pub fn parse_export_in_block(
},
decl_id,
);
// don't need errors generated by parse_internal_call
// further error will be generated by detail `parse_xxx` function.
working_set.parse_errors.truncate(starting_error_count);
let decl = working_set.get_decl(decl_id);
let starting_error_count = working_set.parse_errors.len();
check_call(working_set, call_span, &decl.signature(), &call);
let Ok(is_help) = has_flag_const(working_set, &call, "help") else {
return garbage_pipeline(working_set, &lite_command.parts);
};