Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser#9038): Fix for slot "name" property using interpolation as well… #9143

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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
36 changes: 29 additions & 7 deletions src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,28 @@ function processOnce (el) {

function processSlot (el) {
if (el.tag === 'slot') {
el.slotName = getBindingAttr(el, 'name')
if (process.env.NODE_ENV !== 'production' && el.key) {
warn(
`\`key\` does not work on <slot> because slots are abstract outlets ` +
`and can possibly expand into multiple elements. ` +
`Use the key on a wrapping element instead.`
)
let slotName
Copy link

@satishrdd satishrdd Jan 18, 2019

Choose a reason for hiding this comment

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

Why use let here if we are not editing slotName more than once here,why not use const ?

Copy link
Author

Choose a reason for hiding this comment

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

I was trying to be consistent with the other code but you're right.

Either way there was another PR for this bug so I haven't followed up on this..

slotName = getBindingAttr(el, 'name')
if (process.env.NODE_ENV !== 'production') {
if(el.key) {
warn(
`\`key\` does not work on <slot> because slots are abstract outlets ` +
`and can possibly expand into multiple elements. ` +
`Use the key on a wrapping element instead.`
)
}
if (slotName) {
const res = parseText(slotName, delimiters);
if (res) {
warn(
`name="${slotName}": ` +
`Interpolation on <slot> "name" attribute has been removed. ` +
`Use v-bind or the colon shorthand instead.`
)
}
}
}
el.slotName = slotName
} else {
let slotScope
if (el.tag === 'template') {
Expand Down Expand Up @@ -502,6 +516,14 @@ function processSlot (el) {
}
const slotTarget = getBindingAttr(el, 'slot')
if (slotTarget) {
const res = parseText(slotTarget, delimiters);
if (process.env.NODE_ENV !== 'production' && res) {
warn(
`slot="${slotTarget}": "` +
`Interpolation on "slot" attribute has been removed. ` +
`Use v-bind or the colon shorthand instead.`
);
}
el.slotTarget = slotTarget === '""' ? '"default"' : slotTarget
// preserve slot as an attribute for native shadow DOM compat
// only for non-scoped slots.
Expand Down
18 changes: 15 additions & 3 deletions test/unit/modules/compiler/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,23 @@ describe('parser', () => {
expect(ast.children[0].slotName).toBe('"one"')
})

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

it("slot target", () => {
const ast = parse('<p slot="one">hello world</p>', baseOptions);
expect(ast.slotTarget).toBe('"one"');
});

it("slot target invalid syntax", () => {
// interpolation warning
parse('<p slot="{{error}}">hello world</p>', baseOptions);
expect('Interpolation on "slot" attribute has been removed.').toHaveBeenWarned();
});

it('component properties', () => {
const ast = parse('<my-component :msg="hello"></my-component>', baseOptions)
expect(ast.attrs[0].name).toBe('msg')
Expand Down