feat: v-on with no argument

This commit is contained in:
Evan You
2019-09-24 20:51:48 -04:00
parent 0707fa5d21
commit 9b06e04e0f
6 changed files with 123 additions and 19 deletions

View File

@@ -11,7 +11,8 @@ import {
CREATE_VNODE,
MERGE_PROPS,
RESOLVE_DIRECTIVE,
APPLY_DIRECTIVES
APPLY_DIRECTIVES,
TO_HANDLERS
} from '../../src/runtimeConstants'
import {
CallExpression,
@@ -198,6 +199,67 @@ describe('compiler: element transform', () => {
})
})
test('v-on="obj"', () => {
const { root, node } = parseWithElementTransform(
`<div id="foo" v-on="obj" class="bar" />`
)
expect(root.imports).toContain(MERGE_PROPS)
expect(node.callee).toBe(CREATE_VNODE)
expect(node.arguments[1]).toMatchObject({
type: NodeTypes.JS_CALL_EXPRESSION,
callee: MERGE_PROPS,
arguments: [
createStaticObjectMatcher({
id: 'foo'
}),
{
type: NodeTypes.JS_CALL_EXPRESSION,
callee: TO_HANDLERS,
arguments: [
{
type: NodeTypes.EXPRESSION,
content: `obj`
}
]
},
createStaticObjectMatcher({
class: 'bar'
})
]
})
})
test('v-on="obj" + v-bind="obj"', () => {
const { root, node } = parseWithElementTransform(
`<div id="foo" v-on="handlers" v-bind="obj" />`
)
expect(root.imports).toContain(MERGE_PROPS)
expect(node.callee).toBe(CREATE_VNODE)
expect(node.arguments[1]).toMatchObject({
type: NodeTypes.JS_CALL_EXPRESSION,
callee: MERGE_PROPS,
arguments: [
createStaticObjectMatcher({
id: 'foo'
}),
{
type: NodeTypes.JS_CALL_EXPRESSION,
callee: TO_HANDLERS,
arguments: [
{
type: NodeTypes.EXPRESSION,
content: `handlers`
}
]
},
{
type: NodeTypes.EXPRESSION,
content: `obj`
}
]
})
})
test('error on v-bind with no argument', () => {
const onError = jest.fn()
parseWithElementTransform(`<div v-bind/>`, { onError })