Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,18 @@ function processOnce (el) {
function processSlot (el) {
if (el.tag === 'slot') {
el.slotName = getBindingAttr(el, 'name')
// Fixes: #9038
if(process.env.NODE_ENV !== 'production'){
const slotName = el.attrsMap['name']
if(!dirRE.test(slotName) && parseText(slotName, delimiters)){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why dirRE.test here? Seems unnecessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this to keep the same behavior as in place where previous warning exists (line 596). As you can see that previous warning is shown only when dirRE.test is false.

processSlot is executed outside of processAttrs thus I've added this additional check, to prevent double warnings

warn(
`name="${slotName}": ` +
'Interpolation inside attributes has been removed. ' +
'Use v-bind or the colon shorthand instead. For example, ' +
`instead of <slot name="{{ val }}">, use <slot :name="val">.`
)
}
}
if (process.env.NODE_ENV !== 'production' && el.key) {
warn(
`\`key\` does not work on <slot> because slots are abstract outlets ` +
Expand Down
25 changes: 25 additions & 0 deletions test/unit/modules/compiler/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,4 +737,29 @@ describe('parser', () => {
const ast = parse(`<p>{{\r\nmsg\r\n}}</p>`, baseOptions)
expect(ast.children[0].expression).toBe('_s(msg)')
})

// #9038
it('should warn if interpolation is used in slot name attribute', () => {
parse(`
<div class="wrapper">
<slot name="line-{{ index }}"></slot>
</div>`, baseOptions)

expect('name="line-{{ index }}": Interpolation inside attributes has been removed. ' +
'Use v-bind or the colon shorthand instead. ' +
'For example, instead of <slot name="{{ val }}">, use <slot :name="val">.')
.toHaveBeenWarned()
})

it('should not warn if interpolation is not used in slot name attribute', () => {
parse(`
<div class="wrapper">
<slot :name="'line-' + index"></slot>
</div>`, baseOptions)

expect('name="line-{{ index }}": Interpolation inside attributes has been removed. ' +
'Use v-bind or the colon shorthand instead. ' +
'For example, instead of <slot name="{{ val }}">, use <slot :name="val">.')
.not.toHaveBeenWarned()
})
})