fix(semantic): report duplicate private identifier for static and instance elements#17591
Conversation
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
This PR fixes a bug where TypeScript files with both static and instance private identifiers with the same name (e.g., #foo and static #foo) were not being reported as errors, which violates the ECMAScript specification and TypeScript's type checking rules.
Key changes:
- Added a new diagnostic
static_and_instance_private_identifierfor TS error 2804 - Updated duplicate class element detection logic to correctly identify when private identifiers with the same name have different static status
- Fixed the logic to ensure private identifiers follow JavaScript rules even in TypeScript (static and instance elements cannot share the same private name)
Reviewed changes
Copilot reviewed 2 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_semantic/src/diagnostics.rs | Added new diagnostic function static_and_instance_private_identifier for TS(2804) error with appropriate error message and labels |
| crates/oxc_semantic/src/checker/javascript.rs | Updated duplicate detection logic to correctly handle private identifiers with different static status, ensuring they are reported as errors in both JavaScript and TypeScript |
| tasks/coverage/snapshots/parser_typescript.snap | Updated to show newly detected errors for static/instance private identifier conflicts; Negative Passed count increased from 1496 to 1497 |
| tasks/coverage/snapshots/parser_test262.snap | Updated error messages from generic "Identifier has already been declared" to specific TS(2804) error for static/instance private name conflicts |
| tasks/coverage/snapshots/parser_babel.snap | Updated error messages from generic "Identifier has already been declared" to specific TS(2804) error for static/instance private name conflicts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merging this PR will not alter performanceSummary
Comparing Footnotes
|
Dunqing
left a comment
There was a problem hiding this comment.
The check logic looks good; it just needs to improve the error message.
cb74908 to
d8129a7
Compare
Merge activity
|
d8129a7 to
5755b2d
Compare
### 🚀 Features - 10426af codegen: Print soft space between inline block comments on the same line (#17799) (camc314) - 2261e6e semantic: Improve error message to add `#` for private identifiers (#17779) (Dunqing) ### 🐛 Bug Fixes - 7422b7e parser/trivia: Correctly mark whether a block comment is on a newline (#17754) (camc314) - c32e8d5 codegen: Wrap `TSAsExpression` in parens when used with in/instanceof operators (#17752) (camc314) - 5755b2d semantic: Report duplicate private identifier for static and instance elements (#17591) (camc314) - 0600df3 isolated_declarations: Only print jsdoc comments (#17748) (camc314) - ef7e014 parser: Preserve `@__NO_SIDE_EFFECTS__` annotation with parenthesized expressions (#17711) (camc314) - 59a6228 parser: Detect TS1363 error for type-only imports with mixed default and named/namespace bindings (#17712) (Copilot) ### ⚡ Performance - 864f1fa semantic: Mark duplicate class element error reporting as cold (#17746) (camc314) - 3a452b8 semantic: Use smallvec for storing reference IDs (#17731) (camchenry) - d5979dc minifier: Do not allocate when checking to convert `const` to `let` (#17730) (camchenry) - 3f4429c parser: Do not re-allocate TS interface heritage (#17692) (camchenry) ### 📚 Documentation - 120a27c minifier: Add prettier-ignore for js-in-md part (#17687) (leaysgur) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>

Previously, TypeScript files with both a static private identifier and an instance private identifier with the same name (e.g.,
static #mand#m()) were not being reported as errors.Closes #17518