Skip to content

Commit 61df73d

Browse files
committed
options work right with custom names
1 parent d363c09 commit 61df73d

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ module.exports = function (babel) {
8989
// got css object
9090
// console.log(objStr)
9191
var cssobjNS = option.names['cssobj']
92-
var cssobjName = cssobjNS.name || 'cssobj'
92+
var cssobjName = cssobjNS.name
9393
root.path.unshiftContainer('body', t.importDeclaration(
9494
[t.importDefaultSpecifier(t.identifier(cssobjName))],
95-
t.stringLiteral(cssobjNS.path || 'cssobj')
95+
t.stringLiteral(cssobjNS.path)
9696
))
9797

9898
path.replaceWithSourceString(`${cssobjName} (${config}, ${objStr})`)

test/test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,54 @@ var d = cssobj({}, {
158158

159159
})
160160

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+
161209

162210
describe('babel-plugin-transform-cssobj-jsx', () => {
163211
var lib = function (code) {

0 commit comments

Comments
 (0)