Skip to content

Commit f6f577a

Browse files
tomasAlabesmichael-ciniawsky
authored andcommitted
fix: negative refs (#122)
1 parent 0a27bfc commit f6f577a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

test/basicTest.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,32 @@ describe("basic tests", function() {
206206
runCompilerTest(expected, done);
207207
}); // it useable
208208

209+
it("useable without negative refs", function(done) {
210+
cssRule.use = [
211+
{
212+
loader: "style-loader/useable"
213+
},
214+
"css-loader"
215+
];
216+
217+
fs.writeFileSync(
218+
rootDir + "main.js",
219+
[
220+
"var css = require('./style.css');",
221+
"css.unuse();", // ref still 0
222+
"css.use();", // ref 1
223+
].join("\n")
224+
);
225+
226+
// Run
227+
let expected = [
228+
existingStyle,
229+
`<style type="text/css">${requiredCss}</style>`
230+
].join("\n");
231+
232+
runCompilerTest(expected, done);
233+
}); // it useable
234+
209235
it("local scope", function(done) {
210236
cssRule.use = [
211237
{

useable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports.pitch = function(remainingRequest) {
2121
" return exports;",
2222
"};",
2323
"exports.unuse = exports.unref = function() {",
24-
" if(!(--refs)) {",
24+
" if(refs > 0 && !(--refs)) {",
2525
" dispose();",
2626
" dispose = null;",
2727
" }",

0 commit comments

Comments
 (0)