diff --git a/.changeset/hoisted-tag-var-never.md b/.changeset/hoisted-tag-var-never.md new file mode 100644 index 00000000..aa788d10 --- /dev/null +++ b/.changeset/hoisted-tag-var-never.md @@ -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, ` - 12 | -> 13 |
+> 1 |
+ | ^ (property) "button": string + 2 | // ^? + 3 | + 14 | +> 15 |
| ^ (property) "button": string - 14 | // ^? - 15 |
- 16 | + 16 | // ^? + 17 |
+ 18 | ``` ## Diagnostics -### Ln 15, Col 19 +### Ln 17, Col 19 ```marko - 13 |
- 14 | // ^? -> 15 |
+ 15 |
+ 16 | // ^? +> 17 |
| ^^^^^^^ Property 'missing' does not exist on type '{ button: string; main: string; }'. - 16 | + 18 | ``` diff --git a/packages/language-server/src/__tests__/fixtures/script/style-tag-var/__snapshots__/style-tag-var.expected/index.ts b/packages/language-server/src/__tests__/fixtures/script/style-tag-var/__snapshots__/style-tag-var.expected/index.ts index ba19cdfe..1130a1f9 100644 --- a/packages/language-server/src/__tests__/fixtures/script/style-tag-var/__snapshots__/style-tag-var.expected/index.ts +++ b/packages/language-server/src/__tests__/fixtures/script/style-tag-var/__snapshots__/style-tag-var.expected/index.ts @@ -7,15 +7,21 @@ export interface Input {} (Marko._.error, Marko._.any as MarkoRun.Context), ); const styles = Marko._.hoist(() => __marko_internal_hoist__styles); + Marko._.renderNativeTag("section")()()({ + class: styles.button, + }); { const styles = Marko._.any as { button: string; main: string }; - Marko._.renderNativeTag("style")()()({ - [Marko._.content]: (() => { - return () => { - return Marko._.voidReturn; - }; - })(), - }); + Marko._.renderNativeTag("style")()()( + // ^? + { + [Marko._.content]: (() => { + return () => { + return Marko._.voidReturn; + }; + })(), + }, + ); Marko._.renderNativeTag("main")()()({ id: styles.main, class: styles.button, diff --git a/packages/language-server/src/__tests__/fixtures/script/style-tag-var/index.marko b/packages/language-server/src/__tests__/fixtures/script/style-tag-var/index.marko index d9e8a39c..91c46a7a 100644 --- a/packages/language-server/src/__tests__/fixtures/script/style-tag-var/index.marko +++ b/packages/language-server/src/__tests__/fixtures/script/style-tag-var/index.marko @@ -1,3 +1,5 @@ +
+// ^?