Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ export function componentFactory (
const Super = superProto instanceof Vue
? superProto.constructor as VueClass<Vue>
: Vue
const Extended = Super.extend(options);
const Extended = Super.extend(options)

for(let staticKey in Component) {
if(Component.hasOwnProperty(staticKey)) {
Extended[staticKey] = Component[staticKey];
Object.getOwnPropertyNames(Component).forEach(key => {
if (key !== 'prototype') {
const descriptor = Object.getOwnPropertyDescriptor(Component, key)!
Object.defineProperty(Extended, key, descriptor)
}
}
return Extended;
})

return Extended
}
14 changes: 14 additions & 0 deletions test/test-babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,18 @@ describe('vue-class-component with Babel', () => {
const vm = new MyComp()
expect(vm.test()).to.equal('test')
})

it('should forward static members', () => {
@Component
class MyComp extends Vue {
static foo = 'foo'

static bar () {
return 'bar'
}
}

expect(MyComp.foo).to.equal('foo')
expect(MyComp.bar()).to.equal('bar')
})
})
11 changes: 8 additions & 3 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,18 @@ describe('vue-class-component', () => {
const vm: any = new MyComp()
expect(vm.test).to.equal('foo')
})

it('forwardStatics', function () {
@Component
class MyComp extends Vue {
static myValue = 52

static myFunc() {
return 42
}
}

expect(MyComp.myValue).to.equal(52);

expect(MyComp.myValue).to.equal(52)
expect(MyComp.myFunc()).to.equal(42)
})
})