From 8db58e6ceb7bc7d6792797b134943db2b6e2502d Mon Sep 17 00:00:00 2001 From: Dominic Barnes Date: Tue, 21 Jul 2015 15:17:24 -0700 Subject: [PATCH 1/4] be more specific with testing raw/src internally --- lib/file.js | 9 +++++---- test/api.js | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/file.js b/lib/file.js index baa601b..a5e970a 100644 --- a/lib/file.js +++ b/lib/file.js @@ -102,11 +102,12 @@ File.prototype.dependencies = function () { */ File.prototype.load = function *() { - if (this.src) return this; + if (typeof this.src !== 'undefined') return this; // read the file - this.attrs.src = this.raw = this.raw - || (yield fs.readFile(this.path, 'utf8')); + var raw = this.raw; + if (typeof raw === 'undefined') raw = yield fs.readFile(this.path, 'utf8'); + this.attrs.src = raw; // transform the file and update attributes var entry = this.entry ? this : this.duo.entry(); @@ -124,7 +125,7 @@ File.prototype.load = function *() { */ File.prototype.exists = function *() { - if (this.raw) return true; + if (typeof this.raw !== 'undefined') return true; else return yield exists(this.path); }; diff --git a/test/api.js b/test/api.js index 106d5b1..3dfe1d2 100644 --- a/test/api.js +++ b/test/api.js @@ -570,6 +570,10 @@ describe('Duo API', function () { assert.equal(ctx.b, 'b'); assert.equal(ctx.c, 'c'); }); + + it('should not fail when the input source code is empty', function *() { + yield Duo(path('simple')).entry('', 'css').run(); + }); }); // describe('with .development(false)'); From 1dda5cbffb82bda8506ec6abc7a59809f200456f Mon Sep 17 00:00:00 2001 From: Dominic Barnes Date: Wed, 22 Jul 2015 10:40:54 -0700 Subject: [PATCH 2/4] upgrading eslint config --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 493e44a..4e0f90c 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "coffee-script": "^1.9.3", "duo-jade": "0.x", "eslint": "^0.23.0", - "eslint-config-duo": "0.0.1", + "eslint-config-duo": "0.0.4", "expect.js": "^0.3.1", "gnode": "^0.1.1", "gulp": "^3.9.0", From 400410bcc3cb1cb04fcf033bf704defeb510f9cb Mon Sep 17 00:00:00 2001 From: Dominic Barnes Date: Wed, 22 Jul 2015 10:41:22 -0700 Subject: [PATCH 3/4] using more concise null comparison, which catches both null and undefined --- lib/file.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/file.js b/lib/file.js index a5e970a..44cd115 100644 --- a/lib/file.js +++ b/lib/file.js @@ -106,7 +106,7 @@ File.prototype.load = function *() { // read the file var raw = this.raw; - if (typeof raw === 'undefined') raw = yield fs.readFile(this.path, 'utf8'); + if (raw == null) raw = yield fs.readFile(this.path, 'utf8'); this.attrs.src = raw; // transform the file and update attributes @@ -125,7 +125,7 @@ File.prototype.load = function *() { */ File.prototype.exists = function *() { - if (typeof this.raw !== 'undefined') return true; + if (this.raw == null) return true; else return yield exists(this.path); }; From 0a32f9647fd0eaa40bee5eb7254ca1e3217cd1fc Mon Sep 17 00:00:00 2001 From: Dominic Barnes Date: Wed, 22 Jul 2015 10:48:36 -0700 Subject: [PATCH 4/4] oops, flipped the logic --- lib/file.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/file.js b/lib/file.js index 44cd115..190c1f3 100644 --- a/lib/file.js +++ b/lib/file.js @@ -125,7 +125,7 @@ File.prototype.load = function *() { */ File.prototype.exists = function *() { - if (this.raw == null) return true; + if (this.raw != null) return true; else return yield exists(this.path); };