mirror of
https://github.com/casey/just.git
synced 2024-11-22 02:09:44 +03:00
Don't export constants (#2449)
This commit is contained in:
parent
8cdff483bf
commit
67034cb8b4
@ -3,6 +3,8 @@ use super::*;
|
||||
/// A binding of `name` to `value`
|
||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
pub(crate) struct Binding<'src, V = String> {
|
||||
#[serde(skip)]
|
||||
pub(crate) constant: bool,
|
||||
pub(crate) export: bool,
|
||||
#[serde(skip)]
|
||||
pub(crate) file_depth: u32,
|
||||
|
@ -39,7 +39,7 @@ impl CommandExt for Command {
|
||||
}
|
||||
|
||||
for binding in scope.bindings() {
|
||||
if settings.export || binding.export {
|
||||
if binding.export || (settings.export && !binding.constant) {
|
||||
self.env(binding.name.lexeme(), &binding.value);
|
||||
}
|
||||
}
|
||||
|
@ -32,12 +32,14 @@ impl<'src, 'run> Evaluator<'src, 'run> {
|
||||
|
||||
for (name, value) in overrides {
|
||||
if let Some(assignment) = module.assignments.get(name) {
|
||||
scope.bind(
|
||||
assignment.export,
|
||||
assignment.name,
|
||||
assignment.private,
|
||||
value.clone(),
|
||||
);
|
||||
scope.bind(Binding {
|
||||
constant: false,
|
||||
export: assignment.export,
|
||||
file_depth: 0,
|
||||
name: assignment.name,
|
||||
private: assignment.private,
|
||||
value: value.clone(),
|
||||
});
|
||||
} else {
|
||||
unknown_overrides.push(name.clone());
|
||||
}
|
||||
@ -68,12 +70,14 @@ impl<'src, 'run> Evaluator<'src, 'run> {
|
||||
|
||||
if !self.scope.bound(name) {
|
||||
let value = self.evaluate_expression(&assignment.value)?;
|
||||
self.scope.bind(
|
||||
assignment.export,
|
||||
assignment.name,
|
||||
assignment.private,
|
||||
self.scope.bind(Binding {
|
||||
constant: false,
|
||||
export: assignment.export,
|
||||
file_depth: 0,
|
||||
name: assignment.name,
|
||||
private: assignment.private,
|
||||
value,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Ok(self.scope.value(name).unwrap())
|
||||
@ -340,9 +344,14 @@ impl<'src, 'run> Evaluator<'src, 'run> {
|
||||
rest = &rest[1..];
|
||||
value
|
||||
};
|
||||
evaluator
|
||||
.scope
|
||||
.bind(parameter.export, parameter.name, false, value);
|
||||
evaluator.scope.bind(Binding {
|
||||
constant: false,
|
||||
export: parameter.export,
|
||||
file_depth: 0,
|
||||
name: parameter.name,
|
||||
private: false,
|
||||
value,
|
||||
});
|
||||
}
|
||||
|
||||
Ok((evaluator.scope, positional))
|
||||
|
@ -500,11 +500,12 @@ impl<'run, 'src> Parser<'run, 'src> {
|
||||
}
|
||||
|
||||
Ok(Assignment {
|
||||
file_depth: self.file_depth,
|
||||
constant: false,
|
||||
export,
|
||||
file_depth: self.file_depth,
|
||||
name,
|
||||
value,
|
||||
private: private || name.lexeme().starts_with('_'),
|
||||
value,
|
||||
})
|
||||
}
|
||||
|
||||
|
24
src/scope.rs
24
src/scope.rs
@ -21,9 +21,11 @@ impl<'src, 'run> Scope<'src, 'run> {
|
||||
};
|
||||
|
||||
for (key, value) in constants() {
|
||||
root.bind(
|
||||
false,
|
||||
Name {
|
||||
root.bind(Binding {
|
||||
constant: true,
|
||||
export: false,
|
||||
file_depth: 0,
|
||||
name: Name {
|
||||
token: Token {
|
||||
column: 0,
|
||||
kind: TokenKind::Identifier,
|
||||
@ -34,22 +36,16 @@ impl<'src, 'run> Scope<'src, 'run> {
|
||||
src: key,
|
||||
},
|
||||
},
|
||||
false,
|
||||
(*value).into(),
|
||||
);
|
||||
private: false,
|
||||
value: (*value).into(),
|
||||
});
|
||||
}
|
||||
|
||||
root
|
||||
}
|
||||
|
||||
pub(crate) fn bind(&mut self, export: bool, name: Name<'src>, private: bool, value: String) {
|
||||
self.bindings.insert(Binding {
|
||||
export,
|
||||
file_depth: 0,
|
||||
name,
|
||||
private,
|
||||
value,
|
||||
});
|
||||
pub(crate) fn bind(&mut self, binding: Binding<'src>) {
|
||||
self.bindings.insert(binding);
|
||||
}
|
||||
|
||||
pub(crate) fn bound(&self, name: &str) -> bool {
|
||||
|
@ -43,3 +43,19 @@ fn constants_can_be_redefined() {
|
||||
.stdout("foo")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn constants_are_not_exported() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
set export
|
||||
|
||||
foo:
|
||||
echo $HEXUPPER
|
||||
",
|
||||
)
|
||||
.stderr_regex(".*HEXUPPER: unbound variable.*")
|
||||
.status(127)
|
||||
.run();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user