NUglify icon indicating copy to clipboard operation
NUglify copied to clipboard

NullReferenceException in "ParseUnaryExpression"

Open UweKeim opened this issue 2 years ago • 3 comments

When running Uglify.Js on this string:

  <!--
  var test = true;
  var test1 = false;
  var test 3 = "maybe";
  -->

I am getting a NullReferenceException with this stack trace:

   at NUglify.JavaScript.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, 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.ParseStatements(BlockStatement block)
   at NUglify.JavaScript.JSParser.InternalParse()
   at NUglify.JavaScript.JSParser.Parse(DocumentContext sourceContext)
   at NUglify.JavaScript.JSParser.Parse(DocumentContext sourceContext, CodeSettings settings)
   at NUglify.Uglify.Js(String source, String fileName, CodeSettings codeSettings)
   at NUglify.Uglify.Js(String source, CodeSettings codeSettings)

Is it possible to fix this on your side?

Right now I'm catching all exceptions and returning the un-uglified string but having zero NullReferenceExceptions would really be awesome.

UweKeim avatar Apr 14 '22 08:04 UweKeim

So it shouldn't throw an exception, so I'll look at that.

What syntax is that? Half HTML comment and half JS? What are you expecting this to be and how to behave?

trullock avatar Apr 14 '22 18:04 trullock

Thank you.

This was given to me by one of my webdesign co-workers. I assume this to be an excerpt from a larger script that failed to minify. So this is just a proof-of-concept.

Actually I am unsure how this should behave beside not throwing an exception.

UweKeim avatar Apr 14 '22 18:04 UweKeim

Actually I am unsure how this should behave beside not throwing an exception.

Quite.

The parser generally does handle syntax errors. It usually omits the offending code and reports something useful. I'll take a look but as this is "exceptional" I can't promise a change

trullock avatar Apr 14 '22 18:04 trullock