public JsObjectLiteralProperty(string name, JsExpression value) { if (name == null) throw new ArgumentNullException("name"); if (value == null) throw new ArgumentNullException("value"); Name = name; Value = value; }
public JsVariableDeclaration(string name, JsExpression initializer) { if (name == null) throw new ArgumentNullException("name"); if (!name.IsValidJavaScriptIdentifier()) throw new ArgumentException("name"); Name = name; Initializer = initializer; }
public JsExpression BindBaseCall(IType baseType, string methodName, IList<IType> typeArguments, JsExpression @this) { JsExpression method = JsExpression.Member(JsExpression.Member(GetScriptType(baseType, TypeContext.BindBaseCall), "prototype"), methodName); if (typeArguments != null && typeArguments.Count > 0) method = InstantiateGenericMethod(method, typeArguments); return JsExpression.Invocation(JsExpression.Member(_createTypeReferenceExpression(KnownTypeReference.Delegate), "mkdel"), @this, method); }
public static JsExpression EnsureCanBeEvaluatedMultipleTimes(IList<JsStatement> statementList, JsExpression expression, IList<JsExpression> expressionsThatMustBeEvaluatedBefore, Func<string> createTemporaryVariable) { if (IsJsExpressionComplexEnoughToGetATemporaryVariable.Analyze(expression)) { CreateTemporariesForAllExpressionsThatHaveToBeEvaluatedBeforeNewExpression(statementList, expressionsThatMustBeEvaluatedBefore, expression, createTemporaryVariable); var temp = createTemporaryVariable(); statementList.Add(new JsVariableDeclarationStatement(temp, expression)); return JsExpression.Identifier(temp); } else return expression; }
public JsExpression CloneDelegate(JsExpression source, IType sourceType, IType targetType) { if (Equals(sourceType, targetType)) { // The user does something like "D d1 = F(); var d2 = new D(d1)". Assume he does this for a reason and create a clone of the delegate. return JsExpression.Invocation(JsExpression.Member(_createTypeReferenceExpression(KnownTypeReference.Delegate), "clone"), source); } else { return source; // The clone is just to convert the delegate to a different type. The risk of anyone comparing the references is small, so just return the original as delegates are immutable anyway. } }
public JsClass(ITypeDefinition csharpTypeDefinition, string name, ClassTypeEnum classType, IEnumerable<string> typeArgumentNames, JsExpression baseClass, IEnumerable<JsExpression> implementedInterfaces) : base(csharpTypeDefinition, name) { BaseClass = baseClass; ClassType = classType; TypeArgumentNames = new List<string>(typeArgumentNames ?? new string[0]); ImplementedInterfaces = new List<JsExpression>(implementedInterfaces ?? new JsExpression[0]); NamedConstructors = new List<JsNamedConstructor>(); InstanceMethods = new List<JsMethod>(); StaticMethods = new List<JsMethod>(); StaticInitStatements = new List<JsStatement>(); }
public JsExpression CreateObject(JsExpression containingType, IMethodSymbol constructor, params JsExpression[] arguments) { var constructorReference = containingType.Member("prototype").Member(constructor.GetMemberName()); if (constructor.IsBuiltIn()) { // If the constructor is built-in, then we don't want it invoked at all, since it's just a shim for the built-in // version. Therefore, just call the types constructor passing in the arguments as usual for a normal JS new. return Js.New(containingType, arguments); } else { // Object creation gets transformed into: // new T(T.prototype.ctor, arg1, arg2, arg3...) return constructorReference.Member(SpecialNames.New).Invoke(arguments); } }
public static JsParentheticalExpression Parenthetical(this JsExpression expression) { return(new JsParentheticalExpression(expression)); }
JsExpression IRuntimeLibrary.FromNullable(JsExpression expression, IRuntimeContext context) { return FromNullable(expression, context); }
public static JsMemberReferenceExpression Member(this JsExpression target, string name) { return(new JsMemberReferenceExpression(target, name)); }
/* * public static JsNewExpression NakedNew(JsExpression expression) * { * return new JsNewExpression(expression.Invoke()); * } */ public static JsNewExpression New(JsExpression type, params JsExpression[] arguments) { return(new JsNewExpression(type.Invoke(arguments))); }
JsExpression IRuntimeLibrary.SetAsyncException(JsExpression taskCompletionSource, JsExpression exception, IRuntimeContext context) { return SetAsyncException(taskCompletionSource, exception, context); }
JsExpression IRuntimeLibrary.GetExpressionForLocal(string name, JsExpression accessor, IType type, IRuntimeContext context) { return GetExpressionForLocal(name, accessor, type, context); }
public static JsForStatement For(string variableName, JsExpression initializer, JsExpression condition, params JsExpression[] incrementors) { return(For(Variable(variableName, initializer), condition, incrementors)); }
JsExpression IRuntimeLibrary.MakeEnumerator(IType yieldType, JsExpression moveNext, JsExpression getCurrent, JsExpression dispose, IRuntimeContext context) { return MakeEnumerator(yieldType, moveNext, getCurrent, dispose, context); }
public static JsForInStatement ForIn(string variableName, JsExpression target) { return(ForIn(Variable(variableName), target)); }
public static JsForStatement For(JsVariableDeclarator declarator, JsExpression condition, params JsExpression[] incrementors) { return(For(Declare(declarator), condition, incrementors)); }
public static JsForInStatement ForIn(JsVariableDeclarator declarator, JsExpression target) { return(ForIn(Declare(declarator), target)); }
public static JsForInStatement ForIn(JsVariableDeclaration declaration, JsExpression target) { return(new JsForInStatement(declaration, target)); }
public static JsNewArrayExpression NewArray(JsExpression size) { return(new JsNewArrayExpression(size)); }
JsExpression IRuntimeLibrary.Bind(JsExpression function, JsExpression target, IRuntimeContext context) { return Bind(function, target, context); }
public static JsIndexExpression Index(this JsExpression target, JsExpression index) { return(new JsIndexExpression(target, index)); }
JsExpression IRuntimeLibrary.CloneDelegate(JsExpression source, IType sourceType, IType targetType, IRuntimeContext context) { return CloneDelegate(source, sourceType, targetType, context); }
public static JsThrowStatement Throw(JsExpression expression) { return(new JsThrowStatement(expression)); }
JsExpression IRuntimeLibrary.SetMultiDimensionalArrayValue(JsExpression array, IEnumerable<JsExpression> indices, JsExpression value, IRuntimeContext context) { return SetMultiDimensionalArrayValue(array, indices, value, context); }
public static JsSwitchLabel CaseLabel(JsExpression label) { return(new JsSwitchLabel(false, label)); }
JsExpression IRuntimeLibrary.ApplyConstructor(JsExpression constructor, JsExpression argumentsArray, IRuntimeContext context) { return ApplyConstructor(constructor, argumentsArray, context); }
public static JsIfStatement If(JsExpression condition, JsStatement ifTrue, JsStatement ifFalse = null) { return(new JsIfStatement(condition, ifTrue, ifFalse)); }
JsExpression IRuntimeLibrary.InitializeField(JsExpression jsMember, string scriptName, IMember member, JsExpression initialValue, IRuntimeContext context) { return InitializeField(jsMember, scriptName, member, initialValue, context); }
public static JsReturnStatement Return(JsExpression expression) { return(new JsReturnStatement(expression)); }
public static JsObjectItem Item(string name, JsExpression value) { return(new JsObjectItem(name, value)); }
JsExpression IRuntimeLibrary.Coalesce(JsExpression a, JsExpression b, IRuntimeContext context) { return Coalesce(a, b, context); }
JsExpression IRuntimeLibrary.IntegerDivision(JsExpression numerator, JsExpression denominator, IRuntimeContext context) { return IntegerDivision(numerator, denominator, context); }
public static JsIfStatement If(JsExpression condition, JsExpression ifTrue, JsExpression ifFalse = null) { return(new JsIfStatement(condition, Express(ifTrue), ifFalse != null ? Express(ifFalse) : null)); }
public static JsDoWhileStatement DoWhile(JsExpression condition, JsStatement statement) { return(new JsDoWhileStatement(condition, statement)); }
public static JsFunction Body(this JsFunction function, JsExpression expression) { function.Body.Add(Express(expression)); return(function); }
JsExpression IRuntimeLibrary.MakeException(JsExpression operand, IRuntimeContext context) { return MakeException(operand, context); }
public static JsConditionalExpression Conditional(JsExpression condition, JsExpression ifTrue, JsExpression ifFalse) { return(new JsConditionalExpression(condition, ifTrue, ifFalse)); }
JsExpression IRuntimeLibrary.FloatToInt(JsExpression operand, IRuntimeContext context) { return FloatToInt(operand, context); }
public static void Express(this JsBlockStatement blockStatement, JsExpression expression) { blockStatement.Add(Express(expression)); }
JsExpression IRuntimeLibrary.Lift(JsExpression expression, IRuntimeContext context) { return Lift(expression, context); }
public static JsVariableDeclarator Local(this JsBlockStatement blockStatement, string name, JsExpression initializer) { var variable = Variable(name, initializer); blockStatement.Add(Local(variable)); return(variable); }
JsExpression IRuntimeLibrary.LiftedBooleanOr(JsExpression a, JsExpression b, IRuntimeContext context) { return LiftedBooleanOr(a, b, context); }
public static JsVariableDeclaration Declare(string name, JsExpression initializer = null) { return(Declare(Variable(name, initializer))); }
JsExpression IRuntimeLibrary.BindFirstParameterToThis(JsExpression function, IRuntimeContext context) { return BindFirstParameterToThis(function, context); }
public static void Return(this JsBlockStatement blockStatement, JsExpression expression) { blockStatement.Add(Return(expression)); }
JsExpression IRuntimeLibrary.BindBaseCall(IMethod method, JsExpression @this, IRuntimeContext context) { return BindBaseCall(method, @this, context); }
public static void Assign(this JsBlockStatement blockStatement, JsExpression left, JsExpression right) { blockStatement.Express(Assign(left, right)); }
JsExpression IRuntimeLibrary.MakeEnumerable(IType yieldType, JsExpression getEnumerator, IRuntimeContext context) { return MakeEnumerable(yieldType, getEnumerator, context); }
public static void If(this JsBlockStatement blockStatement, JsExpression condition, JsStatement ifTrue, JsStatement ifFalse = null) { blockStatement.Add(If(condition, ifTrue, ifFalse)); }
JsExpression IRuntimeLibrary.SetAsyncResult(JsExpression taskCompletionSource, JsExpression value, IRuntimeContext context) { return SetAsyncResult(taskCompletionSource, value, context); }
public static void Invoke(this JsBlockStatement blockStatement, JsExpression target, params JsExpression[] arguments) { blockStatement.Express(Invoke(target, arguments)); }
JsExpression IRuntimeLibrary.GetTaskFromTaskCompletionSource(JsExpression taskCompletionSource, IRuntimeContext context) { return GetTaskFromTaskCompletionSource(taskCompletionSource, context); }
public static JsDeleteExpression Delete(this JsExpression target) { return(new JsDeleteExpression(target)); }
JsExpression IRuntimeLibrary.ShallowCopy(JsExpression source, JsExpression target, IRuntimeContext context) { return ShallowCopy(source, target, context); }
public static JsTypeOfExpression TypeOf(JsExpression type) { return(new JsTypeOfExpression(type)); }
JsExpression IRuntimeLibrary.CloneValueType(JsExpression value, IType type, IRuntimeContext context) { return CloneValueType(value, type, context); }
public static JsUnaryExpression Not(JsExpression expression) { return(new JsUnaryExpression(JsUnaryOperator.LogicalNot, expression)); }
private void AssertCorrect(JsExpression expr, string expected) { var actual = OutputFormatter.Format(expr); Assert.That(actual.Replace("\r\n", "\n"), Is.EqualTo(expected.Replace("\r\n", "\n"))); }
public static JsVariableDeclarator Variable(string name, JsExpression initializer = null) { return(new JsVariableDeclarator(name, initializer)); }