-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(es/minifier): Preserve __proto__ shorthand property behavior
#11123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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 detectedLatest 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 Performance ReportMerging #11123 will not alter performanceComparing Summary
Footnotes |
There was a problem hiding this 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.
… and improve maintainability
There was a problem hiding this 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, |
Copilot
AI
Sep 26, 2025
There was a problem hiding this comment.
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.
| raw: None, | |
| raw: Some(format!("\"{}\"", ident.sym)), |
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):
var __proto__ = []; console.log({ __proto__ })is wrongly compressed toconsole.log({ __proto__: [] })#11105