Skip to content

Commit 9a66ece

Browse files
committed
simplify IE bind attr workaround by adjusting check order
1 parent d5a6995 commit 9a66ece

File tree

3 files changed

+52
-87
lines changed

3 files changed

+52
-87
lines changed

src/compiler/compile-props.js

Lines changed: 51 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = function compileProps (el, propOptions) {
2121
var props = []
2222
var names = Object.keys(propOptions)
2323
var i = names.length
24-
var options, name, attr, value, path, parsed, prop, hasBinding
24+
var options, name, attr, value, path, parsed, prop
2525
while (i--) {
2626
name = names[i]
2727
options = propOptions[name] || empty
@@ -47,89 +47,73 @@ module.exports = function compileProps (el, propOptions) {
4747
name: name,
4848
path: path,
4949
options: options,
50-
mode: propBindingModes.ONE_WAY
50+
mode: propBindingModes.ONE_WAY,
51+
raw: null
5152
}
5253

5354
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
6661
}
62+
}
63+
if (value !== null) {
64+
// has dynamic binding!
6765
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
9982
_.warn(
100-
'Prop "' + name + '" expects a two-way binding type.'
83+
'Cannot bind two-way prop with non-settable ' +
84+
'parent path: ' + value
10185
)
10286
}
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.'
10898
)
10999
}
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+
)
110110
}
111-
112111
// push prop
113112
props.push(prop)
114113
}
115114
return makePropsLinkFn(props)
116115
}
117116

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-
133117
/**
134118
* Build a function that applies props to a vm.
135119
*

src/util/env.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,3 @@ exports.nextTick = (function () {
8383
timerFunc(nextTickHandler, 0)
8484
}
8585
})()
86-
87-
// feature detect browsers (IE) that have trouble
88-
// with binding syntax on certain attributes
89-
var div
90-
var preferBinding = false
91-
if (inBrowser) {
92-
div = document.createElement('div')
93-
div.setAttribute(':title', '')
94-
preferBinding = div.getAttribute('title') !== null
95-
}
96-
exports.preferBinding = preferBinding

test/unit/specs/misc_spec.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,6 @@ describe('Misc', function () {
288288
}
289289
}
290290

291-
document.body.appendChild(el)
292-
el.setAttribute(':title', '')
293-
if (el.getAttribute('title') === null) {
294-
// this browser does not need this test
295-
done()
296-
return
297-
}
298-
299291
new Vue({
300292
el: el,
301293
template:
@@ -312,7 +304,7 @@ describe('Misc', function () {
312304
components: {
313305
comp: {
314306
props: ['title'],
315-
ready: function () {
307+
created: function () {
316308
check(this.title)
317309
}
318310
}

0 commit comments

Comments
 (0)