From 68c8585f5f83e2b8df422aea0167ce9c349d358f Mon Sep 17 00:00:00 2001 From: Aaron Chong Date: Sat, 20 Jan 2018 08:58:01 +0800 Subject: [PATCH] Remove deprecated callback parameter --- lib/parser.js | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index 0e5cc948c3..89e0fca6bb 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -276,9 +276,7 @@ Parser.prototype._trimNodes = function (node) { } }; -Parser.prototype.includeFile = function (file, config, cb) { - cb = cb || function () {}; // create empty callback - +Parser.prototype.includeFile = function (file, config) { let context = {}; context.cwf = file; // current working file context.mode = 'include'; @@ -287,14 +285,12 @@ Parser.prototype.includeFile = function (file, config, cb) { let handler = new htmlparser.DomHandler((error, dom) => { if (error) { reject(error); - cb(error); return; } let nodes = dom.map(d => { return this._preprocess(d, context, config); }); resolve(cheerio.html(nodes)); - cb(null, cheerio.html(nodes)); }); let parser = new htmlparser.Parser(handler, { @@ -306,7 +302,6 @@ Parser.prototype.includeFile = function (file, config, cb) { fs.readFile(file, (err, data) => { if (err) { reject(err); - cb(err); return; } let fileExt = utils.getExtName(file); @@ -318,16 +313,13 @@ Parser.prototype.includeFile = function (file, config, cb) { parser.parseComplete(data); } else { let err = new Error(`Unsupported File Extension: '${fileExt}'`); - cb(err); reject(err); } }); }); }; -Parser.prototype.renderFile = function (file, cb) { - cb = cb || function () {}; // create empty callback - +Parser.prototype.renderFile = function (file) { let context = {}; context.cwf = file; // current working file context.mode = 'render'; @@ -335,7 +327,6 @@ Parser.prototype.renderFile = function (file, cb) { let handler = new htmlparser.DomHandler((error, dom) => { if (error) { reject(error); - cb(error); return; } let nodes = dom.map(d => { @@ -346,7 +337,6 @@ Parser.prototype.renderFile = function (file, cb) { }); cheerio.prototype.options.xmlMode = false; resolve(cheerio.html(nodes)); - cb(null, cheerio.html(nodes)); cheerio.prototype.options.xmlMode = true; }); @@ -359,7 +349,6 @@ Parser.prototype.renderFile = function (file, cb) { fs.readFile(file, (err, data) => { if (err) { reject(err); - cb(err); return; } let inputData = data; @@ -373,14 +362,13 @@ Parser.prototype.renderFile = function (file, cb) { parser.parseComplete(data); } else { let err = new Error(`Unsupported File Extension: '${fileExt}'`); - cb(err); reject(err); } }); }); }; -Parser.prototype.resolveBaseUrl = function (pageData, config, cb) { +Parser.prototype.resolveBaseUrl = function (pageData, config) { let {baseUrlMap, rootPath, isDynamic} = config; this.baseUrlMap = baseUrlMap; this.rootPath = rootPath; @@ -388,12 +376,10 @@ Parser.prototype.resolveBaseUrl = function (pageData, config, cb) { if (this.isDynamic) { this.dynamicSource = config.dynamicSource; } - cb = cb || function () {}; // create empty callback return new Promise((resolve, reject) => { let handler = new htmlparser.DomHandler((error, dom) => { if (error) { reject(error); - cb(error); return; } dom.forEach(d => { @@ -406,7 +392,6 @@ Parser.prototype.resolveBaseUrl = function (pageData, config, cb) { }); cheerio.prototype.options.xmlMode = false; resolve(cheerio.html(dom)); - cb(null, cheerio.html(dom)); cheerio.prototype.options.xmlMode = true; });