fix malformed parse tree for invalid let struct pattern (#7782)

Fixes the malformed parse tree produced for an invalid let struct
pattern containing a single identifier (e.g., `let {s};`).

As pointed out by @DavidLoftus, the parser should produce a parse tree
similar to that of `let {ref s};`, since both are missing a binding
power operator `:`, and both do not have a `.` preceding the identifier
(i.e., `state.in_field_shorthand_pattern == true`).

This means that the parser can produce an the `InvalidParse` node just
as it does for `let {ref s};`.

Closes #7674
This commit is contained in:
simontran7
2026-09-15 23:10:17 +00:00
committed by GitHub
parent 437be71f1f
commit 64ce58dd64
3 changed files with 74 additions and 29 deletions
+4 -3
View File
@@ -47,9 +47,10 @@ auto HandlePattern(Context& context) -> void {
state.binding_context, state.ambient_precedence);
break;
default:
if (context.PositionKind().is_word() &&
context.PositionKind(Lookahead::NextToken)
.is_binding_pattern_operator()) {
if ((context.PositionKind().is_word() &&
context.PositionKind(Lookahead::NextToken)
.is_binding_pattern_operator()) ||
state.in_field_shorthand_pattern) {
context.PushStateForPattern(
StateKind::BindingPattern, state.in_var_pattern,
state.in_unused_pattern, state.in_field_shorthand_pattern,