Skip to content

perf: inline references to constant primitive <const> tags#3243

Open
DylanPiercey wants to merge 1 commit into
mainfrom
claude/opt-const-folding
Open

perf: inline references to constant primitive <const> tags#3243
DylanPiercey wants to merge 1 commit into
mainfrom
claude/opt-const-folding

Conversation

@DylanPiercey

Copy link
Copy Markdown
Contributor

What

Constant-folds <const> tags whose value is a statically known primitive (string, finite number, boolean, null, undefined). Each reference to such a const is replaced with the literal value, and the <const> tag itself is dropped — no binding and no reactive signal are emitted.

This is the first in a series of isolated optimization PRs for the runtime-tags translator.

Why

Today a <const x=1/> always produces a derived binding and a reactive signal, even though its value can never change. A reference like ${x} is rendered through _text/_escape at setup rather than being baked into the static template.

Because folding happens by node substitution, it also composes:

  • Dependent expressions fold further via computeNode (e.g. <const total=step + 3/>5).
  • Chained consts compose (total depends on step).
  • Values inline into the static HTML template string and into event-handler bodies.
  • The now-unreferenced binding prunes away, shrinking both generated code and the resumability payload.

Object/array/regexp consts are intentionally not folded (identity-sensitive); their inner primitive-const references still fold.

Example

<let/count=0/>
<const/step=2/>
<const/label="step"/>
<const/total=step + 3/>
<const/info={ label, total }/>

<button onClick() { count += step }>+${step}</button>
<div class=label data-total=total>
  ${label}: ${count} / ${total}
</div>

DOM template before/after this change (debug):

// before: const step/label/total declarations + signals, ${label}/${step}/${total} reactive
// after:
const $template = "<button>+2</button><div class=step data-total=5>step: <!> / 5</div>...";
// count stays reactive (<!> marker); step/label/total fully folded away

Validation

  • New fixture const-tag-fold exercises folding across placeholder, attribute, event-handler and expression positions, composition, a non-foldable object const, and preserved reactivity (count).
  • Across the existing suite, rendered HTML/DOM output is byte-identical (only resumability accessor letters renumber where a binding was removed); minified output sizes consistently decrease.
  • Full runtime-tags (5040) and translator-interop (266) suites pass; eslint + prettier clean.
  • Locations/comments are inherited onto substituted literals so compile-error code frames still point at the original source (covered by error-debug-args).

🤖 Generated with Claude Code

https://claude.ai/code/session_01G1bgkqJCLUsEz3xsossMCN


Generated by Claude Code

@changeset-bot

changeset-bot Bot commented Jun 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 46da484

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

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 20, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: DylanPiercey / name: Dylan Piercey (58b466d)

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The pull request implements a compile-time optimization for <const> tags in @marko/runtime-tags. When a <const> tag's value is a statically known primitive (string, number, boolean, bigint, undefined, or null), the translator now upgrades the associated binding to BindingType.constant with an inline constValue expression stored on the Binding interface. Read sites then substitute the cloned constant directly, serialization-reason tracking skips constant bindings, and the tag's signal/value wiring is omitted in translate.exit. A new const-tag-fold fixture exercises this path, and numerous existing fixture size snapshots are updated to reflect the changed output.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title precisely describes the main optimization: inlining primitive constant values from <const> tags to replace their references, which is the core change across all modified files.
Description check ✅ Passed The description comprehensively explains the constant-folding optimization, its benefits, constraints (primitives only, not objects/arrays), composition behavior, and validation approach, directly relating to all changes in the PR.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/opt-const-folding

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

@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.21%. Comparing base (bc20394) to head (46da484).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3243      +/-   ##
==========================================
+ Coverage   94.18%   94.21%   +0.03%     
==========================================
  Files         382      382              
  Lines       49796    49889      +93     
  Branches     3698     3728      +30     
==========================================
+ Hits        46900    47004     +104     
+ Misses       2870     2859      -11     
  Partials       26       26              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/runtime-tags/src/translator/core/const.ts (1)

71-93: ⚡ Quick win

Let primitive aliases fold too.

