diff --git a/packages/compiler-core/__tests__/parse.spec.ts b/packages/compiler-core/__tests__/parse.spec.ts index e3345a0f26f..63201c4f4d9 100644 --- a/packages/compiler-core/__tests__/parse.spec.ts +++ b/packages/compiler-core/__tests__/parse.spec.ts @@ -1015,6 +1015,43 @@ describe('compiler: parse', () => { }) }) + test('directive with dynamic argument', () => { + const ast = baseParse('
') + const directive = (ast.children[0] as ElementNode).props[0] + + expect(directive).toStrictEqual({ + type: NodeTypes.DIRECTIVE, + name: 'on', + arg: { + type: NodeTypes.SIMPLE_EXPRESSION, + content: 'event', + isStatic: false, + isConstant: false, + + loc: { + source: '[event]', + start: { + column: 11, + line: 1, + offset: 10 + }, + end: { + column: 18, + line: 1, + offset: 17 + } + } + }, + modifiers: [], + exp: undefined, + loc: { + start: { offset: 5, line: 1, column: 6 }, + end: { offset: 17, line: 1, column: 18 }, + source: 'v-on:[event]' + } + }) + }) + test('directive with a modifier', () => { const ast = baseParse('
') const directive = (ast.children[0] as ElementNode).props[0] @@ -1088,6 +1125,43 @@ describe('compiler: parse', () => { }) }) + test('directive with dynamic argument and modifiers', () => { + const ast = baseParse('
') + const directive = (ast.children[0] as ElementNode).props[0] + + expect(directive).toStrictEqual({ + type: NodeTypes.DIRECTIVE, + name: 'on', + arg: { + type: NodeTypes.SIMPLE_EXPRESSION, + content: 'a.b', + isStatic: false, + isConstant: false, + + loc: { + source: '[a.b]', + start: { + column: 11, + line: 1, + offset: 10 + }, + end: { + column: 16, + line: 1, + offset: 15 + } + } + }, + modifiers: ['camel'], + exp: undefined, + loc: { + start: { offset: 5, line: 1, column: 6 }, + end: { offset: 21, line: 1, column: 22 }, + source: 'v-on:[a.b].camel' + } + }) + }) + test('v-bind shorthand', () => { const ast = baseParse('
') const directive = (ast.children[0] as ElementNode).props[0] diff --git a/packages/compiler-core/src/parse.ts b/packages/compiler-core/src/parse.ts index 57a1592544c..b7725cff007 100644 --- a/packages/compiler-core/src/parse.ts +++ b/packages/compiler-core/src/parse.ts @@ -599,7 +599,7 @@ function parseAttribute( const loc = getSelection(context, start) if (!context.inVPre && /^(v-|:|@|#)/.test(name)) { - const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^@|^#)([^\.]+))?(.+)?$/i.exec( + const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec( name )!