From 72d8785abeff66f6b832725e71fe65d9ded803ce Mon Sep 17 00:00:00 2001 From: Marmare314 <49279081+Marmare314@users.noreply.github.com> Date: Tue, 11 Apr 2023 18:44:17 +0200 Subject: fix parenthesized binding (#707) --- src/syntax/ast.rs | 9 ++++++++- src/syntax/parser.rs | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 94114958..4119802e 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -1620,7 +1620,14 @@ pub enum DestructuringKind { impl Pattern { /// The kind of the pattern. pub fn kind(&self) -> PatternKind { - if self.0.children().len() <= 1 { + if self + .0 + .children() + .map(SyntaxNode::kind) + .skip_while(|&kind| kind == SyntaxKind::LeftParen) + .take_while(|&kind| kind != SyntaxKind::RightParen) + .eq([SyntaxKind::Ident]) + { return PatternKind::Ident(self.0.cast_first_match().unwrap_or_default()); } diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index 16d519fe..42183f3a 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -847,11 +847,15 @@ fn pattern(p: &mut Parser) -> PatternKind { let m = p.marker(); if p.at(SyntaxKind::LeftParen) { - collection(p, false); + let kind = collection(p, false); validate_destruct_pattern(p, m); p.wrap(m, SyntaxKind::Pattern); - PatternKind::Destructuring + if kind == SyntaxKind::Parenthesized { + PatternKind::Normal + } else { + PatternKind::Destructuring + } } else { if p.expect(SyntaxKind::Ident) { p.wrap(m, SyntaxKind::Pattern); -- cgit v1.2.3