dciccale / grunt-processhtml

Process html files at build time to modify them depending on the release environment
MIT License
407 stars 30 forks source link

Template literals (Template strings) Failing To Process #132

Open ronnievsmith opened 1 year ago

ronnievsmith commented 1 year ago

Are template strings supported? I am getting the following error from Grunt:

Fatal error: myTemplateStringVar is not defined

My variable looks like below and runs fine in all three major web browsers.

myTemplateStringVar = "xyz";
let thisDt = fragment.querySelector(`dt[data-label=${myTemplateStringVar}]`);
dciccale commented 1 year ago

Hi @ronnieroyston template strings or string interpolation with backticks, is a javascript feature and it has nothing to do with this plugin or grunt.

There is nothing wrong in the code example you shared. I would need more context on where are you running this code specifically to understand what is it that is failing. something I can reproduce

ronnievsmith commented 1 year ago

Thanks for the response Denis. When I remove the newly added template string lines of code the files get built with Grunt. It's a large js file.

The error message was:

Running "processhtml:dist" (processhtml) task
Fatal error: myTemplateStringVar is not defined
dciccale commented 1 year ago

make sure the variable is available in the scope you're using it. i can't help you much more than that without some example. it seems more like a javascript mistake on your code rather than an issue with this particular plugin, I could be wrong but without something to reproduce it is very hard for me to help. if i can get some time later I can make a demo/test to show how variables actually should work fine. but i don't know where are you using that code, is it in your gruntfile or where?