diff --git a/packages/compiler-core/src/codegen.ts b/packages/compiler-core/src/codegen.ts index a7e0727b..a0a72c1f 100644 --- a/packages/compiler-core/src/codegen.ts +++ b/packages/compiler-core/src/codegen.ts @@ -130,7 +130,7 @@ function createCodegenContext( } }) } - advancePositionWithMutation(context, code) + if (code) advancePositionWithMutation(context, code) if (node && !openOnly) { context.map.addMapping({ source: context.filename, @@ -518,7 +518,8 @@ function genObjectExpression(node: ObjectExpression, context: CodegenContext) { push(multilines ? `{` : `{ `) multilines && indent() for (let i = 0; i < properties.length; i++) { - const { key, value } = properties[i] + const { key, value, loc } = properties[i] + push('', { loc } as any, true) // resets source mapping for every property. // key genExpressionAsPropertyKey(key, context) push(`: `) diff --git a/packages/compiler-core/src/transforms/transformElement.ts b/packages/compiler-core/src/transforms/transformElement.ts index e346afbd..0d5cdd04 100644 --- a/packages/compiler-core/src/transforms/transformElement.ts +++ b/packages/compiler-core/src/transforms/transformElement.ts @@ -25,6 +25,7 @@ import { MERGE_PROPS, TO_HANDLERS } from '../runtimeConstants' +import { getInnerRange } from '../utils' const toValidId = (str: string): string => str.replace(/[^\w]/g, '') @@ -121,7 +122,7 @@ function buildProps( const { loc, name, value } = prop properties.push( createObjectProperty( - createExpression(name, true, loc), + createExpression(name, true, getInnerRange(loc, 0, name.length)), createExpression( value ? value.content : '', true, diff --git a/packages/compiler-core/src/transforms/vFor.ts b/packages/compiler-core/src/transforms/vFor.ts index 9c6b315e..8e436dc4 100644 --- a/packages/compiler-core/src/transforms/vFor.ts +++ b/packages/compiler-core/src/transforms/vFor.ts @@ -25,7 +25,7 @@ export const transformFor = createStructuralDirectiveTransform( context.replaceNode({ type: NodeTypes.FOR, - loc: node.loc, + loc: dir.loc, source, valueAlias: value, keyAlias: key,