From f6f577a73c0d34e5ce5372185e442fa45d7600fd Mon Sep 17 00:00:00 2001 From: Tomas Alabes Date: Sun, 26 Mar 2017 14:02:00 -0700 Subject: [PATCH] fix: negative refs (#122) --- test/basicTest.js | 26 ++++++++++++++++++++++++++ useable.js | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/test/basicTest.js b/test/basicTest.js index f47340f..9b6450c 100644 --- a/test/basicTest.js +++ b/test/basicTest.js @@ -206,6 +206,32 @@ describe("basic tests", function() { runCompilerTest(expected, done); }); // it useable + it("useable without negative refs", function(done) { + cssRule.use = [ + { + loader: "style-loader/useable" + }, + "css-loader" + ]; + + fs.writeFileSync( + rootDir + "main.js", + [ + "var css = require('./style.css');", + "css.unuse();", // ref still 0 + "css.use();", // ref 1 + ].join("\n") + ); + + // Run + let expected = [ + existingStyle, + `` + ].join("\n"); + + runCompilerTest(expected, done); + }); // it useable + it("local scope", function(done) { cssRule.use = [ { diff --git a/useable.js b/useable.js index e2099e2..fc6ad34 100644 --- a/useable.js +++ b/useable.js @@ -21,7 +21,7 @@ module.exports.pitch = function(remainingRequest) { " return exports;", "};", "exports.unuse = exports.unref = function() {", - " if(!(--refs)) {", + " if(refs > 0 && !(--refs)) {", " dispose();", " dispose = null;", " }",