From 8a511e213f64bfb9b88d43a4233e929552b556af Mon Sep 17 00:00:00 2001 From: Gijs van Dam Date: Thu, 4 Apr 2019 12:17:35 +0800 Subject: [PATCH] Change order of fallbacks for renderFileAsync The documentation gives the impression that the fallback for a method follows a certain order. For renderFileAsync that order should then be * `.renderFileAsync` * `.renderFile` * `.renderAsync` * `.render` * `.compileFileAsync` * `.compileFile` * `.compileAsync` * `.compile` This commit makes the code follow that order --- index.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index c12d7f9..afb9b19 100644 --- a/index.js +++ b/index.js @@ -344,16 +344,15 @@ Transformer.prototype.renderFileAsync = function (filename, options, locals, cb) return tr.normalizeAsync(this._tr.renderFileAsync(filename, options, locals), cb); } else if (this._hasMethod('renderFile')) { return tr.normalizeAsync(this._tr.renderFile(filename, options, locals), cb); - } else if (this._hasMethod('compile') || this._hasMethod('compileAsync') - || this._hasMethod('compileFile') || this._hasMethod('compileFileAsync')) { - return tr.normalizeAsync(this.compileFileAsync(filename, options).then(function (compiled) { - return {body: compiled.fn(locals || options), dependencies: compiled.dependencies}; - }), cb); - } else { // render || renderAsync + } else if (this._hasMethod('render') || this._hasMethod('renderAsync')) { // render || renderAsync if (!options) options = {}; if (options.filename === undefined) options.filename = filename; return tr.normalizeAsync(tr.readFile(filename, 'utf8').then(function (str) { return this.renderAsync(str, options, locals); }.bind(this)), cb); - } + } else { + return tr.normalizeAsync(this.compileFileAsync(filename, options).then(function (compiled) { + return {body: compiled.fn(locals || options), dependencies: compiled.dependencies}; + }), cb); + } };