Skip to content

Commit

Permalink
Methods optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Feb 9, 2025
1 parent 724fa40 commit 858a3e9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
11 changes: 9 additions & 2 deletions YantraJS.Core/LinqExpressions/JSRegExpBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@
using SwitchCase = YantraJS.Expressions.YSwitchCaseExpression;
using GotoExpression = YantraJS.Expressions.YGoToExpression;
using TryExpression = YantraJS.Expressions.YTryCatchFinallyExpression;
using YantraJS.Core.LambdaGen;

namespace YantraJS.ExpHelper
{
public class JSRegExpBuilder
{
private static ConstructorInfo _New = typeof(JSRegExp).Constructor(typeof(string), typeof(string));
// private static ConstructorInfo _New = typeof(JSRegExp).Constructor(typeof(string), typeof(string));

public static Expression New(Expression exp, Expression exp2)
{
return Expression.TypeAs( Expression.New(_New, exp, exp2), typeof(JSValue));
return
Expression.TypeAs(
NewLambdaExpression.NewExpression<JSRegExp>(() => () => new JSRegExp("","")
, exp
, exp2)
, typeof(JSValue));
// return Expression.TypeAs( Expression.New(_New, exp, exp2), typeof(JSValue));
}

}
Expand Down
17 changes: 11 additions & 6 deletions YantraJS.Core/LinqExpressions/JSStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using SwitchCase = YantraJS.Expressions.YSwitchCaseExpression;
using GotoExpression = YantraJS.Expressions.YGoToExpression;
using TryExpression = YantraJS.Expressions.YTryCatchFinallyExpression;
using YantraJS.Core.LambdaGen;

namespace YantraJS.ExpHelper
{
Expand All @@ -28,17 +29,21 @@ public class JSStringBuilder
// return Expression.Field(ex, _Value);
//}

private static ConstructorInfo _New = typeof(JSString).Constructor(typeof(string));
// private static ConstructorInfo _New = typeof(JSString).Constructor(typeof(string));

public static Expression New(Expression exp)
{
return Expression.TypeAs( Expression.New(_New, exp), typeof(JSValue));
return
Expression.TypeAs(
NewLambdaExpression.NewExpression<JSString>(() => () => new JSString(""), exp)
, typeof(JSValue));
// return Expression.TypeAs( Expression.New(_New, exp), typeof(JSValue));
}

public static Expression ConcatBasicStrings(Expression left, Expression right)
{
return Expression.New(_New, ClrStringBuilder.Concat(left, right));
}
//public static Expression ConcatBasicStrings(Expression left, Expression right)
//{
// return Expression.New(_New, ClrStringBuilder.Concat(left, right));
//}

}
}
27 changes: 17 additions & 10 deletions YantraJS.Core/LinqExpressions/JSTemplateArrayBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,32 @@
using GotoExpression = YantraJS.Expressions.YGoToExpression;
using TryExpression = YantraJS.Expressions.YTryCatchFinallyExpression;
using YantraJS.Expressions;
using YantraJS.Core.LambdaGen;

namespace YantraJS.Core.LinqExpressions
{
public static class JSTemplateArrayBuilder
{

public static Type type = typeof(JSTemplateArray);
//public static Type type = typeof(JSTemplateArray);

private static MethodInfo _new =
type.PublicMethod(nameof(JSTemplateArray.New), typeof(string[]), typeof(string[]), typeof(JSValue[]));
//private static MethodInfo _new =
// type.PublicMethod(nameof(JSTemplateArray.New), typeof(string[]), typeof(string[]), typeof(JSValue[]));

public static Expression New(IList<Expression> cooked, IList<Expression> raw, IList<Expression> args)
{
//public static Expression New(IList<Expression> cooked, IList<Expression> raw, IList<Expression> args)
//{

var c = Expression.NewArrayInit(typeof(string), cooked);
var r = Expression.NewArrayInit(typeof(string), raw);
var v = Expression.NewArrayInit(typeof(JSValue), args);
return Expression.Call(null, _new, c, r, v);
}
// var c = Expression.NewArrayInit(typeof(string), cooked);
// var r = Expression.NewArrayInit(typeof(string), raw);
// var v = Expression.NewArrayInit(typeof(JSValue), args);
// // return Expression.Call(null, _new, c, r, v);
// return NewLambdaExpression.StaticCallExpression<JSValue>(
// () => () => JSTemplateArray.New(null as string[],null as string[], null as JSValue[])
// ,c
// ,r
// ,v
// );
//}

}
}
6 changes: 4 additions & 2 deletions YantraJS.Core/LinqExpressions/JSUndefinedBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Linq.Expressions;
using YantraJS.Core;
using YantraJS.Core.LambdaGen;
using Exp = YantraJS.Expressions.YExpression;
using Expression = YantraJS.Expressions.YExpression;
using ParameterExpression = YantraJS.Expressions.YParameterExpression;
Expand All @@ -11,7 +12,8 @@ namespace YantraJS.ExpHelper
public class JSUndefinedBuilder
{
public static Expression Value =
Expression.Field(null,
typeof(JSUndefined).GetField(nameof(Core.JSUndefined.Value)));
NewLambdaExpression.StaticFieldExpression<JSValue>(() => () => JSUndefined.Value);
//Expression.Field(null,
// typeof(JSUndefined).GetField(nameof(Core.JSUndefined.Value)));
}
}

0 comments on commit 858a3e9

Please sign in to comment.