Skip to content

Commit e211c88

Browse files
committed
add warning for dynamic slot attribute
1 parent 3b2038d commit e211c88

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/compiler/resolve-slots.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { parseTemplate } from '../parsers/template'
22
import {
33
isTemplate,
4-
toArray
4+
toArray,
5+
getBindAttr,
6+
warn
57
} from '../util/index'
68

79
/**
@@ -28,6 +30,9 @@ export function resolveSlots (vm, content) {
2830
(contents[name] || (contents[name] = [])).push(el)
2931
}
3032
/* eslint-enable no-cond-assign */
33+
if (process.env.NODE_ENV !== 'production' && getBindAttr(el, 'slot')) {
34+
warn('The "slot" attribute must be static.')
35+
}
3136
}
3237
for (name in contents) {
3338
contents[name] = extractFragment(contents[name], content)

test/unit/specs/directives/element/slot_spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,4 +444,17 @@ describe('Slot Distribution', function () {
444444
})
445445
expect(vm.$el.textContent).toBe('hi')
446446
})
447+
448+
it('warn dynamic slot attribute', function () {
449+
new Vue({
450+
el: el,
451+
template: '<test><div :slot="1"></div></test>',
452+
components: {
453+
test: {
454+
template: '<div><slot></slot></div>'
455+
}
456+
}
457+
})
458+
expect('"slot" attribute must be static').toHaveBeenWarned()
459+
})
447460
})

0 commit comments

Comments
 (0)