From 78a69acfa1ad1555a490b5a3b8cf799ff46f30a8 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 23 Nov 2023 17:29:06 +0100 Subject: [PATCH] fix: dont error on stores looking like runes when runes explicitly turned off (#9615) --- .changeset/lovely-items-turn.md | 5 +++++ .../svelte/src/compiler/phases/2-analyze/validation.js | 7 ++++--- .../tests/validator/samples/no-runes-mode/_config.js | 7 +++++++ .../tests/validator/samples/no-runes-mode/input.svelte | 6 ++++++ 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 .changeset/lovely-items-turn.md create mode 100644 packages/svelte/tests/validator/samples/no-runes-mode/_config.js create mode 100644 packages/svelte/tests/validator/samples/no-runes-mode/input.svelte diff --git a/.changeset/lovely-items-turn.md b/.changeset/lovely-items-turn.md new file mode 100644 index 0000000000..499b1fadf8 --- /dev/null +++ b/.changeset/lovely-items-turn.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: dont error on stores looking like runes when runes explicitly turned off diff --git a/packages/svelte/src/compiler/phases/2-analyze/validation.js b/packages/svelte/src/compiler/phases/2-analyze/validation.js index 805f673974..e799c38851 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/validation.js +++ b/packages/svelte/src/compiler/phases/2-analyze/validation.js @@ -443,7 +443,7 @@ export const validation = { }; export const validation_legacy = merge(validation, a11y_validators, { - VariableDeclarator(node) { + VariableDeclarator(node, { state }) { if (node.init?.type !== 'CallExpression') return; const callee = node.init.callee; @@ -454,8 +454,9 @@ export const validation_legacy = merge(validation, a11y_validators, { return; } - // TODO check if it's a store subscription that's called? How likely is it that someone uses a store that contains a function? - error(node.init, 'invalid-rune-usage', callee.name); + if (state.scope.get(callee.name)?.kind !== 'store_sub') { + error(node.init, 'invalid-rune-usage', callee.name); + } }, AssignmentExpression(node, { state, path }) { const parent = path.at(-1); diff --git a/packages/svelte/tests/validator/samples/no-runes-mode/_config.js b/packages/svelte/tests/validator/samples/no-runes-mode/_config.js new file mode 100644 index 0000000000..477cb2b131 --- /dev/null +++ b/packages/svelte/tests/validator/samples/no-runes-mode/_config.js @@ -0,0 +1,7 @@ +import { test } from '../../test'; + +export default test({ + compileOptions: { + runes: false + } +}); diff --git a/packages/svelte/tests/validator/samples/no-runes-mode/input.svelte b/packages/svelte/tests/validator/samples/no-runes-mode/input.svelte new file mode 100644 index 0000000000..daa1686fa1 --- /dev/null +++ b/packages/svelte/tests/validator/samples/no-runes-mode/input.svelte @@ -0,0 +1,6 @@ + + +{x}