Skip to content

Commit 0709688

Browse files
simplesmileryyx990803
authored andcommitted
Default a prop before coercion
* Default a prop before coercion * Consider defaulting a coercion too (fixes broken test) * Add test case for coercion after defaulting
1 parent ef55582 commit 0709688

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/compiler/compile-props.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,11 @@ function makePropsLinkFn (props) {
229229

230230
function processPropValue (vm, prop, rawValue, fn) {
231231
const isSimple = prop.dynamic && isSimplePath(prop.parentPath)
232-
let value = coerceProp(prop, rawValue)
232+
let value = rawValue
233233
if (value === undefined) {
234234
value = getPropDefaultValue(vm, prop)
235235
}
236+
value = coerceProp(prop, value)
236237
const coerced = value !== rawValue
237238
if (!assertProp(prop, value, vm)) {
238239
value = undefined

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

+22
Original file line numberDiff line numberDiff line change
@@ -854,4 +854,26 @@ describe('prop', function () {
854854
done()
855855
})
856856
})
857+
858+
it('prop coercion should be applied after defaulting', function () {
859+
var vm = new Vue({
860+
el: el,
861+
template: '<comp></comp>',
862+
components: {
863+
comp: {
864+
props: {
865+
color: {
866+
type: String,
867+
default: 'blue',
868+
coerce: function (color) {
869+
return 'color-' + color
870+
}
871+
}
872+
},
873+
template: '<div>{{ color }}</div>'
874+
}
875+
}
876+
})
877+
expect(vm.$el.textContent).toBe('color-blue')
878+
})
857879
})

0 commit comments

Comments
 (0)