refactor(compiler): improve member expression check for v-on & v-model
This commit is contained in:
@@ -351,5 +351,17 @@ describe('compiler: transform v-model', () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test('mal-formed expression', () => {
|
||||
const onError = jest.fn()
|
||||
parseWithVModel('<span v-model="a + b" />', { onError })
|
||||
|
||||
expect(onError).toHaveBeenCalledTimes(1)
|
||||
expect(onError).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
code: ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -175,6 +175,34 @@ describe('compiler: transform v-on', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('should NOT wrap as function if expression is complex member expression', () => {
|
||||
const node = parseWithVOn(`<div @click="a['b' + c]"/>`)
|
||||
const props = (node.codegenNode as CallExpression)
|
||||
.arguments[1] as ObjectExpression
|
||||
expect(props.properties[0]).toMatchObject({
|
||||
key: { content: `onClick` },
|
||||
value: {
|
||||
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||
content: `a['b' + c]`
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('complex member expression w/ prefixIdentifiers: true', () => {
|
||||
const node = parseWithVOn(`<div @click="a['b' + c]"/>`, {
|
||||
prefixIdentifiers: true
|
||||
})
|
||||
const props = (node.codegenNode as CallExpression)
|
||||
.arguments[1] as ObjectExpression
|
||||
expect(props.properties[0]).toMatchObject({
|
||||
key: { content: `onClick` },
|
||||
value: {
|
||||
type: NodeTypes.COMPOUND_EXPRESSION,
|
||||
children: [{ content: `_ctx.a` }, `['b' + `, { content: `_ctx.c` }, `]`]
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('function expression w/ prefixIdentifiers: true', () => {
|
||||
const node = parseWithVOn(`<div @click="e => foo(e)"/>`, {
|
||||
prefixIdentifiers: true
|
||||
|
||||
Reference in New Issue
Block a user