Skip to content

Conversation

@magic-akari
Copy link
Member

Description:

When minifying object shorthand properties, the __proto__ property should be converted to a computed property ["__proto__"] instead of a regular key-value pair to preserve the original object behavior. This prevents changing the object's prototype chain during minification.

BREAKING CHANGE:

Related issue (if exists):

When minifying object shorthand properties, the `__proto__` property should be converted to a computed property `["__proto__"]` instead of a regular key-value pair to preserve the original object behavior.
This prevents changing the object's prototype chain during minification.
@changeset-bot
Copy link

changeset-bot bot commented Sep 25, 2025

🦋 Changeset detected

Latest commit: 14a7b94

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 25, 2025

CodSpeed Performance Report

Merging #11123 will not alter performance

Comparing magic-akari:fix/issue-11105 (14a7b94) with main (8cfd47b)1

Summary

✅ 140 untouched

Footnotes

  1. No successful run was found on main (4c43db2) during the generation of this report, so 8cfd47b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@magic-akari magic-akari marked this pull request as ready for review September 25, 2025 22:57
@magic-akari magic-akari requested a review from a team as a code owner September 25, 2025 22:57
Copilot AI review requested due to automatic review settings September 25, 2025 22:57
Copy link

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 bug in the ECMAScript minifier where __proto__ shorthand properties were being converted to regular key-value pairs, which incorrectly modified the object's prototype chain. The fix ensures __proto__ shorthand properties are converted to computed properties ["__proto__"] to preserve their original behavior.

  • Adds special handling for __proto__ in shorthand property conversion
  • Converts __proto__ shorthand to computed property syntax instead of regular identifier
  • Preserves object prototype chain behavior during minification

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
crates/swc_ecma_minifier/src/compress/optimize/util.rs Implements the core fix across three visitor implementations to handle __proto__ shorthand conversion
crates/swc_ecma_minifier/tests/fixture/issues/11105/input.js Test input demonstrating the issue with __proto__ shorthand
crates/swc_ecma_minifier/tests/fixture/issues/11105/output.js Expected output showing __proto__ converted to computed property

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

CPunisher
CPunisher previously approved these changes Sep 26, 2025
CPunisher
CPunisher previously approved these changes Sep 26, 2025
Austaras
Austaras previously approved these changes Sep 26, 2025
Copilot AI review requested due to automatic review settings September 26, 2025 11:52
@kdy1 kdy1 dismissed stale reviews from Austaras and CPunisher via 14a7b94 September 26, 2025 11:52
@kdy1 kdy1 requested a review from a team as a code owner September 26, 2025 11:52
@kdy1 kdy1 merged commit 63dbd1d into swc-project:main Sep 26, 2025
33 checks passed
@kdy1 kdy1 added this to the Planned milestone Sep 26, 2025
Copy link

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

expr: Box::new(Expr::Lit(Lit::Str(Str {
span: ident.span,
value: ident.sym.clone(),
raw: None,
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider using Some(format!("\"{}\"", ident.sym)) instead of None for the raw field to maintain consistent string literal formatting in the generated code.

Suggested change
raw: None,
raw: Some(format!("\"{}\"", ident.sym)),

Copilot uses AI. Check for mistakes.
@kdy1 kdy1 modified the milestones: Planned, v1.13.20 Sep 27, 2025
@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

minifier: var __proto__ = []; console.log({ __proto__ }) is wrongly compressed to console.log({ __proto__: [] })

4 participants