Skip to content

Commit 2161336

Browse files
authored
fix $props() and $props.id() autocompletion (#1309)
1 parent aa7c9f2 commit 2161336

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

packages/site-kit/src/lib/codemirror/autocompletionDataProvider.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ const is_statement = (node) => {
533533
* @type {import("./types").Test}
534534
*/
535535
const is_props = (node, _, selected) => {
536-
if (selected.type !== 'svelte') return false;
536+
if (!selected.endsWith('.svelte')) return false;
537537

538538
return (
539539
node.name === 'VariableName' &&
@@ -577,28 +577,17 @@ const is_bindable = (node, context) => {
577577
* @type {import("./types").Test}
578578
*/
579579
const is_props_id_call = (node, context, selected) => {
580-
if (!selected.match(/\.svelte$/)) return false;
581-
if (!is_state_call(node, context, selected)) return false;
582-
if (node.parent?.parent?.name !== 'Script') return false;
583-
return true;
584-
};
585-
586-
/**
587-
* @type {import("./types").Test}
588-
*/
589-
const is_props_id = (node, context, selected) => {
590-
if (!selected.match(/\.svelte$/)) return false;
591-
if (!is_state(node, context, selected)) return false;
592-
if (node.parent?.parent?.name !== 'Script') return false;
593-
return true;
580+
return (
581+
is_state_call(node, context, selected) && node.parent?.parent?.parent?.parent?.name === 'Script'
582+
);
594583
};
595584

596585
export const runes = [
597586
{ snippet: '$state(${})', test: is_state },
598587
{ snippet: '$state', test: is_state_call },
599588
{ snippet: '$props()', test: is_props },
600589
{ snippet: '$props.id', test: is_props_id_call },
601-
{ snippet: '$props.id()', test: is_props_id },
590+
{ snippet: '$props.id()', test: is_props },
602591
{ snippet: '$derived(${});', test: is_state },
603592
{ snippet: '$derived', test: is_state_call },
604593
{ snippet: '$derived.by(() => {\n\t${}\n});', test: is_state },

0 commit comments

Comments
 (0)