From 0a4fa371959595ff4ebcadba37f983dd71c6ed5b Mon Sep 17 00:00:00 2001 From: Markus Wolf Date: Thu, 1 Mar 2018 11:41:38 +0100 Subject: [PATCH 1/2] fix: update for webpack 4 this.options is not available in webpack4 so we check and return an empty object instead. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index ed9c937..6a369b8 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ var loaderUtils = require('loader-utils'); module.exports = function(source) { this.cacheable && this.cacheable(); var query = loaderUtils.parseQuery(this.query); - var options = this.options.ejsLoader || {}; + var options = this.options ? this.options.ejsLoader || {} : {}; ['escape', 'interpolate', 'evaluate'].forEach(function(templateSetting) { var setting = query[templateSetting]; From e20eac812a332004ab534d2cc004680b1ceb4a5e Mon Sep 17 00:00:00 2001 From: Markus Wolf Date: Thu, 1 Mar 2018 17:28:28 +0100 Subject: [PATCH 2/2] refactor: make code more readable and remove ternary --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 6a369b8..a171ec1 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,17 @@ var _ = require('lodash'); var loaderUtils = require('loader-utils'); +function getOptions(context) { + if (context.options && context.options.ejsLoader) { + return context.options.ejsLoader; + } + return {}; +} + module.exports = function(source) { this.cacheable && this.cacheable(); var query = loaderUtils.parseQuery(this.query); - var options = this.options ? this.options.ejsLoader || {} : {}; + var options = getOptions(this); ['escape', 'interpolate', 'evaluate'].forEach(function(templateSetting) { var setting = query[templateSetting];