mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 12:51:57 +00:00
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)
This commit is contained in:
parent
2263377e3f
commit
32028eb1c5
1 changed files with 9 additions and 4 deletions
|
|
@ -2,6 +2,7 @@ use bitflags::bitflags;
|
||||||
use oxc_allocator::{Box, Vec};
|
use oxc_allocator::{Box, Vec};
|
||||||
use oxc_ast::ast::*;
|
use oxc_ast::ast::*;
|
||||||
use oxc_diagnostics::Result;
|
use oxc_diagnostics::Result;
|
||||||
|
use oxc_span::Span;
|
||||||
use oxc_syntax::operator::UnaryOperator;
|
use oxc_syntax::operator::UnaryOperator;
|
||||||
|
|
||||||
use super::list::{
|
use super::list::{
|
||||||
|
|
@ -116,9 +117,10 @@ impl<'a> ParserImpl<'a> {
|
||||||
return self.parse_ts_function_type();
|
return self.parse_ts_function_type();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let left_span = self.start_span();
|
||||||
let left = self.parse_ts_union_type()?;
|
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(
|
pub(crate) fn parse_ts_type_parameters(
|
||||||
|
|
@ -209,8 +211,11 @@ impl<'a> ParserImpl<'a> {
|
||||||
Ok(Some(self.parse_ts_type()?))
|
Ok(Some(self.parse_ts_type()?))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_ts_conditional_type(&mut self, left: TSType<'a>) -> Result<TSType<'a>> {
|
fn parse_ts_conditional_type(
|
||||||
let span = self.start_span();
|
&mut self,
|
||||||
|
left_span: Span,
|
||||||
|
left: TSType<'a>,
|
||||||
|
) -> Result<TSType<'a>> {
|
||||||
if !self.ctx.has_disallow_conditional_types()
|
if !self.ctx.has_disallow_conditional_types()
|
||||||
&& !self.cur_token().is_on_new_line
|
&& !self.cur_token().is_on_new_line
|
||||||
&& self.eat(Kind::Extends)
|
&& self.eat(Kind::Extends)
|
||||||
|
|
@ -229,7 +234,7 @@ impl<'a> ParserImpl<'a> {
|
||||||
self.without_context(Context::DisallowConditionalTypes, Self::parse_ts_type)?;
|
self.without_context(Context::DisallowConditionalTypes, Self::parse_ts_type)?;
|
||||||
|
|
||||||
return Ok(self.ast.ts_conditional_type(
|
return Ok(self.ast.ts_conditional_type(
|
||||||
self.end_span(span),
|
self.end_span(left_span),
|
||||||
left,
|
left,
|
||||||
extends_type,
|
extends_type,
|
||||||
true_type,
|
true_type,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue