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

fix multiline bindings in builder json #1605

Merged
merged 4 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/green-tables-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/mitosis': patch
---

Fix multi line bindings from Mitosis to Builder
18 changes: 18 additions & 0 deletions packages/core/src/__tests__/__snapshots__/builder.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,12 @@ exports[`Builder > Regenerate custom Hero 1`] = `
"code": "400",
"type": "single",
},
"multiBinding": {
"code": "{
hello: state.message
}",
"type": "single",
},
},
"children": [],
"meta": {},
Expand Down Expand Up @@ -969,12 +975,18 @@ exports[`Builder > Regenerate custom Hero 2`] = `
"actions": {},
"bindings": {
"component.options.height": "400",
"component.options.multiBinding": "return {
hello: state.message
}",
},
"children": [],
"code": {
"actions": {},
"bindings": {
"component.options.height": "400",
"component.options.multiBinding": "{
hello: state.message
}",
},
},
"component": {
Expand Down Expand Up @@ -1021,6 +1033,12 @@ exports[`Builder > Regenerate custom Hero 3`] = `
"code": "400",
"type": "single",
},
"multiBinding": {
"code": "{
hello: state.message
}",
"type": "single",
},
},
"children": [],
"meta": {},
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/__tests__/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ describe('Builder', () => {
image="https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F52dcecf48f9c48cc8ddd8f81fec63236"
buttonLink="https://example.com"
buttonText="Click"
multiBinding={{
hello: state.message,
}}
height={400}
css={{
display: "flex",
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/generators/builder/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,20 @@ export const componentToBuilder =
if (value) {
set(el, 'component.options.symbol.content', value);
}
if (el.bindings) {
for (const [key, value] of Object.entries(el.bindings)) {
if (value.match(/\n|;/)) {
if (!el.code) {
el.code = {};
}
if (!el.code.bindings) {
el.code.bindings = {};
}
el.code.bindings[key] = value;
el.bindings[key] = `return ${value}`;
samijaber marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
});

Expand Down