@hadss/turbo-trans-json-plugin 1.0.0-rc.0 → 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 (88) hide show
  1. package/README.md +1 -1
  2. package/dist/core/Types.d.ts +7 -0
  3. package/dist/core/Types.js +7 -1
  4. package/dist/core/analyzers/ClassAnalyzer.d.ts +15 -0
  5. package/dist/core/analyzers/ClassAnalyzer.js +200 -120
  6. package/dist/core/analyzers/CustomTypeAnalyzer.d.ts +3 -0
  7. package/dist/core/analyzers/CustomTypeAnalyzer.js +65 -60
  8. package/dist/core/constants/DecoratorConstants.d.ts +1 -0
  9. package/dist/core/constants/DecoratorConstants.js +3 -1
  10. package/dist/core/handlers/CustomClassHandler.js +0 -1
  11. package/dist/core/import-rewrite/services/BuildProfileUpdater.js +1 -1
  12. package/dist/core/import-rewrite/services/ImportRewriteService.js +1 -1
  13. package/dist/core/interfaces/index.d.ts +2 -2
  14. package/dist/core/services/CodeAnalysisService.js +2 -1
  15. package/dist/core/services/CodeGenerationService/CodeGenerationService.js +1 -1
  16. package/dist/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.d.ts +0 -1
  17. package/dist/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.js +0 -20
  18. package/dist/core/services/CodeGenerationService/generators/OriginalClassGenerator.d.ts +4 -4
  19. package/dist/core/services/CodeGenerationService/generators/OriginalClassGenerator.js +26 -45
  20. package/dist/core/services/CodeGenerationService/generators/SendableClassGenerator.d.ts +22 -0
  21. package/dist/core/services/CodeGenerationService/generators/SendableClassGenerator.js +194 -129
  22. package/dist/core/services/CodeGenerationService/generators/SerializerGenerator.js +20 -15
  23. package/dist/core/services/CodeGenerationService/generators/TempSerializerGenerator.js +2 -1
  24. package/dist/core/services/CodeGenerationService/shared/ImportManager.d.ts +2 -2
  25. package/dist/core/template/HandlebarsTemplateEngine.d.ts +2 -0
  26. package/dist/core/template/HandlebarsTemplateEngine.js +24 -2
  27. package/dist/core/utils/DeepCopyUtil.js +4 -2
  28. package/dist/core/utils/GenericTypeSubstitutionUtil.d.ts +1 -0
  29. package/dist/core/utils/GenericTypeSubstitutionUtil.js +27 -1
  30. package/dist/core/utils/SerializationPathUtil.d.ts +1 -1
  31. package/dist/core/utils/TsMorphUtil.js +6 -1
  32. package/dist/json-plugin/JSONExecuteController.d.ts +4 -0
  33. package/dist/json-plugin/JSONExecuteController.js +46 -36
  34. package/dist/json-plugin/interfaces/impl/TargetContext.js +4 -2
  35. package/dist/json-plugin/tasks/BaseTask.d.ts +2 -2
  36. package/dist/json-plugin/tasks/WatchTask.js +2 -1
  37. package/package.json +1 -1
  38. package/src/core/Types.ts +97 -89
  39. package/src/core/analyzers/ClassAnalyzer.ts +358 -197
  40. package/src/core/analyzers/CustomTypeAnalyzer.ts +145 -74
  41. package/src/core/constants/DecoratorConstants.ts +7 -5
  42. package/src/core/constants/PathConstants.ts +7 -7
  43. package/src/core/constants/StringConstants.ts +95 -97
  44. package/src/core/handlers/BaseTypeHandler.ts +11 -2
  45. package/src/core/handlers/CustomClassHandler.ts +4 -7
  46. package/src/core/handlers/DateHandler.ts +54 -46
  47. package/src/core/handlers/DecimalHandler.ts +53 -45
  48. package/src/core/handlers/EnumHandler.ts +2 -1
  49. package/src/core/handlers/GenericContainerHandler.ts +3 -1
  50. package/src/core/handlers/TupleHandler.ts +2 -1
  51. package/src/core/handlers/TypeHandlerRegistry.ts +3 -2
  52. package/src/core/handlers/UnionTypeHandler.ts +8 -7
  53. package/src/core/import-rewrite/services/BuildProfileUpdater.ts +7 -5
  54. package/src/core/import-rewrite/services/ImportRewriteService.ts +1 -3
  55. package/src/core/import-rewrite/services/ImportTransformService.ts +2 -2
  56. package/src/core/import-rewrite/types/ImportRewriteTypes.ts +3 -3
  57. package/src/core/index.ts +4 -4
  58. package/src/core/interfaces/ITask.ts +6 -5
  59. package/src/core/interfaces/ITaskContext.ts +9 -9
  60. package/src/core/interfaces/index.ts +2 -2
  61. package/src/core/logger/Logger.ts +28 -28
  62. package/src/core/services/CodeAnalysisService.ts +3 -2
  63. package/src/core/services/CodeGenerationEngine.ts +42 -42
  64. package/src/core/services/CodeGenerationService/CodeGenerationService.ts +1 -2
  65. package/src/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.ts +0 -29
  66. package/src/core/services/CodeGenerationService/generators/OriginalClassGenerator.ts +31 -64
  67. package/src/core/services/CodeGenerationService/generators/SendableClassGenerator.ts +261 -170
  68. package/src/core/services/CodeGenerationService/generators/SerializerGenerator.ts +26 -19
  69. package/src/core/services/CodeGenerationService/generators/TempSerializerGenerator.ts +5 -3
  70. package/src/core/services/CodeGenerationService/shared/ImportManager.ts +8 -8
  71. package/src/core/template/HandlebarsTemplateEngine.ts +43 -10
  72. package/src/core/utils/ConfigManager.ts +2 -1
  73. package/src/core/utils/DeepCopyUtil.ts +4 -2
  74. package/src/core/utils/GenericTypeSubstitutionUtil.ts +45 -2
  75. package/src/core/utils/SerializationPathUtil.ts +7 -6
  76. package/src/core/utils/TsMorphUtil.ts +9 -2
  77. package/src/index.ts +2 -2
  78. package/src/json-plugin/JSONExecuteController.ts +51 -38
  79. package/src/json-plugin/interfaces/IModuleContext.ts +8 -8
  80. package/src/json-plugin/interfaces/ITargetContext.ts +6 -6
  81. package/src/json-plugin/interfaces/impl/ModuleContext.ts +10 -10
  82. package/src/json-plugin/interfaces/impl/TargetContext.ts +63 -58
  83. package/src/json-plugin/tasks/BaseTask.ts +5 -4
  84. package/src/json-plugin/tasks/CleanTask.ts +7 -7
  85. package/src/json-plugin/tasks/WatchTask.ts +20 -18
  86. package/template/SerializerPerformanceTemplate.hbs +14 -4
  87. package/template/SerializerStrictTemplate.hbs +9 -1
  88. package/template/SerializerTemplate.hbs +71 -46
