-
-
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.
fix: implict children tweaks (#2285)
- ignore comments when determining whether or not to add an implicit children prop #2263 - do static analysis of the destructuring to see whether or not children is destructured from `$props()`, and if not, add the implicit children prop if there's a slot. This results in less confusing type errors when transforming to runes mode and using a slot
- Loading branch information
1 parent
19694d6
commit efe8463
Showing
16 changed files
with
202 additions
and
69 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
17 changes: 17 additions & 0 deletions
17
packages/svelte2tsx/test/svelte2tsx/samples/runes-with-slots/expected-svelte5.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" /> | ||
;function render() { | ||
|
||
/** @type {SomeType} */ | ||
let { a, b } = $props(); | ||
let x = $state(0); | ||
let y = $derived(x * 2); | ||
|
||
/*Ωignore_startΩ*/;const __sveltets_createSlot = __sveltets_2_createCreateSlot();/*Ωignore_endΩ*/; | ||
async () => { | ||
|
||
{ __sveltets_createSlot("default", { x,y,});}}; | ||
let $$implicit_children = __sveltets_2_snippet({x:x, y:y}); | ||
return { props: /** @type {{children?: typeof $$implicit_children} & SomeType} */({}), slots: {'default': {x:x, y:y}}, events: {} }} | ||
|
||
export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_partial(['children'], __sveltets_2_with_any_event(render()))) { | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/svelte2tsx/test/svelte2tsx/samples/runes-with-slots/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,16 @@ | ||
///<reference types="svelte" /> | ||
;function render() { | ||
|
||
/** @type {SomeType} */ | ||
let { a, b } = $props(); | ||
let x = $state(0); | ||
let y = $derived(x * 2); | ||
|
||
/*Ωignore_startΩ*/;const __sveltets_createSlot = __sveltets_2_createCreateSlot();/*Ωignore_endΩ*/; | ||
async () => { | ||
|
||
{ __sveltets_createSlot("default", { x,y,});}}; | ||
return { props: /** @type {SomeType} */({}), slots: {'default': {x:x, y:y}}, events: {} }} | ||
|
||
export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_partial(__sveltets_2_with_any_event(render()))) { | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/svelte2tsx/test/svelte2tsx/samples/runes-with-slots/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,8 @@ | ||
<script> | ||
/** @type {SomeType} */ | ||
let { a, b } = $props(); | ||
let x = $state(0); | ||
let y = $derived(x * 2); | ||
</script> | ||
|
||
<slot {x} {y} /> |
11 changes: 4 additions & 7 deletions
11
packages/svelte2tsx/test/svelte2tsx/samples/runes/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 |
---|---|---|
@@ -1,16 +1,13 @@ | ||
///<reference types="svelte" /> | ||
;function render() { | ||
|
||
/** @type {a: number, b: string} */ | ||
/** @typedef {{a: number, b: string}} $$_sveltets_Props *//** @type {$$_sveltets_Props} */ | ||
let { a, b } = $props(); | ||
let x = $state(0); | ||
let y = $derived(x * 2); | ||
|
||
/*Ωignore_startΩ*/;const __sveltets_createSlot = __sveltets_2_createCreateSlot();/*Ωignore_endΩ*/; | ||
async () => { | ||
|
||
{ __sveltets_createSlot("default", { x,y,});}}; | ||
return { props: /** @type {a: number, b: string} */({}), slots: {'default': {x:x, y:y}}, events: {} }} | ||
; | ||
async () => {}; | ||
return { props: /** @type {$$_sveltets_Props} */({}), slots: {}, events: {} }} | ||
|
||
export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_partial(__sveltets_2_with_any_event(render()))) { | ||
} |
4 changes: 1 addition & 3 deletions
4
packages/svelte2tsx/test/svelte2tsx/samples/runes/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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
<script> | ||
/** @type {a: number, b: string} */ | ||
/** @type {{a: number, b: string}} */ | ||
let { a, b } = $props(); | ||
let x = $state(0); | ||
let y = $derived(x * 2); | ||
</script> | ||
|
||
<slot {x} {y} /> |
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
28 changes: 19 additions & 9 deletions
28
packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-generics/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 |
---|---|---|
@@ -1,15 +1,25 @@ | ||
///<reference types="svelte" /> | ||
;function render() { | ||
;type $$_sveltets_Props = { a: number, b: string }; | ||
;function render<T>() { | ||
;type $$_sveltets_Props = { a: T, b: string }; | ||
let { a, b } = $props<$$_sveltets_Props>(); | ||
let x = $state(0); | ||
let x = $state<T>(0); | ||
let y = $derived(x * 2); | ||
; | ||
async () => {}; | ||
return { props: {} as any as $$_sveltets_Props, slots: {}, events: {} }} | ||
class __sveltets_Render<T> { | ||
props() { | ||
return render<T>().props; | ||
} | ||
events() { | ||
return __sveltets_2_with_any_event(render<T>()).events; | ||
} | ||
slots() { | ||
return render<T>().slots; | ||
} | ||
} | ||
|
||
/*Ωignore_startΩ*/;const __sveltets_createSlot = __sveltets_2_createCreateSlot();/*Ωignore_endΩ*/; | ||
async () => { | ||
|
||
{ __sveltets_createSlot("default", { x,y,});}}; | ||
return { props: {} as any as $$_sveltets_Props, slots: {'default': {x:x, y:y}}, events: {} }} | ||
|
||
export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_with_any_event(render())) { | ||
import { SvelteComponentTyped as __SvelteComponentTyped__ } from "svelte" | ||
export default class Input__SvelteComponent_<T> extends __SvelteComponentTyped__<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> { | ||
} |
8 changes: 3 additions & 5 deletions
8
packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-generics/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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
<script lang="ts"> | ||
let { a, b } = $props<{ a: number, b: string }>(); | ||
let x = $state(0); | ||
<script lang="ts" generics="T"> | ||
let { a, b } = $props<{ a: T, b: string }>(); | ||
let x = $state<T>(0); | ||
let y = $derived(x * 2); | ||
</script> | ||
|
||
<slot {x} {y} /> |
29 changes: 29 additions & 0 deletions
29
packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-with-slot/expected-svelte5.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,29 @@ | ||
///<reference types="svelte" /> | ||
;function render<T>() { | ||
;type $$_sveltets_Props = { a: T, b: string }; | ||
let { a, b } = $props<$$_sveltets_Props>(); | ||
let x = $state<T>(0); | ||
let y = $derived(x * 2); | ||
|
||
/*Ωignore_startΩ*/;const __sveltets_createSlot = __sveltets_2_createCreateSlot();/*Ωignore_endΩ*/; | ||
async () => { | ||
|
||
{ __sveltets_createSlot("default", { x,y,});}}; | ||
let $$implicit_children = __sveltets_2_snippet({x:x, y:y}); | ||
return { props: {} as any as $$_sveltets_Props & { children?: typeof $$implicit_children }, slots: {'default': {x:x, y:y}}, events: {} }} | ||
class __sveltets_Render<T> { | ||
props() { | ||
return render<T>().props; | ||
} | ||
events() { | ||
return __sveltets_2_with_any_event(render<T>()).events; | ||
} | ||
slots() { | ||
return render<T>().slots; | ||
} | ||
} | ||
|
||
|
||
import { SvelteComponentTyped as __SvelteComponentTyped__ } from "svelte" | ||
export default class Input__SvelteComponent_<T> extends __SvelteComponentTyped__<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> { | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-with-slot/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,28 @@ | ||
///<reference types="svelte" /> | ||
;function render<T>() { | ||
;type $$_sveltets_Props = { a: T, b: string }; | ||
let { a, b } = $props<$$_sveltets_Props>(); | ||
let x = $state<T>(0); | ||
let y = $derived(x * 2); | ||
|
||
/*Ωignore_startΩ*/;const __sveltets_createSlot = __sveltets_2_createCreateSlot();/*Ωignore_endΩ*/; | ||
async () => { | ||
|
||
{ __sveltets_createSlot("default", { x,y,});}}; | ||
return { props: {} as any as $$_sveltets_Props, slots: {'default': {x:x, y:y}}, events: {} }} | ||
class __sveltets_Render<T> { | ||
props() { | ||
return render<T>().props; | ||
} | ||
events() { | ||
return __sveltets_2_with_any_event(render<T>()).events; | ||
} | ||
slots() { | ||
return render<T>().slots; | ||
} | ||
} | ||
|
||
|
||
import { SvelteComponentTyped as __SvelteComponentTyped__ } from "svelte" | ||
export default class Input__SvelteComponent_<T> extends __SvelteComponentTyped__<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> { | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-with-slot/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,7 @@ | ||
<script lang="ts" generics="T"> | ||
let { a, b } = $props<{ a: T, b: string }>(); | ||
let x = $state<T>(0); | ||
let y = $derived(x * 2); | ||
</script> | ||
|
||
<slot {x} {y} /> |
Oops, something went wrong.