-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) control flow for stores (#719)
#493 $store --> (__svelte_store_get(store), $store) By using the comma operand we allow TypeScript's control flow to work. Before that, it was $store --> __svelte_store_get(store) which loses control flow info every time. findReferences and getDefinitions return one additional false positive reference (the svelte2tsx-added declaration) which is a TODO for later Co-authored-by: Simon Holthausen <simon.holthausen@accso.de> Co-authored-by: GrzegorzKazana <kazana.grzegorz@gmail.com>
- Loading branch information
1 parent
80a63ae
commit cbcbea3
Showing
59 changed files
with
620 additions
and
135 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
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
32 changes: 32 additions & 0 deletions
32
...rver/test/plugins/typescript/testfiles/diagnostics/diagnostics-$store-control-flow.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,32 @@ | ||
<script lang="ts"> | ||
import { writable } from 'svelte/store'; | ||
const store = writable<undefined | { a: string | { b: string | boolean }}>({a: 'hi'}); | ||
function isBoolean(t: string | boolean): t is boolean { | ||
return !!t; | ||
} | ||
let test: boolean; | ||
if ($store) { | ||
if (typeof $store.a === 'string') { | ||
test = $store.a === 'string' || $store.a === true; | ||
} else { | ||
if (isBoolean($store.a.b)) { | ||
test = $store.a.b; | ||
test; | ||
} else { | ||
test = $store.a.b; | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
{#if $store} | ||
{#if typeof $store.a === 'string'} | ||
{test = $store.a === 'string' || $store.a === true} | ||
{:else} | ||
{#if isBoolean($store.a.b)} | ||
{test = $store.a.b} | ||
{:else} | ||
{test = $store.a.b} | ||
{/if} | ||
{/if} | ||
{/if} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
packages/language-server/test/plugins/typescript/testfiles/diagnostics/tsconfig.json
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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
/** | ||
This is actually not needed, but makes the tests faster | ||
because TS does not look up other types. | ||
*/ | ||
"types": ["svelte"] | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/language-server/test/plugins/typescript/testfiles/find-references-$store.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> | ||
const findMe = writable(''); | ||
if ($findMe) { | ||
$findMe; | ||
} | ||
</script> | ||
|
||
{$findMe} |
2 changes: 1 addition & 1 deletion
2
packages/language-server/test/plugins/typescript/testfiles/updateimports.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,3 +1,3 @@ | ||
<script> | ||
import Bla from './diagnostics.svelte'; | ||
import Bla from './diagnostics/diagnostics.svelte'; | ||
</script> |
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
Oops, something went wrong.