don't include import path in args to aliased external commands (#14231)

Fixes #13776

# User-Facing Changes

Arguments to aliased externals no longer include nested import paths:

```diff
module foo { export alias bar = ^echo }
use foo
foo bar baz
-bar baz
+baz
```
This commit is contained in:
Solomon 2024-11-06 06:40:29 -07:00 committed by GitHub
parent 23fba6d2ea
commit cc0259bbed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 2 deletions

View file

@ -1343,10 +1343,10 @@ pub fn parse_call(working_set: &mut StateWorkingSet, spans: &[Span], head: Span)
trace!("parsing: alias of external call"); trace!("parsing: alias of external call");
let mut head = head.clone(); let mut head = head.clone();
head.span = spans[0]; // replacing the spans preserves syntax highlighting head.span = Span::concat(&spans[cmd_start..pos]); // replacing the spans preserves syntax highlighting
let mut final_args = args.clone().into_vec(); let mut final_args = args.clone().into_vec();
for arg_span in &spans[1..] { for arg_span in &spans[pos..] {
let arg = parse_external_arg(working_set, *arg_span); let arg = parse_external_arg(working_set, *arg_span);
final_args.push(arg); final_args.push(arg);
} }

View file

@ -2,6 +2,7 @@ use nu_test_support::fs::Stub::{FileWithContent, FileWithContentToBeTrimmed};
use nu_test_support::playground::Playground; use nu_test_support::playground::Playground;
use nu_test_support::{nu, nu_repl_code}; use nu_test_support::{nu, nu_repl_code};
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use rstest::rstest;
#[test] #[test]
fn module_private_import_decl() { fn module_private_import_decl() {
@ -612,6 +613,29 @@ fn deep_import_patterns() {
assert_eq!(actual.out, "foo"); assert_eq!(actual.out, "foo");
} }
#[rstest]
fn deep_import_aliased_external_args(
#[values(
"use spam; spam eggs beans foo bar",
"use spam eggs; eggs beans foo bar",
"use spam eggs beans; beans foo bar",
"use spam eggs beans foo; foo bar"
)]
input: &str,
) {
let module_decl = "
module spam {
export module eggs {
export module beans {
export alias foo = ^echo
}
}
}
";
let actual = nu!(format!("{module_decl}; {input}"));
assert_eq!(actual.out, "bar");
}
#[test] #[test]
fn module_dir() { fn module_dir() {
let import = "use samples/spam"; let import = "use samples/spam";