Skip to content

Commit cde2c06

Browse files
authoredOct 11, 2024··
fix(compiler): clone loc to ifNode (#12131)
fix vuejs/language-tools#4911
1 parent 4474c11 commit cde2c06

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
 

‎packages/compiler-core/src/parser.ts

+4
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,10 @@ function getLoc(start: number, end?: number): SourceLocation {
933933
}
934934
}
935935

936+
export function cloneLoc(loc: SourceLocation): SourceLocation {
937+
return getLoc(loc.start.offset, loc.end.offset)
938+
}
939+
936940
function setLocEnd(loc: SourceLocation, end: number) {
937941
loc.end = tokenizer.getPos(end)
938942
loc.source = getSlice(loc.start.offset, end)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
import { ErrorCodes, createCompilerError } from '../errors'
3131
import { processExpression } from './transformExpression'
3232
import { validateBrowserExpression } from '../validateExpression'
33+
import { cloneLoc } from '../parser'
3334
import { CREATE_COMMENT, FRAGMENT } from '../runtimeHelpers'
3435
import { findDir, findProp, getMemoedVNodeCall, injectProp } from '../utils'
3536
import { PatchFlags } from '@vue/shared'
@@ -110,7 +111,7 @@ export function processIf(
110111
const branch = createIfBranch(node, dir)
111112
const ifNode: IfNode = {
112113
type: NodeTypes.IF,
113-
loc: node.loc,
114+
loc: cloneLoc(node.loc),
114115
branches: [branch],
115116
}
116117
context.replaceNode(ifNode)

0 commit comments

Comments
 (0)
Please sign in to comment.