-
Notifications
You must be signed in to change notification settings - Fork 12
fix: hoisted tag vars no longer collapse to never
#582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
briancarbone
wants to merge
1
commit into
marko-js:main
Choose a base branch
from
briancarbone:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "@marko/language-server": patch | ||
| "@marko/language-tools": patch | ||
| "@marko/ts-plugin": patch | ||
| "@marko/type-check": patch | ||
| "marko-vscode": patch | ||
| --- | ||
|
|
||
| Fix tag variables being typed `never` when referenced before their declaration or hoisted out of control flow, since `Marko._.hoist` only preserved function-typed values. Most visibly, `<style/styles>` used above the style tag errored with "Property does not exist on type 'never'". |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,9 @@ | ||
| # Cleanup | ||
|
|
||
| Duplication, dead code, inconsistencies, refactor opportunities. Format and rules: [README.md](README.md). | ||
|
|
||
| ## Plumb the source node (or tag kind) through `getProgramBindings` | ||
|
|
||
| `packages/language-tools/src/extractors/script/util/attach-scopes.ts` › `getProgramBindings` | 2026-07-30 | impact:low | effort:med | ||
|
|
||
| `ProgramBinding` exposes only `{ name, sources }` (plus mutation info), dropping the declaring node/tag. This makes it impossible for the script extractor's program-level hoist emission (`packages/language-tools/src/extractors/script/index.ts` › `#writeProgram`) to treat any tag kind specially — e.g. declaring a `<style/styles>` CSS-module var with its statically known selector type at program scope instead of routing it through `Marko._.hoist`. If per-tag-kind program-level typing is ever wanted, the binding needs to carry its `Node.Tag` (or at least the tag name). Re-verify: inspect the `ProgramBinding` interface in attach-scopes.ts and confirm it has no node reference. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,9 @@ | ||
| # Performance | ||
|
|
||
| Runtime speed and bundle size opportunities. Format and rules: [README.md](README.md). | ||
|
|
||
| ## Tag-var hoisting is unconditional — no reference analysis | ||
|
|
||
| `packages/language-tools/src/extractors/script/util/attach-scopes.ts` › `attachScopes` | 2026-07-30 | impact:low | effort:high | ||
|
|
||
| Every tag-var binding is pushed to `potentialHoists` unconditionally, and every nested tag var whose walk reaches program scope becomes a `HoistedBinding` — whether or not anything outside its section references it. Each such binding costs a program-level `Marko._.hoist(...)` const plus `readScope`/`readScopes` machinery in the extracted TS, which the TypeScript checker must then evaluate per template. A reference-aware pass (only hoist names actually referenced outside their declaring scope) would shrink extracted output and checker work on templates with many tag vars. Re-verify: extract any template with a tag var inside an `<if>` that is never referenced elsewhere and observe the emitted `hoist`/`readScope` code. |
2 changes: 1 addition & 1 deletion
2
...c/__tests__/fixtures/script/style-tag-var/__snapshots__/style-tag-var.expected/index.html
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| <main data-marko-node-id="0" id="dynamic" class="dynamic"></main><div data-marko-node-id="1" class="dynamic"></div> | ||
| <section data-marko-node-id="0" class="dynamic"></section><main data-marko-node-id="1" id="dynamic" class="dynamic"></main><div data-marko-node-id="2" class="dynamic"></div> |
33 changes: 21 additions & 12 deletions
33
...s__/fixtures/script/style-tag-var/__snapshots__/style-tag-var.expected/index.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,31 @@ | ||
| ## Hovers | ||
| ### Ln 13, Col 35 | ||
| ### Ln 1, Col 23 | ||
| ```marko | ||
| 11 | </style> | ||
| 12 | | ||
| > 13 | <main id=styles.main class=styles.button/> | ||
| > 1 | <section class=styles.button/> | ||
| | ^ (property) "button": string | ||
| 2 | // ^? | ||
| 3 | <style/styles> | ||
| 4 | .button { | ||
| ``` | ||
|
|
||
| ### Ln 15, Col 35 | ||
| ```marko | ||
| 13 | </style> | ||
| 14 | | ||
| > 15 | <main id=styles.main class=styles.button/> | ||
| | ^ (property) "button": string | ||
| 14 | // ^? | ||
| 15 | <div class=styles.missing/> | ||
| 16 | | ||
| 16 | // ^? | ||
| 17 | <div class=styles.missing/> | ||
| 18 | | ||
| ``` | ||
|
|
||
| ## Diagnostics | ||
| ### Ln 15, Col 19 | ||
| ### Ln 17, Col 19 | ||
| ```marko | ||
| 13 | <main id=styles.main class=styles.button/> | ||
| 14 | // ^? | ||
| > 15 | <div class=styles.missing/> | ||
| 15 | <main id=styles.main class=styles.button/> | ||
| 16 | // ^? | ||
| > 17 | <div class=styles.missing/> | ||
| | ^^^^^^^ Property 'missing' does not exist on type '{ button: string; main: string; }'. | ||
| 16 | | ||
| 18 | | ||
| ``` | ||
|
|
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
2 changes: 2 additions & 0 deletions
2
packages/language-server/src/__tests__/fixtures/script/style-tag-var/index.marko
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| <section class=styles.button/> | ||
| // ^? | ||
| <style/styles> | ||
| .button { | ||
| color: blue; | ||
|
|
||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Record actionable feedback in
agent-feedback/README.md. Both additions document out-of-scope follow-ups but omit the required README record.agent-feedback/cleanup.md#L4-L9: add the ProgramBinding follow-up toagent-feedback/README.md.agent-feedback/perf.md#L4-L9: add the tag-variable hoisting performance follow-up toagent-feedback/README.md.📍 Affects 2 files
agent-feedback/cleanup.md#L4-L9(this comment)agent-feedback/perf.md#L4-L9🤖 Prompt for AI Agents
Source: Coding guidelines