Skip to content

Commit e44fbd4

Browse files
authored
perf(es/parser): Reduce comparison (#10933)
1 parent 677d82b commit e44fbd4

File tree

4 files changed

+7
-17
lines changed

4 files changed

+7
-17
lines changed

.changeset/nice-chairs-yawn.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
swc_ecma_lexer: patch
3+
swc_ecma_parser: patch
4+
swc_core: patch
5+
---
6+
7+
pref(es/parser): less cmp

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ fn parse_yield_expr<'a, P: Parser<'a>>(p: &mut P) -> PResult<Box<Expr>> {
138138

139139
if p.is_general_semi() || {
140140
let cur = p.input().cur();
141-
if cur.is_eof() {
142-
return parse_with_arg(p);
143-
}
144141
!cur.is_less()
145142
&& !cur.is_star()
146143
&& !cur.is_slash()
@@ -417,8 +414,6 @@ fn parse_assignment_expr_base<'a, P: Parser<'a>>(p: &mut P) -> PResult<Box<Expr>
417414
if cur.is_error() {
418415
let err = p.input_mut().expect_error_token_and_bump();
419416
return Err(err);
420-
} else if cur.is_eof() {
421-
return Err(eof_error(p));
422417
}
423418

424419
p.state_mut().potential_arrow_start =
@@ -1553,8 +1548,6 @@ pub(crate) fn parse_unary_expr<'a, P: Parser<'a>>(p: &mut P) -> PResult<Box<Expr
15531548
.into());
15541549
} else if cur.is_await() {
15551550
return parse_await_expr(p, None);
1556-
} else if cur.is_eof() {
1557-
syntax_error!(p, p.input().cur_span(), SyntaxError::TS1109);
15581551
}
15591552

15601553
// UpdateExpression
@@ -1673,8 +1666,6 @@ pub fn parse_lhs_expr<'a, P: Parser<'a>, const PARSE_JSX: bool>(p: &mut P) -> PR
16731666
} else if cur.is_error() {
16741667
let err = p.input_mut().expect_error_token_and_bump();
16751668
return Err(err);
1676-
} else if cur.is_eof() {
1677-
return Err(eof_error(p));
16781669
}
16791670

16801671
if p.input().is(&P::Token::LESS) && !peek!(p).is_some_and(|peek| peek.is_bang()) {
@@ -1702,8 +1693,6 @@ pub fn parse_lhs_expr<'a, P: Parser<'a>, const PARSE_JSX: bool>(p: &mut P) -> PR
17021693
} else if cur.is_import() {
17031694
p.bump(); // eat `import`
17041695
return parse_dynamic_import_or_import_meta(p, start, false);
1705-
} else if cur.is_eof() {
1706-
return Err(eof_error(p));
17071696
}
17081697

17091698
let callee = parse_new_expr(p)?;

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -976,8 +976,6 @@ fn parse_ts_enum_member<'a, P: Parser<'a>>(p: &mut P) -> PResult<TsEnumMember> {
976976
} else if cur.is_error() {
977977
let err = p.input_mut().expect_error_token_and_bump();
978978
return Err(err);
979-
} else if cur.is_eof() {
980-
return Err(eof_error(p));
981979
} else {
982980
parse_ident_name(p)
983981
.map(Ident::from)
@@ -1924,8 +1922,6 @@ fn parse_ts_property_name<'a, P: Parser<'a>>(p: &mut P) -> PResult<(bool, Box<Ex
19241922
} else if cur.is_error() {
19251923
let err = p.input_mut().expect_error_token_and_bump();
19261924
return Err(err);
1927-
} else if cur.is_eof() {
1928-
return Err(eof_error(p));
19291925
} else {
19301926
parse_maybe_private_name(p).map(|e| match e {
19311927
Either::Left(e) => {

crates/swc_ecma_parser/src/parser/expr.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ impl<I: Tokens> Parser<I> {
140140
.into());
141141
} else if cur == Token::Await {
142142
return parse_await_expr(self, None);
143-
} else if cur == Token::Eof {
144-
syntax_error!(self, self.input().cur_span(), SyntaxError::TS1109);
145143
}
146144

147145
// UpdateExpression

0 commit comments

Comments
 (0)