From 3b3c069c3b8b116d5359a7643120b6160d9c1d28 Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Sat, 24 Dec 2011 11:00:09 -0800 Subject: [PATCH] Moving rewatch to end of function for scoping (thanks, satyr) --- lib/coffee-script/command.js | 13 ++++++------- src/command.coffee | 8 ++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/coffee-script/command.js b/lib/coffee-script/command.js index 34388099..191a6ed8 100644 --- a/lib/coffee-script/command.js +++ b/lib/coffee-script/command.js @@ -212,11 +212,6 @@ throw e; } }; - rewatch = function() { - var watcher; - if (typeof watcher !== "undefined" && watcher !== null) watcher.close(); - return watcher = fs.watch(source, compile); - }; compile = function() { clearTimeout(compileTimeout); return compileTimeout = wait(25, function() { @@ -235,10 +230,14 @@ }); }; try { - return watcher = fs.watch(source, compile); + watcher = fs.watch(source, compile); } catch (e) { - return watchErr(e); + watchErr(e); } + return rewatch = function() { + if (watcher != null) watcher.close(); + return watcher = fs.watch(source, compile); + }; }; watchDir = function(source, base) { diff --git a/src/command.coffee b/src/command.coffee index 5a56217e..60955cd7 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -186,10 +186,6 @@ watch = (source, base) -> compileJoin() else throw e - rewatch = -> - watcher?.close() - watcher = fs.watch source, compile - compile = -> clearTimeout compileTimeout compileTimeout = wait 25, -> @@ -208,6 +204,10 @@ watch = (source, base) -> catch e watchErr e + rewatch = -> + watcher?.close() + watcher = fs.watch source, compile + # Watch a directory of files for new additions. watchDir = (source, base) ->