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) {
100100
101101 if ( Array . isArray ( parts . styles ) && parts . styles . length > 0 ) {
102102 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
104105 const styleObj = processStyle ( ast )
105106
106107 return '\n this[\'' + moduleName + '\'] = ' + JSON . stringify ( styleObj )
107108 } )
108109
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+ }
114117 }
115118
116119 return { code : output , map }
Original file line number Diff line number Diff line change 11import { shallow } from 'vue-test-utils'
22import Css from './resources/Css.vue'
33
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+ } )
821} )
Original file line number Diff line number Diff line change @@ -13,8 +13,13 @@ export default {
1313 background-color : red ;
1414 }
1515 </style >
16- <style >
16+ <style module >
1717 .testB {
1818 background-color : blue ;
1919 }
2020 </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 {
1313 background-color : red ;
1414 }
1515 </style >
16- <style lang="styl">
16+ <style lang="styl" module >
1717 .testB {
1818 background-color : blue ;
1919 }
2020 </style >
21+ <style >
22+ .testC {
23+ background-color : blue ;
24+ }
25+ </style >
Original file line number Diff line number Diff line change 11import { shallow } from 'vue-test-utils'
22import Stylus from './resources/Stylus.vue'
33
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+ } )
821} )
You can’t perform that action at this time.
0 commit comments