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

NullReferenceException when using "protected" keywords as variable names #80

Closed
Lizzy-Gallagher opened this issue Oct 22, 2019 · 5 comments · Fixed by #131
Closed

NullReferenceException when using "protected" keywords as variable names #80

Lizzy-Gallagher opened this issue Oct 22, 2019 · 5 comments · Fixed by #131

Comments

@Lizzy-Gallagher
Copy link

Lizzy-Gallagher commented Oct 22, 2019

I am minifying some npm packages and came across a failure when using multiple "protected" keywords as variable names.

JavaScript:

var o = {
   "a": function(async) {
   	async = 5;
   },

   "b": function(module) {
   	module.exports = function () { };
   }
};

C#:
result = Uglify.Js(content, fileName: filePath);

Stacktrace:
NullReferenceException: Object reference not set to an instance of an object.
at NUglify.JavaScript.Syntax.MemberExpression.GetFunctionGuess(AstNode target)   at NUglify.JavaScript.Syntax.BinaryExpression.GetFunctionGuess(AstNode target)   at NUglify.JavaScript.Visitors.AnalyzeNodeVisitor.GuessAtName(AstNode node)   at NUglify.JavaScript.Visitors.AnalyzeNodeVisitor.Visit(FunctionObject node)   at NUglify.JavaScript.Syntax.FunctionObject.Accept(IVisitor visitor)   at NUglify.JavaScript.Visitors.AnalyzeNodeVisitor.Visit(BinaryExpression node)   at NUglify.JavaScript.Syntax.BinaryExpression.Accept(IVisitor visitor)   at NUglify.JavaScript.Visitors.AnalyzeNodeVisitor.Visit(BlockStatement node)   at NUglify.JavaScript.Syntax.BlockStatement.Accept(IVisitor visitor)   at NUglify.JavaScript.Visitors.AnalyzeNodeVisitor.Visit(FunctionObject node)   at NUglify.JavaScript.Syntax.FunctionObject.Accept(IVisitor visitor)   at NUglify.JavaScript.Visitors.AnalyzeNodeVisitor.Visit(BlockStatement node)   at NUglify.JavaScript.Syntax.BlockStatement.Accept(IVisitor visitor)   at NUglify.JavaScript.Visitors.AnalyzeNodeVisitor.Visit(FunctionObject node)   at NUglify.JavaScript.Syntax.FunctionObject.Accept(IVisitor visitor)   at NUglify.JavaScript.Visitors.TreeVisitor.Visit(ObjectLiteralProperty node)   at NUglify.JavaScript.Visitors.AnalyzeNodeVisitor.Visit(ObjectLiteralProperty node)   at NUglify.JavaScript.Syntax.ObjectLiteralProperty.Accept(IVisitor visitor)   at NUglify.JavaScript.Visitors.TreeVisitor.Visit(AstNodeList node)   at NUglify.JavaScript.Syntax.AstNodeList.Accept(IVisitor visitor)   at NUglify.JavaScript.Visitors.TreeVisitor.Visit(ObjectLiteral node)   at NUglify.JavaScript.Visitors.AnalyzeNodeVisitor.Visit(ObjectLiteral node)   at NUglify.JavaScript.Syntax.ObjectLiteral.Accept(IVisitor visitor)   at NUglify.JavaScript.Visitors.TreeVisitor.Visit(VariableDeclaration node)   at NUglify.JavaScript.Visitors.AnalyzeNodeVisitor.Visit(VariableDeclaration node)   at NUglify.JavaScript.Syntax.VariableDeclaration.Accept(IVisitor visitor)   at NUglify.JavaScript.Visitors.TreeVisitor.Visit(VarDeclaration node)   at NUglify.JavaScript.Visitors.AnalyzeNodeVisitor.Visit(VarDeclaration node)   at NUglify.JavaScript.Syntax.VarDeclaration.Accept(IVisitor visitor)   at NUglify.JavaScript.Visitors.AnalyzeNodeVisitor.Visit(BlockStatement node)   at NUglify.JavaScript.Syntax.BlockStatement.Accept(IVisitor visitor)   at NUglify.JavaScript.JSParser.InternalParse()   at NUglify.JavaScript.JSParser.Parse(DocumentContext sourceContext)   at NUglify.Uglify.Js(String source, String fileName, CodeSettings codeSettings)   at UserQuery.Minifiy(String filePath)   at UserQuery.Main()   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)   at System.Threading.ThreadHelper.ThreadStart()

@trullock
Copy link
Owner

trullock commented Jun 10, 2020

#94 which covers your b case is now fixed in v1.6.2

@trullock
Copy link
Owner

Technically async isnt a reserved word, because all possible usages as a language feature are uniquely parseable. However, you must be a sadist to use such terms as variable names.

This might be hard to fix, depending on how well the async parsing has been implemented.

We'll try though. PRs welcome!

@trullock
Copy link
Owner

ok I've pushed a fix for the case you've found here, but there are other bugs remaining, namely

function (async) {
        async();
    }

i.e. if you overload async as an identifier, and then call it as a function (with or without arguments) the parser will not understand this line and will strip it, removing the invocation

I don't know how to fix this without some serious rewriting of the parser, which I can't be arsed to do for such a sadistic case.

@trullock
Copy link
Owner

trullock commented Aug 21, 2020

Going to close this issue as its fixed, and i'll open a new one specific to the remaining case. see #130

@trullock trullock mentioned this issue Aug 21, 2020
@trullock
Copy link
Owner

Published 1.6.6 with a fix for this in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants