public override bool Build(ref CodeNode _this, int expressionDepth, Dictionary <string, VariableDescriptor> variables, CodeContext codeContext, InternalCompilerMessageCallback message, FunctionInfo stats, Options opts) { var res = base.Build(ref _this, expressionDepth, variables, codeContext, message, stats, opts); if (!res && _this == this) { if (_left is StringConcatenation) { _this = _left; var temp = (_left as StringConcatenation)._parts; Array.Resize(ref temp, temp.Length + 1); temp[temp.Length - 1] = _right; (_left as StringConcatenation)._parts = temp; } else if (_right is StringConcatenation) { _this = _right; var temp = (_right as StringConcatenation)._parts; Array.Resize(ref temp, temp.Length + 1); Array.Copy(temp, 0, temp, 1, temp.Length - 1); temp[0] = _left; (_right as StringConcatenation)._parts = temp; } else { if (_left.ContextIndependent && _left.ResultType == PredictedType.String) { if (_left.Evaluate(null).ToString().Length == 0) { _this = new ConvertToString(_right); } else { _this = new StringConcatenation(new[] { _left, _right }); } } else if (_right.ContextIndependent && _right.ResultType == PredictedType.String) { if (_right.Evaluate(null).ToString().Length == 0) { _this = new ConvertToString(_left); } else { _this = new StringConcatenation(new[] { _left, _right }); } } else if (_left.ResultType == PredictedType.String || _right.ResultType == PredictedType.String) { _this = new StringConcatenation(new[] { _left, _right }); } } } return(res); }
public override bool Build(ref CodeNode _this, int expressionDepth, Dictionary <string, VariableDescriptor> variables, CodeContext codeContext, CompilerMessageCallback message, FunctionInfo stats, Options opts) { var res = base.Build(ref _this, expressionDepth, variables, codeContext, message, stats, opts); if (!res && _this == this) { if (_left is StringConcatenation) { _this = _left; (_left as StringConcatenation)._parts.Add(_right); } else if (_right is StringConcatenation) { _this = _right; (_right as StringConcatenation)._parts.Insert(0, _left); } else { if (_left.ContextIndependent && _left.Evaluate(null)._valueType == JSValueType.String) { if (_left.Evaluate(null).ToString().Length == 0) { _this = new ConvertToString(_right); } else { _this = new StringConcatenation(new List <Expression>() { _left, _right }); } } else if (_right.ContextIndependent && _right.Evaluate(null)._valueType == JSValueType.String) { if (_right.Evaluate(null).ToString().Length == 0) { _this = new ConvertToString(_left); } else { _this = new StringConcatenation(new List <Expression>() { _left, _right }); } } } } return(res); }