!upstreamAlias keeps a primitive alias on the binding/signal path even after evaluate() has already proven the initializer is inlineable. That leaves the chained-const case from the PR objective unoptimized.

♻️ Proposed fix
-    if (
-      !upstreamAlias &&
-      valueExtra.confident &&
-      t.isIdentifier(node.var) &&
-      canInlineValue(valueExtra.computed)
-    ) {
+    if (
+      valueExtra.confident &&
+      t.isIdentifier(node.var) &&
+      canInlineValue(valueExtra.computed)
+    ) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/runtime-tags/src/translator/core/const.ts` around lines 71 - 93, The
condition `!upstreamAlias &&` in the if statement prevents primitive aliases
from being constant folded, even when evaluate() has proven they are inlineable.
Remove the `!upstreamAlias &&` check from the if statement condition to allow
primitive aliases to participate in constant folding along with the other
existing checks (valueExtra.confident, t.isIdentifier(node.var), and
canInlineValue(valueExtra.computed)).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/runtime-tags/src/translator/core/const.ts`:
- Around line 71-93: The condition `!upstreamAlias &&` in the if statement
prevents primitive aliases from being constant folded, even when evaluate() has
proven they are inlineable. Remove the `!upstreamAlias &&` check from the if
statement condition to allow primitive aliases to participate in constant
folding along with the other existing checks (valueExtra.confident,
t.isIdentifier(node.var), and canInlineValue(valueExtra.computed)).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 356f2f47-b102-42ed-8a47-eacb77513bc3

📥 Commits

Reviewing files that changed from the base of the PR and between bc20394 and 2382d3e.

⛔ Files ignored due to path filters (91)
  • packages/runtime-tags/src/__tests__/fixtures/attr-class-delimited-shapes/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/attr-class-delimited-shapes/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/attr-class-delimited-shapes/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/attr-class-delimited-shapes/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/attr-class-delimited-shapes/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/attr-class-delimited-shapes/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/basic-unused-ref/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/basic-unused-ref/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/bound-attr-computed-key/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/bound-attr-computed-key/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/bound-attr-computed-key/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/render.debug.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/render.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-hoist-error/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-dynamic-spread/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-dynamic-spread/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-dynamic-spread/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-dynamic-spread/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-dynamic-spread/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-dynamic-spread/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/debug-tag/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/debug-tag/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/debug-tag/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/debug-tag/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/declared-alias-closure/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/declared-alias-closure/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/declared-alias-closure/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/declared-alias-closure/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/declared-alias-closure/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/declared-alias-closure/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-input/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-input/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-input/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-unprovided-input/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-unprovided-input/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-unprovided-input/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-input/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-input/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-input/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closure-with-function/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closure-with-function/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closure-with-function/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closures/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closures/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closures/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closures/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closures/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closures/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-name/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-name/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/hoist-only/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/hoist-only/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/import-types/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/known-define-tag-empty-section-closure/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/known-define-tag-empty-section-closure/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/known-define-tag-empty-section-closure/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/known-define-tag-empty-section-closure/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/known-define-tag-empty-section-closure/__snapshots__/render.debug.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/known-define-tag-empty-section-closure/__snapshots__/render.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/log-tag/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/log-tag/__snapshots__/render-csr.debug.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/log-tag/__snapshots__/render-csr.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/pure-signal-resume-function/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/pure-signal-resume-function/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/pure-signal-resume-function/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/pure-signal-resume-function/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/pure-signal-resume-function/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/pure-signal-resume-function/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/return-tag-no-state/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/return-tag-no-state/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/__snapshots__/render.debug.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/__snapshots__/render.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/try-tag-closure/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/try-tag-closure/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
📒 Files selected for processing (36)
  • .changeset/const-fold-primitives.md
  • packages/runtime-tags/src/__tests__/fixtures-interop/ambiguous-tags-and-components-dir/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/custom-tag-parameters-from-args/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-basic-class-to-tags/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-basic-tags-to-class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-class-in-components-in-tags-dir/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-class-to-tags-import/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-event-handler-render-body-tags-to-class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-events-tags-to-class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-nested-attr-tags-class-to-tags/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-nested-class-to-tags/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-nested-tags-to-class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-stateless-tags-to-class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-tag-params-class-to-tags/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-tag-params-tags-to-class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/lazy-class-child-event/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/lazy-class-child-idle/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/lazy-class-child-ssr-toggle/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/lazy-class-child-ssr/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/lazy-class-child-unmount-before-load/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/lazy-class-child-visible/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/let/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/assign-to-owner-closure/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/attr-class-delimited-shapes/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/template.marko
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/test.ts
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-dynamic-spread/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/debug-tag/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/declared-alias-closure/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closures/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/known-define-tag-empty-section-closure/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/pure-signal-resume-function/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/sizes.json
  • packages/runtime-tags/src/translator/core/const.ts

@DylanPiercey DylanPiercey force-pushed the claude/opt-const-folding branch 2 times, most recently from 58b466d to 9034e34 Compare June 20, 2026 21:59

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/runtime-tags/src/translator/util/references.ts (1)

1850-1898: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Preserve non-optional member reads for nullish constants.

Line 1893 can turn a folded null/undefined const read like x.foo into null?.foo/undefined?.foo because the binding remains nullable, changing a thrown TypeError into undefined. Gate this nullable-scope rewrite to the non-const replacement path so source optionality is preserved.

🐛 Proposed fix
-          readBinding.nullable &&
+          !constValueNode &&
+          readBinding.nullable &&
           replaceMember.object.type !== replacement.type
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/runtime-tags/src/translator/util/references.ts` around lines 1850 -
1898, The nullable-scope rewrite that converts a member expression to
OptionalMemberExpression (the if (replaceMember) block starting at line 1893) is
being applied even when constValueNode is present, which incorrectly transforms
const reads like null.foo into null?.foo and changes their semantics from
throwing a TypeError to returning undefined. Guard this nullable rewrite block
to only execute when constValueNode is not set, ensuring the original
optionality of const value replacements is preserved by checking that
constValueNode is falsy before entering the if (replaceMember) condition.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/runtime-tags/src/translator/core/const.ts`:
- Around line 148-155: The canInlineValue function currently returns true for
all values of type "number", which includes NaN and Infinity, but numeric
inlining should only apply to finite numbers. Add a check to filter out
non-finite numbers by testing if the value is finite using Number.isFinite()
when the type is "number", so that non-finite values like NaN and Infinity
continue through the runtime path instead of being inlined.
- Around line 100-101: The assignment `binding.constValue =
t.valueToNode(valueExtra.computed)` at line 101 can result in an Identifier node
referencing "undefined" when the computed value is undefined, which may capture
a shadowed undefined variable in the scope. Instead of passing the raw computed
value to t.valueToNode(), check if valueExtra.computed is undefined and pass
void 0 to t.valueToNode() in that case to ensure the const binding uses the void
0 operator instead of an undefined identifier.

---

Outside diff comments:
In `@packages/runtime-tags/src/translator/util/references.ts`:
- Around line 1850-1898: The nullable-scope rewrite that converts a member
expression to OptionalMemberExpression (the if (replaceMember) block starting at
line 1893) is being applied even when constValueNode is present, which
incorrectly transforms const reads like null.foo into null?.foo and changes
their semantics from throwing a TypeError to returning undefined. Guard this
nullable rewrite block to only execute when constValueNode is not set, ensuring
the original optionality of const value replacements is preserved by checking
that constValueNode is falsy before entering the if (replaceMember) condition.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8746b100-239a-4207-b1a7-ee1b35768135

📥 Commits

Reviewing files that changed from the base of the PR and between 58b466d and 9034e34.

⛔ Files ignored due to path filters (89)
  • packages/runtime-tags/src/__tests__/fixtures/attr-class-delimited-shapes/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/attr-class-delimited-shapes/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/attr-class-delimited-shapes/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/attr-class-delimited-shapes/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/attr-class-delimited-shapes/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/attr-class-delimited-shapes/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/basic-unused-ref/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/basic-unused-ref/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/bound-attr-computed-key/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/bound-attr-computed-key/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/bound-attr-computed-key/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/bound-attr-computed-key/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/render.debug.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/render.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-hoist-error/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/const-tag/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-dynamic-spread/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-dynamic-spread/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-dynamic-spread/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-dynamic-spread/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-dynamic-spread/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-dynamic-spread/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/debug-tag/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/debug-tag/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/debug-tag/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/debug-tag/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-input/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-input/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-input/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-input/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-input/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-unprovided-input/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-unprovided-input/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-unprovided-input/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-unprovided-input/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-unprovided-input/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-input/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-input/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-input/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-input/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/destructure-input/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closure-with-function/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closure-with-function/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closure-with-function/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closure-with-function/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closure-with-function/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closures/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closures/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closures/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-name/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-name/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-name/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-name/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/hoist-only/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/hoist-only/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/import-types/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/known-define-tag-empty-section-closure/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/known-define-tag-empty-section-closure/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/known-define-tag-empty-section-closure/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/known-define-tag-empty-section-closure/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/log-tag/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/log-tag/__snapshots__/render-csr.debug.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/log-tag/__snapshots__/render-csr.md is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/pure-signal-resume-function/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/pure-signal-resume-function/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/pure-signal-resume-function/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/pure-signal-resume-function/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/pure-signal-resume-function/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/pure-signal-resume-function/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/return-tag-no-state/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/return-tag-no-state/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/__snapshots__/dom.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/__snapshots__/dom.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/try-tag-closure/__snapshots__/html.bundle.debug.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/try-tag-closure/__snapshots__/html.bundle.js is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/try-tag-closure/__snapshots__/writes.debug.html is excluded by !**/__snapshots__/** and included by **
  • packages/runtime-tags/src/__tests__/fixtures/try-tag-closure/__snapshots__/writes.html is excluded by !**/__snapshots__/** and included by **
📒 Files selected for processing (43)
  • .changeset/const-fold-primitives.md
  • packages/runtime-tags/src/__tests__/fixtures-interop/ambiguous-tags-and-components-dir/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/custom-tag-parameters-from-args/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-basic-class-to-tags/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-basic-tags-to-class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-class-in-components-in-tags-dir/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-class-to-tags-import/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-event-handler-render-body-tags-to-class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-events-tags-to-class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-nested-attr-tags-class-to-tags/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-nested-class-to-tags/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-nested-tags-to-class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-stateless-tags-to-class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-tag-params-class-to-tags/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/interop-tag-params-tags-to-class/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/lazy-class-child-event/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/lazy-class-child-idle/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/lazy-class-child-ssr-toggle/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/lazy-class-child-ssr/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/lazy-class-child-unmount-before-load/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/lazy-class-child-visible/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures-interop/let/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/assign-to-owner-closure/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/attr-class-delimited-shapes/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/bound-attr-computed-key/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/template.marko
  • packages/runtime-tags/src/__tests__/fixtures/const-tag-fold/test.ts
  • packages/runtime-tags/src/__tests__/fixtures/controllable-select-dynamic-spread/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/debug-tag/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-input/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/destructure-and-reference-unprovided-input/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/destructure-input/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-closure-with-function/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-name/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/known-define-tag-empty-section-closure/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/pure-signal-resume-function/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/tag-param-if-closure/sizes.json
  • packages/runtime-tags/src/__tests__/fixtures/try-tag-closure/sizes.json
  • packages/runtime-tags/src/translator/core/const.ts
  • packages/runtime-tags/src/translator/util/references.ts
  • packages/runtime-tags/src/translator/util/serialize-reasons.ts
✅ Files skipped from review due to trivial changes (37)
  • packages/runtime-tags/src/tests/fixtures-interop/class/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/interop-basic-tags-to-class/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/interop-events-tags-to-class/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/lazy-class-child-event/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/interop-nested-class-to-tags/sizes.json
  • packages/runtime-tags/src/tests/fixtures/bound-attr-computed-key/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/lazy-class-child-ssr/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/lazy-class-child-unmount-before-load/sizes.json
  • packages/runtime-tags/src/tests/fixtures/controllable-select-dynamic-spread/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/custom-tag-parameters-from-args/sizes.json
  • packages/runtime-tags/src/tests/fixtures/assign-to-owner-closure/sizes.json
  • packages/runtime-tags/src/tests/fixtures/tag-param-if-closure/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/interop-event-handler-render-body-tags-to-class/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/interop-tag-params-class-to-tags/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/interop-nested-tags-to-class/sizes.json
  • packages/runtime-tags/src/tests/fixtures/const-tag-fold/sizes.json
  • .changeset/const-fold-primitives.md
  • packages/runtime-tags/src/tests/fixtures/destructure-input/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/lazy-class-child-visible/sizes.json
  • packages/runtime-tags/src/tests/fixtures/dynamic-tag-name/sizes.json
  • packages/runtime-tags/src/tests/fixtures/attr-class-delimited-shapes/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/lazy-class-child-idle/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/interop-basic-class-to-tags/sizes.json
  • packages/runtime-tags/src/tests/fixtures/known-define-tag-empty-section-closure/sizes.json
  • packages/runtime-tags/src/tests/fixtures/destructure-and-reference-unprovided-input/sizes.json
  • packages/runtime-tags/src/tests/fixtures/try-tag-closure/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/ambiguous-tags-and-components-dir/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/lazy-class-child-ssr-toggle/sizes.json
  • packages/runtime-tags/src/tests/fixtures/destructure-and-reference-input/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/let/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/interop-stateless-tags-to-class/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/interop-nested-attr-tags-class-to-tags/sizes.json
  • packages/runtime-tags/src/tests/fixtures/debug-tag/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/interop-class-to-tags-import/sizes.json
  • packages/runtime-tags/src/tests/fixtures/pure-signal-resume-function/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/interop-tag-params-tags-to-class/sizes.json
  • packages/runtime-tags/src/tests/fixtures-interop/interop-class-in-components-in-tags-dir/sizes.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/runtime-tags/src/tests/fixtures/const-tag-fold/test.ts
  • packages/runtime-tags/src/tests/fixtures/const-tag-fold/template.marko

Comment thread packages/runtime-tags/src/translator/core/const.ts Outdated
Comment on lines +148 to +155
function canInlineValue(value: unknown) {
switch (typeof value) {
case "string":
case "number":
case "boolean":
case "bigint":
case "undefined":
return true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Restrict numeric folding to finite numbers.

Line 151 admits NaN and ±Infinity, but this optimization is scoped to finite numbers. Keep non-finite values on the existing runtime path.

🐛 Proposed fix
 function canInlineValue(value: unknown) {
   switch (typeof value) {
+    case "number":
+      return Number.isFinite(value);
     case "string":
-    case "number":
     case "boolean":
     case "bigint":
     case "undefined":
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function canInlineValue(value: unknown) {
switch (typeof value) {
case "string":
case "number":
case "boolean":
case "bigint":
case "undefined":
return true;
function canInlineValue(value: unknown) {
switch (typeof value) {
case "number":
return Number.isFinite(value);
case "string":
case "boolean":
case "bigint":
case "undefined":
return true;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/runtime-tags/src/translator/core/const.ts` around lines 148 - 155,
The canInlineValue function currently returns true for all values of type
"number", which includes NaN and Infinity, but numeric inlining should only
apply to finite numbers. Add a check to filter out non-finite numbers by testing
if the value is finite using Number.isFinite() when the type is "number", so
that non-finite values like NaN and Infinity continue through the runtime path
instead of being inlined.

@DylanPiercey DylanPiercey force-pushed the claude/opt-const-folding branch 4 times, most recently from fc3fb04 to de86c97 Compare June 20, 2026 22:46
Marks a `<const>` whose value is a compile-time primitive as a constant
binding carrying the literal value. Bare references fold into the static
template output via the consumer's own evaluation, while reactive positions
(handlers, expressions) inline the literal through the existing
read-replacement walk. Such constants carry no reactive signal, are never
serialized, and do not register as closures when read from a nested section.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G1bgkqJCLUsEz3xsossMCN
@DylanPiercey DylanPiercey force-pushed the claude/opt-const-folding branch from de86c97 to 46da484 Compare June 20, 2026 22:53
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