@@ -21,7 +21,7 @@ module.exports = function compileProps (el, propOptions) {
21
21
var props = [ ]
22
22
var names = Object . keys ( propOptions )
23
23
var i = names . length
24
- var options , name , attr , value , path , parsed , prop , hasBinding
24
+ var options , name , attr , value , path , parsed , prop
25
25
while ( i -- ) {
26
26
name = names [ i ]
27
27
options = propOptions [ name ] || empty
@@ -47,89 +47,73 @@ module.exports = function compileProps (el, propOptions) {
47
47
name : name ,
48
48
path : path ,
49
49
options : options ,
50
- mode : propBindingModes . ONE_WAY
50
+ mode : propBindingModes . ONE_WAY ,
51
+ raw : null
51
52
}
52
53
53
54
attr = _ . hyphenate ( name )
54
- hasBinding = _ . preferBinding && hasBindingAttr ( el , attr )
55
-
56
- // first check literal version
57
- value = prop . raw = _ . attr ( el , attr )
58
- if ( value === null || hasBinding ) {
59
- // then check dynamic version
60
- if ( ( value = _ . getBindAttr ( el , attr ) ) === null ) {
61
- if ( ( value = _ . getBindAttr ( el , attr + '.sync' ) ) !== null ) {
62
- prop . mode = propBindingModes . TWO_WAY
63
- } else if ( ( value = _ . getBindAttr ( el , attr + '.once' ) ) !== null ) {
64
- prop . mode = propBindingModes . ONE_TIME
65
- }
55
+ // first check dynamic version
56
+ if ( ( value = _ . getBindAttr ( el , attr ) ) === null ) {
57
+ if ( ( value = _ . getBindAttr ( el , attr + '.sync' ) ) !== null ) {
58
+ prop . mode = propBindingModes . TWO_WAY
59
+ } else if ( ( value = _ . getBindAttr ( el , attr + '.once' ) ) !== null ) {
60
+ prop . mode = propBindingModes . ONE_TIME
66
61
}
62
+ }
63
+ if ( value !== null ) {
64
+ // has dynamic binding!
67
65
prop . raw = value
68
- if ( value !== null ) {
69
- parsed = dirParser . parse ( value )
70
- value = parsed . expression
71
- prop . filters = parsed . filters
72
- // check binding type
73
- if ( _ . isLiteral ( value ) ) {
74
- // for expressions containing literal numbers and
75
- // booleans, there's no need to setup a prop binding,
76
- // so we can optimize them as a one-time set.
77
- prop . optimizedLiteral = true
78
- } else {
79
- prop . dynamic = true
80
- // check non-settable path for two-way bindings
81
- if ( process . env . NODE_ENV !== 'production' &&
82
- prop . mode === propBindingModes . TWO_WAY &&
83
- ! settablePathRE . test ( value ) ) {
84
- prop . mode = propBindingModes . ONE_WAY
85
- _ . warn (
86
- 'Cannot bind two-way prop with non-settable ' +
87
- 'parent path: ' + value
88
- )
89
- }
90
- }
91
- prop . parentPath = value
92
-
93
- // warn required two-way
94
- if (
95
- process . env . NODE_ENV !== 'production' &&
96
- options . twoWay &&
97
- prop . mode !== propBindingModes . TWO_WAY
98
- ) {
66
+ parsed = dirParser . parse ( value )
67
+ value = parsed . expression
68
+ prop . filters = parsed . filters
69
+ // check binding type
70
+ if ( _ . isLiteral ( value ) ) {
71
+ // for expressions containing literal numbers and
72
+ // booleans, there's no need to setup a prop binding,
73
+ // so we can optimize them as a one-time set.
74
+ prop . optimizedLiteral = true
75
+ } else {
76
+ prop . dynamic = true
77
+ // check non-settable path for two-way bindings
78
+ if ( process . env . NODE_ENV !== 'production' &&
79
+ prop . mode === propBindingModes . TWO_WAY &&
80
+ ! settablePathRE . test ( value ) ) {
81
+ prop . mode = propBindingModes . ONE_WAY
99
82
_ . warn (
100
- 'Prop "' + name + '" expects a two-way binding type.'
83
+ 'Cannot bind two-way prop with non-settable ' +
84
+ 'parent path: ' + value
101
85
)
102
86
}
103
-
104
- } else if ( options . required ) {
105
- // warn missing required
106
- process . env . NODE_ENV !== 'production' && _ . warn (
107
- 'Missing required prop: ' + name
87
+ }
88
+ prop . parentPath = value
89
+
90
+ // warn required two-way
91
+ if (
92
+ process . env . NODE_ENV !== 'production' &&
93
+ options . twoWay &&
94
+ prop . mode !== propBindingModes . TWO_WAY
95
+ ) {
96
+ _ . warn (
97
+ 'Prop "' + name + '" expects a two-way binding type.'
108
98
)
109
99
}
100
+ /* eslint-disable no-cond-assign */
101
+ } else if ( value = _ . attr ( el , attr ) ) {
102
+ /* eslint-enable no-cond-assign */
103
+ // has literal binding!
104
+ prop . raw = value
105
+ } else if ( options . required ) {
106
+ // warn missing required
107
+ process . env . NODE_ENV !== 'production' && _ . warn (
108
+ 'Missing required prop: ' + name
109
+ )
110
110
}
111
-
112
111
// push prop
113
112
props . push ( prop )
114
113
}
115
114
return makePropsLinkFn ( props )
116
115
}
117
116
118
- /**
119
- * Check existance of an attribute with binding syntax.
120
- *
121
- * @param {Element } el
122
- * @return {String } attr
123
- */
124
-
125
- function hasBindingAttr ( el , attr ) {
126
- /* istanbul ignore next */
127
- return attr !== 'class' && (
128
- el . hasAttribute ( ':' + attr ) ||
129
- el . hasAttribute ( 'v-bind:' + attr )
130
- )
131
- }
132
-
133
117
/**
134
118
* Build a function that applies props to a vm.
135
119
*
0 commit comments