Skip to content

Commit 5d43533

Browse files
authored
perf(es/parser): Remove duplicate check (#10874)
1 parent 5107ba8 commit 5d43533

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,17 @@ pub fn parse_opt_binding_ident<'a>(
127127
) -> PResult<Option<BindingIdent>> {
128128
trace_cur!(p, parse_opt_binding_ident);
129129
let ctx = p.ctx();
130-
let Some(cur) = p.input_mut().cur() else {
130+
p.input_mut().cur();
131+
let Some(token_and_span) = p.input().get_cur() else {
131132
return Ok(None);
132133
};
133-
let is_binding_ident = cur.is_word() && !cur.is_reserved(ctx);
134-
if is_binding_ident || (cur.is_this() && p.input().syntax().typescript()) {
134+
let cur = token_and_span.token();
135+
if cur.is_this() && p.input().syntax().typescript() {
136+
let start = token_and_span.span().lo;
137+
Ok(Some(
138+
Ident::new_no_ctxt(atom!("this"), p.span(start)).into(),
139+
))
140+
} else if cur.is_word() && !cur.is_reserved(ctx) {
135141
parse_binding_ident(p, disallow_let).map(Some)
136142
} else {
137143
Ok(None)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ pub fn parse_binding_pat_or_ident<'a, P: Parser<'a>>(
395395
let Some(cur) = p.input_mut().cur() else {
396396
return Err(eof_error(p));
397397
};
398-
if cur.is_yield() || cur.is_word() {
398+
if cur.is_word() {
399399
parse_binding_ident(p, disallow_let).map(Pat::from)
400400
} else if cur.is_lbracket() {
401401
parse_array_binding_pat(p)

0 commit comments

Comments
 (0)