1
1
mirror of https://github.com/casey/just.git synced 2024-11-22 02:09:44 +03:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Greg Shuflin
ab3fcc41cf
Merge branch 'master' into attributeset 2024-11-03 20:26:47 -08:00
Casey Rodarmor
67034cb8b4
Don't export constants (#2449) 2024-11-02 18:11:24 +00:00
6 changed files with 55 additions and 31 deletions

View File

@ -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,

View File

@ -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);
}
}

View File

@ -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))

View File

@ -491,11 +491,12 @@ impl<'run, 'src> Parser<'run, 'src> {
attributes.ensure_valid_attributes("Assignment", *name, &[AttributeDiscriminant::Private])?;
Ok(Assignment {
file_depth: self.file_depth,
constant: false,
export,
file_depth: self.file_depth,
name,
value,
private: private || name.lexeme().starts_with('_'),
value,
})
}

View File

@ -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 {

View File

@ -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();
}