From dd9792571b2b99bc861c21a7d0706a83e5652a44 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 12:39:34 -0700 Subject: [PATCH] Fix unexport syntax conflicts (#2158) --- src/parser.rs | 6 +++++- tests/unexport.rs | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 3e4bb02..9ea372c 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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) diff --git a/tests/unexport.rs b/tests/unexport.rs index 9ca93e8..af46ea1 100644 --- a/tests/unexport.rs +++ b/tests/unexport.rs @@ -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(); }