Skip to content

Commit ff2aa0d

Browse files
committed
fix(compiler): generate correct mappings for v-for and object properties
1 parent 63b6902 commit ff2aa0d

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

packages/compiler-core/src/codegen.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function createCodegenContext(
130130
}
131131
})
132132
}
133-
advancePositionWithMutation(context, code)
133+
if (code) advancePositionWithMutation(context, code)
134134
if (node && !openOnly) {
135135
context.map.addMapping({
136136
source: context.filename,
@@ -518,7 +518,8 @@ function genObjectExpression(node: ObjectExpression, context: CodegenContext) {
518518
push(multilines ? `{` : `{ `)
519519
multilines && indent()
520520
for (let i = 0; i < properties.length; i++) {
521-
const { key, value } = properties[i]
521+
const { key, value, loc } = properties[i]
522+
push('', { loc } as any, true) // resets source mapping for every property.
522523
// key
523524
genExpressionAsPropertyKey(key, context)
524525
push(`: `)

packages/compiler-core/src/transforms/transformElement.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
MERGE_PROPS,
2626
TO_HANDLERS
2727
} from '../runtimeConstants'
28+
import { getInnerRange } from '../utils'
2829

2930
const toValidId = (str: string): string => str.replace(/[^\w]/g, '')
3031

@@ -121,7 +122,7 @@ function buildProps(
121122
const { loc, name, value } = prop
122123
properties.push(
123124
createObjectProperty(
124-
createExpression(name, true, loc),
125+
createExpression(name, true, getInnerRange(loc, 0, name.length)),
125126
createExpression(
126127
value ? value.content : '',
127128
true,

packages/compiler-core/src/transforms/vFor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const transformFor = createStructuralDirectiveTransform(
2525

2626
context.replaceNode({
2727
type: NodeTypes.FOR,
28-
loc: node.loc,
28+
loc: dir.loc,
2929
source,
3030
valueAlias: value,
3131
keyAlias: key,

0 commit comments

Comments
 (0)