Skip to content

Commit

Permalink
fix: prevent false positive store declarations (#2422)
Browse files Browse the repository at this point in the history
variable declarations not at the top level can't be subscribed to using the `$` prefix
  • Loading branch information
dummdidumm authored Jun 26, 2024
1 parent 6e64abd commit 5312279
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ export function processInstanceScriptContent(
if (ts.isVariableDeclaration(node)) {
events.checkIfIsStringLiteralDeclaration(node);
events.checkIfDeclarationInstantiatedEventDispatcher(node);
implicitStoreValues.addVariableDeclaration(node);
// Only top level declarations can be stores
if (node.parent?.parent?.parent === tsAst) {
implicitStoreValues.addVariableDeclaration(node);
}
}

if (ts.isCallExpression(node)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
///<reference types="svelte" />
;function render() {

function x(tr) {
for (let notAStore of tr.effects) {}
}

$notAStore;
;
async () => {};
return { props: /** @type {Record<string, never>} */ ({}), slots: {}, events: {} }}

export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_partial(__sveltets_2_with_any_event(render()))) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
function x(tr) {
for (let notAStore of tr.effects) {}
}
$notAStore;
</script>

0 comments on commit 5312279

Please sign in to comment.