})
expect(prop).toMatchObject({
type: NodeTypes.JS_PROPERTY,
- value: createObjectMatcher({
- handler: {
- callee: V_ON_MODIFIERS_GUARD,
- arguments: [{ content: '_ctx.test' }, '["stop","prevent"]']
- },
- persistent: { content: 'true', isStatic: false }
- })
+ value: {
+ callee: V_ON_MODIFIERS_GUARD,
+ arguments: [{ content: '_ctx.test' }, '["stop","prevent"]']
+ }
})
})
callee: V_ON_MODIFIERS_GUARD,
arguments: [{ content: '_ctx.test' }, '["stop"]']
},
- persistent: { content: 'true', isStatic: false },
options: createObjectMatcher({
capture: { content: 'true', isStatic: false },
passive: { content: 'true', isStatic: false }
- })
+ }),
+ persistent: { content: 'true', isStatic: false }
})
})
})
'["a"]'
]
},
- persistent: { content: 'true', isStatic: false },
options: createObjectMatcher({
capture: { content: 'true', isStatic: false }
- })
+ }),
+ persistent: { content: 'true', isStatic: false }
})
})
})
createCallExpression,
createObjectExpression,
createSimpleExpression,
- NodeTypes
+ NodeTypes,
+ CallExpression,
+ ObjectExpression
} from '@vue/compiler-core'
import { V_ON_MODIFIERS_GUARD, V_ON_KEYS_GUARD } from '../runtimeHelpers'
const { modifiers } = dir
const baseResult = baseTransform(dir, node, context)
if (!modifiers.length) return baseResult
+
const { key, value } = baseResult.props[0]
const runtimeModifiers = modifiers.filter(m => !(m in EVENT_OPTION_MODIFIERS))
let handler = createCallExpression(context.helper(V_ON_MODIFIERS_GUARD), [
JSON.stringify(runtimeModifiers.filter(m => !(m in NOT_KEY_MODIFIERS)))
])
}
- const properties = [
- createObjectProperty('handler', handler),
- // so the runtime knows the options never change
- createObjectProperty('persistent', createSimpleExpression('true', false))
- ]
+
+ let returnExp: CallExpression | ObjectExpression = handler
const eventOptionModifiers = modifiers.filter(
modifier => modifier in EVENT_OPTION_MODIFIERS
)
if (eventOptionModifiers.length) {
- properties.push(
+ returnExp = createObjectExpression([
+ createObjectProperty('handler', handler),
createObjectProperty(
'options',
createObjectExpression(
)
)
)
- )
- )
+ ),
+ // so the runtime knows the options never change
+ createObjectProperty('persistent', createSimpleExpression('true', false))
+ ])
}
return {
- props: [createObjectProperty(key, createObjectExpression(properties))],
+ props: [createObjectProperty(key, returnExp)],
needRuntime: false
}
}