File tree Expand file tree Collapse file tree 5 files changed +55
-16
lines changed Expand file tree Collapse file tree 5 files changed +55
-16
lines changed Original file line number Diff line number Diff line change @@ -100,17 +100,20 @@ module.exports = function (src, path) {
100
100
101
101
if ( Array . isArray ( parts . styles ) && parts . styles . length > 0 ) {
102
102
const styleStr = parts . styles . map ( ast => {
103
- const moduleName = ast . module || '$style'
103
+ if ( ! module ) return
104
+ const moduleName = ast . module === true ? '$style' : ast . module
104
105
const styleObj = processStyle ( ast )
105
106
106
107
return '\n this[\'' + moduleName + '\'] = ' + JSON . stringify ( styleObj )
107
108
} )
108
109
109
- output += '\n;(function() {' +
110
- '\nvar render = __vue__options__.render' +
111
- '\n__vue__options__.render = function(h) {' + styleStr +
112
- '\n return render.call(this, h)' +
113
- '\n}})()'
110
+ if ( styleStr . length !== 0 ) {
111
+ output += '\n;(function() {' +
112
+ '\nvar beforeCreate = __vue__options__.beforeCreate' +
113
+ '\nvar styleFn = function () { ' + styleStr + ' }' +
114
+ '\n__vue__options__.beforeCreate = beforeCreate ? [].concat(beforeCreate, styleFn) : [styleFn]' +
115
+ '\n})()'
116
+ }
114
117
}
115
118
116
119
return { code : output , map }
Original file line number Diff line number Diff line change 1
1
import { shallow } from 'vue-test-utils'
2
2
import Css from './resources/Css.vue'
3
3
4
- test ( 'processes .vue file with Css style' , ( ) => {
5
- const wrapper = shallow ( Css )
6
- expect ( wrapper . classes ( ) ) . toContain ( 'testA' )
7
- expect ( wrapper . classes ( ) ) . toContain ( 'testB' )
4
+ describe ( 'processes .vue file with Css style' , ( ) => {
5
+ let wrapper
6
+ beforeAll ( ( ) => {
7
+ wrapper = shallow ( Css )
8
+ } )
9
+
10
+ it ( 'should bind from style tags with named module' , ( ) => {
11
+ expect ( wrapper . classes ( ) ) . toContain ( 'testA' )
12
+ } )
13
+
14
+ it ( 'should bind from style tags with anonymous modules' , ( ) => {
15
+ expect ( wrapper . classes ( ) ) . toContain ( 'testB' )
16
+ } )
17
+
18
+ it ( 'should not bind from style tags without a module' , ( ) => {
19
+ expect ( wrapper . vm . $style . testC ) . toBeFalsy ( )
20
+ } )
8
21
} )
Original file line number Diff line number Diff line change @@ -13,8 +13,13 @@ export default {
13
13
background-color : red ;
14
14
}
15
15
</style >
16
- <style >
16
+ <style module >
17
17
.testB {
18
18
background-color : blue ;
19
19
}
20
20
</style >
21
+ <style >
22
+ .testC {
23
+ background-color : blue ;
24
+ }
25
+ </style >
Original file line number Diff line number Diff line change @@ -13,8 +13,13 @@ export default {
13
13
background-color : red ;
14
14
}
15
15
</style >
16
- <style lang="styl">
16
+ <style lang="styl" module >
17
17
.testB {
18
18
background-color : blue ;
19
19
}
20
20
</style >
21
+ <style >
22
+ .testC {
23
+ background-color : blue ;
24
+ }
25
+ </style >
Original file line number Diff line number Diff line change 1
1
import { shallow } from 'vue-test-utils'
2
2
import Stylus from './resources/Stylus.vue'
3
3
4
- test ( 'processes .vue file with Stylus style' , ( ) => {
5
- const wrapper = shallow ( Stylus )
6
- expect ( wrapper . classes ( ) ) . toContain ( 'testA' )
7
- expect ( wrapper . classes ( ) ) . toContain ( 'testB' )
4
+ describe ( 'processes .vue file with Stylus style' , ( ) => {
5
+ let wrapper
6
+ beforeAll ( ( ) => {
7
+ wrapper = shallow ( Stylus )
8
+ } )
9
+
10
+ it ( 'should bind from style tags with named module' , ( ) => {
11
+ expect ( wrapper . classes ( ) ) . toContain ( 'testA' )
12
+ } )
13
+
14
+ it ( 'should bind from style tags with anonymous modules' , ( ) => {
15
+ expect ( wrapper . classes ( ) ) . toContain ( 'testB' )
16
+ } )
17
+
18
+ it ( 'should not bind from style tags without a module' , ( ) => {
19
+ expect ( wrapper . vm . $style . testC ) . toBeFalsy ( )
20
+ } )
8
21
} )
You can’t perform that action at this time.
0 commit comments