Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

feat:try to deal with the template abbreviation of end tag #152

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ export function render(_ctx) {
}"
`;

exports[`compile > component close tag 1`] = `
"import { template as _template } from 'vue/vapor';
const t0 = _template("<div><Comp/></div>")

export function render(_ctx) {
const n0 = t0()
return n0
}"
`;

exports[`compile > custom directive > basic 1`] = `
"import { children as _children, resolveDirective as _resolveDirective, withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
Expand Down Expand Up @@ -130,7 +140,7 @@ export function render(_ctx) {

exports[`compile > directives > v-pre > self-closing v-pre 1`] = `
"import { children as _children, createTextNode as _createTextNode, append as _append, renderEffect as _renderEffect, setText as _setText, setDynamicProp as _setDynamicProp, template as _template } from 'vue/vapor';
const t0 = _template("<div></div><div><Comp></Comp></div>")
const t0 = _template("<div></div><div><Comp/></div>")

export function render(_ctx) {
const n0 = t0()
Expand All @@ -145,7 +155,7 @@ export function render(_ctx) {

exports[`compile > directives > v-pre > should not affect siblings after it 1`] = `
"import { children as _children, createTextNode as _createTextNode, append as _append, renderEffect as _renderEffect, setText as _setText, setDynamicProp as _setDynamicProp, template as _template } from 'vue/vapor';
const t0 = _template("<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div><div><Comp></Comp></div>")
const t0 = _template("<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div><div><Comp/></div>")

export function render(_ctx) {
const n0 = t0()
Expand Down
7 changes: 6 additions & 1 deletion packages/compiler-vapor/__tests__/compile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ describe('compile', () => {
)
expect(code).matchSnapshot()
})
test('component close tag', () => {
const code = compile(`<div><Comp></Comp></div>`)
expect(code).matchSnapshot()
expect(code).contains(JSON.stringify('<div><Comp/></div>'))
})

test('dynamic root', () => {
const code = compile(`{{ 1 }}{{ 2 }}`)
Expand Down Expand Up @@ -96,7 +101,7 @@ describe('compile', () => {
)

expect(code).toMatchSnapshot()
expect(code).contains('<div></div><div><Comp></Comp></div>')
expect(code).contains('<div></div><div><Comp/></div>')
// Waiting for TODO, There should be more here.
})
})
Expand Down
6 changes: 5 additions & 1 deletion packages/compiler-vapor/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ export const transformElement: NodeTransform = (node, context) => {

// TODO remove unnecessary close tag, e.g. if it's the last element of the template
if (!isVoidTag(tag)) {
context.template += `</${tag}>`
if (node.tagType === ElementTypes.COMPONENT) {
context.template = `<${tag}/>`
} else {
context.template += `</${tag}>`
}
}
}
}
Expand Down