diff --git a/packages/compiler-core/__tests__/transforms/vModel.spec.ts b/packages/compiler-core/__tests__/transforms/vModel.spec.ts index 818076a5..3eed83cc 100644 --- a/packages/compiler-core/__tests__/transforms/vModel.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vModel.spec.ts @@ -351,5 +351,17 @@ describe('compiler: transform v-model', () => { }) ) }) + + test('mal-formed expression', () => { + const onError = jest.fn() + parseWithVModel('', { onError }) + + expect(onError).toHaveBeenCalledTimes(1) + expect(onError).toHaveBeenCalledWith( + expect.objectContaining({ + code: ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION + }) + ) + }) }) }) diff --git a/packages/compiler-core/__tests__/transforms/vOn.spec.ts b/packages/compiler-core/__tests__/transforms/vOn.spec.ts index 114fd529..41bd6677 100644 --- a/packages/compiler-core/__tests__/transforms/vOn.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vOn.spec.ts @@ -175,6 +175,34 @@ describe('compiler: transform v-on', () => { }) }) + test('should NOT wrap as function if expression is complex member expression', () => { + const node = parseWithVOn(`
`) + 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(`
`, { + 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(`
`, { prefixIdentifiers: true diff --git a/packages/compiler-core/src/ast.ts b/packages/compiler-core/src/ast.ts index d422fc59..9da05bb8 100644 --- a/packages/compiler-core/src/ast.ts +++ b/packages/compiler-core/src/ast.ts @@ -519,11 +519,12 @@ export function createInterpolation( } export function createCompoundExpression( - children: CompoundExpressionNode['children'] + children: CompoundExpressionNode['children'], + loc: SourceLocation = locStub ): CompoundExpressionNode { return { type: NodeTypes.COMPOUND_EXPRESSION, - loc: locStub, + loc, children } } diff --git a/packages/compiler-core/src/errors.ts b/packages/compiler-core/src/errors.ts index 759f3457..24b2a107 100644 --- a/packages/compiler-core/src/errors.ts +++ b/packages/compiler-core/src/errors.ts @@ -170,7 +170,7 @@ export const errorMessages: { [code: number]: string } = { `These children will be ignored.`, [ErrorCodes.X_V_SLOT_MISPLACED]: `v-slot can only be used on components or