fix(es/minifier): mark properties assigned through destructuring targets as mutated - #12398
Merged
Donny/강동윤 (kdy1) merged 1 commit intoSep 22, 2026
Conversation
Baltasar Blanco (baltasarblanco)
requested review from
a team
as code owners
September 21, 2026 15:14
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
With
hoist_props, a property that is only written through a destructuring assignmenttarget (
[o.n] = [2],({ x: o.n } = obj)) was treated as never written, so it washoisted and its initial value inlined into the assignment target itself, producing invalid
JavaScript (
[1]=[2]).The usage analyzer already marks
oas property-mutated foro.n = vviamark_mutation_if_member, but theAssignTarget::Patbranch ofvisit_assign_exprandthe 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/11084fixture runs withouthoist_props, which is why the originalreport still reproduced. With
@swc/core1.16.2 default options it breaks inside anyfunction body (e.g. an IIFE), and at the top level once
toplevelis enabled.This also updates
issues/9739: its snapshot had frozen the same bug through variableinlining (
[arr[0], arr[1]] = …became writes to fresh array literals, soarrwas neverswapped). The new output keeps the swap.
Testing:
issue_12397_hoist_props_destructuring_member_targets(exec test, 9 variants) failswithout 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.