Skip to content

Commit 2ca8697

Browse files
committed
fix: negative typecheck for watcher's value
1 parent d4eb72d commit 2ca8697

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function renderToString(template) {
1414
}
1515

1616
const renderResult = template._h()
17+
1718
let htmlString = renderResult[0]
1819
const expressions = renderResult[1]
1920
if (expressions.length > 0) {
@@ -36,7 +37,10 @@ export function renderToString(template) {
3637

3738
const watcherReturn = expressionInstance.e()
3839

39-
if (typeof watcherReturn === 'string') {
40+
if (
41+
typeof watcherReturn !== 'object' &&
42+
typeof watcherReturn !== 'function'
43+
) {
4044
htmlString = htmlString.replace(delimiterComment, watcherReturn)
4145
return
4246
}

tests/basic.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,26 @@ test('reactive variable', async () => {
3030
assert.is(out, '<p>hello world</p>')
3131
})
3232

33+
test('reactive variable nested', async () => {
34+
const pageState = reactive({
35+
count: 0,
36+
})
37+
const comp = html`<div
38+
class="flex-[5] relative p-2 overflow-x-auto flex flex-col gap-2"
39+
>
40+
<div class="flex gap-2 items-center">${() => pageState.count}</div>
41+
</div>`
42+
43+
await inlineSnapshot(
44+
renderToString(comp),
45+
`<div
46+
class="flex-[5] relative p-2 overflow-x-auto flex flex-col gap-2"
47+
>
48+
<div class="flex gap-2 items-center">0</div>
49+
</div>`
50+
)
51+
})
52+
3353
test('reactive variable, changing', async () => {
3454
const rVar = reactive({ message: 'hello world' })
3555
const tmp = html`<p>${() => rVar.message}</p>`

0 commit comments

Comments
 (0)