Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 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;
 }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 9
0
 public static JsBinaryExpression BitwiseOr(this JsExpression exp, JsExpression exp2)
 {
     return new JsBinaryExpression { Left = exp, Operator = "|", Right = exp2 };
 }
Exemplo n.º 10
0
 public static JsVariableDeclarationExpression Var(string variableName, JsExpression initializer = null)
 {
     return new JsVariableDeclarationExpression { Declarators = new List<JsVariableDeclarator> { new JsVariableDeclarator { Name = variableName, Initializer = initializer } } };
 }
Exemplo n.º 11
0
 public static JsIndexerAccessExpression IndexerAccess(this JsExpression me, JsExpression prm)
 {
     return new JsIndexerAccessExpression { Member = me, Arguments = new List<JsExpression> { prm } };
 }
Exemplo n.º 12
0
 public static JsIfStatement If(JsExpression condition, JsStatement ifStatement = null, JsStatement elseStatement = null)
 {
     return new JsIfStatement { Condition = condition, IfStatement = ifStatement, ElseStatement = elseStatement };
 }
Exemplo n.º 13
0
 public static JsBinaryExpression GreaterThan(this JsExpression exp, JsExpression exp2)
 {
     return new JsBinaryExpression { Left = exp, Operator = ">", Right = exp2 };
 }
Exemplo n.º 14
0
 public static JsExpression Conditional(this JsExpression condition, JsExpression trueExp, JsExpression falseExp)
 {
     return new JsConditionalExpression { Condition = condition, TrueExpression = trueExp, FalseExpression = falseExp };
 }
Exemplo n.º 15
0
 void _Visit(JsExpression node)
 {
 }
Exemplo n.º 16
0
 public static JsSwitchStatement Switch(JsExpression exp)
 {
     return new JsSwitchStatement { Expression = exp, Sections = new List<JsSwitchSection>() };
 }
Exemplo n.º 17
0
 public static JsBinaryExpression InstanceOf(this JsExpression exp, JsExpression exp2)
 {
     return new JsBinaryExpression { Left = exp, Operator = "instanceof", Right = exp2 };
 }
Exemplo n.º 18
0
 public static JsWhileStatement While(JsExpression condition, JsStatement statement = null)
 {
     return new JsWhileStatement { Condition = condition, Statement = statement };
 }
Exemplo n.º 19
0
 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());
 }
Exemplo n.º 20
0
 /// <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());
 }
Exemplo n.º 21
0
 public static JsJsonNameValue JsonNameValue(string name, JsExpression value)
 {
     return new JsJsonNameValue { Name = new JsJsonMember { Name = name }, Value = value };
 }
Exemplo n.º 22
0
 public static JsAssignmentExpression Assign(this JsExpression me, JsExpression exp2)
 {
     var node = new JsAssignmentExpression { Left = me, Right = exp2 };
     return node;
 }
Exemplo n.º 23
0
 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;
 }
Exemplo n.º 25
0
 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;
 }
Exemplo n.º 27
0
        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
     }
 }
Exemplo n.º 29
0
 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" );
 }
Exemplo n.º 31
0
 public static JsReturnStatement Return(JsExpression exp = null)
 {
     return new JsReturnStatement { Expression = exp };
 }