Skip to content

Commit d1f1055

Browse files
sgvictorinoNotTheDr01ds
authored andcommitted
don't include import path in args to aliased external commands (nushell#14231)
Fixes nushell#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 ```
1 parent 4769257 commit d1f1055

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

crates/nu-parser/src/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,10 +1343,10 @@ pub fn parse_call(working_set: &mut StateWorkingSet, spans: &[Span], head: Span)
13431343
trace!("parsing: alias of external call");
13441344

13451345
let mut head = head.clone();
1346-
head.span = spans[0]; // replacing the spans preserves syntax highlighting
1346+
head.span = Span::concat(&spans[cmd_start..pos]); // replacing the spans preserves syntax highlighting
13471347

13481348
let mut final_args = args.clone().into_vec();
1349-
for arg_span in &spans[1..] {
1349+
for arg_span in &spans[pos..] {
13501350
let arg = parse_external_arg(working_set, *arg_span);
13511351
final_args.push(arg);
13521352
}

tests/modules/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use nu_test_support::fs::Stub::{FileWithContent, FileWithContentToBeTrimmed};
22
use nu_test_support::playground::Playground;
33
use nu_test_support::{nu, nu_repl_code};
44
use pretty_assertions::assert_eq;
5+
use rstest::rstest;
56

67
#[test]
78
fn module_private_import_decl() {
@@ -612,6 +613,29 @@ fn deep_import_patterns() {
612613
assert_eq!(actual.out, "foo");
613614
}
614615

616+
#[rstest]
617+
fn deep_import_aliased_external_args(
618+
#[values(
619+
"use spam; spam eggs beans foo bar",
620+
"use spam eggs; eggs beans foo bar",
621+
"use spam eggs beans; beans foo bar",
622+
"use spam eggs beans foo; foo bar"
623+
)]
624+
input: &str,
625+
) {
626+
let module_decl = "
627+
module spam {
628+
export module eggs {
629+
export module beans {
630+
export alias foo = ^echo
631+
}
632+
}
633+
}
634+
";
635+
let actual = nu!(format!("{module_decl}; {input}"));
636+
assert_eq!(actual.out, "bar");
637+
}
638+
615639
#[test]
616640
fn module_dir() {
617641
let import = "use samples/spam";

0 commit comments

Comments
 (0)