diff --git a/lib/plugins/transform/tokenTemplateValues.js b/lib/plugins/transform/tokenTemplateValues.js index e2b7938..9e30e7c 100644 --- a/lib/plugins/transform/tokenTemplateValues.js +++ b/lib/plugins/transform/tokenTemplateValues.js @@ -40,6 +40,10 @@ module.exports = superclass => class extends superclass { ["error", { "exceptMethods": ["getTraceIndex"] }] */ transform(value) { + let tmpValue = value; + if (typeof tmpValue !== 'object') { + tmpValue = {value: value};// eslint-disable-line object-shorthand + } // Set up variables. // Are we using named values? let tokens = {}; // eslint-disable-line no-unused-vars @@ -53,13 +57,13 @@ module.exports = superclass => class extends superclass { // We are using tokens, which are reassignments of values to new names. for (let i = 0; i < Object.keys(tmpTokens).length; i += 1) { // We need to get the values and assign them to their new names. - tmpTokens[Object.keys(tmpTokens)[i]] = value[tmpTokens[Object.keys(tmpTokens)[i]]]; + tmpTokens[Object.keys(tmpTokens)[i]] = tmpValue[tmpTokens[Object.keys(tmpTokens)[i]]]; } tokens = Object.assign({}, tokens, tmpTokens); } else { // we are not using tokens. - tokens = Object.assign({}, tokens, value); + tokens = Object.assign({}, tokens, tmpValue); } const templatePath = this.getTemplatePath(this.options.origin); diff --git a/test/helpers/templateFive.tpl b/test/helpers/templateFive.tpl new file mode 100644 index 0000000..199cee7 --- /dev/null +++ b/test/helpers/templateFive.tpl @@ -0,0 +1 @@ +this is a {{value}} \ No newline at end of file diff --git a/test/tokenTemplateValues.js b/test/tokenTemplateValues.js index da67c4a..6cb2bc0 100644 --- a/test/tokenTemplateValues.js +++ b/test/tokenTemplateValues.js @@ -73,6 +73,7 @@ const options5 = { } }; +const value2 = 'testBoogie'; const testClass = new Implemented(options, {}); @@ -84,6 +85,8 @@ const testClass4 = new Implemented(options4, {monkey: 'toofer'}); const testClass5 = new Implemented(options5, {monkey: 'toofer'}); +const testClass6 = new Implemented(options, {}); + module.exports = { tokenOnlyValues: (test) => { test.expect(1); @@ -148,6 +151,16 @@ module.exports = { 'Dust template "one" name is: testName, test has the value of \"testKey2: item1.' // eslint-disable-line no-useless-escape ); test.done(); - } + }, + tokenSimpleValue: (test) => { + test.expect(1); + testClass6.options.origin = 'test/helpers/templateFive.tpl'; + testClass.transform(value2); + test.deepEqual( + testClass.value, + 'this is a testBoogie' + ); + test.done(); + }, };