Skip to content

Commit

Permalink
🏃 (#1634)
Browse files Browse the repository at this point in the history
  • Loading branch information
samijaber authored Nov 8, 2024
1 parent 6f6db62 commit e90df53
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-lobsters-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/mitosis': patch
---

[Solid] Fix: handle Fragment with `key` prop
124 changes: 92 additions & 32 deletions packages/core/src/__tests__/__snapshots__/solid.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3743,25 +3743,55 @@ export default MyComponent;
`;

exports[`Solid > jsx > Javascript Test > basicForFragment 1`] = `
"Property or signature expected. (26:17)
24 | {(option, _index) => {
25 | const index = _index();
> 26 | return < key={\`key-\${option}\`} ><div >{option}</div></>}}
| ^
27 |
28 | </For></div>
29 |"
"import { For } from \\"solid-js\\";

function BasicForFragment(props) {
return (
<>
<div>
<For each={[\\"a\\", \\"b\\", \\"c\\"]}>
{(option, _index) => {
const index = _index();
return (
<Fragment key={\`key-\${option}\`}>
<div>{option}</div>
</Fragment>
);
}}
</For>
</div>
</>
);
}

export default BasicForFragment;
"
`;

exports[`Solid > jsx > Javascript Test > basicForFragment 2`] = `
"Property or signature expected. (26:17)
24 | {(option, _index) => {
25 | const index = _index();
> 26 | return < key={\`key-\${option}\`} ><div >{option}</div></>}}
| ^
27 |
28 | </For></div>
29 |"
"import { For } from \\"solid-js\\";

function BasicForFragment(props) {
return (
<>
<div>
<For each={[\\"a\\", \\"b\\", \\"c\\"]}>
{(option, _index) => {
const index = _index();
return (
<Fragment key={\`key-\${option}\`}>
<div>{option}</div>
</Fragment>
);
}}
</For>
</div>
</>
);
}

export default BasicForFragment;
"
`;

exports[`Solid > jsx > Javascript Test > basicForNoTagReference 1`] = `
Expand Down Expand Up @@ -11957,25 +11987,55 @@ export default MyComponent;
`;

exports[`Solid > jsx > Typescript Test > basicForFragment 1`] = `
"Property or signature expected. (26:17)
24 | {(option, _index) => {
25 | const index = _index();
> 26 | return < key={\`key-\${option}\`} ><div >{option}</div></>}}
| ^
27 |
28 | </For></div>
29 |"
"import { For } from \\"solid-js\\";

function BasicForFragment(props: any) {
return (
<>
<div>
<For each={[\\"a\\", \\"b\\", \\"c\\"]}>
{(option, _index) => {
const index = _index();
return (
<Fragment key={\`key-\${option}\`}>
<div>{option}</div>
</Fragment>
);
}}
</For>
</div>
</>
);
}

export default BasicForFragment;
"
`;

exports[`Solid > jsx > Typescript Test > basicForFragment 2`] = `
"Property or signature expected. (26:17)
24 | {(option, _index) => {
25 | const index = _index();
> 26 | return < key={\`key-\${option}\`} ><div >{option}</div></>}}
| ^
27 |
28 | </For></div>
29 |"
"import { For } from \\"solid-js\\";

function BasicForFragment(props: any) {
return (
<>
<div>
<For each={[\\"a\\", \\"b\\", \\"c\\"]}>
{(option, _index) => {
const index = _index();
return (
<Fragment key={\`key-\${option}\`}>
<div>{option}</div>
</Fragment>
);
}}
</For>
</div>
</>
);
}

export default BasicForFragment;
"
`;

exports[`Solid > jsx > Typescript Test > basicForNoTagReference 1`] = `
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/generators/solid/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export const blockToSolid = (

let str = '';

if (json.name === 'Fragment') {
const isFragmentWithoutKey = json.name === 'Fragment' && !json.bindings.key;

if (isFragmentWithoutKey) {
str += '<';
} else {
str += `<${json.name} `;
Expand Down Expand Up @@ -128,7 +130,7 @@ export const blockToSolid = (
.join('\n');
}

if (json.name === 'Fragment') {
if (isFragmentWithoutKey) {
str += '</>';
} else {
str += `</${json.name}>`;
Expand Down

0 comments on commit e90df53

Please sign in to comment.