]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler): clone loc to `ifNode` (#12131)
author山吹色御守 <85992002+KazariEX@users.noreply.github.com>
Fri, 11 Oct 2024 03:07:07 +0000 (11:07 +0800)
committerGitHub <noreply@github.com>
Fri, 11 Oct 2024 03:07:07 +0000 (11:07 +0800)
fix vuejs/language-tools#4911

packages/compiler-core/src/parser.ts
packages/compiler-core/src/transforms/vIf.ts

index 0d66d2055f4ca8ff1e259bca06ec0cd18fcee559..95c5e129f2523ade97a84edc2cbaf31c97cbcb5d 100644 (file)
@@ -933,6 +933,10 @@ function getLoc(start: number, end?: number): SourceLocation {
   }
 }
 
+export function cloneLoc(loc: SourceLocation): SourceLocation {
+  return getLoc(loc.start.offset, loc.end.offset)
+}
+
 function setLocEnd(loc: SourceLocation, end: number) {
   loc.end = tokenizer.getPos(end)
   loc.source = getSlice(loc.start.offset, end)
index caefa197efe5c24daf8f8c14904f61e84a53256a..54c505407a363783a66753dd187278139e3ec388 100644 (file)
@@ -30,6 +30,7 @@ import {
 import { ErrorCodes, createCompilerError } from '../errors'
 import { processExpression } from './transformExpression'
 import { validateBrowserExpression } from '../validateExpression'
+import { cloneLoc } from '../parser'
 import { CREATE_COMMENT, FRAGMENT } from '../runtimeHelpers'
 import { findDir, findProp, getMemoedVNodeCall, injectProp } from '../utils'
 import { PatchFlags } from '@vue/shared'
@@ -110,7 +111,7 @@ export function processIf(
     const branch = createIfBranch(node, dir)
     const ifNode: IfNode = {
       type: NodeTypes.IF,
-      loc: node.loc,
+      loc: cloneLoc(node.loc),
       branches: [branch],
     }
     context.replaceNode(ifNode)