Skip to content

Commit

Permalink
feat: add a few more helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyhuman committed Oct 18, 2024
1 parent 8916721 commit cea9554
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { readFileSync } from 'node:fs'
const __dirname = dirname(fileURLToPath(import.meta.url))

export const DEFAULT_TRANSPILED_IDENTIFIERS = ['_jsx', '_jsxs']
export const IMPORT_PATH_PLACEHOLDER = "<~~{importPath}~~>"

export function readSourceFile(file) {
const source = readFileSync(file, 'utf8')
Expand Down Expand Up @@ -209,7 +210,7 @@ export function generateServerTemplate(name) {
"data-props":JSON.stringify(props)
},
h(${name},props),
h("script",{src:"<~{${name}}~>",type:"module",defer:true})
h("script",{src:"${getServerTemplatePlaceholder(name)}",type:"module",defer:true})
)
)
}
Expand Down Expand Up @@ -267,7 +268,7 @@ export function generateClientTemplate(name) {
}
async connectedCallback() {
const c = await import("<~~{importPath}~~>");
const c = await import("${IMPORT_PATH_PLACEHOLDER}");
const usableComponent = c["${name}"]
const props = JSON.parse(this.dataset.props || '{}');
this.baseProps = props
Expand Down Expand Up @@ -401,3 +402,7 @@ export function isFunctionIsland(
export function getIslandName(name) {
return `island${name.replace(/([A-Z])/g, '-$1').toLowerCase()}`
}

export function getServerTemplatePlaceholder(name) {
return `<~{${name}}~>`
}

0 comments on commit cea9554

Please sign in to comment.