Skip to content

Commit 78a69ac

Browse files
authored
fix: dont error on stores looking like runes when runes explicitly turned off (#9615)
1 parent 72d3a2a commit 78a69ac

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

.changeset/lovely-items-turn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: dont error on stores looking like runes when runes explicitly turned off

packages/svelte/src/compiler/phases/2-analyze/validation.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ export const validation = {
443443
};
444444

445445
export const validation_legacy = merge(validation, a11y_validators, {
446-
VariableDeclarator(node) {
446+
VariableDeclarator(node, { state }) {
447447
if (node.init?.type !== 'CallExpression') return;
448448

449449
const callee = node.init.callee;
@@ -454,8 +454,9 @@ export const validation_legacy = merge(validation, a11y_validators, {
454454
return;
455455
}
456456

457-
// TODO check if it's a store subscription that's called? How likely is it that someone uses a store that contains a function?
458-
error(node.init, 'invalid-rune-usage', callee.name);
457+
if (state.scope.get(callee.name)?.kind !== 'store_sub') {
458+
error(node.init, 'invalid-rune-usage', callee.name);
459+
}
459460
},
460461
AssignmentExpression(node, { state, path }) {
461462
const parent = path.at(-1);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
compileOptions: {
5+
runes: false
6+
}
7+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
import { state } from './store';
3+
const x = $state();
4+
</script>
5+
6+
{x}

0 commit comments

Comments
 (0)