Skip to content

Commit

Permalink
fix store set in reactive statement (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlyu123 committed Jul 29, 2020
1 parent c55114b commit fbb9496
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/svelte2tsx/src/svelte2tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,11 @@ function processInstanceScriptContent(str: MagicString, script: Node): InstanceS
ts.isIdentifier(node.statement.expression.left)
) {
const name = node.statement.expression.left.text;
if (!implicitTopLevelNames.has(name)) {

// svelte won't let you create a variable with $ prefix anyway
const isPotentialStore = name.startsWith('$');

if (!implicitTopLevelNames.has(name) && !isPotentialStore) {
implicitTopLevelNames.set(name, node.label.getStart());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<></>;function render() {

$: store.set( __sveltets_invalidate(() => __sveltets_store_get(store) + 1));
;
() => (<></>);
return { props: {}, slots: {}, getters: {}, events: {} }}

export default class Input__SvelteComponent_ {
$$prop_def = __sveltets_partial(render().props)
$$slot_def = render().slots
$on = __sveltets_eventDef(render().events)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script>
$: $store = $store + 1;
</script>

0 comments on commit fbb9496

Please sign in to comment.