예제 #1
0
 public override void Write(JsWriter writer)
 {
     writer.Write(_name);
     writer.Write(" = ");
     writer.WriteValue(_value);
     writer.Write(";");
 }
예제 #2
0
 public override void Write(JsWriter writer)
 {
     writer.WriteValue(_condition);
     writer.Write(" ? ");
     writer.WriteValue(_left);
     writer.Write(" : ");
     writer.WriteValue(_right);
 }
예제 #3
0
        public override void Write(JsWriter writer)
        {
            writer.Write("{0} = ", FullName);

            Function.Write(writer);

            writer.Write(";");
        }
예제 #4
0
 public override void Write(JsWriter writer)
 {
     writer.Write("new {0}(", _type.JsFullName());
     if (_args != null && _args.Length > 0)
     {
         writer.WriteValues(_args, ", ");
     }
     writer.Write(")");
 }
예제 #5
0
        public override void Write(JsWriter writer)
        {
            var obj = Field.IsStatic ? Field.DeclaringType.JsFullName().Id() : "this".Id();

            obj.Get(Name).Write(writer);
            writer.Write(" = ");
            writer.WriteValue(Field.Type.InitialValue());
            writer.Write(";");
        }
예제 #6
0
 public override void Write(JsWriter writer)
 {
     writer.Write("(");
     _left.Write(writer);
     writer.Write(" ");
     writer.Write(_op);
     writer.Write(" ");
     writer.WriteValue(_value);
     writer.Write(")");
 }
예제 #7
0
        public static void WriteBlock <T>(this JsWriter writer, ICollection <T> seq, string separator) where T : JsNode
        {
//			if (seq.Count <= 1)
//			{
//				writer.Write("{");
//				writer.Write(seq, separator);
//				writer.Write("}");
//				return;
//			}

            writer.WriteLine("{");
            writer.Indent();
            writer.Write(seq, separator);
            writer.WriteLine();
            writer.Unindent();
            writer.Write("}");
        }
예제 #8
0
        public override void Write(JsWriter writer)
        {
            if (_deps.Count > 0)
            {
                writer.Write(_deps, "\n");
                writer.WriteLine();
            }

            if (_namespaces.Count > 0)
            {
                writer.WriteLine("// namespaces");
                writer.Write(_namespaces.Values.OrderBy(x => x.Name), "\n");
                writer.WriteLine();
            }

            writer.Write(_nodes, "\n");
        }
예제 #9
0
        public override void Write(JsWriter writer)
        {
            bool br = _value is JsFunction;

            if (br)
            {
                writer.Write("(");
            }
            _value.Write(writer);
            if (br)
            {
                writer.Write(")");
            }
            writer.Write("(");
            writer.WriteValues(_args, ", ");
            writer.Write(")");
        }
예제 #10
0
        public override void Write(JsWriter writer)
        {
            writer.Write("function");

            if (!string.IsNullOrEmpty(Name))
            {
                writer.Write(" ");
                writer.Write(Name);
            }

            writer.Write("(");
            bool sep = false;

            foreach (var parameter in _parameters)
            {
                if (sep)
                {
                    writer.Write(", ");
                }
                writer.Write(parameter);
                sep = true;
            }
            writer.Write(") ");

            _body.Write(writer);
        }
예제 #11
0
        public override void Write(JsWriter writer)
        {
            _obj.Write(writer);

            var s = _name as String;

            if (s != null && s.IsJsid())
            {
                writer.Write(".");
                writer.Write(s);
            }
            else
            {
                writer.Write("[");
                writer.WriteValue(_name);
                writer.Write("]");
            }
        }
예제 #12
0
 private void WriteStaticFields(JsWriter writer, string name)
 {
     if (_staticFields.Count > 0)
     {
         writer.WriteLine("{0}.$init_fields = function() {{", name);
         writer.Indent();
         writer.Write(_staticFields, "\n");
         writer.WriteLine();
         writer.Unindent();
         writer.WriteLine("};");                 // end of static fields initializer
     }
 }
