Skip to content

Commit 833e340

Browse files
Empty string (#152)
* test: add empty string test * Fix empty strings
1 parent 75b2b94 commit 833e340

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const sf = require('sheetify')
2+
3+
sf``

test/prefix.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,31 @@ test('prefix', function (t) {
112112
}
113113
}
114114
})
115+
116+
t.test('should return a prefix when an empty string is passed', function (t) {
117+
t.plan(1)
118+
119+
const ws = concat(function (buf) {
120+
const res = String(buf).trim()
121+
t.equal(res, '', 'css is equal')
122+
})
123+
124+
const bOpts = { browserField: false }
125+
const bpath = path.join(__dirname, 'fixtures/prefix-empty-source.js')
126+
browserify(bpath, bOpts)
127+
.transform(sheetify)
128+
.transform(function (file) {
129+
return through(function (buf, enc, next) {
130+
const str = buf.toString('utf8')
131+
this.push(str.replace(/sheetify\/insert/, 'insert-css'))
132+
next()
133+
})
134+
})
135+
.plugin('css-extract', { out: outFn })
136+
.bundle()
137+
138+
function outFn () {
139+
return ws
140+
}
141+
})
115142
})

transform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function transform (filename, options) {
192192
// then replace the AST nodes with new values
193193
// (obj, fn) -> null
194194
function iterate (val, done) {
195-
if (val.css) return handleCss(val)
195+
if (typeof val.css === 'string') return handleCss(val)
196196

197197
if (/\.js$/.test(val.filename)) {
198198
delete require.cache[require.resolve(val.filename)]

0 commit comments

Comments
 (0)