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

Lambda syntax error throws exception #284

Closed andrey-serdyuk closed 2 years ago

andrey-serdyuk commented 2 years ago

I receive an exception when I run Uglify.Js which is unable to try-catch. How can I try-catch it please? Thanks v1.16.4

at NUglify.JavaScript.JSParser.ParseArrowFunction(AstNode parameters)
   at NUglify.JavaScript.JSParser.ParseLeftHandSideExpression(Boolean isMinus)
   at NUglify.JavaScript.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)
   at NUglify.JavaScript.JSParser.ParseExpressionStatement(Boolean fSourceElement)
   at NUglify.JavaScript.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment)
   at NUglify.JavaScript.JSParser.ParseFunctionBody(BlockStatement body)
   at NUglify.JavaScript.JSParser.ParseFunctionPart2(FunctionType functionType, SourceContext context, BindingIdentifier name, ArrayLiteral computedName, Boolean isGenerator, Boolean isAsync)
   at NUglify.JavaScript.JSParser.ParseFunction(FunctionType functionType, SourceContext fncCtx)
   at NUglify.JavaScript.JSParser.ParseLeftHandSideExpression(Boolean isMinus)
   at NUglify.JavaScript.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)
   at NUglify.JavaScript.JSParser.ParseVarDecl(JSToken inToken)
   at NUglify.JavaScript.JSParser.ParseVariableStatement()
   at NUglify.JavaScript.JSParser.ParseStatements(BlockStatement block)
   at NUglify.JavaScript.JSParser.InternalParse()
   at NUglify.Uglify.Js(String source, String fileName, CodeSettings codeSettings)
   at Minifier.Minifiers.UglifyMinifier.MinifyJs(String path, String source) in C:\Dev\Minifier\Minifier\Minifiers\UglifyMinifier.cs:line 65
trullock commented 2 years ago

It's failing to parse a lambda, can you provide your JavaScript

andrey-serdyuk commented 2 years ago

I know exact JS error in the file. I did this syntax error in order to check my code stabily but instead of receiving an Uglify errors list or to catch an exception it simply crashed.

andrey-serdyuk commented 2 years ago

If you could provide an Uglify error for case when parsing is imposible it could be very helpfull imo

trullock commented 2 years ago

It should do what you describe. There is a bug.

Please provide the repro code

andrey-serdyuk commented 2 years ago

Here is the original code which passes minification successfully:

var SurfSight = function (_settings) {
    this.showPlaceholder = (container) => {
        $(container).find('video').hide();
        $(container).find('.videoID').show();
    };
};

Here is the code which causes the crash.

var SurfSight = function (_settings) {
    this.showPlaceholder (container) => {
        $(container).find('video').hide();
        $(container).find('.videoID').show();
    };
};

I've changed the row this.showPlaceholder (container) => { by removing the sign '=' to cause syntax error in purpose to check my minifier code stability and it crashed.

trullock commented 2 years ago

Thanks, I'll take a look

andrey-serdyuk commented 2 years ago

Thank you

trullock commented 2 years ago

Fixed in v1.16.6

andrey-serdyuk commented 2 years ago

Hi. Thanks for the fix. There is a problem to install this version yet.

Install-Package NUglify -Version 1.16.6 **Install-Package : NU1102: Unable to find package NUglify with version (>= 1.16.6)

trullock commented 2 years ago

Ughh the build failed for some reason. Will look later

trullock commented 2 years ago

1.17.0 should publish shortly

andrey-serdyuk commented 2 years ago

Thank you very much

trullock commented 2 years ago

Now fix your syntax error 😂

andrey-serdyuk commented 2 years ago

😂 Thank you very much, friend