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

fail if we find any async functions #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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()
})
Loading