Skip to content

Commit a248607

Browse files
committed
fix(parser): Fix for slot "name" property using interpolation as well as the "slot" property. (#9038)
1 parent 93850f4 commit a248607

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

src/compiler/parser/index.js

+29-7
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,28 @@ function processOnce (el) {
465465

466466
function processSlot (el) {
467467
if (el.tag === 'slot') {
468-
el.slotName = getBindingAttr(el, 'name')
469-
if (process.env.NODE_ENV !== 'production' && el.key) {
470-
warn(
471-
`\`key\` does not work on <slot> because slots are abstract outlets ` +
472-
`and can possibly expand into multiple elements. ` +
473-
`Use the key on a wrapping element instead.`
474-
)
468+
let slotName
469+
slotName = getBindingAttr(el, 'name')
470+
if (process.env.NODE_ENV !== 'production') {
471+
if(el.key) {
472+
warn(
473+
`\`key\` does not work on <slot> because slots are abstract outlets ` +
474+
`and can possibly expand into multiple elements. ` +
475+
`Use the key on a wrapping element instead.`
476+
)
477+
}
478+
if (slotName) {
479+
const res = parseText(slotName, delimiters);
480+
if (res) {
481+
warn(
482+
`name="${slotName}": ` +
483+
`Interpolation on <slot> "name" attribute has been removed. ` +
484+
`Use v-bind or the colon shorthand instead.`
485+
)
486+
}
487+
}
475488
}
489+
el.slotName = slotName
476490
} else {
477491
let slotScope
478492
if (el.tag === 'template') {
@@ -502,6 +516,14 @@ function processSlot (el) {
502516
}
503517
const slotTarget = getBindingAttr(el, 'slot')
504518
if (slotTarget) {
519+
const res = parseText(slotTarget, delimiters);
520+
if (process.env.NODE_ENV !== 'production' && res) {
521+
warn(
522+
`slot="${slotTarget}": "` +
523+
`Interpolation on "slot" attribute has been removed. ` +
524+
`Use v-bind or the colon shorthand instead.`
525+
);
526+
}
505527
el.slotTarget = slotTarget === '""' ? '"default"' : slotTarget
506528
// preserve slot as an attribute for native shadow DOM compat
507529
// only for non-scoped slots.

test/unit/modules/compiler/parser.spec.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,23 @@ describe('parser', () => {
476476
expect(ast.children[0].slotName).toBe('"one"')
477477
})
478478

479-
it('slot target', () => {
480-
const ast = parse('<p slot="one">hello world</p>', baseOptions)
481-
expect(ast.slotTarget).toBe('"one"')
479+
it('slot tag name invalid syntax', () => {
480+
// interpolation warning
481+
parse('<div><slot name="{{error}}">hello world</slot></div>', baseOptions);
482+
expect('Interpolation on <slot> "name" attribute has been removed.').toHaveBeenWarned();
482483
})
483484

485+
it("slot target", () => {
486+
const ast = parse('<p slot="one">hello world</p>', baseOptions);
487+
expect(ast.slotTarget).toBe('"one"');
488+
});
489+
490+
it("slot target invalid syntax", () => {
491+
// interpolation warning
492+
parse('<p slot="{{error}}">hello world</p>', baseOptions);
493+
expect('Interpolation on "slot" attribute has been removed.').toHaveBeenWarned();
494+
});
495+
484496
it('component properties', () => {
485497
const ast = parse('<my-component :msg="hello"></my-component>', baseOptions)
486498
expect(ast.attrs[0].name).toBe('msg')

0 commit comments

Comments
 (0)