Alias to keywords (eg source) (#4835)

* Allow aliasing source

* Add test
This commit is contained in:
JT 2022-03-13 11:30:37 -07:00 committed by GitHub
parent ff3dffd813
commit c023d4111a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 4 deletions

View File

@ -0,0 +1,13 @@
use nu_test_support::{nu, pipeline};
#[test]
fn echo_range_is_lazy() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
alias bar = source sample_def.nu; bar; greet
"#
));
assert_eq!(actual.out, "hello");
}

View File

@ -1,3 +1,4 @@
mod alias;
mod all; mod all;
mod any; mod any;
mod append; mod append;

View File

@ -897,10 +897,19 @@ pub fn parse_call(
new_spans.extend(&spans[(pos + 1)..]); new_spans.extend(&spans[(pos + 1)..]);
} }
working_set.enter_scope(); let alias_id = working_set.hide_alias(&name);
working_set.hide_alias(&name); let lite_command = LiteCommand {
let (mut result, err) = parse_expression(working_set, &new_spans, false); comments: vec![],
working_set.exit_scope(); parts: new_spans.clone(),
};
let (mut result, err) = parse_builtin_commands(working_set, &lite_command);
if let Some(frame) = working_set.delta.scope.last_mut() {
if let Some(alias_id) = alias_id {
frame.aliases.insert(name.clone(), alias_id);
}
}
let mut result = result.expressions.remove(0);
result.replace_span(working_set, expansion_span, orig_span); result.replace_span(working_set, expansion_span, orig_span);

3
tests/fixtures/formats/sample_def.nu vendored Normal file
View File

@ -0,0 +1,3 @@
def greet [] {
"hello"
}