diff --git a/src/data.ts b/src/data.ts index d26de99..2e226d4 100644 --- a/src/data.ts +++ b/src/data.ts @@ -20,7 +20,9 @@ export function collectDataFromConstructor (vm: Vue, Component: VueClass) { // create plain data object const plainData = {} Object.keys(data).forEach(key => { - plainData[key] = data[key] + if (data[key] !== undefined) { + plainData[key] = data[key] + } }) return plainData diff --git a/test/test-babel.js b/test/test-babel.js index a722de4..2a4be82 100644 --- a/test/test-babel.js +++ b/test/test-babel.js @@ -1,4 +1,4 @@ -import Component from '../lib/index' +import Component, { createDecorator } from '../lib/index' import { expect } from 'chai' import Vue from 'vue' @@ -17,4 +17,22 @@ describe('vue-class-component with Babel', () => { const c = new MyComp() expect(c.foo).to.equal('hello') }) + + it('should not collect uninitialized class properties', () => { + const Prop = createDecorator((options, key) => { + if (!options.props) { + options.props = {} + } + options.props[key] = true + }) + + @Component + class MyComp { + foo + @Prop bar + } + const c = new MyComp() + expect('foo' in c.$data).to.be.false + expect('bar' in c.$data).to.be.false + }) }) \ No newline at end of file