wip: tune perf

This commit is contained in:
Evan You 2023-11-18 12:01:55 +08:00
parent 082b5a71c6
commit caabba7590
1 changed files with 7 additions and 10 deletions

View File

@ -74,7 +74,6 @@ let currentProp: AttributeNode | DirectiveNode | null = null
let currentAttrValue = '' let currentAttrValue = ''
let currentAttrStartIndex = -1 let currentAttrStartIndex = -1
let currentAttrEndIndex = -1 let currentAttrEndIndex = -1
let currentAttrs: Set<string> = new Set()
let inPre = 0 let inPre = 0
let inVPre = false let inVPre = false
let currentVPreBoundary: ElementNode | null = null let currentVPreBoundary: ElementNode | null = null
@ -124,7 +123,6 @@ const tokenizer = new Tokenizer(stack, {
loc: getLoc(start - 1), loc: getLoc(start - 1),
codegenNode: undefined codegenNode: undefined
} }
currentAttrs.clear()
}, },
onopentagend(end) { onopentagend(end) {
@ -249,18 +247,18 @@ const tokenizer = new Tokenizer(stack, {
}, },
onattribnameend(end) { onattribnameend(end) {
// check duplicate attrs
const start = currentProp!.loc.start.offset const start = currentProp!.loc.start.offset
const name = getSlice(start, end) const name = getSlice(start, end)
if (currentProp!.type === NodeTypes.DIRECTIVE) { if (currentProp!.type === NodeTypes.DIRECTIVE) {
currentProp!.rawName = name currentProp!.rawName = name
} }
if (currentAttrs.has(name)) { // check duplicate attrs
currentProp = null if (
// TODO emit error DUPLICATE_ATTRIBUTE currentElement!.props.some(
throw new Error(`duplicate attr ${name}`) p => (p.type === NodeTypes.DIRECTIVE ? p.rawName : p.name) === name
} else { )
currentAttrs.add(name) ) {
// TODO duplicate
} }
}, },
@ -688,7 +686,6 @@ function reset() {
tokenizer.reset() tokenizer.reset()
currentElement = null currentElement = null
currentProp = null currentProp = null
currentAttrs.clear()
currentAttrValue = '' currentAttrValue = ''
currentAttrStartIndex = -1 currentAttrStartIndex = -1
currentAttrEndIndex = -1 currentAttrEndIndex = -1