File tree 5 files changed +51
-5
lines changed
5 files changed +51
-5
lines changed Original file line number Diff line number Diff line change 35
35
"devDependencies" : {
36
36
"@types/chai" : " ^3.4.34" ,
37
37
"@types/mocha" : " ^2.2.32" ,
38
+ "babel-core" : " ^6.18.2" ,
39
+ "babel-loader" : " ^6.2.7" ,
40
+ "babel-plugin-transform-class-properties" : " ^6.18.0" ,
41
+ "babel-plugin-transform-decorators-legacy" : " ^1.3.4" ,
42
+ "babel-preset-es2015" : " ^6.18.0" ,
38
43
"chai" : " ^3.5.0" ,
39
44
"mocha" : " ^3.1.2" ,
40
45
"node-libs-browser" : " ^1.0.0" ,
Original file line number Diff line number Diff line change @@ -65,8 +65,12 @@ export function componentFactory (
65
65
66
66
// find super
67
67
const superProto = Object . getPrototypeOf ( Component . prototype )
68
- const Super : VueClass = superProto instanceof Vue
69
- ? superProto . constructor as VueClass
70
- : Vue
71
- return Super . extend ( options )
68
+ if ( ! ( superProto instanceof Vue ) ) {
69
+ Component . prototype = Object . create ( Vue . prototype )
70
+ Component . prototype . constructor = Component
71
+ Object . keys ( Vue ) . forEach ( key => {
72
+ Component [ key ] = Vue [ key ]
73
+ } )
74
+ }
75
+ return Component . extend ( options )
72
76
}
Original file line number Diff line number Diff line change
1
+ {
2
+ "presets" : [
3
+ [" es2015" , {"modules" : false }]
4
+ ],
5
+ "plugins" : [
6
+ " transform-decorators-legacy" ,
7
+ " transform-class-properties"
8
+ ]
9
+ }
Original file line number Diff line number Diff line change
1
+ import Component from '../lib/index'
2
+ import { expect } from 'chai'
3
+ import Vue from 'vue'
4
+
5
+ describe ( 'vue-class-component with Babel' , ( ) => {
6
+ it ( 'should be instantiated without any errors' , ( ) => {
7
+ @Component
8
+ class MyComp { }
9
+ expect ( ( ) => new MyComp ( ) ) . to . not . throw ( Error )
10
+ } )
11
+
12
+ it ( 'should collect class properties as data' , ( ) => {
13
+ @Component
14
+ class MyComp {
15
+ foo = 'hello'
16
+ }
17
+ const c = new MyComp ( )
18
+ expect ( c . foo ) . to . equal ( 'hello' )
19
+ } )
20
+ } )
Original file line number Diff line number Diff line change 1
1
module . exports = {
2
- entry : './test/test.ts' ,
2
+ entry : [
3
+ './test/test.ts' ,
4
+ './test/test-babel.js'
5
+ ] ,
3
6
output : {
4
7
path : './test' ,
5
8
filename : 'test.build.js'
@@ -10,6 +13,11 @@ module.exports = {
10
13
test : / \. t s $ / ,
11
14
exclude : / n o d e _ m o d u l e s | v u e \/ s r c / ,
12
15
loader : 'ts'
16
+ } ,
17
+ {
18
+ test : / \. j s $ / ,
19
+ exclude : / n o d e _ m o d u l e s | v u e \/ s r c / ,
20
+ loader : 'babel'
13
21
}
14
22
]
15
23
}
You can’t perform that action at this time.
0 commit comments