Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UglifyJS can fail silently #69

Open
invicticide opened this issue Dec 31, 2017 · 1 comment
Open

UglifyJS can fail silently #69

invicticide opened this issue Dec 31, 2017 · 1 comment
Assignees

Comments

@invicticide
Copy link
Owner

In user script, I had a function like this:

function rollDieInline()
{
	return `The die shows ${Math.ceil(Math.random() * 6)}.`;
}

After compiling with outputFormat: minify, the JS portion of the output was not minified. No error messages or exceptions were observed.

Running command-line uglifyjs manually against this file threw an error `unexpected character `` on that function. Apparently UglifyJS doesn't like string interpolation in return statements for some reason?

So there's that, and there's also the broader issue that html-minifier appears to be swallowing errors/exceptions from UglifyJS. I was able to get some log messages out by setting the log: (function) property in the html-minifier options (when calling it in Compiler.ApplyTemplate) and while UglifyJS does hand that callback an object containing a line/column number and error message, the position doesn't match up with anything useful, because it's an offset into a dynamic buffer that's already been through one or two other minification passes (css and html) and doesn't map to any actual source file any more.

The right solution may be to call UglifyJS separately rather than letting html-minifier do all the work for us, and then we can handle its errors directly, and at least return relevant surrounding context from the working minification buffer when an error is thrown.

@invicticide invicticide self-assigned this Dec 31, 2017
@invicticide
Copy link
Owner Author

I've added Compiler.OnMinifierLog to trap "log" output from the minifier, but it's a stopgap at best.

invicticide pushed a commit that referenced this issue Dec 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant