Skip to content

Commit 825ec15

Browse files
committed
fix(compiler-core): support static slot names containing dots for 2.x compat
close #1241
1 parent 0d26413 commit 825ec15

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

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

+30
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,36 @@ describe('compiler: parse', () => {
14011401
})
14021402
})
14031403

1404+
// #1241 special case for 2.x compat
1405+
test('v-slot arg containing dots', () => {
1406+
const ast = baseParse('<Comp v-slot:foo.bar="{ a }" />')
1407+
const directive = (ast.children[0] as ElementNode).props[0]
1408+
1409+
expect(directive).toMatchObject({
1410+
type: NodeTypes.DIRECTIVE,
1411+
name: 'slot',
1412+
arg: {
1413+
type: NodeTypes.SIMPLE_EXPRESSION,
1414+
content: 'foo.bar',
1415+
isStatic: true,
1416+
isConstant: true,
1417+
loc: {
1418+
source: 'foo.bar',
1419+
start: {
1420+
column: 14,
1421+
line: 1,
1422+
offset: 13
1423+
},
1424+
end: {
1425+
column: 21,
1426+
line: 1,
1427+
offset: 20
1428+
}
1429+
}
1430+
}
1431+
})
1432+
})
1433+
14041434
test('v-pre', () => {
14051435
const ast = baseParse(
14061436
`<div v-pre :id="foo"><Comp/>{{ bar }}</div>\n` +

packages/compiler-core/src/parse.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -603,14 +603,23 @@ function parseAttribute(
603603
name
604604
)!
605605

606+
const dirName =
607+
match[1] ||
608+
(startsWith(name, ':') ? 'bind' : startsWith(name, '@') ? 'on' : 'slot')
609+
606610
let arg: ExpressionNode | undefined
607611

608612
if (match[2]) {
613+
const isSlot = dirName === 'slot'
609614
const startOffset = name.indexOf(match[2])
610615
const loc = getSelection(
611616
context,
612617
getNewPosition(context, start, startOffset),
613-
getNewPosition(context, start, startOffset + match[2].length)
618+
getNewPosition(
619+
context,
620+
start,
621+
startOffset + match[2].length + ((isSlot && match[3]) || '').length
622+
)
614623
)
615624
let content = match[2]
616625
let isStatic = true
@@ -626,6 +635,11 @@ function parseAttribute(
626635
}
627636

628637
content = content.substr(1, content.length - 2)
638+
} else if (isSlot) {
639+
// #1241 special case for v-slot: vuetify relies extensively on slot
640+
// names containing dots. v-slot doesn't have any modifiers and Vue 2.x
641+
// supports such usage so we are keeping it consistent with 2.x.
642+
content += match[3] || ''
629643
}
630644

631645
arg = {
@@ -647,13 +661,7 @@ function parseAttribute(
647661

648662
return {
649663
type: NodeTypes.DIRECTIVE,
650-
name:
651-
match[1] ||
652-
(startsWith(name, ':')
653-
? 'bind'
654-
: startsWith(name, '@')
655-
? 'on'
656-
: 'slot'),
664+
name: dirName,
657665
exp: value && {
658666
type: NodeTypes.SIMPLE_EXPRESSION,
659667
content: value.content,

0 commit comments

Comments
 (0)