public override JsNode ExportMethod(IMethod me)
        {
            if (Sk.IsGlobalMethod(me))
            {
                return(CreateGlobalMemberConverter().ExportMethod(me));
            }
            var node = base.ExportMethod(me);

            if (node == null)
            {
                return(node);
            }
            if (!node.Is(JsNodeType.Function))
            {
                return(node);
            }

            var func = (JsFunction)node;

            func.Name = null;
            var ce     = me.GetDeclaringTypeDefinition();
            var member = ExportTypePrefix(ce, me.IsStatic);

            member = member.Member(SkJs.GetEntityJsName(me));
            if (LongFunctionNames)
            {
                func.Name = SkJs.GetLongFunctionName(me);
            }
            var st = member.Assign(func).Statement();

            return(st);
        }
Exemple #2
0
        protected JsBlock ExportMethodBody(IMethod me)
        {
            if (CompilerConfiguration.Current.EnableLogging)
            {
                Log.Debug("JsTypeImporter: Visit Method: " + me.ToString());
            }
            var nativeCode = Sk.GetNativeCode(me);

            if (nativeCode != null)
            {
                var block = Js.Block().Add(Js.CodeStatement(nativeCode)); //TODO: double semicolon?
                return(block);
            }
            var def = me.GetDefinition();

            if (def == null || def.IsNull)
            {
                if (me.IsAutomaticEventAccessor())
                {
                    if (me.IsEventAddAccessor())
                    {
                        var node = GenerateAutomaticEventAccessor((IEvent)me.GetOwner(), false);
                        return(node.Block);
                    }
                    else if (me.IsEventRemoveAccessor())
                    {
                        var node = GenerateAutomaticEventAccessor((IEvent)me.GetOwner(), true);
                        return(node.Block);
                    }
                }
                else if (me.IsAutomaticPropertyAccessor())
                {
                    var bf = Js.Member(AutoPropertyPrefix + SkJs.GetEntityJsName(me.AccessorOwner));
                    if (!me.IsStatic)
                    {
                        bf.PreviousMember = Js.This();
                    }
                    else if (!Sk.IsGlobalMethod(me))
                    {
                        bf.PreviousMember = SkJs.EntityToMember(me.DeclaringTypeDefinition);
                    }
                    if (me.IsGetter())
                    {
                        return(Js.Block().Add(Js.Return(bf)));
                    }
                    else
                    {
                        return(Js.Block().Add(bf.Assign(Js.Member("value")).Statement()));
                    }
                }
                return(null);
            }
            var block2 = (JsBlock)AstNodeConverter.Visit(def);

            block2.ContainsYield = false;
            if (def.Descendants.OfType <YieldReturnStatement>().FirstOrDefault() != null)
            {
                block2.ContainsYield = true;
                if (!AstNodeConverter.SupportClrYield)
                {
                    if (block2.Statements == null)
                    {
                        block2.Statements = new List <JsStatement>();
                    }
                    //block2.Statements.Insert(0, Js.Var("$yield", Js.NewJsonArray()).Statement());
                    //block2.Statements.Add(AstNodeConverter.GenerateYieldReturnStatement(me));
                }
            }
            return(block2);
        }