@hadss/turbo-trans-json-plugin 1.0.0-rc.1 → 1.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/core/analyzers/ClassAnalyzer.d.ts +15 -0
  2. package/dist/core/analyzers/ClassAnalyzer.js +193 -144
  3. package/dist/core/analyzers/CustomTypeAnalyzer.d.ts +3 -0
  4. package/dist/core/analyzers/CustomTypeAnalyzer.js +65 -60
  5. package/dist/core/constants/DecoratorConstants.js +2 -1
  6. package/dist/core/import-rewrite/services/BuildProfileUpdater.js +1 -1
  7. package/dist/core/import-rewrite/services/ImportRewriteService.js +1 -1
  8. package/dist/core/interfaces/index.d.ts +2 -2
  9. package/dist/core/services/CodeAnalysisService.js +2 -1
  10. package/dist/core/services/CodeGenerationService/generators/OriginalClassGenerator.d.ts +2 -0
  11. package/dist/core/services/CodeGenerationService/generators/OriginalClassGenerator.js +22 -15
  12. package/dist/core/services/CodeGenerationService/generators/SendableClassGenerator.d.ts +22 -0
  13. package/dist/core/services/CodeGenerationService/generators/SendableClassGenerator.js +194 -129
  14. package/dist/core/services/CodeGenerationService/generators/SerializerGenerator.js +1 -1
  15. package/dist/core/services/CodeGenerationService/generators/TempSerializerGenerator.js +2 -1
  16. package/dist/core/services/CodeGenerationService/shared/ImportManager.d.ts +2 -2
  17. package/dist/core/template/HandlebarsTemplateEngine.d.ts +2 -0
  18. package/dist/core/template/HandlebarsTemplateEngine.js +21 -2
  19. package/dist/core/utils/DeepCopyUtil.js +1 -1
  20. package/dist/core/utils/SerializationPathUtil.d.ts +1 -1
  21. package/dist/core/utils/TsMorphUtil.js +2 -1
  22. package/dist/json-plugin/JSONExecuteController.d.ts +4 -0
  23. package/dist/json-plugin/JSONExecuteController.js +46 -36
  24. package/dist/json-plugin/interfaces/impl/TargetContext.js +4 -2
  25. package/dist/json-plugin/tasks/BaseTask.d.ts +2 -2
  26. package/dist/json-plugin/tasks/WatchTask.js +2 -1
  27. package/package.json +1 -1
  28. package/src/core/Types.ts +90 -90
  29. package/src/core/analyzers/ClassAnalyzer.ts +335 -230
  30. package/src/core/analyzers/CustomTypeAnalyzer.ts +145 -73
  31. package/src/core/constants/DecoratorConstants.ts +7 -6
  32. package/src/core/constants/PathConstants.ts +7 -7
  33. package/src/core/constants/StringConstants.ts +95 -95
  34. package/src/core/handlers/BaseTypeHandler.ts +11 -2
  35. package/src/core/handlers/CustomClassHandler.ts +4 -4
  36. package/src/core/handlers/DateHandler.ts +54 -46
  37. package/src/core/handlers/DecimalHandler.ts +53 -45
  38. package/src/core/handlers/EnumHandler.ts +2 -1
  39. package/src/core/handlers/GenericContainerHandler.ts +3 -1
  40. package/src/core/handlers/TupleHandler.ts +2 -1
  41. package/src/core/handlers/TypeHandlerRegistry.ts +2 -1
  42. package/src/core/handlers/UnionTypeHandler.ts +8 -7
  43. package/src/core/import-rewrite/services/BuildProfileUpdater.ts +6 -4
  44. package/src/core/import-rewrite/services/ImportRewriteService.ts +1 -1
  45. package/src/core/import-rewrite/services/ImportTransformService.ts +2 -2
  46. package/src/core/import-rewrite/types/ImportRewriteTypes.ts +3 -3
  47. package/src/core/index.ts +4 -4
  48. package/src/core/interfaces/ITask.ts +6 -5
  49. package/src/core/interfaces/ITaskContext.ts +9 -9
  50. package/src/core/interfaces/index.ts +2 -2
  51. package/src/core/logger/Logger.ts +28 -28
  52. package/src/core/services/CodeAnalysisService.ts +2 -1
  53. package/src/core/services/CodeGenerationEngine.ts +42 -42
  54. package/src/core/services/CodeGenerationService/generators/OriginalClassGenerator.ts +25 -22
  55. package/src/core/services/CodeGenerationService/generators/SendableClassGenerator.ts +261 -170
  56. package/src/core/services/CodeGenerationService/generators/SerializerGenerator.ts +1 -1
  57. package/src/core/services/CodeGenerationService/generators/TempSerializerGenerator.ts +5 -3
  58. package/src/core/services/CodeGenerationService/shared/ImportManager.ts +8 -8
  59. package/src/core/template/HandlebarsTemplateEngine.ts +39 -11
  60. package/src/core/utils/ConfigManager.ts +2 -1
  61. package/src/core/utils/DeepCopyUtil.ts +1 -1
  62. package/src/core/utils/GenericTypeSubstitutionUtil.ts +1 -8
  63. package/src/core/utils/SerializationPathUtil.ts +7 -6
  64. package/src/core/utils/TsMorphUtil.ts +4 -1
  65. package/src/index.ts +2 -2
  66. package/src/json-plugin/JSONExecuteController.ts +51 -38
  67. package/src/json-plugin/interfaces/IModuleContext.ts +8 -8
  68. package/src/json-plugin/interfaces/ITargetContext.ts +6 -6
  69. package/src/json-plugin/interfaces/impl/ModuleContext.ts +10 -10
  70. package/src/json-plugin/interfaces/impl/TargetContext.ts +63 -58
  71. package/src/json-plugin/tasks/BaseTask.ts +5 -3
  72. package/src/json-plugin/tasks/CleanTask.ts +7 -7
  73. package/src/json-plugin/tasks/WatchTask.ts +20 -18
  74. package/template/SerializerPerformanceTemplate.hbs +5 -5
  75. package/template/SerializerStrictTemplate.hbs +1 -1
  76. package/template/SerializerTemplate.hbs +59 -42
