Skip to content

Analysis: Map state down to the nodes that read it - #2189

Merged
marcoroth merged 1 commit into
analysis-affected-templatesfrom
analysis-dependency-index
Aug 11, 2026
Merged

Analysis: Map state down to the nodes that read it#2189
marcoroth merged 1 commit into
analysis-affected-templatesfrom
analysis-dependency-index

Conversation

@marcoroth

@marcoroth marcoroth commented Aug 11, 2026

Copy link
Copy Markdown
Owner

This pull request takes dependency tracking from the file level to the node level.

affectedTemplates answers which templates a change invalidates. That is enough to decide what to re-render, but not enough to decide what to re-render within a template. dependencyIndex answers the finer question:

dependencyIndex(Herb, "app/views/posts/show.html.erb", source)
// {
//   "@post": [
//     { kind: "text_content", expression: "@post.title", location: "1:9",  nodePath: [0, 1, 1] },
//     { kind: "text_content", expression: "@post.body",  location: "1:35", nodePath: [0, 2, 1] },
//   ],
// }

Each entry records what kind of node reads the state, the expression that reads it, where it is, and a path of child indices leading back to it.

text_content for an ERB tag in the body, attribute_value for one inside an attribute, which also records which attribute:

<div class="<%= @active ? "on" : "off" %>">

render for a call that passes state to another template, and conditional for an if, unless or case. A conditional counts when anything inside it reads the state, not just its own condition, because the whole branch is what gets re-rendered:

<div><% if @admin %><%= @post.name %><% end %></div>

@admin is read by the condition, and @post by the body, so both map to the conditional, and @post maps to the inner tag as well.

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

🌿 Interactive Playground and Documentation Preview

A preview deployment has been built for this pull request. Try out the changes live in the interactive playground:


🌱 Grown from commit 6580105


✅ Preview deployment has been cleaned up.

@pkg-pr-new

pkg-pr-new Bot commented Aug 11, 2026

Copy link
Copy Markdown
npx https://pkg.pr.new/@herb-tools/formatter@2189
npx https://pkg.pr.new/@herb-tools/language-server@2189
npx https://pkg.pr.new/@herb-tools/linter@2189

commit: 6580105

@marcoroth
marcoroth marked this pull request as ready for review August 11, 2026 17:45
@marcoroth
marcoroth merged commit 2ebb02a into main Aug 11, 2026
23 checks passed
@marcoroth
marcoroth deleted the analysis-dependency-index branch August 11, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

analysis typescript TypeScript source across the javascript/ packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant