Skip to content

Commit

Permalink
fix svelte <script> (#1317)
Browse files Browse the repository at this point in the history
* f

* rl
  • Loading branch information
samijaber authored Jan 12, 2024
1 parent 8ae7424 commit f84e2c7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .yarn/versions/1df68f61.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
undecided:
- "@builder.io/mitosis-repo"
- "@builder.io/mitosis"
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@builder.io/mitosis-cli",
"version": "0.0.95",
"version": "0.0.96",
"description": "mitosis CLI",
"types": "build/types/types.d.ts",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"name": "Builder.io",
"url": "https://www.builder.io"
},
"version": "0.0.136",
"version": "0.0.137",
"homepage": "https://github.com/BuilderIO/mitosis",
"main": "./dist/src/index.js",
"exports": {
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/generators/svelte/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const mappers: {
Show: BlockToSvelte;
Slot: BlockToSvelte;
style: BlockToSvelte;
script: BlockToSvelte;
} = {
style: ({ json, options, parentComponent }) => {
let props = '';
Expand All @@ -46,6 +47,26 @@ const mappers: {
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
return `{@html \`<\${'style'} ${bindings} ${props}>\${${innerText}}<\${'/style'}>\`}`;
},
script: ({ json, options, parentComponent }) => {
let props = '';
for (const key in json.properties) {
const value = json.properties[key];
props += ` ${key}="${value}" `;
}

let bindings = '';

for (const key in json.bindings) {
const value = json.bindings[key];
if (value && key !== 'innerHTML') {
bindings += ` ${key}=\${${value.code}} `;
}
}

const innerText = json.bindings.innerHTML?.code || '';

return `{@html \`<script ${bindings} ${props}>\${${innerText}}</script>\`}`;
},
Fragment: ({ json, options, parentComponent }) => {
if (json.bindings.innerHTML?.code) {
return BINDINGS_MAPPER.innerHTML(json, options);
Expand Down

1 comment on commit f84e2c7

@vercel
Copy link

@vercel vercel bot commented on f84e2c7 Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.