Skip to content

Commit

Permalink
fix Svelte forwarded ref props (BuilderIO#970)
Browse files Browse the repository at this point in the history
* fix

* update snapshots
  • Loading branch information
samijaber authored Jan 3, 2023
1 parent 6a2c951 commit 57bb305
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
8 changes: 0 additions & 8 deletions packages/core/src/__tests__/__snapshots__/svelte.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1344,8 +1344,6 @@ exports[`Svelte > jsx > Javascript Test > basicForwardRef 1`] = `
"<script>
export let inputRef;
let inputRef;
let name = \\"PatrickJS\\";
</script>
Expand All @@ -1364,8 +1362,6 @@ exports[`Svelte > jsx > Javascript Test > basicForwardRefMetadata 1`] = `
"<script>
export let inputRef;
let inputRef;
let name = \\"PatrickJS\\";
</script>
Expand Down Expand Up @@ -3691,8 +3687,6 @@ exports[`Svelte > jsx > Typescript Test > basicForwardRef 1`] = `
<script lang=\\"ts\\">
export let inputRef: Props[\\"inputRef\\"];
let inputRef;
let name = \\"PatrickJS\\";
</script>
Expand All @@ -3718,8 +3712,6 @@ exports[`Svelte > jsx > Typescript Test > basicForwardRefMetadata 1`] = `
<script lang=\\"ts\\">
export let inputRef: Props[\\"inputRef\\"];
let inputRef;
let name = \\"PatrickJS\\";
</script>
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/generators/svelte/svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,16 @@ export const componentToSvelte: TranspilerGenerator<ToSvelteOptions> =
let json = fastClone(component);
json = runPreJsonPlugins(json, options.plugins);

const refs = Array.from(getRefs(json));
useBindValue(json, options);

gettersToFunctions(json);

const props = Array.from(getProps(json)).filter((prop) => !isSlotProperty(prop));

const refs = Array.from(getRefs(json))
.map(stripStateAndProps({ json, options }))
.filter((x) => !props.includes(x));

json = runPostJsonPlugins(json, options.plugins);

const css = collectCss(json);
Expand Down Expand Up @@ -276,7 +279,7 @@ export const componentToSvelte: TranspilerGenerator<ToSvelteOptions> =
${functionsString.length < 4 ? '' : functionsString}
${getterString.length < 4 ? '' : getterString}
${refs.map((ref) => `let ${stripStateAndProps({ json, options })(ref)}`).join('\n')}
${refs.map((ref) => `let ${ref}`).join('\n')}
${
options.stateType === 'proxies'
Expand Down

0 comments on commit 57bb305

Please sign in to comment.