Exemplo n.º 1
0
        protected override void DoEmit()
        {
            this.Emitter.Writers = new Stack <IWriter>();
            this.Outputs         = new Dictionary <string, StringBuilder>();

            var types = this.Emitter.Types.ToArray();

            Array.Sort(types, (t1, t2) => BridgeTypes.GetNamespaceFilename(t1, this.Emitter).Item1.CompareTo(BridgeTypes.GetNamespaceFilename(t2, this.Emitter).Item1));
            this.Emitter.InitEmitter();

            var last = types.LastOrDefault();

            foreach (var type in types)
            {
                if (type.ParentType != null)
                {
                    continue;
                }

                this.Emitter.Translator.EmitNode = type.TypeDeclaration;

                if (type.IsObjectLiteral)
                {
                    continue;
                }

                ITypeInfo typeInfo;

                if (this.Emitter.TypeInfoDefinitions.ContainsKey(type.Key))
                {
                    typeInfo = this.Emitter.TypeInfoDefinitions[type.Key];

                    type.Module       = typeInfo.Module;
                    type.FileName     = typeInfo.FileName;
                    type.Dependencies = typeInfo.Dependencies;
                    typeInfo          = type;
                }
                else
                {
                    typeInfo = type;
                }

                this.Emitter.TypeInfo = type;
                this.Emitter.Output   = this.GetOutputForType(typeInfo);
                var nestedTypes = types.Where(t => t.ParentType == type);
                new ClassBlock(this.Emitter, this.Emitter.TypeInfo, nestedTypes, types).Emit();
                this.WriteNewLine();

                if (type != last)
                {
                    this.WriteNewLine();
                }
            }

            this.InsertDependencies(this.Emitter.Output);

            this.EndBlock();
            this.TransformOutputs();
        }
Exemplo n.º 2
0
        protected virtual StringBuilder GetOutputForType(ITypeInfo typeInfo)
        {
            var info     = BridgeTypes.GetNamespaceFilename(typeInfo, this.Emitter);
            var ns       = info.Item1;
            var fileName = info.Item2;
            var module   = info.Item3;

            StringBuilder output = null;
            OutputKey     key    = new OutputKey(fileName, module, ns);

            if (this.ns != null && (this.ns != ns || this.outputKey != null && !this.outputKey.Equals(key)))
            {
                this.EndBlock();
                this.WriteNewLine();
            }

            this.ns        = ns;
            this.outputKey = key;

            if (this.Outputs.ContainsKey(key))
            {
                output = this.Outputs[key];
            }
            else
            {
                if (this.Emitter.Output != null)
                {
                    this.InsertDependencies(this.Emitter.Output);
                }

                output = new StringBuilder();
                this.Emitter.Output = output;

                if (ns != null)
                {
                    if (module == null || module.Type == ModuleType.UMD)
                    {
                        output.Append("declare ");
                    }

                    output.Append("namespace " + ns + " ");
                    this.BeginBlock();
                }

                this.Outputs.Add(key, output);
                this.Emitter.CurrentDependencies = new List <IPluginDependency>();
            }

            return(output);
        }
Exemplo n.º 3
0
        protected virtual StringBuilder GetOutputForType(ITypeInfo typeInfo)
        {
            var info     = BridgeTypes.GetNamespaceFilename(typeInfo, this.Emitter);
            var ns       = info.Item1;
            var fileName = info.Item2;

            if (this.ns != null && this.ns != ns)
            {
                this.EndBlock();
                this.WriteNewLine();
            }

            this.ns = ns;

            StringBuilder output = null;

            if (this.Outputs.ContainsKey(fileName))
            {
                output = this.Outputs[fileName];
            }
            else
            {
                if (this.Emitter.Output != null)
                {
                    this.InsertDependencies(this.Emitter.Output);
                }

                output = new StringBuilder();
                this.Emitter.Output = output;

                if (ns != null)
                {
                    output.Append("declare module " + ns + " ");
                    this.BeginBlock();
                }

                this.Outputs.Add(fileName, output);
                this.Emitter.CurrentDependencies = new List <IPluginDependency>();
            }

            return(output);
        }
Exemplo n.º 4
0
        protected override void DoEmit()
        {
            this.Emitter.Tag     = "TS";
            this.Emitter.Writers = new Stack <IWriter>();
            this.Outputs         = new Dictionary <OutputKey, StringBuilder>();

            var types = this.Emitter.Types.ToArray();

            Array.Sort(types, (t1, t2) =>
            {
                var t1ns = BridgeTypes.GetNamespaceFilename(t1, this.Emitter);
                var t2ns = BridgeTypes.GetNamespaceFilename(t2, this.Emitter);

                if (t1ns.Item1 == null && t2ns.Item1 == null)
                {
                    return(0);
                }

                if (t1ns.Item1 == null)
                {
                    return(-1);
                }

                if (t2ns.Item1 == null)
                {
                    return(1);
                }

                var key1 = t1ns.Item1 + (t1ns.Item3 != null ? t1ns.Item3.ExportAsNamespace : "");
                var key2 = t2ns.Item1 + (t2ns.Item3 != null ? t2ns.Item3.ExportAsNamespace : "");

                return(t1ns.Item1.CompareTo(t2ns.Item1));
            });
            this.Emitter.InitEmitter();

            bool nsExists = false;
            var  last     = types.LastOrDefault();

            foreach (var type in types)
            {
                if (!nsExists)
                {
                    var tns = BridgeTypes.GetNamespaceFilename(type, this.Emitter);

                    if (tns.Item1 != null)
                    {
                        nsExists = true;
                    }
                }

                if (type.ParentType != null)
                {
                    continue;
                }

                this.Emitter.Translator.EmitNode = type.TypeDeclaration;

                if (type.IsObjectLiteral)
                {
                    continue;
                }

                ITypeInfo typeInfo;

                if (this.Emitter.TypeInfoDefinitions.ContainsKey(type.Key))
                {
                    typeInfo = this.Emitter.TypeInfoDefinitions[type.Key];

                    type.Module       = typeInfo.Module;
                    type.FileName     = typeInfo.FileName;
                    type.Dependencies = typeInfo.Dependencies;
                    typeInfo          = type;
                }
                else
                {
                    typeInfo = type;
                }

                this.Emitter.TypeInfo = type;
                type.JsName           = BridgeTypes.ToJsName(type.Type, this.Emitter, true);

                this.Emitter.Output = this.GetOutputForType(typeInfo);
                var nestedTypes = types.Where(t => t.ParentType == type);
                new ClassBlock(this.Emitter, this.Emitter.TypeInfo, nestedTypes, types, this.ns).Emit();
                this.WriteNewLine();

                if (type != last)
                {
                    this.WriteNewLine();
                }
            }

            this.InsertDependencies(this.Emitter.Output);
            if (this.outputKey != null && nsExists)
            {
                this.EndBlock();
            }

            this.TransformOutputs();
        }