From cc0259bbed9f141922b4c6f84bdc603f7e7c647c Mon Sep 17 00:00:00 2001 From: Solomon Date: Wed, 6 Nov 2024 06:40:29 -0700 Subject: [PATCH] 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 ``` --- crates/nu-parser/src/parser.rs | 4 ++-- tests/modules/mod.rs | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) 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";