wip: pass all compiler-dom tests

This commit is contained in:
Evan You 2023-11-19 11:46:44 +08:00
parent 40f72d5e50
commit 5a44b84cde
2 changed files with 19 additions and 7 deletions

View File

@ -238,6 +238,8 @@ export default class Tokenizer {
private baseState = State.Text
/** For special parsing behavior inside of script and style tags. */
public inRCDATA = false
/** For disabling RCDATA tags handling */
public inXML = false
/** Reocrd newline positions for fast line / column calculation */
private newlines: number[] = []
@ -528,7 +530,7 @@ export default class Tokenizer {
// - everything except <template> is RAWTEXT
// - <template> with lang other than html is also RAWTEXT
this.state = State.InSFCRootTagName
} else {
} else if (!this.inXML) {
// HTML mode
// - <script>, <style> RAWTEXT
// - <title>, <textarea> RCDATA
@ -539,6 +541,8 @@ export default class Tokenizer {
this.state =
lower === 115 /* s */ ? State.BeforeSpecialS : State.InTagName
}
} else {
this.state = State.InTagName
}
} else if (c === CharCodes.Slash) {
this.state = State.BeforeClosingTagName

View File

@ -406,14 +406,17 @@ function getSlice(start: number, end: number) {
function endOpenTag(end: number) {
addNode(currentElement!)
const name = currentElement!.tag
if (currentOptions.isPreTag(name)) {
const { tag, ns } = currentElement!
if (ns === Namespaces.HTML && currentOptions.isPreTag(tag)) {
inPre++
}
if (currentOptions.isVoidTag(name)) {
if (currentOptions.isVoidTag(tag)) {
onCloseTag(currentElement!, end)
} else {
stack.unshift(currentElement!)
if (ns === Namespaces.SVG || ns === Namespaces.MATH_ML) {
tokenizer.inXML = true
}
}
currentElement = null
}
@ -458,7 +461,7 @@ function onCloseTag(el: ElementNode, end: number) {
el.loc.end = tokenizer.getPos(end + offset + 1)
// refine element type
const tag = el.tag
const { tag, ns } = el
if (!inVPre) {
if (tag === 'slot') {
el.tagType = ElementTypes.SLOT
@ -473,14 +476,19 @@ function onCloseTag(el: ElementNode, end: number) {
if (!tokenizer.inRCDATA) {
el.children = condenseWhitespace(el.children, el.tag)
}
if (currentOptions.isPreTag(tag)) {
if (ns === Namespaces.HTML && currentOptions.isPreTag(tag)) {
inPre--
}
if (currentVPreBoundary === el) {
inVPre = false
currentVPreBoundary = null
}
if (
tokenizer.inXML &&
(stack[0] ? stack[0].ns : currentOptions.ns) === Namespaces.HTML
) {
tokenizer.inXML = false
}
}
const specialTemplateDir = new Set(['if', 'else', 'else-if', 'for', 'slot'])