@@ -13,10 +13,12 @@
13
13
  * limitations under the License.
14
14
  */
15
15
 
16
- import { ITask, Logger, ImportRewriteServiceImpl, ConfigManager, CodeGenerationEngine } from '../../core';
16
+ import {
17
+ ITask, Logger, ImportRewriteServiceImpl, ConfigManager, CodeGenerationEngine, IGenerationResult
18
+ } from '../../core';
17
19
  import { BuildProfileUpdaterImpl } from '../../core/import-rewrite/services/BuildProfileUpdater';
18
20
  import { ITargetContext } from '../interfaces/ITargetContext';
19
- import {TaskConstants} from '../constants/TaskConstants';
21
+ import { TaskConstants } from '../constants/TaskConstants';
20
22
  import SerializationPathUtil from '../../core/utils/SerializationPathUtil';
21
23
 
22
24
  export abstract class BaseTask implements ITask {
@@ -38,7 +40,7 @@ export abstract class BaseTask implements ITask {
38
40
  return scanFiles;
39
41
  }
40
42
 
41
- protected processWithLogging(scanFiles: string[], context: ITargetContext, taskName: string) {
43
+ protected processWithLogging(scanFiles: string[], context: ITargetContext, taskName: string): IGenerationResult {
42
44
  Logger.debug(`Start executing ${taskName} and process ${scanFiles.length} files`);
43
45
 
44
46
  this.buildProfileUpdater.updateSourceRoots(context); // 更新builde-profile.json5中的sourceRoot
@@ -19,18 +19,18 @@ import { ITargetContext } from '../interfaces/ITargetContext';
19
19
  import SerializationPathUtil from '../../core/utils/SerializationPathUtil';
20
20
 
21
21
  export class CleanTask implements ITask {
22
- readonly taskName: string = TaskConstants.CLEAN_TASK
23
- readonly dependencies: string[] = [] // CLI任务无依赖
24
- readonly postDependencies: string[] = [] // CLI任务无依赖
22
+ readonly taskName: string = TaskConstants.CLEAN_TASK;
23
+ readonly dependencies: string[] = []; // CLI任务无依赖
24
+ readonly postDependencies: string[] = []; // CLI任务无依赖
25
25
 
26
26
  run(context: ITargetContext): void {
27
- Logger.info('Start the code cleaning task')
27
+ Logger.info('Start the code cleaning task');
28
28
 
29
- const generatedRootDir = context.getOutputRoot()
29
+ const generatedRootDir: string = context.getOutputRoot();
30
30
 
31
31
  if (SerializationPathUtil.exist(generatedRootDir)) {
32
- Logger.info(`Clean up the generated directory: ${generatedRootDir}`)
33
- SerializationPathUtil.rmSync(generatedRootDir, { recursive: true, force: true })
32
+ Logger.info(`Clean up the generated directory: ${generatedRootDir}`);
33
+ SerializationPathUtil.rmSync(generatedRootDir, { recursive: true, force: true });
34
34
  }
35
35
  }
36
36
  }
@@ -55,45 +55,47 @@ export class WatchTask extends BaseTask {
55
55
  }
56
56
 
57
57
  private setupWatchEvents(context: ITargetContext): void {
58
- if (!this.watcher) return
58
+ if (!this.watcher) {
59
+ return;
60
+ }
59
61
 
60
- let debounceTimer: NodeJS.Timeout | null = null
62
+ let debounceTimer: NodeJS.Timeout | null = null;
61
63
 
62
64
  // 防抖处理,避免频繁触发
63
- const debouncedGenerate = (filePath: string) => {
65
+ const debouncedGenerate: (filePath: string) => void = (filePath: string) => {
64
66
  if (debounceTimer) {
65
- clearTimeout(debounceTimer)
67
+ clearTimeout(debounceTimer);
66
68
  }
67
69
  debounceTimer = setTimeout(() => {
68
- this.generateCode(filePath, context)
69
- }, 500) // 500ms 防抖
70
- }
70
+ this.generateCode(filePath, context);
71
+ }, 500); // 500ms 防抖
72
+ };
71
73
 
72
74
  this.watcher
73
75
  .on('add', (filePath: string) => {
74
- Logger.info(`New file detected: ${filePath}`)
75
- debouncedGenerate(filePath)
76
+ Logger.info(`New file detected: ${filePath}`);
77
+ debouncedGenerate(filePath);
76
78
  })
77
79
  .on('change', (filePath: string) => {
78
- Logger.info(`File change detected: ${filePath}`)
79
- debouncedGenerate(filePath)
80
+ Logger.info(`File change detected: ${filePath}`);
81
+ debouncedGenerate(filePath);
80
82
  })
81
83
  .on('unlink', (filePath: string) => {
82
- Logger.info(`File deletion detected: ${filePath}`)
83
- debouncedGenerate(filePath)
84
+ Logger.info(`File deletion detected: ${filePath}`);
85
+ debouncedGenerate(filePath);
84
86
  })
85
87
  .on('error', (error: unknown) => {
86
- Logger.error(`File monitoring error: ${error}`)
88
+ Logger.error(`File monitoring error: ${error}`);
87
89
  })
88
90
  .on('ready', () => {
89
- Logger.info('The initial file scan is complete. Start listening for file changes...')
90
- })
91
+ Logger.info('The initial file scan is complete. Start listening for file changes...');
92
+ });
91
93
  }
