Skip to content

Commit

Permalink
fix(parser): fix false positive parsing optional member expr
Browse files Browse the repository at this point in the history
  • Loading branch information
camc314 committed Mar 4, 2025
1 parent 2326cef commit b38b20b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
12 changes: 9 additions & 3 deletions crates/oxc_parser/src/js/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,10 +711,16 @@ impl<'a> ParserImpl<'a> {
kind if kind.is_identifier_name() => {
self.parse_static_member_expression(lhs_span, lhs, true)?
}
Kind::Eof => {
return Err(diagnostics::unexpected_end(self.cur_token().span()));
Kind::Bang
| Kind::LAngle
| Kind::LParen
| Kind::NoSubstitutionTemplate
| Kind::ShiftLeft
| Kind::TemplateHead
| Kind::LBrack => break,
_ => {
return Err(diagnostics::unexpected_token(self.cur_token().span()));
}
_ => break,
}
}
// computed member expression is not allowed in decorator
Expand Down
1 change: 1 addition & 0 deletions tasks/coverage/misc/fail/oxc-9525-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x?.;
1 change: 1 addition & 0 deletions tasks/coverage/misc/fail/oxc-9525-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[x?.];
3 changes: 3 additions & 0 deletions tasks/coverage/misc/fail/oxc-9525-3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
() => {
x?.
}
24 changes: 22 additions & 2 deletions tasks/coverage/snapshots/parser_misc.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parser_misc Summary:
AST Parsed : 32/32 (100.00%)
Positive Passed: 32/32 (100.00%)
Negative Passed: 27/27 (100.00%)
Negative Passed: 30/30 (100.00%)

× Unexpected token
╭─[misc/fail/oxc-169.js:2:1]
Expand Down Expand Up @@ -272,13 +272,33 @@ Negative Passed: 27/27 (100.00%)
5 │ }
╰────

× Unexpected end of file
× Unexpected token
╭─[misc/fail/oxc-9497.js:2:8]
1let repro = {};
2repro.f?.
· ──
╰────

× Unexpected token
╭─[misc/fail/oxc-9525-1.js:1:2]
1x?.;
· ──
╰────

× Unexpected token
╭─[misc/fail/oxc-9525-2.js:1:3]
1 │ [x?.];
· ──
╰────

× Unexpected token
╭─[misc/fail/oxc-9525-3.js:2:4]
1 │ () => {
2x?.
· ──
3 │ }
╰────

× The keyword 'let' is reserved
╭─[misc/fail/oxc.js:3:1]
2
Expand Down

0 comments on commit b38b20b

Please sign in to comment.