feat(parser): improve errors for private ident outside class#19080
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
Updates the parser to emit a more specific diagnostic (TS18016) when encountering private identifiers (#foo) in places where they’re syntactically invalid (e.g., object literals, destructuring patterns, TS type members), and refreshes coverage snapshots accordingly.
Changes:
- Add a TS18016 diagnostic for private identifiers used outside class bodies during property-name parsing.
- Extend
parse_property_nameto optionally acceptPrivateIdentifiertokens (gated by a boolean flag) and update call sites. - Update parser coverage snapshots (TypeScript, Babel fixtures, Test262) to reflect the new error output.
Reviewed changes
Copilot reviewed 5 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tasks/coverage/snapshots/parser_typescript.snap | Snapshot updates to reflect TS18016 (and related diagnostics) for invalid private identifiers. |
| tasks/coverage/snapshots/parser_test262.snap | Snapshot updates for Test262 negative cases now reporting TS18016 where applicable. |
| tasks/coverage/snapshots/parser_babel.snap | Snapshot updates for Babel parser fixtures to reflect TS18016 output. |
| crates/oxc_parser/src/ts/types.rs | Update TS type-member parsing to call the new parse_property_name(false) signature. |
| crates/oxc_parser/src/js/object.rs | Add allow_private_identifier parameter, handle Kind::PrivateIdentifier, and update call sites. |
| crates/oxc_parser/src/js/class.rs | Use parse_property_name(true) for class element names and keep private-name validations. |
| crates/oxc_parser/src/js/binding.rs | Update destructuring binding property parsing to call parse_property_name(false). |
| crates/oxc_parser/src/diagnostics.rs | Add new private_identifiers_not_allowed_outside_class_bodies TS(18016) diagnostic. |
CodSpeed Performance ReportMerging this PR will improve performance by 69.78%Comparing Summary
Performance Changes
Footnotes
|
fa7b65f to
4fecb4a
Compare
| ╰──── | ||
|
|
||
| × Unexpected token | ||
| × TS(18016): Private identifiers are not allowed outside class bodies. |
There was a problem hiding this comment.
why do we have two errors, where one has a ts code. ecmascript syntax errors should not have a ts code.
There was a problem hiding this comment.
we were checking this both in the parser and in semantic - i've changed it see the upstack PR so that we only check this in the parser. this fixes the duplicate error diagnostic
4fecb4a to
59a439a
Compare
7160485 to
13be494
Compare
a2f6120 to
ef013de
Compare
e3620ad to
cd89ad2
Compare
ef013de to
f7e7567
Compare
cd89ad2 to
6851ec2
Compare
f7e7567 to
2a792c5
Compare

No description provided.