7

Using the latest version of Microsoft.AspNet.Web.Optimization v1.1.3 I am unable to get bundling to minify the JavaScript if it includes template literals. For example if I include the following in one of my bundle scripts:

var name = 'Bob';
var formattedName = `${name} says hello`;

The resulting bundle will join all files but it won't minify code, and gives me this error:

/* Minification failed. Returning unminified contents.
(2,13-14): run-time error JS1014: Invalid character: `
(2,15-16): run-time error JS1004: Expected ';': {
(2,30-31): run-time error JS1014: Invalid character: `
(3,1-2): run-time error JS1107: Expecting more source characters
*/

I understand this feature was only introduced in ECMAScript2015 and it's clearly not supported but is there a clean workaround other than reverting back to the old string concatenation methods?

var name = 'Bob';
var formattedName = name + ' says hello';

Also, will template literal support go into future versions of Microsoft.AspNet.Web.Optimization?

2
  • Any joy getting this resolved? Or is it still an issue? Commented Feb 27, 2020 at 11:03
  • No, it was left unresolved for me. I ended up refactoring the app to use Gulp, Babel and various other JS libraries to bundle the app since I wasn't using any .NET features. One approach is to convert your code to an older version of JavaScript that's compatible with this using Babel. Or simply use another bundling library Commented Mar 10, 2020 at 9:52

1 Answer 1

2

I am using the bundleconfig.json method for minifying some script files and I encountered similar errors when running the appropriate task:

Illegal assignment: =
Expected ';'
Expected ';'
Expected expression
Expected '}'

I managed to change the literal from this:

style.textContent = `
...
`;

To this:

style.textContent = `
...`;

It will probably not answer your specific question (as you used Gulp), but might help someone out there, that doesn't want to start using npm's various packages for the same objective.

Sign up to request clarification or add additional context in comments.

1 Comment

This trick still works to resolve the issue, trailing back-tick needs to be on the same line as the end of the string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.