private void WriteGetFields(JsWriter writer, string baseName, string name) { if (_instanceFields.Count > 0) { writer.WriteLine("{0}.prototype.$fields = function() {{", name); writer.Indent(); var f = new JsArray(_instanceFields.Select(x => (object)x.Field.JsName())); if (Base != null && Base.HasInstanceFields) { f.Var("f").Write(writer); writer.WriteLine(); writer.WriteLine("return {0}.prototype.$fields.apply(this).concat(f);", baseName); } else { f.Return().Write(writer); writer.WriteLine(); } writer.Unindent(); writer.WriteLine("};"); // end of $fields } }
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("}"); }
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 } }
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("}"); }
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 }