Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Sep 10, 2025

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.

@github-actions github-actions bot added A-codegen Area - Code Generation C-bug Category - Bug labels Sep 10, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@overlookmotel overlookmotel marked this pull request as ready for review September 10, 2025 03:48
Copilot AI review requested due to automatic review settings September 10, 2025 03:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AssignmentTargetPropertyProperty to 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-hq
Copy link

codspeed-hq bot commented Sep 10, 2025

CodSpeed Instrumentation Performance Report

Merging #13638 will not alter performance

Comparing 09-10-fix_codegen_use_backticks_for_computed_object_property_keys_in_destructuring_assignments (de9e74b) with main (9fa551a)

Summary

✅ 37 untouched benchmarks

@sapphi-red
Copy link
Member

Currently, ({ ["test-key"]: key }); and (class { ["test-key"] = key }); uses double quotes. If we are going to use backticks for ({["computed"]:a}=obj), I think we need to use backticks for them as well, otherwise I guess the gzip ratio would be degraded.

@overlookmotel
Copy link
Member Author

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.

@overlookmotel overlookmotel marked this pull request as draft September 10, 2025 07:37
@overlookmotel
Copy link
Member Author

I looked into it. There's loads of places where computed keys are printed with " quotes, in preference to backticks.

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.

@overlookmotel overlookmotel deleted the 09-10-fix_codegen_use_backticks_for_computed_object_property_keys_in_destructuring_assignments branch September 10, 2025 16:02
graphite-app bot pushed a commit that referenced this pull request Sep 11, 2025
…ndingProperty` (#13659)

Small optimization to codegen. It's not possible for a property to be both `computed` and `shorthand`, so only check `if !shorthand` once, and skip all other key-related code if `shorthand == true`.

(came across this while working on #13638)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-codegen Area - Code Generation C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants