fix(compiler): generate correct mappings for v-for and object properties (#69)

This commit is contained in:
Rahul Kadyan 2019-09-27 18:49:03 +05:30 committed by Evan You
parent 050ef698c4
commit a407b16b2b
3 changed files with 6 additions and 4 deletions

View File

@ -130,7 +130,7 @@ function createCodegenContext(
} }
}) })
} }
advancePositionWithMutation(context, code) if (code) advancePositionWithMutation(context, code)
if (node && !openOnly) { if (node && !openOnly) {
context.map.addMapping({ context.map.addMapping({
source: context.filename, source: context.filename,
@ -518,7 +518,8 @@ function genObjectExpression(node: ObjectExpression, context: CodegenContext) {
push(multilines ? `{` : `{ `) push(multilines ? `{` : `{ `)
multilines && indent() multilines && indent()
for (let i = 0; i < properties.length; i++) { 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 // key
genExpressionAsPropertyKey(key, context) genExpressionAsPropertyKey(key, context)
push(`: `) push(`: `)

View File

@ -25,6 +25,7 @@ import {
MERGE_PROPS, MERGE_PROPS,
TO_HANDLERS TO_HANDLERS
} from '../runtimeConstants' } from '../runtimeConstants'
import { getInnerRange } from '../utils'
const toValidId = (str: string): string => str.replace(/[^\w]/g, '') const toValidId = (str: string): string => str.replace(/[^\w]/g, '')
@ -121,7 +122,7 @@ function buildProps(
const { loc, name, value } = prop const { loc, name, value } = prop
properties.push( properties.push(
createObjectProperty( createObjectProperty(
createExpression(name, true, loc), createExpression(name, true, getInnerRange(loc, 0, name.length)),
createExpression( createExpression(
value ? value.content : '', value ? value.content : '',
true, true,

View File

@ -25,7 +25,7 @@ export const transformFor = createStructuralDirectiveTransform(
context.replaceNode({ context.replaceNode({
type: NodeTypes.FOR, type: NodeTypes.FOR,
loc: node.loc, loc: dir.loc,
source, source,
valueAlias: value, valueAlias: value,
keyAlias: key, keyAlias: key,