13
I am implementing a function that has deferred value to return and within the function I have many nested conditional expressions:
e.g.:
deferred = Q.defer()
FS.readFile("foo.txt", "utf-8", (error, text) ->
if error
deferred.reject(new Error(error))
else
deferred.resolve(text)
)
return deferred.promise
which than will be compiled into:
var deferred;
deferred = Q.defer();
FS.readFile("foo.txt", "utf-8", function(error, text) {
if (error) {
--> return <-- deferred.reject(new Error(error));
} else {
--> return <-- deferred.resolve(text);
}
});
return deferred.promise;
I need only the last return, but not the if/else returns (i.e. --> return <-- in the compiled code)
How can I avoid such a behavior (implicit returns where they are do not needed) of the coffeescript compiler?