Skip to content

fix: prevent false positives when detecting runes mode #9599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fair-crabs-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: prevent false positives when detecting runes mode
8 changes: 7 additions & 1 deletion packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ export function analyze_component(root, options) {
if (declaration === null && /[a-z]/.test(store_name[0])) {
error(references[0].node, 'illegal-global', name);
} else if (declaration !== null && Runes.includes(name)) {
warn(warnings, declaration.node, [], 'store-with-rune-name', store_name);
for (const { node, path } of references) {
if (path.at(-1)?.type === 'CallExpression') {
warn(warnings, node, [], 'store-with-rune-name', store_name);
}
}
}
}

Expand All @@ -302,6 +306,8 @@ export function analyze_component(root, options) {

const binding = instance.scope.declare(b.id(name), 'store_sub', 'synthetic');
binding.references = references;
instance.scope.references.set(name, references);
module.scope.references.delete(name);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import { writable } from 'svelte/store';

export let initial;
const state = writable(initial);
</script>

<div>{$state}</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"code": "store-with-rune-name",
"message": "It looks like you're using the $state rune, but there is a local binding called state. Referencing a local variable with a $ prefix will create a store subscription. Please rename state to avoid the ambiguity.",
"start": {
"column": 7,
"line": 2
"column": 1,
"line": 3
},
"end": {
"column": 12,
"line": 2
"column": 7,
"line": 3
}
}
]