예제 #13
0
        public override void Write(JsWriter writer)
        {
            writer.Write("/* {0} */", _instruction.ToString("I: N", CultureInfo.InvariantCulture));
            writer.Write("[");
            writer.Write((int)_instruction.Code);

            var value = _value;

            if (value != null && !Ignore(_instruction.Code))
            {
                writer.Write(", ");

                switch (Type.GetTypeCode(value.GetType()))
                {
                case TypeCode.Boolean:
                case TypeCode.Char:
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Single:
                case TypeCode.Double:
                case TypeCode.String:
                    writer.WriteValue(value);
                    break;

                case TypeCode.Object:
                    var var = value as JsVar;
                    writer.WriteValue(var != null ? var.Id() : value);
                    break;

                default:
                    throw new NotSupportedException();
                }
            }

            writer.Write("]");
        }
예제 #14
0
        public override void Write(JsWriter writer)
        {
            writer.Write("{");

            if (NewLine)
            {
                writer.WriteLine();
                writer.Indent();
            }

            bool sep = false;

            foreach (var pair in _properties)
            {
                if (sep)
                {
                    writer.Write(",");
                    if (NewLine)
                    {
                        writer.WriteLine();
                    }
                }
                var key = pair.Key;

                var name = key as string;
                if (name != null)
                {
                    if (name.IsJsid())
                    {
                        writer.Write("{0}:", name);
                    }
                    else
                    {
                        writer.Write("'{0}':", name.JsEscape());
                    }
                }
                else
                {
                    writer.WriteValue(key);
                    writer.Write(":");
                }

                writer.WriteValue(pair.Value);
                sep = true;
            }

            if (NewLine)
            {
                writer.WriteLine();
                writer.Unindent();
            }

            writer.Write("}");
        }
예제 #15
0
        public static void WriteValues(this JsWriter writer, IEnumerable seq, string sep)
        {
            if (seq == null)
            {
                return;
            }
            bool f = false;

            foreach (var value in seq)
            {
                if (f)
                {
                    writer.Write(sep);
                }
                writer.WriteValue(value);
                f = true;
            }
        }
예제 #16
0
        public static void Write <T>(this JsWriter writer, IEnumerable <T> seq, string sep) where T : JsNode
        {
            if (seq == null)
            {
                return;
            }

            bool f = false;

            foreach (var node in seq)
            {
                if (f && !string.IsNullOrEmpty(sep))
                {
                    writer.Write(sep);
                }
                node.Write(writer);
                f = true;
            }
        }
예제 #17
0
        public override void Write(JsWriter writer)
        {
            var    name     = Type.JsFullName();
            string baseName = null;

            if (Base != null)
            {
                baseName = Base.Type.JsFullName();
            }

            WriteClassFunction(writer, baseName, name);
            WriteGetFields(writer, baseName, name);
            WriteStaticFields(writer, name);

            writer.Write(_members, "\n");

            if (Base != null)
            {
                writer.WriteLine();
                //TODO: enable when explicit base ref will be needed
                //writer.WriteLine("{0}.prototype.$base = {1}.prototype;", name, baseName);
                writer.WriteLine("$inherit({0}, {1});", name, baseName);
            }
        }
예제 #18
0
 public override void Write(JsWriter writer)
 {
     writer.Write("return ");
     writer.WriteValue(_value);
     writer.Write(";");
 }
예제 #19
0
 public override void Write(JsWriter writer)
 {
     _expression.Write(writer);
     writer.Write(";");
 }
