File tree 2 files changed +50
-2
lines changed 2 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -89,10 +89,10 @@ module.exports = function (babel) {
89
89
// got css object
90
90
// console.log(objStr)
91
91
var cssobjNS = option . names [ 'cssobj' ]
92
- var cssobjName = cssobjNS . name || 'cssobj'
92
+ var cssobjName = cssobjNS . name
93
93
root . path . unshiftContainer ( 'body' , t . importDeclaration (
94
94
[ t . importDefaultSpecifier ( t . identifier ( cssobjName ) ) ] ,
95
- t . stringLiteral ( cssobjNS . path || 'cssobj' )
95
+ t . stringLiteral ( cssobjNS . path )
96
96
) )
97
97
98
98
path . replaceWithSourceString ( `${ cssobjName } (${ config } , ${ objStr } )` )
Original file line number Diff line number Diff line change @@ -158,6 +158,54 @@ var d = cssobj({}, {
158
158
159
159
} )
160
160
161
+ describe ( 'babel-plugin-transform-cssobj with custom name' , ( ) => {
162
+ var lib = function ( code ) {
163
+ return transform ( code , {
164
+ plugins : [ [
165
+ './index' ,
166
+ {
167
+ names : {
168
+ cssobj : {
169
+ name : 'abc' ,
170
+ path : './cssobj'
171
+ } ,
172
+ 'default-unit' : {
173
+ name : 'unit' ,
174
+ path : './unit'
175
+ } ,
176
+ flexbox : {
177
+ name : 'box' ,
178
+ }
179
+ }
180
+ }
181
+ ] ]
182
+ } ) . code
183
+ }
184
+
185
+ it ( 'should work with custom cssobj name' , function ( ) {
186
+ let node = `CSSOBJ\`\``
187
+ expect ( lib ( node ) ) . equal ( `import abc from "./cssobj";
188
+ abc({}, {});` )
189
+ } )
190
+
191
+ it ( 'should work with custom plugin name' , function ( ) {
192
+ let node = `CSSOBJ\`
193
+ ---
194
+ plugins:
195
+ - default-unit
196
+ - flexbox
197
+ ---
198
+ \``
199
+ expect ( lib ( node ) ) . equal ( `import abc from "./cssobj";
200
+ import unit from "./unit";
201
+ import box from "cssobj-plugin-flexbox";
202
+ abc({
203
+ plugins: [unit(), box()]
204
+ }, {});` )
205
+ } )
206
+
207
+ } )
208
+
161
209
162
210
describe ( 'babel-plugin-transform-cssobj-jsx' , ( ) => {
163
211
var lib = function ( code ) {
You can’t perform that action at this time.
0 commit comments