Skip to content

Commit 82f5140

Browse files
bvanjoikdy1
authored andcommitted
refactor(es/parser): Remove unnecessary PResult (#10900)
1 parent a3629c7 commit 82f5140

File tree

3 files changed

+34
-33
lines changed

3 files changed

+34
-33
lines changed

crates/swc_ecma_lexer/src/common/parser/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ pub fn parse_array_lit<'a, P: Parser<'a>>(p: &mut P) -> PResult<Box<Expr>> {
9797
Ok(ArrayLit { span, elems }.into())
9898
}
9999

100-
pub fn at_possible_async<'a, P: Parser<'a>>(p: &P, expr: &Expr) -> PResult<bool> {
100+
pub fn at_possible_async<'a, P: Parser<'a>>(p: &P, expr: &Expr) -> bool {
101101
// TODO(kdy1): !this.state.containsEsc &&
102-
Ok(p.state().potential_arrow_start == Some(expr.span_lo()) && expr.is_ident_ref_to("async"))
102+
p.state().potential_arrow_start == Some(expr.span_lo()) && expr.is_ident_ref_to("async")
103103
}
104104

105105
fn parse_yield_expr<'a, P: Parser<'a>>(p: &mut P) -> PResult<Box<Expr>> {
@@ -622,7 +622,7 @@ fn parse_subscript<'a, P: Parser<'a>>(
622622
Some(Callee::Expr(ref expr)) => expr,
623623
_ => unreachable!(),
624624
},
625-
)?
625+
)
626626
{
627627
// Almost certainly this is a generic async function `async <T>() => ...
628628
// But it might be a call with a type argument `async<T>();`

crates/swc_ecma_lexer/src/common/parser/stmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub fn parse_var_stmt<'a, P: Parser<'a>>(p: &mut P, for_loop: bool) -> PResult<B
214214

215215
if p.syntax().typescript() && for_loop {
216216
let cur = p.input().cur();
217-
let res = if cur.is_in() || cur.is_of() {
217+
let res: PResult<bool> = if cur.is_in() || cur.is_of() {
218218
ts_look_ahead(p, |p| {
219219
//
220220
if !p.input_mut().eat(&P::Token::OF) && !p.input_mut().eat(&P::Token::IN) {

crates/swc_ecma_lexer/src/common/parser/typescript.rs

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ where
6363
{
6464
debug_assert!(p.input().syntax().typescript());
6565
let mut buf = Vec::with_capacity(8);
66-
while !is_ts_list_terminator(p, kind)? {
66+
while !is_ts_list_terminator(p, kind) {
6767
// Skipping "parseListElement" from the TS source since that's just for error
6868
// handling.
6969
buf.push(parse_element(p)?);
@@ -110,7 +110,7 @@ where
110110
loop {
111111
trace_cur!(p, parse_ts_delimited_list_inner__element);
112112

113-
if is_ts_list_terminator(p, kind)? {
113+
if is_ts_list_terminator(p, kind) {
114114
break;
115115
}
116116

@@ -121,7 +121,7 @@ where
121121
continue;
122122
}
123123

124-
if is_ts_list_terminator(p, kind)? {
124+
if is_ts_list_terminator(p, kind) {
125125
break;
126126
}
127127

@@ -159,21 +159,21 @@ where
159159
}
160160

161161
/// `tsIsListTerminator`
162-
fn is_ts_list_terminator<'a>(p: &mut impl Parser<'a>, kind: ParsingContext) -> PResult<bool> {
162+
fn is_ts_list_terminator<'a>(p: &mut impl Parser<'a>, kind: ParsingContext) -> bool {
163163
debug_assert!(p.input().syntax().typescript());
164164
let cur = p.input().cur();
165-
Ok(match kind {
165+
match kind {
166166
ParsingContext::EnumMembers | ParsingContext::TypeMembers => cur.is_rbrace(),
167167
ParsingContext::HeritageClauseElement => {
168168
cur.is_lbrace() || cur.is_implements() || cur.is_extends()
169169
}
170170
ParsingContext::TupleElementTypes => cur.is_rbracket(),
171171
ParsingContext::TypeParametersOrArguments => cur.is_greater(),
172-
})
172+
}
173173
}
174174

175175
/// `tsNextTokenCanFollowModifier`
176-
pub(super) fn ts_next_token_can_follow_modifier<'a>(p: &mut impl Parser<'a>) -> PResult<bool> {
176+
pub(super) fn ts_next_token_can_follow_modifier<'a>(p: &mut impl Parser<'a>) -> bool {
177177
debug_assert!(p.input().syntax().typescript());
178178
// Note: TypeScript's implementation is much more complicated because
179179
// more things are considered modifiers there.
@@ -183,15 +183,15 @@ pub(super) fn ts_next_token_can_follow_modifier<'a>(p: &mut impl Parser<'a>) ->
183183
p.bump();
184184

185185
let cur = p.input().cur();
186-
Ok(!p.input().had_line_break_before_cur() && cur.is_lbracket()
186+
!p.input().had_line_break_before_cur() && cur.is_lbracket()
187187
|| cur.is_lbrace()
188188
|| cur.is_star()
189189
|| cur.is_dotdotdot()
190190
|| cur.is_hash()
191191
|| cur.is_word()
192192
|| cur.is_str()
193193
|| cur.is_num()
194-
|| cur.is_bigint())
194+
|| cur.is_bigint()
195195
}
196196

197197
/// `tsTryParse`
@@ -242,12 +242,12 @@ fn parse_ts_type_member_semicolon<'a, P: Parser<'a>>(p: &mut P) -> PResult<()> {
242242
}
243243

244244
/// `tsIsStartOfConstructSignature`
245-
fn is_ts_start_of_construct_signature<'a, P: Parser<'a>>(p: &mut P) -> PResult<bool> {
245+
fn is_ts_start_of_construct_signature<'a, P: Parser<'a>>(p: &mut P) -> bool {
246246
debug_assert!(p.input().syntax().typescript());
247247

248248
p.bump();
249249
let cur = p.input().cur();
250-
Ok(cur.is_lparen() || cur.is_less())
250+
cur.is_lparen() || cur.is_less()
251251
}
252252

253253
/// `tsParseDelimitedList`
@@ -370,7 +370,7 @@ pub fn parse_ts_modifier<'a, P: Parser<'a>>(
370370
{
371371
return Ok(None);
372372
}
373-
if try_parse_ts_bool(p, |p| ts_next_token_can_follow_modifier(p).map(Some))? {
373+
if try_parse_ts_bool(p, |p| Ok(Some(ts_next_token_can_follow_modifier(p))))? {
374374
return Ok(Some(allowed_modifiers[pos]));
375375
}
376376
}
@@ -450,9 +450,9 @@ pub fn parse_ts_entity_name<'a, P: Parser<'a>>(
450450
Ok(entity)
451451
}
452452

453-
pub fn ts_look_ahead<'a, P: Parser<'a>, T, F>(p: &mut P, op: F) -> PResult<T>
453+
pub fn ts_look_ahead<'a, P: Parser<'a>, T, F>(p: &mut P, op: F) -> T
454454
where
455-
F: FnOnce(&mut P) -> PResult<T>,
455+
F: FnOnce(&mut P) -> T,
456456
{
457457
debug_assert!(p.input().syntax().typescript());
458458
let mut cloned = p.clone();
@@ -1211,28 +1211,29 @@ fn is_ts_unambiguously_start_of_fn_type<'a, P: Parser<'a>>(p: &mut P) -> PResult
12111211
Ok(false)
12121212
}
12131213

1214-
fn is_ts_start_of_fn_type<'a, P: Parser<'a>>(p: &mut P) -> PResult<bool> {
1214+
fn is_ts_start_of_fn_type<'a, P: Parser<'a>>(p: &mut P) -> bool {
12151215
debug_assert!(p.input().syntax().typescript());
12161216

12171217
if p.input().cur().is_less() {
1218-
return Ok(true);
1218+
return true;
12191219
}
12201220

1221-
Ok(p.input().cur().is_lparen() && ts_look_ahead(p, is_ts_unambiguously_start_of_fn_type)?)
1221+
p.input().cur().is_lparen()
1222+
&& ts_look_ahead(p, is_ts_unambiguously_start_of_fn_type).unwrap_or_default()
12221223
}
12231224

12241225
/// `tsIsUnambiguouslyIndexSignature`
1225-
fn is_ts_unambiguously_index_signature<'a, P: Parser<'a>>(p: &mut P) -> PResult<bool> {
1226+
fn is_ts_unambiguously_index_signature<'a, P: Parser<'a>>(p: &mut P) -> bool {
12261227
debug_assert!(p.input().syntax().typescript());
12271228

12281229
// Note: babel's comment is wrong
12291230
p.assert_and_bump(&P::Token::LBRACKET); // Skip '['
12301231

12311232
// ',' is for error recovery
1232-
Ok(p.eat_ident_ref() && {
1233+
p.eat_ident_ref() && {
12331234
let cur = p.input().cur();
12341235
cur.is_comma() || cur.is_colon()
1235-
})
1236+
}
12361237
}
12371238

12381239
/// `tsTryParseIndexSignature`
@@ -1246,7 +1247,7 @@ pub fn try_parse_ts_index_signature<'a, P: Parser<'a>>(
12461247
return Ok(Default::default());
12471248
}
12481249

1249-
if !(p.input().cur().is_lbracket() && ts_look_ahead(p, is_ts_unambiguously_index_signature)?) {
1250+
if !(p.input().cur().is_lbracket() && ts_look_ahead(p, is_ts_unambiguously_index_signature)) {
12501251
return Ok(None);
12511252
}
12521253

@@ -1378,26 +1379,26 @@ fn parse_ts_binding_list_for_signature<'a, P: Parser<'a>>(p: &mut P) -> PResult<
13781379
}
13791380

13801381
/// `tsIsStartOfMappedType`
1381-
pub fn is_ts_start_of_mapped_type<'a, P: Parser<'a>>(p: &mut P) -> PResult<bool> {
1382+
pub fn is_ts_start_of_mapped_type<'a, P: Parser<'a>>(p: &mut P) -> bool {
13821383
debug_assert!(p.input().syntax().typescript());
13831384

13841385
p.bump();
13851386
if p.input_mut().eat(&P::Token::PLUS) || p.input_mut().eat(&P::Token::MINUS) {
1386-
return Ok(p.input().is(&P::Token::READONLY));
1387+
return p.input().is(&P::Token::READONLY);
13871388
}
13881389

13891390
p.input_mut().eat(&P::Token::READONLY);
13901391

13911392
if !p.input().is(&P::Token::LBRACKET) {
1392-
return Ok(false);
1393+
return false;
13931394
}
13941395
p.bump();
13951396
if !p.is_ident_ref() {
1396-
return Ok(false);
1397+
return false;
13971398
}
13981399
p.bump();
13991400

1400-
Ok(p.input().is(&P::Token::IN))
1401+
p.input().is(&P::Token::IN)
14011402
}
14021403

14031404
/// `tsParseSignatureMember`
@@ -1814,7 +1815,7 @@ fn parse_ts_non_conditional_type<'a, P: Parser<'a>>(p: &mut P) -> PResult<Box<Ts
18141815

18151816
debug_assert!(p.input().syntax().typescript());
18161817

1817-
if is_ts_start_of_fn_type(p)? {
1818+
if is_ts_start_of_fn_type(p) {
18181819
return parse_ts_fn_or_constructor_type(p, true)
18191820
.map(TsType::from)
18201821
.map(Box::new);
@@ -2010,7 +2011,7 @@ fn parse_ts_type_member<'a, P: Parser<'a>>(p: &mut P) -> PResult<TsTypeElement>
20102011
return parse_ts_signature_member(p, SignatureParsingMode::TSCallSignatureDeclaration)
20112012
.map(into_type_elem);
20122013
}
2013-
if p.input().is(&P::Token::NEW) && ts_look_ahead(p, is_ts_start_of_construct_signature)? {
2014+
if p.input().is(&P::Token::NEW) && ts_look_ahead(p, is_ts_start_of_construct_signature) {
20142015
return parse_ts_signature_member(p, SignatureParsingMode::TSConstructSignatureDeclaration)
20152016
.map(into_type_elem);
20162017
}
@@ -2529,7 +2530,7 @@ fn parse_ts_non_array_type<'a, P: Parser<'a>>(p: &mut P) -> PResult<Box<TsType>>
25292530
} else if cur.is_typeof() {
25302531
return parse_ts_type_query(p).map(TsType::from).map(Box::new);
25312532
} else if cur.is_lbrace() {
2532-
return if ts_look_ahead(p, is_ts_start_of_mapped_type)? {
2533+
return if ts_look_ahead(p, is_ts_start_of_mapped_type) {
25332534
parse_ts_mapped_type(p).map(TsType::from).map(Box::new)
25342535
} else {
25352536
parse_ts_type_lit(p).map(TsType::from).map(Box::new)

0 commit comments

Comments
 (0)