Skip to content

Commit 90334c8

Browse files
oscard0mpaoloricciutiRich-Harris
authored
fix: avoid throwing store_invalid_subscription_module for runes (#12848)
* fix: avoid throwing `store_invalid_subscription_module` for runes Co-authored-by: Paolo Ricciuti <[email protected]> * move test to the validator suite, which is faster --------- Co-authored-by: Paolo Ricciuti <[email protected]> Co-authored-by: Rich Harris <[email protected]>
1 parent 19beb77 commit 90334c8

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

.changeset/funny-bugs-kiss.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: avoid throwing `store_invalid_subscription_module` for runes

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export function analyze_module(ast, options) {
223223

224224
const binding = scope.get(name.slice(1));
225225

226-
if (binding !== null) {
226+
if (binding !== null && !is_rune(name)) {
227227
e.store_invalid_subscription_module(references[0].node);
228228
}
229229
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { test } from '../../test';
2+
3+
export default test({});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const state = $state(0);
2+
3+
const derived = $derived(state + 2);
4+
5+
let effect = {};
6+
let inspect = {};
7+
8+
$effect.root(() => {
9+
$inspect(state);
10+
11+
$effect(() => {
12+
console.log(state);
13+
});
14+
});

packages/svelte/tests/validator/test.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from 'node:fs';
22
import { it, assert } from 'vitest';
3-
import { compile } from 'svelte/compiler';
3+
import { compile, compileModule } from 'svelte/compiler';
44
import { try_load_json } from '../helpers.js';
55
import { suite, type BaseTest } from '../suite.js';
66
import type { CompileError } from '#compiler';
@@ -14,19 +14,24 @@ interface ValidatorTest extends BaseTest {
1414
}
1515

1616
const { test, run } = suite<ValidatorTest>(async (config, cwd) => {
17-
const input = fs
18-
.readFileSync(`${cwd}/input.svelte`, 'utf-8')
19-
.replace(/\s+$/, '')
20-
.replace(/\r/g, '');
21-
2217
const expected_warnings = try_load_json(`${cwd}/warnings.json`) || [];
2318
const expected_errors = try_load_json(`${cwd}/errors.json`);
2419
const options = try_load_json(`${cwd}/options.json`);
2520

2621
let error;
2722

2823
try {
29-
const { warnings } = compile(input, {
24+
const module = fs.existsSync(`${cwd}/input.svelte.js`);
25+
26+
const input = (
27+
module
28+
? fs.readFileSync(`${cwd}/input.svelte.js`, 'utf-8')
29+
: fs.readFileSync(`${cwd}/input.svelte`, 'utf-8')
30+
)
31+
.replace(/\s+$/, '')
32+
.replace(/\r/g, '');
33+
34+
const { warnings } = (module ? compileModule : compile)(input, {
3035
...config.compileOptions,
3136
generate: false,
3237
...options

0 commit comments

Comments
 (0)