From 99c892e87071948f02bcb63303a863faa718105e Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Mon, 16 Dec 2024 02:20:41 +0800 Subject: [PATCH] fix(compiler-core): avoid self updates of `v-pre` --- packages/compiler-core/src/parser.ts | 5 +++-- packages/compiler-core/src/utils.ts | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/compiler-core/src/parser.ts b/packages/compiler-core/src/parser.ts index 95c5e129f25..ed462e215b4 100644 --- a/packages/compiler-core/src/parser.ts +++ b/packages/compiler-core/src/parser.ts @@ -43,6 +43,7 @@ import { isCoreComponent, isSimpleIdentifier, isStaticArgOf, + isVPre, } from './utils' import { decodeHTML } from 'entities/lib/decode.js' import { @@ -246,7 +247,7 @@ const tokenizer = new Tokenizer(stack, { ondirarg(start, end) { if (start === end) return const arg = getSlice(start, end) - if (inVPre) { + if (inVPre && !isVPre(currentProp!)) { ;(currentProp as AttributeNode).name += arg setLocEnd((currentProp as AttributeNode).nameLoc, end) } else { @@ -262,7 +263,7 @@ const tokenizer = new Tokenizer(stack, { ondirmodifier(start, end) { const mod = getSlice(start, end) - if (inVPre) { + if (inVPre && !isVPre(currentProp!)) { ;(currentProp as AttributeNode).name += '.' + mod setLocEnd((currentProp as AttributeNode).nameLoc, end) } else if ((currentProp as DirectiveNode).name === 'slot') { diff --git a/packages/compiler-core/src/utils.ts b/packages/compiler-core/src/utils.ts index b49d70bb2fb..3881b4374e2 100644 --- a/packages/compiler-core/src/utils.ts +++ b/packages/compiler-core/src/utils.ts @@ -343,6 +343,10 @@ export function isText( return node.type === NodeTypes.INTERPOLATION || node.type === NodeTypes.TEXT } +export function isVPre(p: ElementNode['props'][0]): p is DirectiveNode { + return p.type === NodeTypes.DIRECTIVE && p.name === 'pre' +} + export function isVSlot(p: ElementNode['props'][0]): p is DirectiveNode { return p.type === NodeTypes.DIRECTIVE && p.name === 'slot' }