trullock / NUglify

NUglify is a HTML, JavaScript and CSS minification Library for .NET (fork of AjaxMin + new features)
Other
398 stars 79 forks source link

await myfunc() === "value" minifies to false (!1) #293

Closed Mehuge closed 2 years ago

Mehuge commented 2 years ago

Combination of await and === comparison causes nuglify to substitute with false. Similar happens with !==

Example Code

window.XCP = window.XCP || {};
XCP.Global = class {
  async example1() {
    this.myfuncresult = await myfunc() == "value"
  }
  async example2() {
    this.myfuncresult = await myfunc() === "value"
  }
}

Resulting Minified code: The example2() method just sets this.myfuncresult to false.

window.XCP=window.XCP||{};XCP.Global = (class {
async example1(){this.myfuncresult=await myfunc()=="value"}
async example2(){this.myfuncresult=!1}})
})

Version: 1.17.3

Code used to run the minifier:

var jsSettings = new CodeSettings();
jsSettings.MinifyCode = true;
jsSettings.LocalRenaming = LocalRenaming.CrunchAll;
var result = Uglify.Js(File.ReadAllText(serverBundle), jsSettings);
File.WriteAllText(serverBundle, result.Code);
trullock commented 2 years ago

Thanks for the comprehensive ticket, I'll take a look

trullock commented 2 years ago

This repro can be simplified to

async function myfunc()
{
    return await myfunc() === "value";
}

The issues is how await is evaluated wrt ===, it thinks the return type is always a number, so they are never strictly equal in this case, hence getting !1

trullock commented 2 years ago

Fixed in 1.17.7