92
94
 
93
95
  private generateCode(scanFile: string, context: ITargetContext): void {
94
96
  // 统一处理:逐文件分析 → 直接生成
95
- const processingResult = this.engine.processFileUnified(scanFile, context)
97
+ const processingResult = this.engine.processFileUnified(scanFile, context);
96
98
 
97
- Logger.info(`The code generation is complete, and the output path is ${processingResult?.outputPath}`)
99
+ Logger.info(`The code generation is complete, and the output path is ${processingResult?.outputPath}`);
98
100
  }
99
101
  }
@@ -7,7 +7,7 @@ deserialize(decoder: Decoder, plain: ESObject): {{class.className}}{{#if class.g
7
7
  const result = new {{class.className}}{{#if class.generics.isGeneric}}<{{genericParametersString class.generics.parameters}}>{{/if}}(
8
8
  {{#each (getCtorProperties class.constructorParams properties)}}
9
9
  {{#unless analysis.decorators.isTransient}}
10
- {{#if analysis.decorators.isPlainValue}}plain[keys[{{getPropertyIndex this ../properties}}]]{{else}}{{#if (and (eqPrimitiveType analysis.type.kind) (not (hasDecoratorWith analysis.decorators)))}}decoder.{{serializer.decodeMethod}}(plain[keys[{{getPropertyIndex this ../properties}}]]){{else}}this.{{analysis.name}}Serializer.deserialize(decoder, plain[keys[{{getPropertyIndex this ../properties}}]]){{/if}}{{#if serializer.needsTypeAssertion}} as {{analysis.type.sourceText}}{{/if}}{{/if}}{{#unless @last}},{{/unless}}
10
+ {{#if analysis.decorators.isPlainValue}}plain[keys[{{getPropertyIndex this ../properties}}]]{{else}}{{#if (and (eqPrimitiveType analysis.type.kind) (not (hasDecoratorWith analysis.decorators)))}}decoder.{{serializer.decodeMethod}}(plain[keys[{{getPropertyIndex this ../properties}}]]){{else}}this.{{getSerializer analysis}}.deserialize(decoder, plain[keys[{{getPropertyIndex this ../properties}}]]){{/if}}{{#if serializer.needsTypeAssertion}} as {{analysis.type.sourceText}}{{/if}}{{/if}}{{#unless @last}},{{/unless}}
11
11
  {{/unless}}
12
12
  {{/each}});
13
13
  {{else}}
@@ -23,19 +23,19 @@ deserialize(decoder: Decoder, plain: ESObject): {{class.className}}{{#if class.g
23
23
  {{! 有默认值的属性 }}
24
24
  {{#if (eq analysis.visibility "private")}}
25
25
  ObjectUtils.setProp(result, '{{analysis.name}}', {{analysis.name}}PlainValue === undefined ? {{analysis.defaultValue}} :
26
- {{#if analysis.decorators.isPlainValue}}plain[keys[{{getPropertyIndex this ../properties}}]]{{else}}{{#if (and (eqPrimitiveType analysis.type.kind) (not (hasDecoratorWith analysis.decorators)))}}decoder.{{serializer.decodeMethod}}(plain[keys[{{getPropertyIndex this ../properties}}]]){{else}}this.{{analysis.name}}Serializer.deserialize(decoder, plain[keys[{{getPropertyIndex this ../properties}}]]){{/if}}{{#if serializer.needsTypeAssertion}} as {{analysis.type.sourceText}}{{/if}}{{/if}});
26
+ {{#if analysis.decorators.isPlainValue}}plain[keys[{{getPropertyIndex this ../properties}}]]{{else}}{{#if (and (eqPrimitiveType analysis.type.kind) (not (hasDecoratorWith analysis.decorators)))}}decoder.{{serializer.decodeMethod}}(plain[keys[{{getPropertyIndex this ../properties}}]]){{else}}this.{{getSerializer analysis}}.deserialize(decoder, plain[keys[{{getPropertyIndex this ../properties}}]]){{/if}}{{#if serializer.needsTypeAssertion}} as {{analysis.type.sourceText}}{{/if}}{{/if}});
27
27
  {{else}}
28
28
  result.{{analysis.name}} = {{analysis.name}}PlainValue === undefined ? {{analysis.defaultValue}} :
29
- {{#if analysis.decorators.isPlainValue}}plain[keys[{{getPropertyIndex this ../properties}}]]{{else}}{{#if (and (eqPrimitiveType analysis.type.kind) (not (hasDecoratorWith analysis.decorators)))}}decoder.{{serializer.decodeMethod}}(plain[keys[{{getPropertyIndex this ../properties}}]]){{else}}this.{{analysis.name}}Serializer.deserialize(decoder, plain[keys[{{getPropertyIndex this ../properties}}]]){{/if}}{{#if serializer.needsTypeAssertion}} as {{analysis.type.sourceText}}{{/if}}{{/if}};
29
+ {{#if analysis.decorators.isPlainValue}}plain[keys[{{getPropertyIndex this ../properties}}]]{{else}}{{#if (and (eqPrimitiveType analysis.type.kind) (not (hasDecoratorWith analysis.decorators)))}}decoder.{{serializer.decodeMethod}}(plain[keys[{{getPropertyIndex this ../properties}}]]){{else}}this.{{getSerializer analysis}}.deserialize(decoder, plain[keys[{{getPropertyIndex this ../properties}}]]){{/if}}{{#if serializer.needsTypeAssertion}} as {{analysis.type.sourceText}}{{/if}}{{/if}};
30
30
  {{/if}}
31
31
  {{else}}
32
32
  {{! 无默认值的属性 }}
33
33
  {{#if (eq analysis.visibility "private")}}
34
34
  ObjectUtils.setProp(result, '{{analysis.name}}', {{analysis.name}}PlainValue === undefined ? undefined :
35
- {{#if analysis.decorators.isPlainValue}}plain[keys[{{getPropertyIndex this ../properties}}]]{{else}}{{#if (and (eqPrimitiveType analysis.type.kind) (not (hasDecoratorWith analysis.decorators)))}}decoder.{{serializer.decodeMethod}}(plain[keys[{{getPropertyIndex this ../properties}}]]){{else}}this.{{analysis.name}}Serializer.deserialize(decoder, plain[keys[{{getPropertyIndex this ../properties}}]]){{/if}}{{#if serializer.needsTypeAssertion}} as {{analysis.type.sourceText}}{{/if}}{{/if}});
35
+ {{#if analysis.decorators.isPlainValue}}plain[keys[{{getPropertyIndex this ../properties}}]]{{else}}{{#if (and (eqPrimitiveType analysis.type.kind) (not (hasDecoratorWith analysis.decorators)))}}decoder.{{serializer.decodeMethod}}(plain[keys[{{getPropertyIndex this ../properties}}]]){{else}}this.{{getSerializer analysis}}.deserialize(decoder, plain[keys[{{getPropertyIndex this ../properties}}]]){{/if}}{{#if serializer.needsTypeAssertion}} as {{analysis.type.sourceText}}{{/if}}{{/if}});
36
36
  {{else}}
37
37
  result.{{analysis.name}} = {{analysis.name}}PlainValue === undefined ? undefined :
38
- {{#if analysis.decorators.isPlainValue}}plain[keys[{{getPropertyIndex this ../properties}}]]{{else}}{{#if (and (eqPrimitiveType analysis.type.kind) (not (hasDecoratorWith analysis.decorators)))}}decoder.{{serializer.decodeMethod}}(plain[keys[{{getPropertyIndex this ../properties}}]]){{else}}this.{{analysis.name}}Serializer.deserialize(decoder, plain[keys[{{getPropertyIndex this ../properties}}]]){{/if}}{{#if serializer.needsTypeAssertion}} as {{analysis.type.sourceText}}{{/if}}{{/if}};
38
+ {{#if analysis.decorators.isPlainValue}}plain[keys[{{getPropertyIndex this ../properties}}]]{{else}}{{#if (and (eqPrimitiveType analysis.type.kind) (not (hasDecoratorWith analysis.decorators)))}}decoder.{{serializer.decodeMethod}}(plain[keys[{{getPropertyIndex this ../properties}}]]){{else}}this.{{getSerializer analysis}}.deserialize(decoder, plain[keys[{{getPropertyIndex this ../properties}}]]){{/if}}{{#if serializer.needsTypeAssertion}} as {{analysis.type.sourceText}}{{/if}}{{/if}};
39
39
  {{/if}}
40
40
  {{/if}}
41
41
  {{/unless}}
@@ -33,7 +33,7 @@ deserialize(decoder: Decoder, plain: ESObject): {{class.className}}{{#if class.g
33
33
  {{#if (and (eqPrimitiveType analysis.type.kind) (not (hasDecoratorWith analysis.decorators)))}}
34
34
  {{analysis.name}}Value = decoder.{{serializer.decodeMethod}}(value);
35
35
  {{else}}
36
- {{analysis.name}}Value = this.{{analysis.name}}Serializer.deserialize(decoder, value){{#if serializer.needsTypeAssertion}} as {{analysis.type.sourceText}}{{/if}};
36
+ {{analysis.name}}Value = this.{{getSerializer analysis}}.deserialize(decoder, value){{#if serializer.needsTypeAssertion}} as {{analysis.type.sourceText}}{{/if}};
37
37
  {{/if}}
38
38
  {{/if}}
39
39
  break;
@@ -14,11 +14,15 @@ export class {{class.className}}Serializer<{{genericParametersString class.gener
14
14
  {{! 属性序列化器声明 }}
15
15
  {{#each properties}}
16
16
  {{#unless (eqPrimitiveType analysis.type.kind)}}
17
- private readonly {{analysis.name}}Serializer: {{serializer.typeDeclaration}};
17
+ private get{{toUpperCase analysis.name}}Serializer: () => {{serializer.typeDeclaration}};
18
18
  {{/unless}}
19
19
  {{/each}}
20
20
 
21
- readonly serialDescriptor: SerialDescriptor;
21
+ private getSerialDescriptor: () => SerialDescriptor;
22
+
23
+ get serialDescriptor(): SerialDescriptor {
24
+ return this.getSerialDescriptor();
25
+ }
22
26
 
23
27
  constructor(
24
28
  {{#each class.generics.parameters}}
@@ -29,39 +33,37 @@ export class {{class.className}}Serializer<{{genericParametersString class.gener
29
33
  {{! 初始化属性序列化器 }}
30
34
  {{#each properties}}
31
35
  {{#unless (eqPrimitiveType analysis.type.kind)}}
32
- this.{{analysis.name}}Serializer = {{serializer.instantiationTemplate}};
36
+ this.get{{toUpperCase analysis.name}}Serializer = () => {
37
+ const serializer: {{serializer.typeDeclaration}} = {{serializer.instantiationTemplate}};
38
+ this.get{{toUpperCase analysis.name}}Serializer = () => serializer;
39
+ return serializer;
40
+ };
33
41
  {{/unless}}
34
42
  {{/each}}
35
43
 
36
- this.serialDescriptor = buildClassSerialDescriptor(
37
- {{class.className}}_SERIAL_NAME,
38
- builder => {
39
- {{#each properties}}
40
- {{! 处理数字属性名的特殊情况 }}
41
- {{#if (isNumericPropertyName (formatPropertyName analysis))}}
42
- builder.element({
43
- elementName: '{{formatPropertyName analysis}}',
44
- elementDecodingName: this.fixNonNegativeIntegerElementName('{{formatPropertyName analysis}}'),
45
- descriptor:
46
- {{#if (eqPrimitiveType analysis.type.kind)}}
47
- {{serializer.name}}.INSTANCE.serialDescriptor
48
- {{else}}
49
- this.{{analysis.name}}Serializer.serialDescriptor
50
- {{/if}}
51
- });
52
- {{else}}
53
- builder.element({
54
- elementName: '{{formatPropertyName analysis}}',
55
- descriptor:
56
- {{#if (eqPrimitiveType analysis.type.kind)}}
57
- {{serializer.name}}.INSTANCE.serialDescriptor
58
- {{else}}
59
- this.{{analysis.name}}Serializer.serialDescriptor
44
+ this.getSerialDescriptor = () => {
45
+ const descriptor: SerialDescriptor = buildClassSerialDescriptor(
46
+ {{class.className}}_SERIAL_NAME,
47
+ builder => {
48
+ {{#each properties}}
49
+ {{! 处理数字属性名的特殊情况 }}
50
+ builder.element({
51
+ elementName: '{{formatPropertyName analysis}}',
52
+ {{#if (isNumericPropertyName (formatPropertyName analysis))}}
53
+ elementDecodingName: this.fixNonNegativeIntegerElementName('{{formatPropertyName analysis}}'),
60
54
  {{/if}}
61
- });
62
- {{/if}}
63
- {{/each}}
64
- });
55
+ descriptor:
56
+ {{#if (eqPrimitiveType analysis.type.kind)}}
57
+ {{serializer.name}}.INSTANCE.serialDescriptor
58
+ {{else}}
59
+ lazy(() => this.{{getSerializer analysis}}.serialDescriptor)
60
+ {{/if}}
61
+ });
62
+ {{/each}}
63
+ });
64
+ this.getSerialDescriptor = () => descriptor;
65
+ return descriptor;
66
+ }
65
67
  }
66
68
  {{else}}
67
69
  {{! 非泛型类:单例模式 }}
@@ -78,30 +80,45 @@ export class {{class.className}}Serializer extends Serializer<{{class.className}
78
80
 
79
81
  {{! 属性序列化器声明 }}
80
82
  {{#each properties}}
83
+ {{#if (eqPrimitiveType analysis.type.kind)}}
81
84
  private readonly {{analysis.name}}Serializer: {{serializer.typeDeclaration}} = {{serializer.instantiationTemplate}};
85
+ {{else}}
86
+ private get{{toUpperCase analysis.name}}Serializer: () => {{serializer.typeDeclaration}} = () => {
87
+ const serializer: {{serializer.typeDeclaration}} = {{serializer.instantiationTemplate}};
88
+ this.get{{toUpperCase analysis.name}}Serializer = () => serializer;
89
+ return serializer;
90
+ };
91
+ {{/if}}
82
92
  {{/each}}
83
93
 
84
94
  {{! 序列描述符构建 }}
85
- readonly serialDescriptor: SerialDescriptor = buildClassSerialDescriptor(
95
+ private getSerialDescriptor: () => SerialDescriptor = () => {
96
+ const descriptor: SerialDescriptor = buildClassSerialDescriptor(
86
97
  {{class.className}}_SERIAL_NAME,
87
98
  builder => {
88
99
  {{#each properties}}
89
- {{! 处理数字属性名的特殊情况 }}
90
- {{#if (isNumericPropertyName (formatPropertyName analysis))}}
91
100
  builder.element({
92
101
  elementName: '{{formatPropertyName analysis}}',
102
+ {{! 处理数字属性名的特殊情况 }}
103
+ {{#if (isNumericPropertyName (formatPropertyName analysis))}}
93
104
  elementDecodingName: this.fixNonNegativeIntegerElementName('{{formatPropertyName analysis}}'),
105
+ {{/if}}
106
+ {{#if (eqPrimitiveType analysis.type.kind)}}
94
107
  descriptor: this.{{analysis.name}}Serializer.serialDescriptor
108
+ {{else}}
109
+ descriptor: lazy(() => this.{{getSerializer analysis}}.serialDescriptor)
110
+ {{/if}}
95
111
  });
96
- {{else}}
97
- builder.element({
98
- elementName: '{{formatPropertyName analysis}}',
99
- descriptor: this.{{analysis.name}}Serializer.serialDescriptor
100
- });
101
- {{/if}}
102
112
  {{/each}}
103
113
  }
104
114
  )
115
+ this.getSerialDescriptor = () => descriptor;
116
+ return descriptor;
117
+ }
118
+
119
+ get serialDescriptor(): SerialDescriptor {
120
+ return this.getSerialDescriptor();
121
+ }
105
122
 
106
123
  private constructor() {
107
124
  super();
@@ -130,13 +147,13 @@ export class {{class.className}}Serializer extends Serializer<{{class.className}
130
147
  {{#if (and (eqPrimitiveType analysis.type.kind) (not (hasDecoratorWith analysis.decorators)))}}
131
148
  encoder.{{serializer.encodeMethod}}(result, keys[{{@index}}], ObjectUtils.getProp(value, '{{analysis.name}}'));
132
149
  {{else}}
133
- encoder.encodeSerializableElement(result, keys[{{@index}}], this.{{analysis.name}}Serializer, ObjectUtils.getProp(value, '{{analysis.name}}'));
150
+ encoder.encodeSerializableElement(result, keys[{{@index}}], this.{{getSerializer analysis}}, ObjectUtils.getProp(value, '{{analysis.name}}'));
134
151
  {{/if}}
135
152
  {{else}}
136
153
  {{#if (and (eqPrimitiveType analysis.type.kind) (not (hasDecoratorWith analysis.decorators)))}}
137
154
  encoder.{{serializer.encodeMethod}}(result, keys[{{@index}}], value.{{analysis.name}});
138
155
  {{else}}
139
- encoder.encodeSerializableElement(result, keys[{{@index}}], this.{{analysis.name}}Serializer, value.{{analysis.name}});
156
+ encoder.encodeSerializableElement(result, keys[{{@index}}], this.{{getSerializer analysis}}, value.{{analysis.name}});
140
157
  {{/if}}
141
158
  {{/if}}
142
159
  {{/each}}