Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vuejs/vue
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: dev
Choose a base ref
...
head repository: aaron61591/vue
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: dev
Choose a head ref

There isn’t anything to compare.

vuejs:dev and aaron61591:dev are entirely different commit histories.

Showing with 14 additions and 5 deletions.
  1. +8 −3 src/compiler/compile-props.js
  2. +6 −2 test/unit/specs/compiler/compile_spec.js
11 changes: 8 additions & 3 deletions src/compiler/compile-props.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ var literalValueRE = /^(true|false)$|^\d.*/
module.exports = function compileProps (el, propOptions) {
var props = []
var i = propOptions.length
var options, name, value, path, prop, literal, single
var options, name, attr, value, path, prop, literal, single
while (i--) {
options = propOptions[i]
name = options.name
@@ -36,7 +36,12 @@ module.exports = function compileProps (el, propOptions) {
)
continue
}
value = el.getAttribute(_.hyphenate(name))
attr = _.hyphenate(name)
value = el.getAttribute(attr)
if (value === null) {
attr = 'data-' + attr
value = el.getAttribute(attr)
}
// create a prop descriptor
prop = {
name: name,
@@ -48,7 +53,7 @@ module.exports = function compileProps (el, propOptions) {
if (value !== null) {
// important so that this doesn't get compiled
// again as a normal attribute binding
el.removeAttribute(name)
el.removeAttribute(attr)
var tokens = textParser.parse(value)
if (tokens) {
if (el && el.nodeType === 1) {
8 changes: 6 additions & 2 deletions test/unit/specs/compiler/compile_spec.js
Original file line number Diff line number Diff line change
@@ -176,7 +176,8 @@ if (_.inBrowser) {
a: 123
}
}
}
},
'withDataPrefix'
].map(function (p) {
return typeof p === 'string' ? { name: p } : p
})
@@ -191,6 +192,7 @@ if (_.inBrowser) {
el.setAttribute('camel-case', 'hi')
el.setAttribute('boolean-literal', '{{true}}')
el.setAttribute('boolean', '')
el.setAttribute('data-with-data-prefix', '1')
compiler.compileAndLinkProps(vm, el, props)
// should skip literals and one-time bindings
expect(vm._bindDir.calls.count()).toBe(4)
@@ -228,7 +230,7 @@ if (_.inBrowser) {
expect(args[3]).toBe(def)
// literal and one time should've been set on the _data
// and numbers should be casted
expect(Object.keys(vm._data).length).toBe(9)
expect(Object.keys(vm._data).length).toBe(10)
expect(vm.a).toBe(1)
expect(vm._data.a).toBe(1)
expect(vm.someOtherAttr).toBe(2)
@@ -247,6 +249,8 @@ if (_.inBrowser) {
expect(vm._data.booleanAbsent).toBe(false)
expect(vm.factory).toBe(vm._data.factory)
expect(vm.factory.a).toBe(123)
expect(vm.withDataPrefix).toBe(1)
expect(vm._data.withDataPrefix).toBe(1)
})

it('props on root instance', function () {