-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) implement generics attr on script tags (#2020)
- Loading branch information
1 parent
2f25562
commit 932b8d3
Showing
17 changed files
with
260 additions
and
52 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
5 changes: 5 additions & 0 deletions
5
packages/svelte-vscode/test/grammar/samples/script-generics-multiline/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,5 @@ | ||
<script lang="ts" generics=" | ||
T extends 'a' |'b' |'c' | ||
"> | ||
export let t: T; | ||
</script> |
28 changes: 28 additions & 0 deletions
28
packages/svelte-vscode/test/grammar/samples/script-generics-multiline/input.svelte.snap
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 @@ | ||
><script lang="ts" generics=" | ||
#^ source.svelte meta.script.svelte meta.tag.start.svelte punctuation.definition.tag.begin.svelte | ||
# ^^^^^^ source.svelte meta.script.svelte meta.tag.start.svelte entity.name.tag.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte | ||
# ^^^^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.attribute.lang.svelte entity.other.attribute-name.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.attribute.lang.svelte punctuation.separator.key-value.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.attribute.lang.svelte string.quoted.svelte punctuation.definition.string.begin.svelte | ||
# ^^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.attribute.lang.svelte string.quoted.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.attribute.lang.svelte string.quoted.svelte punctuation.definition.string.end.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte | ||
# ^^^^^^^^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte entity.other.attribute-name.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte punctuation.separator.key-value.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte punctuation.definition.string.begin.svelte | ||
> T extends 'a' |'b' |'c' | ||
#^^^^^^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.embedded.expression.svelte source.ts | ||
# ^^^^^^^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.embedded.expression.svelte source.ts storage.modifier.ts | ||
# ^^^^^^^^^^^^^^^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.embedded.expression.svelte source.ts | ||
> "> | ||
#^^^^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.embedded.expression.svelte source.ts | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte punctuation.definition.string.end.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte punctuation.definition.tag.end.svelte | ||
> export let t: T; | ||
#^^^^^^^^^^^^^^^^^^^^^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.embedded.block.svelte source.ts | ||
></script> | ||
#^^ source.svelte meta.script.svelte meta.tag.end.svelte punctuation.definition.tag.begin.svelte | ||
# ^^^^^^ source.svelte meta.script.svelte meta.tag.end.svelte entity.name.tag.svelte | ||
# ^ source.svelte meta.script.svelte meta.tag.end.svelte punctuation.definition.tag.end.svelte | ||
> |
3 changes: 3 additions & 0 deletions
3
packages/svelte-vscode/test/grammar/samples/script-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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<script generics="T" lang="ts"> | ||
export let t: T; | ||
</script> |
23 changes: 23 additions & 0 deletions
23
packages/svelte-vscode/test/grammar/samples/script-generics/input.svelte.snap
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,23 @@ | ||
><script generics="T" lang="ts"> | ||
#^ source.svelte meta.script.svelte meta.tag.start.svelte punctuation.definition.tag.begin.svelte | ||
# ^^^^^^ source.svelte meta.script.svelte meta.tag.start.svelte entity.name.tag.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte | ||
# ^^^^^^^^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte entity.other.attribute-name.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte punctuation.separator.key-value.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte punctuation.definition.string.begin.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.embedded.expression.svelte source.ts | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte punctuation.definition.string.end.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte | ||
# ^^^^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.attribute.lang.svelte entity.other.attribute-name.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.attribute.lang.svelte punctuation.separator.key-value.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.attribute.lang.svelte string.quoted.svelte punctuation.definition.string.begin.svelte | ||
# ^^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.attribute.lang.svelte string.quoted.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte meta.attribute.lang.svelte string.quoted.svelte punctuation.definition.string.end.svelte | ||
# ^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.tag.start.svelte punctuation.definition.tag.end.svelte | ||
> export let t: T; | ||
#^^^^^^^^^^^^^^^^^^^^^ source.svelte meta.script.svelte meta.lang.ts.svelte meta.embedded.block.svelte source.ts | ||
></script> | ||
#^^ source.svelte meta.script.svelte meta.tag.end.svelte punctuation.definition.tag.begin.svelte | ||
# ^^^^^^ source.svelte meta.script.svelte meta.tag.end.svelte entity.name.tag.svelte | ||
# ^ source.svelte meta.script.svelte meta.tag.end.svelte punctuation.definition.tag.end.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
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
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
39 changes: 39 additions & 0 deletions
39
packages/svelte2tsx/test/svelte2tsx/samples/ts-generics-attribute1/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,39 @@ | ||
///<reference types="svelte" /> | ||
; | ||
import { createEventDispatcher } from 'svelte'; | ||
function render<A, B extends keyof A, C extends boolean>() { | ||
|
||
|
||
|
||
let a: A/*Ωignore_startΩ*/;a = __sveltets_2_any(a);/*Ωignore_endΩ*/; | ||
let b: B/*Ωignore_startΩ*/;b = __sveltets_2_any(b);/*Ωignore_endΩ*/; | ||
let c: C/*Ωignore_startΩ*/;c = __sveltets_2_any(c);/*Ωignore_endΩ*/; | ||
|
||
const dispatch = createEventDispatcher<{a: A}>(); | ||
|
||
function getA() { | ||
return a; | ||
} | ||
|
||
/*Ωignore_startΩ*/;const __sveltets_createSlot = __sveltets_2_createCreateSlot();/*Ωignore_endΩ*/; | ||
async () => { | ||
|
||
{ __sveltets_createSlot("default", { c,});}}; | ||
return { props: {a: a , b: b , c: c , getA: getA} as {a: A, b: B, c: C, getA?: typeof getA}, slots: {'default': {c:c}}, events: {...__sveltets_2_toEventTypings<{a: A}>()} }} | ||
class __sveltets_Render<A,B extends keyof A,C extends boolean> { | ||
props() { | ||
return render<A,B,C>().props; | ||
} | ||
events() { | ||
return __sveltets_2_with_any_event(render<A,B,C>()).events; | ||
} | ||
slots() { | ||
return render<A,B,C>().slots; | ||
} | ||
} | ||
|
||
|
||
import { SvelteComponentTyped as __SvelteComponentTyped__ } from "svelte" | ||
export default class Input__SvelteComponent_<A,B extends keyof A,C extends boolean> extends __SvelteComponentTyped__<ReturnType<__sveltets_Render<A,B,C>['props']>, ReturnType<__sveltets_Render<A,B,C>['events']>, ReturnType<__sveltets_Render<A,B,C>['slots']>> { | ||
get getA() { return __sveltets_2_nonNullable(this.$$prop_def.getA) } | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/svelte2tsx/test/svelte2tsx/samples/ts-generics-attribute1/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,15 @@ | ||
<script lang="ts" generics="A, B extends keyof A, C extends boolean"> | ||
import { createEventDispatcher } from 'svelte'; | ||
export let a: A; | ||
export let b: B; | ||
export let c: C; | ||
const dispatch = createEventDispatcher<{a: A}>(); | ||
export function getA() { | ||
return a; | ||
} | ||
</script> | ||
|
||
<slot {c} /> |
Oops, something went wrong.