From 37aec5b19965bedbe67fa1b454be6a7017ccedec Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Thu, 14 Apr 2022 08:50:54 +0800 Subject: [PATCH] refactor(es/parser): Simplify logic (#4329) --- crates/swc_ecma_parser/src/parser/typescript.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/swc_ecma_parser/src/parser/typescript.rs b/crates/swc_ecma_parser/src/parser/typescript.rs index 372f49c73af..d7cd6383a15 100644 --- a/crates/swc_ecma_parser/src/parser/typescript.rs +++ b/crates/swc_ecma_parser/src/parser/typescript.rs @@ -909,7 +909,13 @@ impl Parser { } let check_type = ty; - let extends_type = p.parse_ts_non_conditional_type_within_ctx()?; + let extends_type = { + p.with_ctx(Context { + disallow_conditional_types: true, + ..p.ctx() + }) + .parse_ts_non_conditional_type()? + }; expect!(p, '?'); @@ -929,14 +935,6 @@ impl Parser { }) } - fn parse_ts_non_conditional_type_within_ctx(&mut self) -> PResult> { - self.with_ctx(Context { - disallow_conditional_types: true, - ..self.ctx() - }) - .parse_ts_non_conditional_type() - } - /// `tsParseNonConditionalType` fn parse_ts_non_conditional_type(&mut self) -> PResult> { trace_cur!(self, parse_ts_non_conditional_type);