Skip to content

Commit bcc1770

Browse files
committed
fix boolean prop handling (fix #1727)
1 parent 2f87089 commit bcc1770

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/compiler/compile-props.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ module.exports = function compileProps (el, propOptions) {
9797
'Prop "' + name + '" expects a two-way binding type.'
9898
)
9999
}
100-
/* eslint-disable no-cond-assign */
101-
} else if (value = _.attr(el, attr)) {
102-
/* eslint-enable no-cond-assign */
100+
} else if ((value = _.attr(el, attr)) !== null) {
103101
// has literal binding!
104102
prop.raw = value
105103
} else if (options.required) {

test/unit/specs/compiler/compile_spec.js

+4
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ if (_.inBrowser) {
241241
var props = {
242242
testNormal: null,
243243
testLiteral: null,
244+
testBoolean: { type: Boolean },
244245
testTwoWay: null,
245246
twoWayWarn: null,
246247
testOneTime: null,
@@ -250,6 +251,7 @@ if (_.inBrowser) {
250251
el.innerHTML = '<div ' +
251252
'v-bind:test-normal="a" ' +
252253
'test-literal="1" ' +
254+
'test-boolean ' +
253255
':optimize-literal="1" ' +
254256
':optimize-literal-str="\'true\'"' +
255257
':test-two-way.sync="a" ' +
@@ -260,6 +262,8 @@ if (_.inBrowser) {
260262
// literal
261263
expect(vm.testLiteral).toBe('1')
262264
expect(vm._data.testLiteral).toBe('1')
265+
expect(vm.testBoolean).toBe(true)
266+
expect(vm._data.testBoolean).toBe(true)
263267
expect(vm.optimizeLiteral).toBe(1)
264268
expect(vm._data.optimizeLiteral).toBe(1)
265269
expect(vm.optimizeLiteralStr).toBe('true')

test/unit/specs/directives/internal/prop_spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -574,5 +574,22 @@ if (_.inBrowser) {
574574
done()
575575
})
576576
})
577+
578+
it('treat boolean props properly', function () {
579+
var vm = new Vue({
580+
el: el,
581+
template: '<comp v-ref:child prop-a></comp>',
582+
components: {
583+
comp: {
584+
props: {
585+
propA: Boolean,
586+
propB: Boolean
587+
}
588+
}
589+
}
590+
})
591+
expect(vm.$refs.child.propA).toBe(true)
592+
expect(vm.$refs.child.propB).toBe(false)
593+
})
577594
})
578595
}

0 commit comments

Comments
 (0)