Skip to content

Commit 5786cb1

Browse files
committed
should warn invalid prop keys
1 parent 903223a commit 5786cb1

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/directives/prop.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var _ = require('../util')
22
var Watcher = require('../watcher')
3+
var identRE = require('../parsers/path').identRE
34

45
module.exports = {
56

@@ -10,6 +11,13 @@ module.exports = {
1011
var childKey = this.arg
1112
var parentKey = this.expression
1213

14+
if (!identRE.test(childKey)) {
15+
_.warn(
16+
'Invalid prop key: "' + childKey + '". Prop keys ' +
17+
'must be valid identifiers.'
18+
)
19+
}
20+
1321
// simple lock to avoid circular updates.
1422
// without this it would stabilize too, but this makes
1523
// sure it doesn't cause other watchers to re-evaluate.
@@ -28,7 +36,8 @@ module.exports = {
2836
function (val) {
2937
if (!locked) {
3038
lock()
31-
child.$set(childKey, val)
39+
// all props have been initialized already
40+
child[childKey] = val
3241
}
3342
}
3443
)

src/parsers/path.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var _ = require('../util')
22
var Cache = require('../cache')
33
var pathCache = new Cache(1000)
4-
var identRE = /^[$_a-zA-Z]+[\w$]*$/
4+
var identRE = exports.identRE = /^[$_a-zA-Z]+[\w$]*$/
55

66
/**
77
* Path-parsing algorithm scooped from Polymer/observe-js

test/unit/specs/directives/prop_spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ if (_.inBrowser) {
5858
})
5959
})
6060

61+
it('warn invalid keys', function () {
62+
var vm = new Vue({
63+
el: el,
64+
template: '<test a.b.c="{{test}}"></test>',
65+
components: {
66+
test: {
67+
props: ['a.b.c']
68+
}
69+
}
70+
})
71+
expect(hasWarned(_, 'Invalid prop key'))
72+
})
73+
6174
it('teardown', function (done) {
6275
var vm = new Vue({
6376
el: el,

0 commit comments

Comments
 (0)