]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler): generate correct mappings for v-for and object properties (#69)
authorRahul Kadyan <hi@znck.me>
Fri, 27 Sep 2019 13:19:03 +0000 (18:49 +0530)
committerEvan You <yyx990803@gmail.com>
Fri, 27 Sep 2019 13:19:03 +0000 (09:19 -0400)
packages/compiler-core/src/codegen.ts
packages/compiler-core/src/transforms/transformElement.ts
packages/compiler-core/src/transforms/vFor.ts

index a7e0727b3a70f74c4279128b4183b195e47fc939..a0a72c1f27502262ce51c7181424078b9b566814 100644 (file)
@@ -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(`: `)
index e346afbd1ebe4f365ccab99571a1a31de6f226a6..0d5cdd049df1237eb6b51807f4e557bcbf32e2bd 100644 (file)
@@ -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,
index 9c6b315eba35c9a3da577d39f31032c17d71d917..8e436dc4311951f60cd2bfa0e2f98a2fa4dc2aec 100644 (file)
@@ -25,7 +25,7 @@ export const transformFor = createStructuralDirectiveTransform(
 
         context.replaceNode({
           type: NodeTypes.FOR,
-          loc: node.loc,
+          loc: dir.loc,
           source,
           valueAlias: value,
           keyAlias: key,