Skip to content

Commit b58d6a9

Browse files
committed
fix(compiler-vapor): empty block
1 parent d376349 commit b58d6a9

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ export function render(_ctx) {
213213
}"
214214
`;
215215

216+
exports[`compiler: element transform > empty template 1`] = `
217+
"
218+
export function render(_ctx) {
219+
return null
220+
}"
221+
`;
222+
216223
exports[`compiler: element transform > invalid html nesting 1`] = `
217224
"import { insert as _insert, template as _template } from 'vue/vapor';
218225
const t0 = _template("<div>123</div>")

packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,4 +803,10 @@ describe('compiler: element transform', () => {
803803
{ type: IRNodeTypes.INSERT_NODE, parent: 3, elements: [2] },
804804
])
805805
})
806+
807+
test('empty template', () => {
808+
const { code } = compileWithElementTransform('')
809+
expect(code).toMatchSnapshot()
810+
expect(code).contain('return null')
811+
})
806812
})

packages/compiler-vapor/src/generators/block.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function genBlockContent(
4242
const { dynamic, effect, operation, returns } = block
4343
const resetBlock = context.enterBlock(block)
4444

45-
if (root)
45+
if (root) {
4646
for (const name of context.ir.component) {
4747
push(
4848
NEWLINE,
@@ -53,6 +53,7 @@ export function genBlockContent(
5353
),
5454
)
5555
}
56+
}
5657

5758
for (const child of dynamic.children) {
5859
push(...genChildren(child, context, child.id!))
@@ -67,10 +68,11 @@ export function genBlockContent(
6768

6869
push(NEWLINE, `return `)
6970

71+
const returnNodes = returns.map(n => `n${n}`)
7072
const returnsCode: CodeFragment[] =
71-
returns.length > 1
72-
? genMulti(SEGMENTS_ARRAY, ...returns.map(n => `n${n}`))
73-
: [`n${returns[0]}`]
73+
returnNodes.length > 1
74+
? genMulti(SEGMENTS_ARRAY, ...returnNodes)
75+
: [returnNodes[0] || 'null']
7476
push(...(customReturns ? customReturns(returnsCode) : returnsCode))
7577

7678
resetBlock()

0 commit comments

Comments
 (0)