public JsFunctionDefinitionExpression CompileMethod(IList<IParameter> parameters, IDictionary<IVariable, VariableData> variables, BlockStatement body, bool staticMethodWithThisAsFirstArgument) { SetRegion(body.GetRegion()); try { _result = MethodCompiler.FixByRefParameters(parameters, variables); VisitChildren(body); JsBlockStatement jsbody; if (_result.Count == 1 && _result[0] is JsBlockStatement) jsbody = (JsBlockStatement)_result[0]; else jsbody = new JsBlockStatement(_result); return JsExpression.FunctionDefinition((staticMethodWithThisAsFirstArgument ? new[] { _namer.ThisAlias } : new string[0]).Concat(parameters.Select(p => variables[p].Name)), jsbody); } catch (Exception ex) { _errorReporter.InternalError(ex); return JsExpression.FunctionDefinition(new string[0], JsBlockStatement.EmptyStatement); } }
public JsFunctionDefinitionExpression CompileMethod(IList<IParameter> parameters, IDictionary<IVariable, VariableData> variables, BlockStatement body, bool staticMethodWithThisAsFirstArgument, bool expandParams, StateMachineType stateMachineType, IType iteratorBlockYieldTypeOrAsyncTaskGenericArgument = null) { SetRegion(body.GetRegion()); try { _result = MethodCompiler.PrepareParameters(parameters, variables, expandParams: expandParams, staticMethodWithThisAsFirstArgument: staticMethodWithThisAsFirstArgument); VisitChildren(body); JsBlockStatement jsbody; if (_result.Count == 1 && _result[0] is JsBlockStatement) jsbody = (JsBlockStatement)_result[0]; else jsbody = JsStatement.Block(_result); var result = JsExpression.FunctionDefinition((staticMethodWithThisAsFirstArgument ? new[] { _namer.ThisAlias } : new string[0]).Concat(parameters.Where((p, i) => i != parameters.Count - 1 || !expandParams).Select(p => variables[p].Name)), jsbody); switch (stateMachineType) { case StateMachineType.NormalMethod: result = StateMachineRewriteNormalMethod(result); break; case StateMachineType.IteratorBlockReturningIEnumerable: case StateMachineType.IteratorBlockReturningIEnumerator: result = StateMachineRewriteIteratorBlock(result, stateMachineType == StateMachineType.IteratorBlockReturningIEnumerable, iteratorBlockYieldTypeOrAsyncTaskGenericArgument); break; case StateMachineType.AsyncVoid: case StateMachineType.AsyncTask: result = StateMachineRewriteAsyncMethod(result, stateMachineType == StateMachineType.AsyncTask, iteratorBlockYieldTypeOrAsyncTaskGenericArgument); break; default: throw new ArgumentException("stateMachineType"); } return result; } catch (Exception ex) { _errorReporter.InternalError(ex); return JsExpression.FunctionDefinition(new string[0], JsStatement.EmptyBlock); } }
public JsFunctionDefinitionExpression CompileMethod(IList<IParameter> parameters, IDictionary<IVariable, VariableData> variables, BlockStatement body) { _filename = body.GetRegion().FileName; try { _result = MethodCompiler.FixByRefParameters(parameters, variables); VisitChildren(body); JsBlockStatement jsbody; if (_result.Count == 1 && _result[0] is JsBlockStatement) jsbody = (JsBlockStatement)_result[0]; else jsbody = new JsBlockStatement(_result); return JsExpression.FunctionDefinition(parameters.Select(p => variables[p].Name), jsbody); } catch (Exception ex) { _errorReporter.InternalError(ex, _filename, _location); return JsExpression.FunctionDefinition(new string[0], JsBlockStatement.EmptyStatement); } }