diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 9202045076..e4d3765e17 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -1343,10 +1343,10 @@ pub fn parse_call(working_set: &mut StateWorkingSet, spans: &[Span], head: Span) trace!("parsing: alias of external call"); 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(); - for arg_span in &spans[1..] { + for arg_span in &spans[pos..] { let arg = parse_external_arg(working_set, *arg_span); final_args.push(arg); } diff --git a/tests/modules/mod.rs b/tests/modules/mod.rs index 9aa1282f21..5f73419c01 100644 --- a/tests/modules/mod.rs +++ b/tests/modules/mod.rs @@ -2,6 +2,7 @@ use nu_test_support::fs::Stub::{FileWithContent, FileWithContentToBeTrimmed}; use nu_test_support::playground::Playground; use nu_test_support::{nu, nu_repl_code}; use pretty_assertions::assert_eq; +use rstest::rstest; #[test] fn module_private_import_decl() { @@ -612,6 +613,29 @@ fn deep_import_patterns() { 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] fn module_dir() { let import = "use samples/spam";