Skip to content

fix(runtime-tags): treat a member computed key as a read, not a member write - #4495

Open
NUAAwqy wants to merge 1 commit into
marko-js:mainfrom
NUAAwqy:fix/rest-computed-key-member-write
Open

NUAAwqy wants to merge 1 commit into
marko-js:mainfrom
NUAAwqy:fix/rest-computed-key-member-write

Conversation

@NUAAwqy

@NUAAwqy NUAAwqy commented Oct 22, 2026

Copy link
Copy Markdown

Problem

trackReference walks a reference up while its parent is any member expression, without checking the
reference is the member's object, and then asks isAssignedMember. So for obj[rest] = 1 the computed
key rest is treated as if its own members were assigned. When rest is a <const> rest binding, valid
code fails to compile:

rest is a rest element, a copy rebuilt from the value it is destructured from whenever that changes,
so assigning its members would be lost.

The key is only read — nothing assigns rest. The same missing check also records a needless
addAssignedProperty de-optimization for ordinary keys (o[x] = 1, o[x]++, delete o[x]).

Fix

Stop the walk unless the reference is the member's object; a computed key is just a read. One line
(+ a two-line comment) in translator/util/references.ts. Node comparison is direct, per AGENTS.md.

Tests

New fixture rest-computed-member-key (html/dom/ssr/csr, generated snapshots) fails to compile before the
guard and passes after. Real member writes still error: --grep rest = 307 passing, including
error-assign-to-rest-element and error-assign-to-rest-element-member (rest.b = 5). Full
runtime-tags translator suite green, repo-wide oxlint/oxfmt clean, and build:sizes produces no
.sizes/.sizes.json delta (translator-only change, zero shipped runtime bytes).

Resolves the tracked agent-feedback item for this defect; the item file is deleted in this PR per
agent-feedback/README.md rule 8.

…r write

trackReference walked a reference up while its parent was any member expression,
without checking the reference was the member object. So for obj[rest] = 1 the
computed key rest was tested with isAssignedMember, and a <const> rest binding
used as a key threw "assigning its members would be lost" even though nothing
assigns the rest. Guard the walk so only the member object continues it; a
computed key is just read.

Adds a rest-computed-member-key fixture that fails to compile without the guard,
and removes the matching agent-feedback item.

Signed-off-by: NUAAwqy <NUAAwqy@users.noreply.github.com>
@changeset-bot

changeset-bot Bot commented Oct 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1d1606e

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

This PR includes changesets to release 1 package
Name Type
@marko/runtime-tags Patch

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

@coderabbitai

coderabbitai Bot commented Oct 22, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a9b1c922-0820-41c5-b3e7-a8c423d057e0
📥 Commits

Reviewing files that changed from the base of the PR and between 0209cae and 1d1606e.

⛔ Files ignored due to path filters: 8
  • packages/runtime-tags/src/__tests__/fixtures/rest-computed-member-key/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/rest-computed-member-key/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/rest-computed-member-key/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/rest-computed-member-key/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/rest-computed-member-key/__snapshots__/render.debug.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/rest-computed-member-key/__snapshots__/render.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/rest-computed-member-key/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/rest-computed-member-key/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
📒 Files selected for processing: 6
  • .changeset/rest-computed-member-key.md
  • agent-feedback/items/2026-10-21-stop-a-computed-key-from-counting-as-a-member-write.md
  • packages/runtime-tags/src/__tests__/fixtures/rest-computed-member-key/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/rest-computed-member-key/template.marko
  • packages/runtime-tags/src/__tests__/fixtures/rest-computed-member-key/test.ts
  • packages/runtime-tags/src/translator/util/references.ts
💤 Files with no reviewable changes: 1
  • agent-feedback/items/2026-10-21-stop-a-computed-key-from-counting-as-a-member-write.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

trackReference now stops traversing a member expression when the reference is used as its key rather than its object. A new fixture renders values accessed with rest-binding keys and tests updates to those keys through a button click. The change also adds a patch changeset and removes the related bug-report document.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 1d160

Computed-key rest bindings can be used without being misclassified as assigned, and the fixture checks that their lookups update. No actionable merge risk remains; the change is ready for normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (3 skipped: 3 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main fix: computed member keys are treated as reads instead of member writes.
Description check Passed The description is directly related to the changes. It explains the defect, the fix, the regression fixture, validation results, and deletion of the tracked feedback item.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (3 skipped: 3 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant