public static JsJsonObjectExpression Add(this JsJsonObjectExpression exp, string name, JsExpression value) { if (exp.NamesValues == null) exp.NamesValues = new List<JsJsonNameValue>(); exp.NamesValues.Add(JsonNameValue(name, value)); return exp; }
public static JsVariableDeclarationExpression AndVar(this JsVariableDeclarationExpression decl, string variableName, JsExpression initializer = null) { if (decl.Declarators == null) decl.Declarators = new List<JsVariableDeclarator>(); decl.Declarators.Add(new JsVariableDeclarator { Name = variableName, Initializer = initializer }); return decl; }
public static JsSwitchStatement Case(this JsSwitchStatement node, JsExpression value, List<JsStatement> statements) { if (node.Sections == null) node.Sections = new List<JsSwitchSection>(); node.Sections.Add(new JsSwitchSection { Labels = new List<JsSwitchLabel> { new JsSwitchLabel { Expression = value } }, Statements = statements }); return node; }
public static JsInvocationExpression AddArgument(this JsInvocationExpression exp, JsExpression arg) { if (exp.Arguments == null) exp.Arguments = new List<JsExpression> { arg }; else exp.Arguments.Add(arg); return exp; }
public static JsInvocationExpression InsertArgument(this JsInvocationExpression exp, int index, JsExpression arg) { if (exp.Arguments == null) exp.Arguments = new List<JsExpression> { arg }; else exp.Arguments.Insert(index, arg); return exp; }
void YieldReturnInCurrentStep(JsExpression item) { var result = Js.Value(true); var stepIndex = Steps.Count - 1; AddToCurrentStep(Js.This().Member("_current").Assign(item).Statement()); AddToCurrentStep(_state().Assign(Js.Value(stepIndex + 1)).Statement()); AddToCurrentStep(Js.Member("result").Assign(result).Statement()); AddToCurrentStep(Js.Return(result)); }
void ProcessTarget() { if (Res.TargetResult != null && !Member.IsStatic() && Member.SymbolKind != SymbolKind.Constructor) //TargetResult==null when ctor { JsTarget = VisitExpression(Res.TargetResult); if (JsMember.PreviousMember != null) throw new NotSupportedException(); JsMember.PreviousMember = JsTarget; } }
public static JsExpressionStatement getJsExpressionStatement( JsExpression exp ) { JsExpressionStatement result = new JsExpressionStatement(); result.Expression = exp; return result; }
public static JsBinaryExpression BitwiseOr(this JsExpression exp, JsExpression exp2) { return new JsBinaryExpression { Left = exp, Operator = "|", Right = exp2 }; }
public static JsVariableDeclarationExpression Var(string variableName, JsExpression initializer = null) { return new JsVariableDeclarationExpression { Declarators = new List<JsVariableDeclarator> { new JsVariableDeclarator { Name = variableName, Initializer = initializer } } }; }
public static JsIndexerAccessExpression IndexerAccess(this JsExpression me, JsExpression prm) { return new JsIndexerAccessExpression { Member = me, Arguments = new List<JsExpression> { prm } }; }
public static JsIfStatement If(JsExpression condition, JsStatement ifStatement = null, JsStatement elseStatement = null) { return new JsIfStatement { Condition = condition, IfStatement = ifStatement, ElseStatement = elseStatement }; }
public static JsBinaryExpression GreaterThan(this JsExpression exp, JsExpression exp2) { return new JsBinaryExpression { Left = exp, Operator = ">", Right = exp2 }; }
public static JsExpression Conditional(this JsExpression condition, JsExpression trueExp, JsExpression falseExp) { return new JsConditionalExpression { Condition = condition, TrueExpression = trueExp, FalseExpression = falseExp }; }
void _Visit(JsExpression node) { }
public static JsSwitchStatement Switch(JsExpression exp) { return new JsSwitchStatement { Expression = exp, Sections = new List<JsSwitchSection>() }; }
public static JsBinaryExpression InstanceOf(this JsExpression exp, JsExpression exp2) { return new JsBinaryExpression { Left = exp, Operator = "instanceof", Right = exp2 }; }
public static JsWhileStatement While(JsExpression condition, JsStatement statement = null) { return new JsWhileStatement { Condition = condition, Statement = statement }; }
public static JsInvocationExpression InvokeWithContextIfNeeded(this JsExpression me, JsExpression context, params JsExpression[] prms) { if (context == null) return me.Invoke(prms); var prms2 = prms.ToList(); prms2.Insert(0, context); return me.Member("call").Invoke(prms2.ToArray()); }
/// <summary> /// MyFunction(prm1, prm2) -> MyFunction.call(context, prm1, prm2) /// </summary> /// <param name="node"></param> /// <param name="context"></param> /// <returns></returns> public static void ToCallWithContext(JsInvocationExpression node, JsExpression context) { node.Member = node.Member.Member("call"); if (node.Arguments == null) node.Arguments = new List<JsExpression>(); node.Arguments.Insert(0, Js.This()); }
public static JsJsonNameValue JsonNameValue(string name, JsExpression value) { return new JsJsonNameValue { Name = new JsJsonMember { Name = name }, Value = value }; }
public static JsAssignmentExpression Assign(this JsExpression me, JsExpression exp2) { var node = new JsAssignmentExpression { Left = me, Right = exp2 }; return node; }
public static JsBinaryExpression LessThanOrEqualTo(this JsExpression exp, JsExpression exp2) { return new JsBinaryExpression { Left = exp, Operator = "<=", Right = exp2 }; }
public static JsBinaryExpression getJsBinaryExpression( JsExpression leftExp, string operatorStr, JsExpression rightExp ) { JsBinaryExpression result = new JsBinaryExpression(); result.Left = leftExp; result.Operator = operatorStr; result.Right = rightExp; return result; }
public static JsNewObjectExpression New(JsExpression ctor, params JsExpression[] prms) { return new JsNewObjectExpression { Invocation = ctor.Invoke(prms) }; }
public static JsReturnStatement getJsReturnStatement(JsExpression exp) { JsReturnStatement pReturn = new JsReturnStatement(); pReturn.Expression = exp; return pReturn; }
public static JsExpression NewArray(string type, JsExpression size, JsExpression[] items) { if (type.IsNullOrEmpty()) type = "Array"; if (type == "Array") { if (items != null) return NewJsonArray(items); else if (size == null) return NewJsonArray(); } //Typed arrays if (items != null) return Js.New(Member(type), NewJsonArray(items)); if (size == null) return Js.New(Member(type)); return Js.New(Member(type), size); }
protected override void _visit(JsExpression node) { if (node != null) { // TODO: JsExpression } }
public static JsBinaryExpression NotEqual(this JsExpression exp, JsExpression exp2) { return new JsBinaryExpression { Left = exp, Operator = "!=", Right = exp2 }; }
protected virtual void _visit( JsExpression node ) { throw new NotImplementedException( "JsExpression" ); }
public static JsReturnStatement Return(JsExpression exp = null) { return new JsReturnStatement { Expression = exp }; }