【优化】修复proto和cfg生成的typescript代码在eslint下有警告的问题

main
walon 2021-08-09 20:23:25 +08:00
parent 42d297ac29
commit 5e0c35c2fc
7 changed files with 8 additions and 13 deletions

View File

@ -94,7 +94,7 @@ namespace Luban.Job.Cfg.Defs
get get
{ {
var table = Assembly.GetCfgTable(Ref.FirstTable); var table = Assembly.GetCfgTable(Ref.FirstTable);
return $"{TsRefVarName} : {table.ValueTType.Apply(TypescriptDefineTypeNameVisitor.Ins)}"; return $"{TsRefVarName} : {table.ValueTType.Apply(TypescriptDefineTypeNameVisitor.Ins)}{(IsNullable ? " | undefined" : " = undefined!")}";
} }
} }

View File

@ -128,11 +128,11 @@ namespace Luban.Job.Cfg.Defs
var table = field.Assembly.GetCfgTable(field.Ref.FirstTable); var table = field.Assembly.GetCfgTable(field.Ref.FirstTable);
if (field.IsNullable) if (field.IsNullable)
{ {
return $"this.{refVarName} = {name} != null ? (_tables.get('{tableName}') as {table.FullName}).get({name}) : null"; return $"this.{refVarName} = {name} != undefined ? (_tables.get('{tableName}') as {table.FullName}).get({name}) : undefined";
} }
else else
{ {
return $"this.{refVarName} = (_tables.get('{tableName}') as {table.FullName}).get({name})"; return $"this.{refVarName} = (_tables.get('{tableName}') as {table.FullName}).get({name})!";
} }
} }

View File

@ -114,7 +114,7 @@ export class {{name}} {
getDataMap(): Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap } getDataMap(): Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap }
getDataList(): {{ts_define_type value_type}}[] { return this._dataList } getDataList(): {{ts_define_type value_type}}[] { return this._dataList }
get(key: {{ts_define_type key_type}}): {{ts_define_type value_type}} { return this._dataMap.get(key) } get(key: {{ts_define_type key_type}}): {{ts_define_type value_type}} | undefined { return this._dataMap.get(key) }
resolve(_tables: Map<string, any>) { resolve(_tables: Map<string, any>) {
for(var v of this._dataList) { for(var v of this._dataList) {

View File

@ -44,7 +44,7 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def
{{~end~}} {{~end~}}
{{~ for field in export_fields ~}} {{~ for field in export_fields ~}}
{{~if !field.ctype.is_nullable~}} {{~if !field.ctype.is_nullable~}}
if (_json_.{{field.name}} == null) { throw new Error() } if (_json_.{{field.name}} == undefined) { throw new Error() }
{{~end~}} {{~end~}}
{{ts_json_constructor ('this.' + field.ts_style_name) ( '_json_.' + field.name) field.ctype}} {{ts_json_constructor ('this.' + field.ts_style_name) ( '_json_.' + field.name) field.ctype}}
{{~end~}} {{~end~}}
@ -115,7 +115,7 @@ export class {{name}}{
getDataMap(): Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap; } getDataMap(): Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap; }
getDataList(): {{ts_define_type value_type}}[] { return this._dataList; } getDataList(): {{ts_define_type value_type}}[] { return this._dataList; }
get(key: {{ts_define_type key_type}}): {{ts_define_type value_type}} { return this._dataMap.get(key); } get(key: {{ts_define_type key_type}}): {{ts_define_type value_type}} | undefined { return this._dataMap.get(key); }
resolve(_tables: Map<string, any>) { resolve(_tables: Map<string, any>) {
for(var v of this._dataList) { for(var v of this._dataList) {

View File

@ -11,7 +11,7 @@ namespace Luban.Job.Common.TypeVisitors
{ {
if (type.IsNullable) if (type.IsNullable)
{ {
return $"if({byteBufName}.ReadBool()) {{ {type.Apply(TypescriptBinUnderingConstructorVisitor.Ins, byteBufName, fieldName)} }} else {{ {fieldName} = null }}"; return $"if({byteBufName}.ReadBool()) {{ {type.Apply(TypescriptBinUnderingConstructorVisitor.Ins, byteBufName, fieldName)} }} else {{ {fieldName} = undefined }}";
} }
else else
{ {

View File

@ -11,7 +11,7 @@ namespace Luban.Job.Cfg.TypeVisitors
{ {
if (type.IsNullable) if (type.IsNullable)
{ {
return $"if({jsonFieldName} != null) {{ {type.Apply(TypescriptJsonUnderingConstructorVisitor.Ins, jsonFieldName, fieldName)} }} else {{ {fieldName} = null }}"; return $"if({jsonFieldName} != undefined) {{ {type.Apply(TypescriptJsonUnderingConstructorVisitor.Ins, jsonFieldName, fieldName)} }} else {{ {fieldName} = undefined }}";
} }
else else
{ {

View File

@ -61,10 +61,6 @@ namespace Luban.Job.Proto.Generate
export {{if x.is_abstract_type}} abstract {{end}} class {{name}} extends {{if parent_def_type}}{{x.parent}}{{else}}BeanBase{{end}} { export {{if x.is_abstract_type}} abstract {{end}} class {{name}} extends {{if parent_def_type}}{{x.parent}}{{else}}BeanBase{{end}} {
{{~if x.is_abstract_type~}} {{~if x.is_abstract_type~}}
static serializeTo(_buf_ : ByteBuf, _bean_ : {{name}}) { static serializeTo(_buf_ : ByteBuf, _bean_ : {{name}}) {
if (_bean_ == null) {
_buf_.WriteInt(0)
return
}
_buf_.WriteInt(_bean_.getTypeId()) _buf_.WriteInt(_bean_.getTypeId())
_bean_.serialize(_buf_) _bean_.serialize(_buf_)
} }
@ -72,7 +68,6 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} extends {{if pa
static deserializeFrom(_buf_ : ByteBuf) : {{name}} { static deserializeFrom(_buf_ : ByteBuf) : {{name}} {
let _bean_ :{{name}} let _bean_ :{{name}}
switch (_buf_.ReadInt()) { switch (_buf_.ReadInt()) {
case 0 : return null
{{~ for child in x.hierarchy_not_abstract_children~}} {{~ for child in x.hierarchy_not_abstract_children~}}
case {{child.id}}: _bean_ = new {{child.full_name}}(); break case {{child.id}}: _bean_ = new {{child.full_name}}(); break
{{~end~}} {{~end~}}