Skip to content

Commit

Permalink
fail if we find any async functions
Browse files Browse the repository at this point in the history
  • Loading branch information
brianleroux committed Jun 28, 2024
1 parent 92c9caf commit 21cc77c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ function renderTemplate({ name, elements, attrs=[], state={} }) {
? templateRenderFunction
: elements[name]

if (template.constructor.name ==='AsyncFunction')
throw Error(`illegal_async_function: ${name} must be a Function not an AsyncFunction`)

if (template && typeof template === 'function') {
return fragment(template({ html: render, state }))
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"type": "module",
"main": "index.mjs",
"scripts": {
"test": "tape ./test/enhance.test.mjs | tap-arc"
"test": "tape ./test/*.test.mjs | tap-arc"
},
"keywords": [],
"keywords": ["webcomponents", "customelements", "ssr"],
"author": "kj <[email protected]>",
"license": "Apache-2.0",
"devDependencies": {
Expand Down
19 changes: 19 additions & 0 deletions test/illegal_async_function.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import test from 'tape'
import enhance from '../index.mjs'

test('cannot async', t=> {
let html = enhance({
elements: {
'el-hi': async function wups() {
return 'wat'
}
}
})
try {
let res = html`<el-hi></el-hi>`
}
catch (e) {
t.ok(e.message.startsWith('illegal_async'), e.message)
}
t.end()
})

0 comments on commit 21cc77c

Please sign in to comment.