From 32028eb1c57f3fb1c143f94890c9ecf803d4df71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Sun, 3 Mar 2024 07:25:55 +0100 Subject: [PATCH] fix(parser): TSConditionalType span start (#2570) Span start should be the checkType.start (as all my PR, I try to make it work, don't hesitate to close and to it in a better way) [playground](https://oxc-project.github.io/oxc/playground/?code=3YCAAIDFgICAgICAgIC6nsrEgtelB%2FCnUFVHa8WBImPvKP4Ye3U5jBKASUfm8OtkXZASTLptdPlvM%2Fult4BgRbjIq3Yts9L2pZ%2FhVs8hMF%2Bwpqd%2FfdHggA%3D%3D) --- crates/oxc_parser/src/ts/types.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/oxc_parser/src/ts/types.rs b/crates/oxc_parser/src/ts/types.rs index 484cfa329..ad2bfd6fc 100644 --- a/crates/oxc_parser/src/ts/types.rs +++ b/crates/oxc_parser/src/ts/types.rs @@ -2,6 +2,7 @@ use bitflags::bitflags; use oxc_allocator::{Box, Vec}; use oxc_ast::ast::*; use oxc_diagnostics::Result; +use oxc_span::Span; use oxc_syntax::operator::UnaryOperator; use super::list::{ @@ -116,9 +117,10 @@ impl<'a> ParserImpl<'a> { return self.parse_ts_function_type(); } + let left_span = self.start_span(); let left = self.parse_ts_union_type()?; - self.parse_ts_conditional_type(left) + self.parse_ts_conditional_type(left_span, left) } pub(crate) fn parse_ts_type_parameters( @@ -209,8 +211,11 @@ impl<'a> ParserImpl<'a> { Ok(Some(self.parse_ts_type()?)) } - fn parse_ts_conditional_type(&mut self, left: TSType<'a>) -> Result> { - let span = self.start_span(); + fn parse_ts_conditional_type( + &mut self, + left_span: Span, + left: TSType<'a>, + ) -> Result> { if !self.ctx.has_disallow_conditional_types() && !self.cur_token().is_on_new_line && self.eat(Kind::Extends) @@ -229,7 +234,7 @@ impl<'a> ParserImpl<'a> { self.without_context(Context::DisallowConditionalTypes, Self::parse_ts_type)?; return Ok(self.ast.ts_conditional_type( - self.end_span(span), + self.end_span(left_span), left, extends_type, true_type,