fix: avoid throwing `store_invalid_subscription_module` for runes (#12848)

* fix: avoid throwing `store_invalid_subscription_module` for runes

Co-authored-by: Paolo Ricciuti <ricciutipaolo@gmail.com>

* move test to the validator suite, which is faster

---------

Co-authored-by: Paolo Ricciuti <ricciutipaolo@gmail.com>
Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/12846/head
Oscar Dominguez 4 months ago committed by GitHub
parent 19beb7754e
commit 90334c812c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: avoid throwing `store_invalid_subscription_module` for runes

@ -223,7 +223,7 @@ export function analyze_module(ast, options) {
const binding = scope.get(name.slice(1));
if (binding !== null) {
if (binding !== null && !is_rune(name)) {
e.store_invalid_subscription_module(references[0].node);
}
}

@ -0,0 +1,3 @@
import { test } from '../../test';
export default test({});

@ -0,0 +1,14 @@
const state = $state(0);
const derived = $derived(state + 2);
let effect = {};
let inspect = {};
$effect.root(() => {
$inspect(state);
$effect(() => {
console.log(state);
});
});

@ -1,6 +1,6 @@
import * as fs from 'node:fs';
import { it, assert } from 'vitest';
import { compile } from 'svelte/compiler';
import { compile, compileModule } from 'svelte/compiler';
import { try_load_json } from '../helpers.js';
import { suite, type BaseTest } from '../suite.js';
import type { CompileError } from '#compiler';
@ -14,11 +14,6 @@ interface ValidatorTest extends BaseTest {
}
const { test, run } = suite<ValidatorTest>(async (config, cwd) => {
const input = fs
.readFileSync(`${cwd}/input.svelte`, 'utf-8')
.replace(/\s+$/, '')
.replace(/\r/g, '');
const expected_warnings = try_load_json(`${cwd}/warnings.json`) || [];
const expected_errors = try_load_json(`${cwd}/errors.json`);
const options = try_load_json(`${cwd}/options.json`);
@ -26,7 +21,17 @@ const { test, run } = suite<ValidatorTest>(async (config, cwd) => {
let error;
try {
const { warnings } = compile(input, {
const module = fs.existsSync(`${cwd}/input.svelte.js`);
const input = (
module
? fs.readFileSync(`${cwd}/input.svelte.js`, 'utf-8')
: fs.readFileSync(`${cwd}/input.svelte`, 'utf-8')
)
.replace(/\s+$/, '')
.replace(/\r/g, '');
const { warnings } = (module ? compileModule : compile)(input, {
...config.compileOptions,
generate: false,
...options

Loading…
Cancel
Save