Skip to content

refact(es/minifier): Inline into shorthand prop early#11766

Open
Austaras wants to merge 3 commits intoswc-project:mainfrom
Austaras:main
Open

refact(es/minifier): Inline into shorthand prop early#11766
Austaras wants to merge 3 commits intoswc-project:mainfrom
Austaras:main

Conversation

@Austaras
Copy link
Copy Markdown
Member

@Austaras Austaras commented Apr 3, 2026

Description:

BREAKING CHANGE:

Related issue (if exists):

@Austaras Austaras requested a review from a team as a code owner April 3, 2026 10:09
Copilot AI review requested due to automatic review settings April 3, 2026 10:09
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 3, 2026

⚠️ No Changeset found

Latest commit: ca4951d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

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

Copy link
Copy Markdown
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

Refactors the minifier’s inlining logic to support inlining into object-literal shorthand properties earlier, while preserving correct __proto__ semantics.

Changes:

  • Exposes prop_name_from_ident so other optimizer passes can safely expand shorthand props (handling __proto__ via computed keys).
  • Adds a visit_mut_prop hook to inline identifiers inside Prop::Shorthand and convert them to KeyValueProp.
  • Extracts identifier inlining logic into a reusable inline_ident helper and reuses it from inline().

Reviewed changes

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

File Description
crates/swc_ecma_minifier/src/compress/optimize/util.rs Makes prop_name_from_ident available for shorthand→key-value expansion while preserving __proto__ behavior.
crates/swc_ecma_minifier/src/compress/optimize/mod.rs Adds shorthand property inlining during AST visitation and expands shorthand into key-value props.
crates/swc_ecma_minifier/src/compress/optimize/inline.rs Refactors identifier inlining into inline_ident and calls it from expression inlining.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2501 to +2504
*n = Prop::KeyValue(KeyValueProp {
key,
value: expr.clone(),
});
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

expr is owned here (returned from inline_ident), but it’s cloned when building KeyValueProp. This adds avoidable allocation/AST cloning; move expr into value instead of cloning it.

Suggested change
*n = Prop::KeyValue(KeyValueProp {
key,
value: expr.clone(),
});
*n = Prop::KeyValue(KeyValueProp { key, value: expr });

Copilot uses AI. Check for mistakes.

if let Some(value) = self.vars.vars_for_inlining.remove(&id) {
self.changed = true;
report_change!("inline: Replacing '{}' with an expression", i);
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

Same issue as above: this report_change! call uses i, which is not defined in inline_ident. Use ident (or an Id derived from it) so this compiles and logs the correct identifier.

Suggested change
report_change!("inline: Replacing '{}' with an expression", i);
report_change!("inline: Replacing '{}' with an expression", ident.sym);

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d5419cf6aa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

self.changed = true;
report_change!("inline: Replacing '{}' with an expression", i);
self.changed = true;
report_change!("inline: Replacing a variable `{}` with cheap expression", i);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Replace stale i reference in inline_ident logging

After extracting inline_ident, the logging calls still format {} with i, but this function only has ident; when the debug feature is enabled, report_change! expands to tracing::debug! and this becomes an unresolved identifier compile error. This breaks swc_ecma_minifier builds in debug-feature workflows (e.g. cargo check -p swc_ecma_minifier --features debug).

Useful? React with 👍 / 👎.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

Binary Sizes

File Size
swc.linux-x64-gnu.node 28M (29075272 bytes)

Commit: 0d8ba38

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 3, 2026

Merging this PR will not alter performance

✅ 219 untouched benchmarks


Comparing Austaras:main (ca4951d) with main (236eff0)1

Open in CodSpeed

Footnotes

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

Copilot AI review requested due to automatic review settings April 3, 2026 16:44
Copy link
Copy Markdown
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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

/// `__proto__`. When the property name is `__proto__`, it must be converted to
/// a computed property to preserve JavaScript semantics.
fn prop_name_from_ident(ident: Ident) -> PropName {
pub(crate) fn prop_name_from_ident(ident: Ident) -> PropName {
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

prop_name_from_ident is only referenced within the compress::optimize module (currently optimize/mod.rs and this file). Exposing it as pub(crate) increases the crate-wide API surface unnecessarily; consider reducing visibility to pub(super) (or pub(in crate::compress::optimize)) to keep the helper scoped to this module.

Suggested change
pub(crate) fn prop_name_from_ident(ident: Ident) -> PropName {
pub(super) fn prop_name_from_ident(ident: Ident) -> PropName {

Copilot uses AI. Check for mistakes.
@kdy1
Copy link
Copy Markdown
Member

kdy1 commented Apr 7, 2026

Can you make tests I added pass?

Copilot AI review requested due to automatic review settings April 7, 2026 07:57
Copy link
Copy Markdown
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

Copilot reviewed 50 out of 50 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants