don't execute the callback inside of a try-catch as if the callback errors then it'll emit the error back to the callback

This commit is contained in:
Sebastian McKenzie 2015-10-05 16:46:45 +01:00
parent 52202543ff
commit de45daaef8

View File

@ -34,17 +34,21 @@ export function transformFile(filename: string, opts?: Object, callback: Functio
opts.filename = filename;
fs.readFile(filename, function (err, code) {
if (err) return callback(err);
let result;
try {
result = transform(code, opts);
} catch (err) {
return callback(err);
if (!err) {
try {
result = transform(code, opts);
} catch (_err) {
err = _err;
}
}
callback(null, result);
if (err) {
callback(err);
} else {
callback(null, result);
}
});
}