-
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: hoist snippets to module context if possible
- Loading branch information
1 parent
050ecc1
commit 761eb3c
Showing
10 changed files
with
199 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
50 changes: 50 additions & 0 deletions
50
packages/svelte2tsx/test/svelte2tsx/samples/snippet-module-hoist-1.v5/expectedv2.ts
This file contains 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,50 @@ | ||
///<reference types="svelte" /> | ||
; | ||
let module = true; | ||
;; | ||
|
||
import { imported } from './x'; | ||
const hoistable1/*Ωignore_positionΩ*/ = ()/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => { | ||
{ svelteHTML.createElement("div", {}); } | ||
};return __sveltets_2_any(0)}; const hoistable2/*Ωignore_positionΩ*/ = (bar)/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => { | ||
{ svelteHTML.createElement("div", {});bar; } | ||
};return __sveltets_2_any(0)}; const hoistable3/*Ωignore_positionΩ*/ = (bar: string)/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => { | ||
{ svelteHTML.createElement("div", {});bar; } | ||
};return __sveltets_2_any(0)}; const hoistable4/*Ωignore_positionΩ*/ = (foo)/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => { | ||
{ svelteHTML.createElement("div", {});foo; } | ||
};return __sveltets_2_any(0)}; const hoistable5/*Ωignore_positionΩ*/ = ()/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => { | ||
{ svelteHTML.createElement("button", { "onclick":e => e,}); } | ||
};return __sveltets_2_any(0)}; const hoistable6/*Ωignore_positionΩ*/ = ()/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => { | ||
{ svelteHTML.createElement("div", {});module; } | ||
};return __sveltets_2_any(0)}; const hoistable7/*Ωignore_positionΩ*/ = ()/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => { | ||
{ svelteHTML.createElement("div", {});imported; } | ||
};return __sveltets_2_any(0)};function render() { | ||
const not_hoistable/*Ωignore_positionΩ*/ = ()/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => { | ||
{ svelteHTML.createElement("div", {});foo; } | ||
};return __sveltets_2_any(0)}; | ||
|
||
let foo = true; | ||
; | ||
async () => { | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}; | ||
return { props: /** @type {Record<string, never>} */ ({}), exports: {}, bindings: "", slots: {}, events: {} }} | ||
const Input__SvelteComponent_ = __sveltets_2_isomorphic_component(__sveltets_2_partial(__sveltets_2_with_any_event(render()))); | ||
/*Ωignore_startΩ*/type Input__SvelteComponent_ = InstanceType<typeof Input__SvelteComponent_>; | ||
/*Ωignore_endΩ*/export default Input__SvelteComponent_; |
40 changes: 40 additions & 0 deletions
40
packages/svelte2tsx/test/svelte2tsx/samples/snippet-module-hoist-1.v5/input.svelte
This file contains 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,40 @@ | ||
<script module> | ||
let module = true; | ||
</script> | ||
|
||
<script lang="ts"> | ||
import { imported } from './x'; | ||
let foo = true; | ||
</script> | ||
|
||
{#snippet hoistable1()} | ||
<div>hello</div> | ||
{/snippet} | ||
|
||
{#snippet hoistable2(bar)} | ||
<div>{bar}</div> | ||
{/snippet} | ||
|
||
{#snippet hoistable3(bar: string)} | ||
<div>{bar}</div> | ||
{/snippet} | ||
|
||
{#snippet hoistable4(foo)} | ||
<div>{foo}</div> | ||
{/snippet} | ||
|
||
{#snippet hoistable5()} | ||
<button onclick={e => e}>click</button> | ||
{/snippet} | ||
|
||
{#snippet hoistable6()} | ||
<div>{module}</div> | ||
{/snippet} | ||
|
||
{#snippet hoistable7()} | ||
<div>{imported}</div> | ||
{/snippet} | ||
|
||
{#snippet not_hoistable()} | ||
<div>{foo}</div> | ||
{/snippet} |
21 changes: 21 additions & 0 deletions
21
packages/svelte2tsx/test/svelte2tsx/samples/snippet-module-hoist-2.v5/expectedv2.ts
This file contains 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,21 @@ | ||
///<reference types="svelte" /> | ||
; | ||
import { imported } from './x'; | ||
function render() { | ||
const hoistable/*Ωignore_positionΩ*/ = ()/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => { | ||
{ svelteHTML.createElement("div", {}); } | ||
};return __sveltets_2_any(0)}; const not_hoistable/*Ωignore_positionΩ*/ = ()/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => { | ||
{ svelteHTML.createElement("div", {});foo; } | ||
};return __sveltets_2_any(0)}; | ||
|
||
let foo = true; | ||
; | ||
async () => { | ||
|
||
|
||
|
||
}; | ||
return { props: /** @type {Record<string, never>} */ ({}), exports: {}, bindings: "", slots: {}, events: {} }} | ||
const Input__SvelteComponent_ = __sveltets_2_isomorphic_component(__sveltets_2_partial(__sveltets_2_with_any_event(render()))); | ||
/*Ωignore_startΩ*/type Input__SvelteComponent_ = InstanceType<typeof Input__SvelteComponent_>; | ||
/*Ωignore_endΩ*/export default Input__SvelteComponent_; |
12 changes: 12 additions & 0 deletions
12
packages/svelte2tsx/test/svelte2tsx/samples/snippet-module-hoist-2.v5/input.svelte
This file contains 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,12 @@ | ||
<script lang="ts"> | ||
import { imported } from './x'; | ||
let foo = true; | ||
</script> | ||
|
||
{#snippet hoistable()} | ||
<div>hello</div> | ||
{/snippet} | ||
|
||
{#snippet not_hoistable()} | ||
<div>{foo}</div> | ||
{/snippet} |
17 changes: 17 additions & 0 deletions
17
packages/svelte2tsx/test/svelte2tsx/samples/snippet-module-hoist-3.v5/expectedv2.ts
This file contains 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,17 @@ | ||
///<reference types="svelte" /> | ||
; | ||
let foo = true; | ||
; const hoistable1/*Ωignore_positionΩ*/ = ()/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => { | ||
{ svelteHTML.createElement("div", {}); } | ||
};return __sveltets_2_any(0)}; const hoistable2/*Ωignore_positionΩ*/ = ()/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => { | ||
{ svelteHTML.createElement("div", {});foo; } | ||
};return __sveltets_2_any(0)};;function render() { | ||
async () => { | ||
|
||
|
||
|
||
}; | ||
return { props: /** @type {Record<string, never>} */ ({}), exports: {}, bindings: "", slots: {}, events: {} }} | ||
const Input__SvelteComponent_ = __sveltets_2_isomorphic_component(__sveltets_2_partial(__sveltets_2_with_any_event(render()))); | ||
/*Ωignore_startΩ*/type Input__SvelteComponent_ = InstanceType<typeof Input__SvelteComponent_>; | ||
/*Ωignore_endΩ*/export default Input__SvelteComponent_; |
11 changes: 11 additions & 0 deletions
11
packages/svelte2tsx/test/svelte2tsx/samples/snippet-module-hoist-3.v5/input.svelte
This file contains 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,11 @@ | ||
<script module lang="ts"> | ||
let foo = true; | ||
</script> | ||
|
||
{#snippet hoistable1()} | ||
<div>hello</div> | ||
{/snippet} | ||
|
||
{#snippet hoistable2()} | ||
<div>{foo}</div> | ||
{/snippet} |