From: Evan You Date: Sun, 18 Apr 2021 02:05:18 +0000 (-0400) Subject: perf(compiler): skip unncessary checks when parsing end tag X-Git-Tag: v3.1.0-beta.1~59^2~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=048ac299f35709b25ae1bc1efa67d2abc53dbc3b;p=thirdparty%2Fvuejs%2Fcore.git perf(compiler): skip unncessary checks when parsing end tag --- diff --git a/packages/compiler-core/src/parse.ts b/packages/compiler-core/src/parse.ts index 9db216f169..383c115bba 100644 --- a/packages/compiler-core/src/parse.ts +++ b/packages/compiler-core/src/parse.ts @@ -444,11 +444,21 @@ const isSpecialTemplateDirective = /*#__PURE__*/ makeMap( /** * Parse a tag (E.g. `
`) with that type (start tag or end tag). */ +function parseTag( + context: ParserContext, + type: TagType.Start, + parent: ElementNode | undefined +): ElementNode +function parseTag( + context: ParserContext, + type: TagType.End, + parent: ElementNode | undefined +): void function parseTag( context: ParserContext, type: TagType, parent: ElementNode | undefined -): ElementNode { +): ElementNode | undefined { __TEST__ && assert(/^<\/?[a-z]/i.test(context.source)) __TEST__ && assert( @@ -478,6 +488,7 @@ function parseTag( // check v-pre if ( + type === TagType.Start && !context.inVPre && props.some(p => p.type === NodeTypes.DIRECTIVE && p.name === 'pre') ) { @@ -489,6 +500,22 @@ function parseTag( props = parseAttributes(context, type).filter(p => p.name !== 'v-pre') } + // Tag close. + let isSelfClosing = false + if (context.source.length === 0) { + emitError(context, ErrorCodes.EOF_IN_TAG) + } else { + isSelfClosing = startsWith(context.source, '/>') + if (type === TagType.End && isSelfClosing) { + emitError(context, ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS) + } + advanceBy(context, isSelfClosing ? 2 : 1) + } + + if (type === TagType.End) { + return + } + // warn v-if/v-for usage on the same element if (__COMPAT__ && __DEV__ && !__TEST__) { let hasIf = false @@ -512,18 +539,6 @@ function parseTag( } } - // Tag close. - let isSelfClosing = false - if (context.source.length === 0) { - emitError(context, ErrorCodes.EOF_IN_TAG) - } else { - isSelfClosing = startsWith(context.source, '/>') - if (type === TagType.End && isSelfClosing) { - emitError(context, ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS) - } - advanceBy(context, isSelfClosing ? 2 : 1) - } - let tagType = ElementTypes.ELEMENT const options = context.options if (!context.inVPre && !options.isCustomElement(tag)) { @@ -565,11 +580,10 @@ function parseTag( tagType = ElementTypes.SLOT } else if ( tag === 'template' && - props.some(p => { - return ( + props.some( + p => p.type === NodeTypes.DIRECTIVE && isSpecialTemplateDirective(p.name) - ) - }) + ) ) { tagType = ElementTypes.TEMPLATE }