Skip to content

fix(transformer/decorators): avoid accessor name collisions#21023

Closed
filimon-danopoulos wants to merge 1 commit intooxc-project:mainfrom
filimon-danopoulos:main
Closed

fix(transformer/decorators): avoid accessor name collisions#21023
filimon-danopoulos wants to merge 1 commit intooxc-project:mainfrom
filimon-danopoulos:main

Conversation

@filimon-danopoulos
Copy link
Copy Markdown

@filimon-danopoulos filimon-danopoulos commented Apr 3, 2026

LLM notice I am not a Rust developer and I have used an LLM to generate the changes in this PR. I have done an initial vetting and review but this is not in my field of expertise. If the changes come of as utter slop please feel free to close the PR without explanation.

This pull request introduces a utility to generate unique storage names for the backing fields and adds test cases to verify correct behavior across different scenarios where collisions might occur.

Transformer logic improvements:

  • Added a unique_storage_name function to generate unique backing storage names for accessors, preventing naming collisions within the same class. This function uses a set to track used names and appends numeric suffixes as needed.

fixes #20946

@github-actions github-actions Bot added A-transformer Area - Transformer / Transpiler C-bug Category - Bug labels Apr 3, 2026
@filimon-danopoulos filimon-danopoulos changed the title fix(legacy-decorators): avoid accessor storage name collisions (#20946) fix(transform): avoid accessor storage name collisions (#20946) Apr 4, 2026
@camc314 camc314 changed the title fix(transform): avoid accessor storage name collisions (#20946) fix(transformer/decorators): avoid accessor name collisions Apr 5, 2026
@filimon-danopoulos
Copy link
Copy Markdown
Author

Closing in favour of #21106

@Dunqing
Copy link
Copy Markdown
Member

Dunqing commented Apr 8, 2026

Thank you for contributing! I was meant to push a simplified commit into this PR, but I have no permission! So I created another PR. Hope you don't mind.

graphite-app Bot pushed a commit that referenced this pull request Apr 8, 2026
…21106)

## Summary

- Use raw property/identifier names instead of `get_var_name_from_node` (which strips leading underscores) when generating private backing field names for accessor properties
- For non-computed keys, use `PropertyKey::name()` which preserves leading underscores
- For computed keys, match on `Expression::Identifier` to get the raw name directly
- No counters, maps, or helper functions needed — collisions are avoided at the source

This prevents `accessor prop` and `accessor _prop` from producing the same `#_prop_accessor_storage` name, which caused a runtime `TypeError: Cannot initialize the same private elements twice on an object`.

Closes #20946
Supersedes #21023

## Test plan

- [x] Added test fixture covering both non-computed (`prop`/`_prop`) and computed (`[prop]`/`[_prop]`) accessor name collisions
- [x] All existing accessor tests pass unchanged
- [x] `cargo test -p oxc_transformer` passes
- [x] Full `cargo run -p oxc_transform_conformance` passes
- [x] `cargo clippy` clean

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@filimon-danopoulos
Copy link
Copy Markdown
Author

Thank you for contributing! I was meant to push a simplified commit into this PR, but I have no permission! So I created another PR. Hope you don't mind.

No worries I don't mind at all I'm just happy we have a fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transformer: Collision in lowered accessors with legacy decorators for _prop and prop

4 participants