Skip to content

Commit

Permalink
Fix unexport syntax conflicts (#2158)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jun 14, 2024
1 parent e6c37aa commit dd97925
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,13 @@ impl<'run, 'src> Parser<'run, 'src> {
self.presume_keyword(Keyword::Export)?;
items.push(Item::Assignment(self.parse_assignment(true)?));
}
Some(Keyword::Unexport) => {
Some(Keyword::Unexport)
if self.next_are(&[Identifier, Identifier, Eof])
|| self.next_are(&[Identifier, Identifier, Eol]) =>
{
self.presume_keyword(Keyword::Unexport)?;
let name = self.parse_name()?;
self.expect_eol()?;
items.push(Item::Unexport { name });
}
Some(Keyword::Import)
Expand Down
24 changes: 23 additions & 1 deletion tests/unexport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ fn unexport_doesnt_override_local_recipe_export() {
)
.args(["recipe", "value"])
.stdout("variable: value\n")
.status(0)
.run();
}

#[test]
fn unexport_does_not_conflict_with_recipe_syntax() {
Test::new()
.justfile(
"
unexport foo:
@echo {{foo}}
",
)
.args(["unexport", "bar"])
.stdout("bar\n")
.run();
}

#[test]
fn unexport_does_not_conflict_with_assignment_syntax() {
Test::new()
.justfile("unexport := 'foo'")
.args(["--evaluate", "unexport"])
.stdout("foo")
.run();
}

0 comments on commit dd97925

Please sign in to comment.