예제 #20
0
        private void WriteClassFunction(JsWriter writer, string baseName, string name)
        {
            if (Type.IsAvmString())
            {
                return;
            }

            if (Type.IsInt64())
            {
                writer.WriteLine("{0} = function(hi, lo) {{", name);
                writer.Indent();
                writer.WriteLine("this.m_hi = hi ? hi : 0;");
                writer.WriteLine("this.m_lo = lo ? lo : 0;");
                writer.WriteLine("return this;");
                writer.Unindent();
                writer.WriteLine("};");                 // end of function
                return;
            }

            if (Type.IsBoxableType())
            {
                var valueType = Type.IsEnum ? Type.ValueType : Type;
                writer.WriteLine("{0} = function(v) {{", name);
                writer.Indent();
                writer.WriteLine("this.{0} = v !== undefined ? v : {1};", SpecialFields.BoxValue, valueType.InitialValue().ToJsString());
                writer.WriteLine("return this;");
                writer.Unindent();
                writer.WriteLine("};");                 // end of function
                return;
            }

            if (Type.IsNullableInstance())
            {
                writer.WriteLine("{0} = function(v) {{", name);
                writer.Indent();

                var valueType = Type.GetTypeArgument(0);
                writer.WriteLine("this.{0} = v !== undefined ? v : {1};", SpecialFields.BoxValue, valueType.InitialValue().ToJsString());
                writer.WriteLine("this.{0} = v !== undefined;", Type.GetHasValueField().JsName());
                writer.WriteLine("return this;");

                writer.Unindent();
                writer.WriteLine("};");                 // end of function
                return;
            }

            writer.WriteLine("{0} = function() {{", name);
            if (_instanceFields.Count > 0 || baseName != null)
            {
                writer.Indent();

                if (baseName != null)
                {
                    writer.WriteLine("{0}.apply(this);", baseName);
                }

                if (_instanceFields.Count > 0)
                {
                    writer.Write(_instanceFields, "\n");
                    writer.WriteLine();
                }

                writer.WriteLine("return this;");
                writer.Unindent();
            }
            writer.WriteLine("};");             // end of function
        }
예제 #21
0
 public override void Write(JsWriter writer)
 {
     writer.Write("[");
     writer.WriteValues(_values, "," + _separator);
     writer.Write("]");
 }
예제 #22
0
 public override void Write(JsWriter writer)
 {
     writer.Write(_op);
     _value.Write(writer);
 }
예제 #23
0
 public override void Write(JsWriter writer)
 {
     writer.Write(_text);
 }
예제 #24
0
        public static void WriteValue(this JsWriter writer, object value)
        {
            if (value == null)
            {
                writer.Write("null");
                return;
            }

            switch (Type.GetTypeCode(value.GetType()))
            {
            case TypeCode.Empty:
            case TypeCode.DBNull:
                writer.Write("null");
                break;

            case TypeCode.Boolean:
                writer.Write((bool)value ? "true" : "false");
                break;

            case TypeCode.Char:
                break;

            case TypeCode.SByte:
            case TypeCode.Byte:
            case TypeCode.Int16:
            case TypeCode.UInt16:
            case TypeCode.Int32:
            case TypeCode.UInt32:
            case TypeCode.Int64:
            case TypeCode.UInt64:
            case TypeCode.Single:
            case TypeCode.Double:
            case TypeCode.Decimal:
                writer.Write(Convert.ToString(value, CultureInfo.InvariantCulture));
                break;

            case TypeCode.DateTime:
                break;

            case TypeCode.String:
                writer.Write("'" + ((string)value).JsEscape() + "'");
                break;

            case TypeCode.Object:
                var obj = value as JsNode;
                if (obj != null)
                {
                    obj.Write(writer);
                    return;
                }

                var sequence = value as IEnumerable;
                if (sequence != null)
                {
                    writer.Write("[");
                    var sep = false;
                    foreach (var item in sequence)
                    {
                        if (sep)
                        {
                            writer.Write(",");
                        }
                        WriteValue(writer, item);
                        sep = true;
                    }
                    writer.Write("]");
                    return;
                }

                throw new NotSupportedException();

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #25
0
 public override void Write(JsWriter writer)
 {
     writer.Write("var {0} = ", Name);
     Value.Write(writer);
     writer.Write(";");
 }
예제 #26
0
 public override void Write(JsWriter writer)
 {
     writer.Write(Value);
 }
예제 #27
0
 public override void Write(JsWriter writer)
 {
     writer.Write("{0} = ", PoolName);
     new JsArray(_list.Cast <object>()).Write(writer);
     writer.WriteLine(";");
 }