fix(codegen): use backticks for computed object property keys in destructuring assignments#13638
Conversation
…ructuring assignments
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 codegen issue where computed object property keys in destructuring assignments were incorrectly using double quotes instead of backticks. The change reverts to allowing backticks for computed keys while maintaining the fix for non-computed keys.
- Simplified conditional logic in
AssignmentTargetPropertyPropertyto only handle non-computed string literals specially - Updated test expectation to use backticks for computed property keys
- Preserves the original fix that prevents invalid syntax like
({my-key: value} = obj)
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/oxc_codegen/src/gen.rs | Simplified string literal handling to only apply special quote rules for non-computed keys |
| crates/oxc_codegen/tests/integration/js.rs | Updated test expectation to verify backticks are used in computed property keys |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
CodSpeed Instrumentation Performance ReportMerging #13638 will not alter performanceComparing Summary
|
|
Currently, |
|
Good point! I'll check if it'd be quick to change the other computed key cases. If so, I'll update this PR. If it's going to be time-consuming, I'll just close it. |
|
I looked into it. There's loads of places where computed keys are printed with Ideally I think we'd switch them all to use backticks, but that'd be more work than its worth right now. In meantime, as @sapphi-red pointed out, being consistent is the best for compression. So closing this. |

Follow-on after #13631.
That PR fixed a bug where codegen generated invalid code like
({`my-key`: value} = obj), by using normal quotes instead of backticks ({"my-key": value}).However, it went too far. Backticks are fine when the key is computed e.g.
({[`my-key`]: value} = obj). This PR reverts to original behavior of allowing backticks in computed keys.