From eb9561878b2f272e5f7e70cfa596a490aa0a30d9 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Tue, 3 Dec 2024 12:57:04 +0100 Subject: [PATCH] Support asserts syntax without predicate FIX: Allow TypeScript syntax, where the condition is just a variable. Issue https://github.com/lezer-parser/javascript/issues/41 --- src/javascript.grammar | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/javascript.grammar b/src/javascript.grammar index a1105ad..b4e5423 100644 --- a/src/javascript.grammar +++ b/src/javascript.grammar @@ -246,7 +246,12 @@ patternAssign { TypeAnnotation { ":" type } -TypePredicate { ":" tskw<"asserts">? (VariableName | kw<"this">) !predicate tskw<"is"> type } +TypePredicate { + ":" ( + tskw<"asserts">? (VariableName | kw<"this">) (tskw<"is"> type)? | + (VariableName | kw<"this">) !predicate tskw<"is"> type + ) +} patternAssignTyped { pattern Optional? TypeAnnotation? ("=" expressionNoComma)?