refactor: restore isSelfClosing as optional property

This commit is contained in:
Evan You 2023-11-25 22:55:39 +08:00
parent bab5bd375b
commit 157cfcb796
4 changed files with 8 additions and 0 deletions

View File

@ -3831,6 +3831,7 @@ exports[`compiler: parse > Errors > X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END > <
{ {
"children": [], "children": [],
"codegenNode": undefined, "codegenNode": undefined,
"isSelfClosing": true,
"loc": { "loc": {
"end": { "end": {
"column": 25, "column": 25,
@ -4417,6 +4418,7 @@ exports[`compiler: parse > self closing multiple tag 1`] = `
{ {
"children": [], "children": [],
"codegenNode": undefined, "codegenNode": undefined,
"isSelfClosing": true,
"loc": { "loc": {
"end": { "end": {
"column": 37, "column": 37,
@ -4497,6 +4499,7 @@ exports[`compiler: parse > self closing multiple tag 1`] = `
{ {
"children": [], "children": [],
"codegenNode": undefined, "codegenNode": undefined,
"isSelfClosing": true,
"loc": { "loc": {
"end": { "end": {
"column": 37, "column": 37,
@ -4611,6 +4614,7 @@ exports[`compiler: parse > valid html 1`] = `
{ {
"children": [], "children": [],
"codegenNode": undefined, "codegenNode": undefined,
"isSelfClosing": true,
"loc": { "loc": {
"end": { "end": {
"column": 39, "column": 39,

View File

@ -501,6 +501,7 @@ describe('compiler: parse', () => {
codegenNode: undefined, codegenNode: undefined,
props: [], props: [],
children: [], children: [],
isSelfClosing: true,
loc: { loc: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 6, line: 1, column: 7 }, end: { offset: 6, line: 1, column: 7 },
@ -545,6 +546,7 @@ describe('compiler: parse', () => {
codegenNode: undefined, codegenNode: undefined,
props: [], props: [],
children: [], children: [],
isSelfClosing: true,
loc: { loc: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 6, line: 1, column: 7 }, end: { offset: 6, line: 1, column: 7 },

View File

@ -131,6 +131,7 @@ export interface BaseElementNode extends Node {
tagType: ElementTypes tagType: ElementTypes
props: Array<AttributeNode | DirectiveNode> props: Array<AttributeNode | DirectiveNode>
children: TemplateChildNode[] children: TemplateChildNode[]
isSelfClosing?: boolean
innerLoc?: SourceLocation // only for SFC root level elements innerLoc?: SourceLocation // only for SFC root level elements
} }

View File

@ -172,6 +172,7 @@ const tokenizer = new Tokenizer(stack, {
onselfclosingtag(end) { onselfclosingtag(end) {
const name = currentOpenTag!.tag const name = currentOpenTag!.tag
currentOpenTag!.isSelfClosing = true
endOpenTag(end) endOpenTag(end)
if (stack[0]?.tag === name) { if (stack[0]?.tag === name) {
onCloseTag(stack.shift()!, end) onCloseTag(stack.shift()!, end)