Skip to content

Commit 3a8ec0c

Browse files
committed
should not collect uninitialized class properties
1 parent 997bf95 commit 3a8ec0c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/data.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export function collectDataFromConstructor (vm: Vue, Component: VueClass) {
2020
// create plain data object
2121
const plainData = {}
2222
Object.keys(data).forEach(key => {
23-
plainData[key] = data[key]
23+
if (data[key] !== undefined) {
24+
plainData[key] = data[key]
25+
}
2426
})
2527

2628
return plainData

test/test-babel.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Component from '../lib/index'
1+
import Component, { createDecorator } from '../lib/index'
22
import { expect } from 'chai'
33
import Vue from 'vue'
44

@@ -17,4 +17,22 @@ describe('vue-class-component with Babel', () => {
1717
const c = new MyComp()
1818
expect(c.foo).to.equal('hello')
1919
})
20+
21+
it('should not collect uninitialized class properties', () => {
22+
const Prop = createDecorator((options, key) => {
23+
if (!options.props) {
24+
options.props = {}
25+
}
26+
options.props[key] = true
27+
})
28+
29+
@Component
30+
class MyComp {
31+
foo
32+
@Prop bar
33+
}
34+
const c = new MyComp()
35+
expect('foo' in c.$data).to.be.false
36+
expect('bar' in c.$data).to.be.false
37+
})
2038
})

0 commit comments

Comments
 (0)