feat: add warning when using $bindable runes without calling it (#11181)

* feat: add warning when using `$bindable` rune without calling it

* --amend
pull/11201/head
Tan Li Hau 7 months ago committed by GitHub
parent 777527b5a3
commit 1510c13113
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
feat: add warning when using `$bindable` rune without calling it

@ -1174,6 +1174,15 @@ export const validation_runes = merge(validation, a11y_validators, {
}
}
},
AssignmentPattern(node, { state, path }) {
if (
node.right.type === 'Identifier' &&
node.right.name === '$bindable' &&
!state.scope.get('bindable')
) {
warn(state.analysis.warnings, node, path, 'invalid-bindable-declaration');
}
},
// TODO this is a code smell. need to refactor this stuff
ClassBody: validation_runes_js.ClassBody,
ClassDeclaration: validation_runes_js.ClassDeclaration,

@ -39,7 +39,9 @@ const runes = {
'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?`
`Component properties are declared using $props() in runes mode. Did you forget to call the function?`,
'invalid-bindable-declaration': () =>
`Bindable component properties are declared using $bindable() in runes mode. Did you forget to call the function?`
};
/** @satisfies {Warnings} */

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

@ -0,0 +1,3 @@
<script>
let { a = $bindable } = $props();
</script>

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