fix(v-model): generate separate modifiers for v-model with args

This commit is contained in:
Evan You
2019-11-07 09:40:34 -05:00
parent c53ca29ea1
commit f178874ace
3 changed files with 49 additions and 17 deletions

View File

@@ -43,13 +43,12 @@ export const transformModel: DirectiveTransform = (dir, node, context) => {
const propName = arg ? arg : createSimpleExpression('modelValue', true)
const eventName = arg
? arg.type === NodeTypes.SIMPLE_EXPRESSION && arg.isStatic
? createSimpleExpression('onUpdate:' + arg.content, true)
? `onUpdate:${arg.content}`
: createCompoundExpression([
createSimpleExpression('onUpdate:', true),
'+',
'"onUpdate:" + ',
...(arg.type === NodeTypes.SIMPLE_EXPRESSION ? [arg] : arg.children)
])
: createSimpleExpression('onUpdate:modelValue', true)
: `onUpdate:modelValue`
const props = [
// modelValue: foo
@@ -80,9 +79,19 @@ export const transformModel: DirectiveTransform = (dir, node, context) => {
const modifiers = dir.modifiers
.map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
.join(`, `)
const modifiersKey = arg
? arg.type === NodeTypes.SIMPLE_EXPRESSION && arg.isStatic
? `${arg.content}Modifiers`
: createCompoundExpression([
...(arg.type === NodeTypes.SIMPLE_EXPRESSION
? [arg]
: arg.children),
' + "Modifiers"'
])
: `modelModifiers`
props.push(
createObjectProperty(
`modelModifiers`,
modifiersKey,
createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, true)
)
)