Skip to content

Commit

Permalink
fix(v-bind): respect .prop modifier on components (vuejs#6159)
Browse files Browse the repository at this point in the history
  • Loading branch information
javoski authored and yyx990803 committed Jul 19, 2017
1 parent d03fa26 commit 06b9b0b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ function processAttrs (el) {
)
}
}
if (!el.component && (
isProp || platformMustUseProp(el.tag, el.attrsMap.type, name)
if (isProp || (
!el.component && platformMustUseProp(el.tag, el.attrsMap.type, name)
)) {
addProp(el, name, value)
} else {
Expand Down
19 changes: 19 additions & 0 deletions test/unit/features/component/component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,25 @@ describe('Component', () => {
}).then(done)
})

it('dynamic elements with domProps', done => {
const vm = new Vue({
template: '<component :is="view" :value.prop="val"></component>',
data: {
view: 'input',
val: 'hello'
}
}).$mount()
expect(vm.$el.tagName).toBe('INPUT')
expect(vm.$el.value).toBe('hello')
vm.view = 'textarea'
vm.val += ' world'
waitForUpdate(() => {
expect(vm.$el.tagName).toBe('TEXTAREA')
expect(vm.$el.value).toBe('hello world')
vm.view = ''
}).then(done)
})

it('should compile parent template directives & content in parent scope', done => {
const vm = new Vue({
data: {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/modules/compiler/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,14 @@ describe('parser', () => {
expect(ast.props).toBeUndefined()
})

it('use prop when prop modifier was explicitly declared', () => {
const ast = parse('<component is="textarea" :value.prop="val" />', baseOptions)
expect(ast.attrs).toBeUndefined()
expect(ast.props.length).toBe(1)
expect(ast.props[0].name).toBe('value')
expect(ast.props[0].value).toBe('val')
})

it('pre/post transforms', () => {
const options = extend({}, baseOptions)
const spy1 = jasmine.createSpy('preTransform')
Expand Down

0 comments on commit 06b9b0b

Please sign in to comment.