feat(sdk): variable usage scan + preview-values adapter seam#2048
Open
Conversation
3 tasks
Collaborator
Author
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Jul 8, 2026
c9bc8fb to
d3ab9db
Compare
a4cd1b5 to
a2085a5
Compare
Third PR of the template-variables Studio stack.
- parsers: scanVariableUsage(scriptText) — browser-safe acorn scan for
getVariables() reads (destructuring, member access, single-alias
tracking). Anything opaque (computed keys, rest spreads, escaping values
object, parse errors) flips scanIncomplete so consumers treat usedIds as
a lower bound rather than a fact. Compositions have no DOM binding for
variable reads, so script scanning is the only usage signal.
- sdk: comp.getVariableUsage() cross-references the scan of every inline
script against the declared schema → { usedIds, unusedDeclarations,
undeclaredReads, scanIncomplete }.
- sdk: optional PreviewAdapter.setPreviewVariables(values | null) +
comp.setPreviewVariables() delegation — the platform seam for
"preview with these values" (ephemeral, never persisted; values must
reach the runtime before composition scripts run). Studio's adapter
implements it in a later PR; embedders can implement their own.
- fallow: targeted suppressions — complexity on the three AST classifiers
(precedent: gsapParserAcorn) and code-duplication markers on two
pre-existing mutate.ts clone groups the stack's line shifts re-attributed
to this diff.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
d3ab9db to
ed9f222
Compare
a2085a5 to
6acf033
Compare
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.

What
Third PR of the template-variables stack: usage analysis + the preview-values adapter seam.
scanVariableUsage(scriptText)— browser-safe acorn scan forgetVariables()reads (destructuring, member access, single-alias tracking). Anything opaque (computed keys, rest spreads, escaping values object, parse errors) flipsscanIncompleteso consumers treatusedIdsas a lower bound, never a factcomp.getVariableUsage()cross-references the scan of every inline script against the declared schema →{ usedIds, unusedDeclarations, undeclaredReads, scanIncomplete }PreviewAdapter.setPreviewVariables(values | null)+comp.setPreviewVariables()delegation — the platform seam for "preview with these values" (ephemeral, never persisted)window.__hfVariablesreads now flipscanIncomplete(they're invisible to the scanner),var(--id)CSS consumers count as usage (a variable consumed only via CSS must not be badged unused), and scans are content-keyed-cached (same rationale as_gsapLabelCache)Why
Compositions read variables via JS calls — there's no DOM attribute to scan — so script analysis is the only way to answer "which variables does this composition actually use". The honest-lower-bound design (scanIncomplete) is the load-bearing decision: a wrong "unused" badge invites users to delete variables their render depends on.
Test plan
variableUsage.test.ts(9 scanner cases incl. alias tracking, escape flagging, parse errors),session.variableusage.test.ts(cross-reference report, adapter delegation)🤖 Generated with Claude Code