Skip to content

fix(es/minifier): mark properties assigned through destructuring targets as mutated - #12398

Merged
Donny/강동윤 (kdy1) merged 1 commit into
swc-project:mainfrom
baltasarblanco:fix/12397-hoist-props-destructuring-targets
Sep 22, 2026
Merged

Donny/강동윤 (kdy1) merged 1 commit into
swc-project:mainfrom
baltasarblanco:fix/12397-hoist-props-destructuring-targets

Conversation

@baltasarblanco

@baltasarblanco Baltasar Blanco (baltasarblanco) commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Description:

With hoist_props, a property that is only written through a destructuring assignment
target ([o.n] = [2], ({ x: o.n } = obj)) was treated as never written, so it was
hoisted and its initial value inlined into the assignment target itself, producing invalid
JavaScript ([1]=[2]).

The usage analyzer already marks o as property-mutated for o.n = v via
mark_mutation_if_member, but the AssignTarget::Pat branch of visit_assign_expr and
the for-in/for-of heads never did. This PR walks the pattern and marks every member target
at any depth (array, object, default, rest) the same way. It only ever over-preserves.

The extra work runs only for assignments with a pattern on the left and for-in/for-of
heads, as a single walk of the pattern.

The existing issues/11084 fixture runs without hoist_props, which is why the original
report still reproduced. With @swc/core 1.16.2 default options it breaks inside any
function body (e.g. an IIFE), and at the top level once toplevel is enabled.

This also updates issues/9739: its snapshot had frozen the same bug through variable
inlining ([arr[0], arr[1]] = … became writes to fresh array literals, so arr was never
swapped). The new output keeps the swap.

Testing:

  • issue_12397_hoist_props_destructuring_member_targets (exec test, 9 variants) fails
    without the change and passes with it.
  • cargo test -p swc_ecma_minifier --no-fail-fast: 0 failures across all test binaries.
  • cargo clippy -p swc_ecma_minifier --all-targets -- -D warnings: clean.

Fixes #12397. Follow-up of #11084 / #11221.

@codspeed

codspeed Bot commented Sep 21, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 61 untouched benchmarks
⏩ 207 skipped benchmarks1


Comparing baltasarblanco:fix/12397-hoist-props-destructuring-targets (601e1db) with main (4b42cd5)

Open in CodSpeed

Footnotes

  1. 207 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@kdy1 Donny/강동윤 (kdy1) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@kdy1
Donny/강동윤 (kdy1) merged commit 42e4f7e into swc-project:main Sep 22, 2026
54 of 69 checks passed
@github-actions github-actions Bot added this to the Planned milestone Sep 22, 2026
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.

es/minifier: hoist_props inlines properties written through destructuring assignment targets (incomplete fix of #11084)

2 participants