Skip to content

Commit d6db243

Browse files
committed
free parse_this_expr
1 parent 5cd5185 commit d6db243

File tree

2 files changed

+6
-5
lines changed
  • crates
    • swc_ecma_lexer/src/common/parser
    • swc_ecma_parser/src/parser

2 files changed

+6
-5
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,13 +2548,12 @@ pub fn try_parse_async_start<'a, P: Parser<'a>>(
25482548
None
25492549
}
25502550

2551-
pub fn parse_this_expr<'a>(p: &mut impl Parser<'a>, start: BytePos) -> PResult<Box<Expr>> {
2551+
pub fn parse_this_expr<'a>(p: &mut impl Parser<'a>, start: BytePos) -> PResult<ThisExpr> {
25522552
debug_assert!(p.input_mut().cur().is_some_and(|t| t.is_this()));
25532553
p.input_mut().bump();
25542554
Ok(ThisExpr {
25552555
span: p.span(start),
2556-
}
2557-
.into())
2556+
})
25582557
}
25592558

25602559
/// Parse a primary expression or arrow function
@@ -2576,7 +2575,7 @@ pub(crate) fn parse_primary_expr<'a, P: Parser<'a>>(p: &mut P) -> PResult<Box<Ex
25762575

25772576
if let Some(token) = p.input_mut().cur() {
25782577
if token.is_this() {
2579-
return parse_this_expr(p, start);
2578+
return parse_this_expr(p, start).map(|expr| Box::new(Expr::This(expr)));
25802579
} else if token.is_async() {
25812580
if let Some(res) = try_parse_async_start(p, can_be_arrow) {
25822581
return res;

crates/swc_ecma_parser/src/parser/expr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ impl<I: Tokens> Parser<I> {
192192
.unwrap_or(false);
193193
if let Some(tok) = self.input.cur() {
194194
match *tok {
195-
Token::This => return parse_this_expr(self, start),
195+
Token::This => {
196+
return parse_this_expr(self, start).map(|expr| Box::new(Expr::This(expr)))
197+
}
196198
Token::Async => {
197199
if let Some(res) = try_parse_async_start(self, can_be_arrow) {
198200
return res;

0 commit comments

Comments
 (0)