Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow as expressions for bindable props #2372

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"range": { "start": { "line": 4, "character": 0 }, "end": { "line": 4, "character": 0 } },
"severity": 1,
"source": "ts",
"message": "`<svelte:element>` must have a 'this' attribute",
"message": "`<svelte:element>` must have a 'this' attribute with a value",
"code": -1
}
]
7 changes: 6 additions & 1 deletion packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ export class ExportedNames {
: element.name.text;

if (element.initializer) {
const call = element.initializer;
let call = element.initializer;
// if it's an as expression we need to check wether the as
// expression expression is a call
if (ts.isAsExpression(call)) {
call = call.expression;
}
if (ts.isCallExpression(call) && ts.isIdentifier(call.expression)) {
if (call.expression.text === '$bindable') {
this.$props.bindings.push(name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
///<reference types="svelte" />
;function render() {
/*Ωignore_startΩ*/;type $$ComponentProps = { a: unknown, b?: unknown };/*Ωignore_endΩ*/
let { a, b = $bindable() }: $$ComponentProps = $props();
/*Ωignore_startΩ*/;type $$ComponentProps = { a: unknown, b?: unknown, c?: number };/*Ωignore_endΩ*/
let { a, b = $bindable(), c = $bindable(0) as number }: $$ComponentProps = $props();
;
async () => {};
return { props: {} as any as $$ComponentProps, slots: {}, events: {} }}

export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_with_any_event(render())) {
constructor(options = __sveltets_2_runes_constructor(__sveltets_2_with_any_event(render()))) { super(options); }
$$bindings = __sveltets_$$bindings('b');
$$bindings = __sveltets_$$bindings('b', 'c');
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<script lang="ts">
let { a, b = $bindable() } = $props();
let { a, b = $bindable(), c = $bindable(0) as number } = $props();
</script>
Loading