4

The following script falls over when the ASP.NET bundler tries to minify it.

/* Minification failed. Returning unminified contents.
(164,59-60): run-time error JS1195: Expected expression: >
(164,87-88): run-time error JS1004: Expected ';': )
*/

...

var isFruit = $("select#fruit").children().filter((i, e) => $(e).text() === "Fruit...").length > 0;

My guess is that the minifier is working with an older JS version than the rest of my project (as the code works fine in Visual Studio and in the browser), so it doesn't recognise the lambda expression syntax. How would I go about fixing this?

Extragorey
  • 1,654
  • 16
  • 30
  • What bundler & version are you using? – SLaks Jan 30 '18 at 03:48
  • Just the default for VS2015. System.Web.Optimization, version 1.1 apparently. – Extragorey Jan 30 '18 at 03:51
  • That library has not been updated in four years. – SLaks Jan 30 '18 at 04:14
  • Ah, well that might explain it then. Which library would you suggest using instead? – Extragorey Jan 30 '18 at 04:19
  • A [related question](https://stackoverflow.com/q/28067798/1178314) has some alternative in its answers, included [`BundelTransformer`](https://github.com/Taritsyn/BundleTransformer) which seems to be the more straightforward to put in place since it is an extension of Web.Optimization. – Frédéric Mar 16 '23 at 09:50

1 Answers1

3

You can use babeljs.io - REPL to convert such expressions to pure JavaScript. It is widely used by React developers to convert JSX expressions to pure javascript.

var isFruit = $("select#fruit").children().filter(function (i, e) {
    return $(e).text() === "Fruit...";
}).length > 0;
Dharmesh
  • 943
  • 4
  • 15
  • 26