@@ -80,36 +80,44 @@ class CustomTypeAnalyzer {
80
80
  const imports = sourceFile.getImportDeclarations();
81
81
  for (const importDecl of imports) {
82
82
  const namedImports = importDecl.getNamedImports();
83
+ const matchedImport = namedImports.find(ni => ni.getName() === targetName);
84
+ if (!matchedImport) {
85
+ continue;
86
+ }
83
87
  const specifierValue = importDecl.getModuleSpecifierValue();
84
- for (const namedImport of namedImports) {
85
- const importName = namedImport.getName();
86
- if (importName === targetName) {
87
- const moduleSpecifier = importDecl.getModuleSpecifierValue();
88
- const resolvedPath = this.resolveImportPath(moduleSpecifier, sourceFile);
89
- if (resolvedPath && SerializationPathUtil_1.default.exist(resolvedPath)) {
90
- const externalSourceFile = this.getOrLoadSourceFile(resolvedPath);
91
- if (externalSourceFile) {
92
- const typeDetail = this.searchInSourceFile(targetName, externalSourceFile);
93
- if (typeDetail) {
94
- return {
95
- typeName: targetName,
96
- typeKind: typeDetail.kind,
97
- importPath: specifierValue,
98
- source: {
99
- type: 'imported',
100
- sourceFilePath: externalSourceFile.getFilePath(),
101
- originalImport: specifierValue
102
- },
103
- details: typeDetail
104
- };
105
- }
106
- }
107
- }
108
- }
88
+ const result = this.processImportMatch(importDecl, targetName, sourceFile, specifierValue);
89
+ if (result) {
90
+ return result;
109
91
  }
110
92
  }
111
93
  return null;
112
94
  }
95
+ processImportMatch(importDecl, targetName, sourceFile, specifierValue) {
96
+ const moduleSpecifier = importDecl.getModuleSpecifierValue();
97
+ const resolvedPath = this.resolveImportPath(moduleSpecifier, sourceFile);
98
+ if (!resolvedPath || !SerializationPathUtil_1.default.exist(resolvedPath)) {
99
+ return null;
100
+ }
101
+ const externalSourceFile = this.getOrLoadSourceFile(resolvedPath);
102
+ if (!externalSourceFile) {
103
+ return null;
104
+ }
105
+ const typeDetail = this.searchInSourceFile(targetName, externalSourceFile);
106
+ if (!typeDetail) {
107
+ return null;
108
+ }
109
+ return {
110
+ typeName: targetName,
111
+ typeKind: typeDetail.kind,
112
+ importPath: specifierValue,
113
+ source: {
114
+ type: 'imported',
115
+ sourceFilePath: externalSourceFile.getFilePath(),
116
+ originalImport: specifierValue
117
+ },
118
+ details: typeDetail
119
+ };
120
+ }
113
121
  findInCrossModule(targetName, sourceFile) {
114
122
  return null;
115
123
  }
@@ -146,49 +154,46 @@ class CustomTypeAnalyzer {
146
154
  let numericValue = 0;
147
155
  const enumMembers = enumDecl.getMembers();
148
156
  for (const member of enumMembers) {
149
- const memberName = member.getName();
150
- let memberValue;
151
- let literalValue;
152
- const initializer = member.getInitializer();
153
- if (initializer) {
154
- const initText = initializer.getText().trim();
155
- if (initText.startsWith('"') && initText.endsWith('"')) {
156
- memberValue = initText.slice(1, -1);
157
- literalValue = initText;
158
- valueType = 'string';
159
- }
160
- else if (initText.startsWith("'") && initText.endsWith("'")) {
161
- memberValue = initText.slice(1, -1);
162
- literalValue = `"${memberValue}"`;
163
- valueType = 'string';
164
- }
165
- else {
166
- const numValue = parseInt(initText, 10);
167
- if (!isNaN(numValue)) {
168
- memberValue = numValue;
169
- literalValue = numValue.toString();
170
- numericValue = numValue + 1;
171
- }
172
- else {
173
- memberValue = initText;
174
- literalValue = `"${initText}"`;
175
- valueType = 'string';
176
- }
177
- }
178
- }
179
- else {
180
- memberValue = numericValue;
181
- literalValue = numericValue.toString();
182
- numericValue++;
157
+ const { memberValue, literalValue, type, nextValue } = this.parseEnumMember(member, numericValue);
158
+ numericValue = nextValue;
159
+ if (type === 'string') {
160
+ valueType = 'string';
183
161
  }
184
162
  members.push({
185
- name: memberName,
163
+ name: member.getName(),
186
164
  value: memberValue,
187
165
  literalValue
188
166
  });
189
167
  }
190
168
  return { kind: __1.TypeKind.ENUM, valueType, members };
191
169
  }
170
+ parseEnumMember(member, numericValue) {
171
+ const initializer = member.getInitializer();
172
+ if (!initializer) {
173
+ return {
174
+ memberValue: numericValue,
175
+ literalValue: numericValue.toString(),
176
+ type: 'number',
177
+ nextValue: numericValue + 1
178
+ };
179
+ }
180
+ const initText = initializer.getText().trim();
181
+ if (initText.startsWith('"') && initText.endsWith('"')) {
182
+ return this.createStringEnumResult(initText.slice(1, -1), initText, numericValue);
183
+ }
184
+ if (initText.startsWith("'") && initText.endsWith("'")) {
185
+ const val = initText.slice(1, -1);
186
+ return this.createStringEnumResult(val, `"${val}"`, numericValue);
187
+ }
188
+ const numValue = parseInt(initText, 10);
189
+ if (!isNaN(numValue)) {
190
+ return { memberValue: numValue, literalValue: numValue.toString(), type: 'number', nextValue: numValue + 1 };
191
+ }
192
+ return this.createStringEnumResult(initText, `"${initText}"`, numericValue);
193
+ }
194
+ createStringEnumResult(memberValue, literalValue, numericValue) {
195
+ return { memberValue, literalValue, type: 'string', nextValue: numericValue };
196
+ }
192
197
  parseClassDetails(classDecl) {
193
198
  return {
194
199
  kind: __1.TypeKind.CLASS,
@@ -3,5 +3,6 @@ export declare class DecoratorConstants {
3
3
  static readonly SERIAL_NAME = "SerialName";
4
4
  static readonly REQUIRED = "Required";
5
5
  static readonly TRANSIENT = "Transient";
6
+ static readonly PLAIN_VALUE = "PlainValue";
6
7
  static readonly SERIAL_DECORATORS: string[];
7
8
  }
@@ -10,4 +10,6 @@ DecoratorConstants.SERIALIZABLE = 'Serializable';
10
10
  DecoratorConstants.SERIAL_NAME = 'SerialName';
11
11
  DecoratorConstants.REQUIRED = 'Required';
12
12
  DecoratorConstants.TRANSIENT = 'Transient';
13
- DecoratorConstants.SERIAL_DECORATORS = [_a.SERIALIZABLE, _a.SERIAL_NAME, _a.REQUIRED, _a.TRANSIENT];
13
+ DecoratorConstants.PLAIN_VALUE = 'PlainValue';
14
+ DecoratorConstants.SERIAL_DECORATORS = [_a.SERIALIZABLE, _a.SERIAL_NAME, _a.REQUIRED, _a.TRANSIENT,
15
+ _a.PLAIN_VALUE];
@@ -166,7 +166,6 @@ class CustomClassHandler extends BaseTypeHandler_1.BaseTypeHandler {
166
166
  throw new CustomError_1.CustomError(`Type ${classDetails.classDecl.getName()} is not sendable.
167
167
  please add @Sendable or @Serializable({ generateSendable: true })`, CustomError_1.ErrorCodes.NOT_SENDABLE);
168
168
  }
169
- return structure.sourceText;
170
169
  }
171
170
  generatePropertyConversion(structure, sourceValue, direction) {
172
171
  const classDetails = structure.classDetails;
@@ -64,7 +64,7 @@ class BuildProfileUpdaterImpl {
64
64
  }
65
65
  updateSourceRootsConfig(config) {
66
66
  let updated = false;
67
- const generatedSourceRoot = "./src/generated";
67
+ const generatedSourceRoot = './src/generated';
68
68
  __1.Logger.info(`target.source.sourceRoots start`);
69
69
  if (config.targets && Array.isArray(config.targets)) {
70
70
  for (const target of config.targets) {
@@ -25,7 +25,7 @@ class ImportRewriteServiceImpl {
25
25
  this.transformService.rewriteFileImports(filePath, context, generatedFileInfos, options.preserveOriginalImports);
26
26
  successCount++;
27
27
  }
28
- catch (error) {
28
+ catch {
29
29
  errorCount++;
30
30
  }
31
31
  }
@@ -1,2 +1,2 @@
1
- export { ITask } from './ITask';
2
- export { ITaskContext } from './ITaskContext';
1
+ export type { ITask } from './ITask';
2
+ export type { ITaskContext } from './ITaskContext';
@@ -5,7 +5,8 @@ const __1 = require("..");
5
5
  const ClassAnalyzer_1 = require("../analyzers/ClassAnalyzer");
6
6
  const TsMorphUtil_1 = require("../utils/TsMorphUtil");
7
7
  class CodeAnalysisService {
8
- constructor() { }
8
+ constructor() {
9
+ }
9
10
  analyzeFile(filePath) {
10
11
  __1.Logger.debug(`开始分析文件: ${filePath}`);
11
12
  const sourceFile = TsMorphUtil_1.TsMorphUtil.getProject().addSourceFileAtPath(filePath);
@@ -37,7 +37,7 @@ class CodeGenerationService {
37
37
  for (const classAnalysis of results) {
38
38
  serializableGeneratorContext.push(this.serializerGenerator.generate(outputSourceFile, classAnalysis, context));
39
39
  }
40
- this.originalClassGenerator.generate(outputSourceFile, originalSourceFile, results, context);
40
+ this.originalClassGenerator.generate(outputSourceFile, originalSourceFile, results);
41
41
  for (const content of serializableGeneratorContext) {
42
42
  this.serializerGenerator.generateRegistration(outputSourceFile, content);
43
43
  }
@@ -6,7 +6,6 @@ export declare class MergedSendableClassGenerator {
6
6
  private removeTurboTransDecorators;
7
7
  private addSendableDecorator;
8
8
  private addITSerializableInterface;
9
- private generateGetTypeMethod;
10
9
  private generateConvertToSendableMethod;
11
10
  private generateToOriginMethod;
12
11
  private generateToJsonMethod;
@@ -45,18 +45,6 @@ class MergedSendableClassGenerator {
45
45
  }
46
46
  classDecl.addImplements(['ITSerializable', 'lang.ISendable']);
47
47
  }
48
- generateGetTypeMethod(classDecl, classAnalysis) {
49
- if (classDecl.getMethod('getType')) {
50
- __1.Logger.warn(`类 ${classAnalysis.className} 已存在getType方法,跳过生成`);
51
- return;
52
- }
53
- const methodBody = `return ${classAnalysis.className};`;
54
- classDecl.addMethod({
55
- name: 'getType',
56
- returnType: 'Function',
57
- statements: [methodBody]
58
- });
59
- }
60
48
  generateConvertToSendableMethod(classDecl, classAnalysis) {
61
49
  if (classDecl.getMethod('toSendable')) {
62
50
  __1.Logger.warn(`类 ${classAnalysis.className} 已存在toSendable方法,跳过生成`);
@@ -95,14 +83,6 @@ class MergedSendableClassGenerator {
95
83
  return;
96
84
  }
97
85
  const methodBody = 'return TJSON.toString(this, typeKey)';
98
- const genericParameters = classAnalysis.generics.parameters;
99
- let fullTypeName;
100
- if (genericParameters.length > 0) {
101
- fullTypeName = `${classDecl.getNameOrThrow()}<${genericParameters.join(', ')}>`;
102
- }
103
- else {
104
- fullTypeName = classDecl.getNameOrThrow();
105
- }
106
86
  classDecl.addMethod({
107
87
  name: 'toJson',
108
88
  returnType: 'string',
@@ -1,20 +1,20 @@
1
1
  import { SourceFile } from 'ts-morph';
2
- import { ClassAnalysis, ITaskContext } from '../../..';
2
+ import { ClassAnalysis } from '../../..';
3
3
  import { ImportManager } from '../shared/ImportManager';
4
4
  export declare class OriginalClassGenerator {
5
5
  private readonly importManager;
6
6
  private readonly mergedSendableGenerator;
7
7
  constructor(importManager: ImportManager);
8
- generate(outputSourceFile: SourceFile, originalSourceFile: SourceFile, results: ClassAnalysis[], context: ITaskContext): void;
8
+ generate(outputSourceFile: SourceFile, originalSourceFile: SourceFile, results: ClassAnalysis[]): void;
9
9
  private copySourceFileContentWithoutImports;
10
10
  private addITSerializableInterface;
11
- private generateSerialNameConstant;
12
11
  private addStaticSerialName;
13
- private generateGetTypeMethod;
14
12
  private generateConvertToSendableMethod;
15
13
  private generateToJsonMethod;
16
14
  private registerImports;
17
15
  private generateConvertToSendableMethodBody;
16
+ private getConstructorProperties;
17
+ private getAssignmentProperties;
18
18
  private generateConstructorCall;
19
19
  private generatePropertyAssignment;
20
20
  private generatePropertyConversion;
@@ -16,7 +16,7 @@ class OriginalClassGenerator {
16
16
  this.importManager = importManager;
17
17
  this.mergedSendableGenerator = new MergedSendableClassGenerator_1.MergedSendableClassGenerator();
18
18
  }
19
- generate(outputSourceFile, originalSourceFile, results, context) {
19
+ generate(outputSourceFile, originalSourceFile, results) {
20
20
  this.registerImports();
21
21
  const contentWithoutImports = this.copySourceFileContentWithoutImports(originalSourceFile);
22
22
  const tempSourceFile = TsMorphUtil_1.TsMorphUtil.getProject().createSourceFile('temp.ts', contentWithoutImports, {
@@ -31,7 +31,7 @@ class OriginalClassGenerator {
31
31
  }
32
32
  else {
33
33
  this.addITSerializableInterface(targetClass);
34
- this.addStaticSerialName(targetClass, result, context);
34
+ this.addStaticSerialName(targetClass, result);
35
35
  this.generateConvertToSendableMethod(targetClass, result);
36
36
  this.generateToJsonMethod(targetClass, result);
37
37
  }
@@ -85,13 +85,7 @@ class OriginalClassGenerator {
85
85
  classDecl.addImplements('ITSerializable');
86
86
  __1.Logger.debug(`为类 ${classDecl.getName()} 添加ITSerializable接口实现`);
87
87
  }
88
- generateSerialNameConstant(result, context) {
89
- const relativePath = context.calculateSourceRootToModuleRoot(result.sourceFilePath);
90
- const serialName = SerializationPathUtil_1.default.join(context.getPackageName(), relativePath, result.className + '.class')
91
- .replaceAll(SerializationPathUtil_1.default.sep, '/');
92
- return result.decorators.serialName || serialName;
93
- }
94
- addStaticSerialName(classDecl, result, context) {
88
+ addStaticSerialName(classDecl, result) {
95
89
  classDecl.addProperty({
96
90
  name: 'SERIAL_NAME',
97
91
  type: 'string',
@@ -101,18 +95,6 @@ class OriginalClassGenerator {
101
95
  });
102
96
  __1.Logger.debug(`为类 ${classDecl.getName()} 添加静态属性 serialName`);
103
97
  }
104
- generateGetTypeMethod(classDecl, result) {
105
- if (classDecl.getMethod('getType')) {
106
- __1.Logger.warn(`类 ${result.className} 已存在getType方法,跳过生成`);
107
- return;
108
- }
109
- const methodBody = `return ${result.className};`;
110
- classDecl.addMethod({
111
- name: 'getType',
112
- returnType: 'Function',
113
- statements: [methodBody]
114
- });
115
- }
116
98
  generateConvertToSendableMethod(classDecl, result) {
117
99
  if (classDecl.getMethod('toSendable')) {
118
100
  __1.Logger.warn(`类 ${result.className} 已存在toSendable方法,跳过生成`);
@@ -144,14 +126,6 @@ class OriginalClassGenerator {
144
126
  return;
145
127
  }
146
128
  const methodBody = 'return TJSON.toString(this, typeKey)';
147
- const genericParameters = result.generics.parameters;
148
- let fullTypeName;
149
- if (genericParameters.length > 0) {
150
- fullTypeName = `${classDecl.getNameOrThrow()}<${genericParameters.join(', ')}>`;
151
- }
152
- else {
153
- fullTypeName = classDecl.getNameOrThrow();
154
- }
155
129
  classDecl.addMethod({
156
130
  name: 'toJson',
157
131
  returnType: 'string',
@@ -165,9 +139,27 @@ class OriginalClassGenerator {
165
139
  }
166
140
  registerImports() {
167
141
  this.importManager.registerJsonImports(['ITSerializable', 'TJSON']);
168
- this.importManager.registerCoreImports(['TypeKey', 'Serializable']);
142
+ this.importManager.registerCoreImports(['TypeKey', 'Serializable', 'Encoder', 'SerialDescriptor']);
169
143
  }
170
144
  generateConvertToSendableMethodBody(classAnalysis, returnType) {
145
+ const constructorProps = this.getConstructorProperties(classAnalysis);
146
+ const assignmentProps = this.getAssignmentProperties(classAnalysis);
147
+ const statements = [];
148
+ const constructorCall = this.generateConstructorCall(constructorProps, returnType);
149
+ statements.push(`const sendable = ${constructorCall};`);
150
+ if (assignmentProps.length > 0) {
151
+ statements.push('');
152
+ statements.push('// 非构造函数属性赋值');
153
+ assignmentProps.forEach((prop) => {
154
+ const assignment = this.generatePropertyAssignment(prop);
155
+ statements.push(`sendable.${prop.name} = ${assignment};`);
156
+ });
157
+ }
158
+ statements.push('');
159
+ statements.push('return sendable;');
160
+ return statements.join('\n');
161
+ }
162
+ getConstructorProperties(classAnalysis) {
171
163
  const constructorProps = [];
172
164
  classAnalysis.constructorParams.forEach((cp) => {
173
165
  const matchingProperty = classAnalysis.properties.find((p) => p.name === cp.name);
@@ -181,23 +173,12 @@ class OriginalClassGenerator {
181
173
  });
182
174
  }
183
175
  });
184
- const assignmentProps = classAnalysis.properties.filter((p) => {
176
+ return constructorProps;
177
+ }
178
+ getAssignmentProperties(classAnalysis) {
179
+ return classAnalysis.properties.filter((p) => {
185
180
  return classAnalysis.constructorParams.every((cp) => cp.name !== p.name);
186
181
  });
187
- const statements = [];
188
- const constructorCall = this.generateConstructorCall(constructorProps, returnType);
189
- statements.push(`const sendable = ${constructorCall};`);
190
- if (assignmentProps.length > 0) {
191
- statements.push('');
192
- statements.push('// 非构造函数属性赋值');
193
- assignmentProps.forEach((prop) => {
194
- const assignment = this.generatePropertyAssignment(prop);
195
- statements.push(`sendable.${prop.name} = ${assignment};`);
196
- });
197
- }
198
- statements.push('');
199
- statements.push('return sendable;');
200
- return statements.join('\n');
201
182
  }
202
183
  generateConstructorCall(constructorProps, returnType) {
203
184
  if (constructorProps.length === 0) {
@@ -9,16 +9,38 @@ export declare class SendableClassGenerator {
9
9
  private updateInheritanceToSendable;
10
10
  private removeImplements;
11
11
  private removeAllDecorators;
12
+ private removeClassDecorators;
13
+ private removePropertyDecorators;
14
+ private removeMethodDecorators;
15
+ private logAndRemoveDecorator;
12
16
  private convertPropertyTypesToSendable;
17
+ private convertSinglePropertyToSendable;
18
+ private updatePropertyType;
19
+ private updatePropertyInitializer;
13
20
  private addSendableConstraints;
14
21
  private addToOriginMethod;
15
22
  private generatedToOriginMethodBody;
23
+ private getConstructorCall;
16
24
  private generatePropertyConversion;
17
25
  private getSendableClassName;
18
26
  private addNecessaryImports;
27
+ private processPropertyDependencyImports;
28
+ private registerDependencyImport;
29
+ private processBaseClassImport;
30
+ private processCollectionsImport;
31
+ private copySourceFileImports;
32
+ private processSingleImportDeclaration;
33
+ private registerModuleImports;
34
+ private registerPackageImports;
19
35
  private convertConstructorParameterTypes;
36
+ private convertSingleConstructorParameters;
37
+ private convertSingleParameter;
20
38
  private isObjectType;
21
39
  needsCollectionsImport(result: ClassAnalysis): boolean;
22
40
  private convertInitializerToSendable;
41
+ private convertArrayLiteralToSendable;
42
+ private replaceObjectConstructors;
43
+ private replaceObjectConstructorMatch;
44
+ private replaceCollectionTypes;
23
45
  private convertToSendableType;
24
46
  }