fix: warn when `$props` rune not called (#10655)

It's a warning because even when typing it out and knowing what to do you'll always be in a state where the validation kicks in, and it would be too distracting to always see a compiler error during that short time frame.
closes #10374
pull/10656/head
Simon H 9 months ago committed by GitHub
parent 77b1f2fe51
commit 6625c1e080
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: warn when `$props` rune not called

@ -1002,7 +1002,12 @@ export const validation_runes = merge(validation, a11y_validators, {
const init = node.init; const init = node.init;
const rune = get_rune(init, state.scope); const rune = get_rune(init, state.scope);
if (rune === null) return; if (rune === null) {
if (init?.type === 'Identifier' && init.name === '$props' && !state.scope.get('props')) {
warn(state.analysis.warnings, node, path, 'invalid-props-declaration');
}
return;
}
const args = /** @type {import('estree').CallExpression} */ (init).arguments; const args = /** @type {import('estree').CallExpression} */ (init).arguments;

@ -27,7 +27,10 @@ const runes = {
/** @param {string} name */ /** @param {string} name */
'non-state-reference': (name) => 'non-state-reference': (name) =>
`${name} is updated, but is not declared with $state(...). Changing its value will not correctly trigger updates.`, `${name} is updated, but is not declared with $state(...). Changing its value will not correctly trigger updates.`,
'derived-iife': () => `Use \`$derived.by(() => {...})\` instead of \`$derived((() => {...})());\`` 'derived-iife': () =>
`Use \`$derived.by(() => {...})\` instead of \`$derived((() => {...})());\``,
'invalid-props-declaration': () =>
`Component properties are declared using $props() in runes mode. Did you forget to call the function?`
}; };
/** @satisfies {Warnings} */ /** @satisfies {Warnings} */

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

@ -0,0 +1,14 @@
[
{
"code": "invalid-props-declaration",
"message": "Component properties are declared using $props() in runes mode. Did you forget to call the function?",
"start": {
"column": 5,
"line": 2
},
"end": {
"column": 19,
"line": 2
}
}
]
Loading…
Cancel
Save