Skip to content

Commit 0d26413

Browse files
committed
fix(compiler-core): fix parsing for directive with dynamic argument containing dots
1 parent f39ad0b commit 0d26413

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

packages/compiler-core/__tests__/parse.spec.ts

+74
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,43 @@ describe('compiler: parse', () => {
10151015
})
10161016
})
10171017

1018+
test('directive with dynamic argument', () => {
1019+
const ast = baseParse('<div v-on:[event]/>')
1020+
const directive = (ast.children[0] as ElementNode).props[0]
1021+
1022+
expect(directive).toStrictEqual({
1023+
type: NodeTypes.DIRECTIVE,
1024+
name: 'on',
1025+
arg: {
1026+
type: NodeTypes.SIMPLE_EXPRESSION,
1027+
content: 'event',
1028+
isStatic: false,
1029+
isConstant: false,
1030+
1031+
loc: {
1032+
source: '[event]',
1033+
start: {
1034+
column: 11,
1035+
line: 1,
1036+
offset: 10
1037+
},
1038+
end: {
1039+
column: 18,
1040+
line: 1,
1041+
offset: 17
1042+
}
1043+
}
1044+
},
1045+
modifiers: [],
1046+
exp: undefined,
1047+
loc: {
1048+
start: { offset: 5, line: 1, column: 6 },
1049+
end: { offset: 17, line: 1, column: 18 },
1050+
source: 'v-on:[event]'
1051+
}
1052+
})
1053+
})
1054+
10181055
test('directive with a modifier', () => {
10191056
const ast = baseParse('<div v-on.enter/>')
10201057
const directive = (ast.children[0] as ElementNode).props[0]
@@ -1088,6 +1125,43 @@ describe('compiler: parse', () => {
10881125
})
10891126
})
10901127

1128+
test('directive with dynamic argument and modifiers', () => {
1129+
const ast = baseParse('<div v-on:[a.b].camel/>')
1130+
const directive = (ast.children[0] as ElementNode).props[0]
1131+
1132+
expect(directive).toStrictEqual({
1133+
type: NodeTypes.DIRECTIVE,
1134+
name: 'on',
1135+
arg: {
1136+
type: NodeTypes.SIMPLE_EXPRESSION,
1137+
content: 'a.b',
1138+
isStatic: false,
1139+
isConstant: false,
1140+
1141+
loc: {
1142+
source: '[a.b]',
1143+
start: {
1144+
column: 11,
1145+
line: 1,
1146+
offset: 10
1147+
},
1148+
end: {
1149+
column: 16,
1150+
line: 1,
1151+
offset: 15
1152+
}
1153+
}
1154+
},
1155+
modifiers: ['camel'],
1156+
exp: undefined,
1157+
loc: {
1158+
start: { offset: 5, line: 1, column: 6 },
1159+
end: { offset: 21, line: 1, column: 22 },
1160+
source: 'v-on:[a.b].camel'
1161+
}
1162+
})
1163+
})
1164+
10911165
test('v-bind shorthand', () => {
10921166
const ast = baseParse('<div :a=b />')
10931167
const directive = (ast.children[0] as ElementNode).props[0]

packages/compiler-core/src/parse.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ function parseAttribute(
599599
const loc = getSelection(context, start)
600600

601601
if (!context.inVPre && /^(v-|:|@|#)/.test(name)) {
602-
const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^@|^#)([^\.]+))?(.+)?$/i.exec(
602+
const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(
603603
name
604604
)!
605605

0 commit comments

Comments
 (0)