Skip to content

Commit 87cc059

Browse files
committed
fix(parser): fix end span for optional binding pattern without type annotation
1 parent c43fbdd commit 87cc059

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ target/
2222
/editors/vscode/out/
2323
/editors/vscode/*.vsix
2424

25+
# Jetbrains
26+
/.idea/
27+
2528
# Cloned conformance repos
2629
tasks/coverage/babel/
2730
tasks/coverage/test262/

crates/oxc_parser/src/js/binding.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@ impl<'a> ParserImpl<'a> {
1919
allow_question: bool,
2020
) -> Result<BindingPattern<'a>> {
2121
let mut kind = self.parse_binding_pattern_kind()?;
22-
let optional = if allow_question && self.is_ts { self.eat(Kind::Question) } else { false };
22+
let optional = if allow_question && self.is_ts {
23+
let span = self.start_span();
24+
if self.eat(Kind::Question) { Some(self.end_span(span)) } else { None }
25+
} else {
26+
None
27+
};
2328
let type_annotation = self.parse_ts_type_annotation()?;
2429
if let Some(type_annotation) = &type_annotation {
2530
Self::extend_binding_pattern_span_end(type_annotation.span, &mut kind);
31+
} else if let Some(span) = optional {
32+
Self::extend_binding_pattern_span_end(span, &mut kind);
2633
}
27-
Ok(self.ast.binding_pattern(kind, type_annotation, optional))
34+
Ok(self.ast.binding_pattern(kind, type_annotation, optional.is_some()))
2835
}
2936

3037
pub(crate) fn parse_binding_pattern_kind(&mut self) -> Result<BindingPatternKind<'a>> {

0 commit comments

Comments
 (0)