@lcap/nasl 3.8.0-beta.8 → 3.8.2-alpha.1

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 (113) hide show
  1. package/.nyc_output/fe4ca6db-1eb6-4898-8aa5-ba8f8d4128f2.json +1 -0
  2. package/.nyc_output/processinfo/fe4ca6db-1eb6-4898-8aa5-ba8f8d4128f2.json +1 -0
  3. package/.nyc_output/processinfo/index.json +1 -1
  4. package/coverage/cobertura-coverage.xml +9325 -77393
  5. package/out/concepts/AuthLogicForCallInterface__.js +13 -2
  6. package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
  7. package/out/concepts/BackendVariable__.js +11 -1
  8. package/out/concepts/BackendVariable__.js.map +1 -1
  9. package/out/concepts/BindDirective__.js +1 -1
  10. package/out/concepts/BindDirective__.js.map +1 -1
  11. package/out/concepts/BindStyle__.js +1 -1
  12. package/out/concepts/BindStyle__.js.map +1 -1
  13. package/out/concepts/BusinessComponent__.js +14 -3
  14. package/out/concepts/BusinessComponent__.js.map +1 -1
  15. package/out/concepts/BusinessLogic__.js +13 -2
  16. package/out/concepts/BusinessLogic__.js.map +1 -1
  17. package/out/concepts/CallConnector__.js +2 -1
  18. package/out/concepts/CallConnector__.js.map +1 -1
  19. package/out/concepts/CallInterface__.js +12 -3
  20. package/out/concepts/CallInterface__.js.map +1 -1
  21. package/out/concepts/CallLogic__.js +24 -1
  22. package/out/concepts/CallLogic__.js.map +1 -1
  23. package/out/concepts/EntityProperty__.js +3 -2
  24. package/out/concepts/EntityProperty__.js.map +1 -1
  25. package/out/concepts/Entity__.js +1 -1
  26. package/out/concepts/Entity__.js.map +1 -1
  27. package/out/concepts/EnumItem__.js +2 -2
  28. package/out/concepts/EnumItem__.js.map +1 -1
  29. package/out/concepts/Interface__.js +1 -1
  30. package/out/concepts/Interface__.js.map +1 -1
  31. package/out/concepts/Logic__.js +13 -2
  32. package/out/concepts/Logic__.js.map +1 -1
  33. package/out/concepts/NewComposite__.d.ts +1 -0
  34. package/out/concepts/NewComposite__.js +23 -0
  35. package/out/concepts/NewComposite__.js.map +1 -1
  36. package/out/concepts/OverriddenLogic__.js +13 -2
  37. package/out/concepts/OverriddenLogic__.js.map +1 -1
  38. package/out/concepts/Param__.js +1 -1
  39. package/out/concepts/Param__.js.map +1 -1
  40. package/out/concepts/Structure__.js +1 -3
  41. package/out/concepts/Structure__.js.map +1 -1
  42. package/out/concepts/SubLogic__.js +13 -2
  43. package/out/concepts/SubLogic__.js.map +1 -1
  44. package/out/concepts/TypeAnnotation__.js +6 -3
  45. package/out/concepts/TypeAnnotation__.js.map +1 -1
  46. package/out/concepts/ViewComponentDeclaration__.js +3 -3
  47. package/out/concepts/ViewComponentDeclaration__.js.map +1 -1
  48. package/out/concepts/ViewElement__.d.ts +2 -0
  49. package/out/concepts/ViewElement__.js +60 -19
  50. package/out/concepts/ViewElement__.js.map +1 -1
  51. package/out/concepts/View__.js +24 -2
  52. package/out/concepts/View__.js.map +1 -1
  53. package/out/generator/genBundleFiles.js +1 -1
  54. package/out/generator/genBundleFiles.js.map +1 -1
  55. package/out/natural/genNaturalTS.d.ts +69 -16
  56. package/out/natural/genNaturalTS.js +198 -117
  57. package/out/natural/genNaturalTS.js.map +1 -1
  58. package/out/natural/getContext/index.d.ts +38 -26
  59. package/out/natural/getContext/index.js +318 -160
  60. package/out/natural/getContext/index.js.map +1 -1
  61. package/out/natural/index.d.ts +1 -0
  62. package/out/natural/index.js +1 -0
  63. package/out/natural/index.js.map +1 -1
  64. package/out/natural/tools.d.ts +11 -0
  65. package/out/natural/tools.js +162 -0
  66. package/out/natural/tools.js.map +1 -0
  67. package/out/natural/transformTS2UI.js +63 -26
  68. package/out/natural/transformTS2UI.js.map +1 -1
  69. package/out/natural/transformTSCode.js +26 -15
  70. package/out/natural/transformTSCode.js.map +1 -1
  71. package/out/server/naslServer.js +1 -0
  72. package/out/server/naslServer.js.map +1 -1
  73. package/out/translator/utils.js +1 -1
  74. package/out/translator/utils.js.map +1 -1
  75. package/package.json +1 -1
  76. package/sandbox/stdlib/nasl.util.ts +2 -2
  77. package/sandbox-natural/stdlib/nasl.core.ts +11 -0
  78. package/sandbox-natural/stdlib/nasl.ui.pre.d.ts +37 -37
  79. package/sandbox-natural/stdlib/nasl.util.ts +6 -6
  80. package/src/concepts/AuthLogicForCallInterface__.ts +13 -1
  81. package/src/concepts/BackendVariable__.ts +11 -1
  82. package/src/concepts/BindDirective__.ts +1 -1
  83. package/src/concepts/BindStyle__.ts +1 -1
  84. package/src/concepts/BusinessComponent__.ts +14 -2
  85. package/src/concepts/BusinessLogic__.ts +13 -1
  86. package/src/concepts/CallConnector__.ts +2 -1
  87. package/src/concepts/CallInterface__.ts +10 -3
  88. package/src/concepts/CallLogic__.ts +34 -14
  89. package/src/concepts/EntityProperty__.ts +5 -5
  90. package/src/concepts/Entity__.ts +1 -1
  91. package/src/concepts/EnumItem__.ts +2 -2
  92. package/src/concepts/Interface__.ts +1 -1
  93. package/src/concepts/Logic__.ts +13 -1
  94. package/src/concepts/NewComposite__.ts +24 -0
  95. package/src/concepts/OverriddenLogic__.ts +13 -1
  96. package/src/concepts/Param__.ts +1 -1
  97. package/src/concepts/Structure__.ts +1 -3
  98. package/src/concepts/SubLogic__.ts +13 -1
  99. package/src/concepts/TypeAnnotation__.ts +5 -3
  100. package/src/concepts/ViewComponentDeclaration__.ts +3 -3
  101. package/src/concepts/ViewElement__.ts +78 -19
  102. package/src/concepts/View__.ts +48 -24
  103. package/src/generator/genBundleFiles.ts +1 -1
  104. package/src/natural/genNaturalTS.ts +363 -147
  105. package/src/natural/getContext/index.ts +363 -175
  106. package/src/natural/index.ts +1 -0
  107. package/src/natural/tools.ts +138 -0
  108. package/src/natural/transformTS2UI.ts +60 -25
  109. package/src/natural/transformTSCode.ts +26 -16
  110. package/src/server/naslServer.ts +1 -0
  111. package/src/translator/utils.ts +1 -1
  112. package/.nyc_output/047fb941-6e69-4829-8b3c-14d37e06c63b.json +0 -1
  113. package/.nyc_output/processinfo/047fb941-6e69-4829-8b3c-14d37e06c63b.json +0 -1
@@ -2,3 +2,4 @@ export * from './genNaturalTS';
2
2
  export * from './transformTSCode';
3
3
  export * from './transformTS2UI';
4
4
  export * from './getContext/getUILib';
5
+ export * from './tools';
@@ -0,0 +1,138 @@
1
+ import { App, BaseNode } from "src/concepts";
2
+ import * as utils from '../utils';
3
+
4
+ // 获取当前逻辑的类型
5
+ export const getLogicType = (activeLogic: any) => {
6
+ const { parentNode } = activeLogic || {};
7
+ let logicType = 'global_logic';
8
+ if (parentNode?.concept === 'View') {
9
+ logicType = 'view_logic';
10
+ } else if (parentNode?.concept === 'BindEvent') {
11
+ logicType = 'event_logic';
12
+ }
13
+ if (activeLogic?.concept === 'BusinessLogic') {
14
+ logicType = 'business_Logic';
15
+ }
16
+ return logicType;
17
+ };
18
+
19
+ // 获取所有未使用的 module
20
+ export const getUsedModule = (json: BaseNode) => {
21
+ const useModule = [] as any;
22
+ const conceptMap = ['CallInterface', 'CallConnector', 'CallLogic'];
23
+ utils.traverse(({ node }: { node: any; }) => {
24
+ if (conceptMap.includes(node.concept)) {
25
+ if (/(apis\.|connector\.|extensions\.)/.test(node.calleeNamespace)) {
26
+ const symbol = node.calleeNamespace.match(/(\w+)(?=\.)|(\w+$)/g)[1];
27
+ const item = {
28
+ symbol,
29
+ key: symbol,
30
+ node,
31
+ } as any;
32
+ useModule.push(item);
33
+ }
34
+ }
35
+ if (node.concept === 'ViewElement' && node?.tag) {
36
+ const symbol = utils.kebab2Camel(node.tag);
37
+ const item = {
38
+ symbol,
39
+ key: symbol,
40
+ node,
41
+ } as any;
42
+ useModule.push(item);
43
+ }
44
+ }, { node: json }, { mode: 'anyObject' });
45
+ return useModule;
46
+ };
47
+
48
+
49
+ /**
50
+ * 根据生成的 NASL JSON,获取未导入的模块
51
+ * @param json: 当前生成的 NASL JSON
52
+ * @param app: 当前应用
53
+ * @param material: 召回的所有 Module
54
+ * @returns 需要导入的所有 Module 信息,包含 category、symbol、version
55
+ */
56
+ export const getUnImportedModulesForLogic = (json: BaseNode, app: App, material: any) => {
57
+ const useModule = getUsedModule(json);
58
+ const needImportModule = {
59
+ interfaces: new Map(),
60
+ connectors: new Map(),
61
+ library: new Map(),
62
+ extensionMaterials: new Map(),
63
+ needImportConnector: false
64
+ } as any;
65
+
66
+ useModule.forEach((item: any) => {
67
+ if (item.node.concept === 'CallInterface') {
68
+ // 从app.interfaceDependencies中找到对应的接口
69
+ const interfaceNode = app.interfaceDependencies?.find((node: any) => node.name === item.symbol);
70
+ if (!interfaceNode) {
71
+ item.category = 'interface';
72
+ const key = `${item.symbol}-${item?.node?.calleeName}`;
73
+ item.key = key;
74
+ needImportModule.interfaces.set(key, item);
75
+ }
76
+ } else if (item.node.concept === 'CallConnector') {
77
+ item.category = 'connector';
78
+ const connectorNode = app.connectorDependencies?.find((node: any) => node.name === item.symbol);
79
+
80
+ // 如果 连接器 不存在,则需要导入并初始化连接
81
+ if (!connectorNode) {
82
+ item.operator = 'importAndInit';
83
+ const curDep = material?.connectors?.find((node: any) => node.name === item.symbol)
84
+ item.version = curDep?.version;
85
+ item.provider = curDep?.provider || '资产中心';
86
+ needImportModule.needImportConnector = true;
87
+ needImportModule.connectors.set(item.symbol, item);
88
+ } else {
89
+ item.version = connectorNode.version;
90
+ // 查找连接
91
+ const connection = app.connections?.find((conn: any) => conn.connector.name === item.symbol);
92
+ // 如果 连接器 已存在,且连接已经被初始化过,需要修改生成 logic 中的名字,utils.traverse 修改
93
+ // 如果 连接器 已存在,且连接未被初始化过,则需要初始化连接
94
+ if (connection) {
95
+ item.operator = 'rename';
96
+ item.rename = { newName: connection.name, oldName: item.node.calleeConnectionName };
97
+ } else {
98
+ item.operator = 'init';
99
+ needImportModule.connectors.set(item.symbol, item);
100
+ }
101
+ }
102
+
103
+
104
+ } else if (item.node.concept === 'CallLogic') {
105
+ // 从app.logicDependencies中找到对应的逻辑
106
+ item.category = 'library';
107
+ const logicNode = app.dependencies?.find((node: any) => node.name === item.symbol);
108
+ if (!logicNode) {
109
+ const curDep = material?.dependencies?.find((node: any) => node.name === item.symbol);
110
+ item.version = curDep?.version;
111
+ item.provider = curDep?.provider || '资产中心';
112
+ needImportModule.library.set(item.symbol, item);
113
+ }
114
+ } else if (item.node.concept === 'ViewElement') {
115
+ const name = utils.kebab2Camel(item.node.tag);
116
+ const module = material?.extensionMaterials?.find((node: any) => utils.kebab2Camel(node.name) === name);
117
+ const imported = app.dependencies?.find((node: any) => node.name === module?.libraryName);
118
+ if (module && module.libraryName && !imported) {
119
+ const { libraryName } = module;
120
+ item.category = 'library';
121
+ item.key = `${libraryName}-${name}`;
122
+ item.symbol = libraryName;
123
+ const curDep = material?.dependencies?.find((node: any) => node.name === item.symbol);
124
+ item.version = curDep?.version;
125
+ item.provider = curDep?.provider || '';
126
+ needImportModule.extensionMaterials.set(name, item);
127
+ }
128
+ }
129
+ });
130
+
131
+ needImportModule.interfaces = Array.from(needImportModule.interfaces.values());
132
+ needImportModule.connectors = Array.from(needImportModule.connectors.values());
133
+ needImportModule.library = Array.from(needImportModule.library.values());
134
+ needImportModule.extensionMaterials = Array.from(needImportModule.extensionMaterials.values());
135
+
136
+ return needImportModule;
137
+ };
138
+
@@ -413,7 +413,7 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
413
413
  });
414
414
  }
415
415
  if (callee.length === 2 && callee[0].type === 'Identifier' && callee[0].name.endsWith('Entity')) {
416
- const entityName = callee[0].name.replace(/Entity$/, '');
416
+ const entityName = callee[0].name.replace(/Entity/, '');
417
417
  return new naslTypes.CallLogic({
418
418
  calleeNamespace: `app.dataSources.defaultDS.entities.${entityName}.logics`,
419
419
  calleeName: (callee[1] as babelTypes.Identifier).name,
@@ -580,7 +580,7 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
580
580
  } else if (/^app.dataSources|app.logics/.test(calleeName)) {
581
581
  if (calleeName?.includes('.entities.')) {
582
582
  const calleeNamespace = generate((node?.callee as any)?.object?.object)?.code;
583
- const entityName = (node?.callee as any)?.object?.property?.name?.replace(/Entity$/, '');
583
+ const entityName = (node?.callee as any)?.object?.property?.name?.replace(/Entity/, '');
584
584
  return new naslTypes.CallLogic({
585
585
  calleeNamespace: `${calleeNamespace}.${entityName}.logics`,
586
586
  calleeName: (node?.callee as any)?.property?.name,
@@ -971,29 +971,55 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
971
971
  }
972
972
 
973
973
  // 处理逻辑
974
- function transformNode2Logic(node: babelTypes.FunctionDeclaration, name?: string): naslTypes.Logic {
974
+ function transformNode2Logic(node: babelTypes.FunctionDeclaration, name: string, type: string): naslTypes.Logic {
975
975
  const parameters: babelTypes.Identifier[] = node.params as babelTypes.Identifier[];
976
976
  const statements: babelTypes.Statement[] = node.body.body;
977
977
 
978
978
  const curLogic: any = new naslTypes.Logic({ name: name ?? node.id.name });
979
- parameters.forEach((item: babelTypes.Identifier) => {
980
- const param = transformParam(item);
981
- if (param && param.name !== 'event' && !curLogic.params.find((_: any) => _.name === param.name)) curLogic.addParam(param);
982
- });
979
+ if (type !== 'event_logic') {
980
+ parameters.forEach((item: babelTypes.Identifier) => {
981
+ const param = transformParam(item);
982
+ if (param && param.name !== 'event' && !curLogic.params.find((_: any) => _.name === param.name)) curLogic.addParam(param);
983
+ });
984
+ }
983
985
  statements.forEach((item) => {
984
986
  if (item.type === 'ReturnStatement' && item?.argument) {
985
- if (!curLogic.returns.length) {
986
- curLogic.returns.push(new naslTypes.Return({
987
- name: 'result',
988
- }));
987
+ if (type === 'view_logic') {
988
+ if (item.argument?.type === 'Identifier') {
989
+ if (!curLogic.returns.length) {
990
+ const curVariable = curLogic?.variables?.find((it: any) => it.name === (item?.argument as any)?.name);
991
+ if (curVariable) {
992
+ curLogic.variables = curLogic?.variables?.filter((it: any) => it.name !== (item?.argument as any)?.name);
993
+ curLogic.addReturn(curVariable as any);
994
+ }
995
+ }
996
+ } else {
997
+ if (!curLogic.returns.length) {
998
+ curLogic.returns.push(new naslTypes.Return({
999
+ name: 'result',
1000
+ }));
1001
+ }
1002
+ const logicItem = new naslTypes.Assignment({
1003
+ left: new naslTypes.Identifier({
1004
+ name: curLogic.returns[0].name,
1005
+ }),
1006
+ right: transformNode2Expression(item.argument, 'logic')
1007
+ });
1008
+ curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
1009
+ }
1010
+ } else {
1011
+ if (item.argument?.type !== 'Identifier') {
1012
+ curLogic.addVariable('tempVar');
1013
+ const logicItem = new naslTypes.Assignment({
1014
+ left: new naslTypes.Identifier({
1015
+ name: 'tempVar',
1016
+ }),
1017
+ right: transformNode2Expression(item.argument, 'logic')
1018
+ });
1019
+ curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
1020
+ }
989
1021
  }
990
- const logicItem = new naslTypes.Assignment({
991
- left: new naslTypes.Identifier({
992
- name: curLogic.returns[0].name,
993
- }),
994
- right: transformNode2Expression(item.argument, 'logic')
995
- });
996
- curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
1022
+
997
1023
  } else {
998
1024
  let logicItem = transformNode2Expression(item, 'logic');
999
1025
  if (logicItem) {
@@ -1080,24 +1106,24 @@ function transformNode2ViewElement(node: babelTypes.NewExpression, componentName
1080
1106
  name,
1081
1107
  });
1082
1108
  viewNode.properties.forEach((prop: any, propIndex: number) => {
1083
- if (prop.value.type === 'ArrayExpression' && ['FunctionExpression', 'ArrowFunctionExpression'].includes(prop.value.elements[0].type)) {
1109
+ if (prop?.value?.type === 'ArrayExpression' && ['FunctionExpression', 'ArrowFunctionExpression'].includes(prop?.value?.elements?.[0]?.type)) {
1084
1110
  // 事件逻辑
1085
1111
  const eventName = prop?.key?.name?.replace(/^on/, '')?.toLowerCase();
1086
1112
  const bindEvent = new naslTypes.BindEvent({ name: eventName });
1087
1113
  prop.value.elements.forEach((element: any) => {
1088
1114
  const logicName = bindEvent.getLogicUniqueName();
1089
- const curLogic: any = transformNode2Logic(element, logicName);
1115
+ const curLogic: any = transformNode2Logic(element, logicName, 'event_logic');
1090
1116
  bindEvent.addLogic(curLogic);
1091
1117
  });
1092
1118
  newViewElement.addBindEvent(bindEvent);
1093
- } else if (['FunctionExpression', 'ArrowFunctionExpression'].includes(prop.value.type) && /^on/.test(prop.key.name)) {
1119
+ } else if (['FunctionExpression', 'ArrowFunctionExpression'].includes(prop?.value?.type) && /^on/.test(prop.key.name)) {
1094
1120
  // 事件逻辑
1095
1121
  const eventName = prop?.key?.name?.replace(/^on/, '')?.toLowerCase();
1096
1122
  const bindEvent = new naslTypes.BindEvent({ name: eventName });
1097
1123
  const logicName = bindEvent.getLogicUniqueName();
1098
- bindEvent.addLogic(transformNode2Logic(prop.value, logicName));
1124
+ bindEvent.addLogic(transformNode2Logic(prop.value, logicName, 'event_logic'));
1099
1125
  newViewElement.addBindEvent(bindEvent);
1100
- } else if (['FunctionExpression', 'ArrowFunctionExpression'].includes(prop.value.type) && ['ArrayExpression'].includes(prop.value.body?.type)) {
1126
+ } else if (['FunctionExpression', 'ArrowFunctionExpression'].includes(prop?.value?.type) && ['ArrayExpression'].includes(prop.value.body?.type)) {
1101
1127
  // 子组件
1102
1128
  const slotTarget = prop.key.name.replace(/^slot/, '').toLowerCase();
1103
1129
  if (slotTarget === 'default') {
@@ -1174,7 +1200,7 @@ function transformNode2ViewConstruct(node: babelTypes.Node): naslTypes.ViewEleme
1174
1200
  // 页面逻辑
1175
1201
  if (node.type === 'FunctionDeclaration') {
1176
1202
  const logicName = node.id.name.replace(/^viewLogic_/, '');
1177
- return transformNode2Logic(node, logicName);
1203
+ return transformNode2Logic(node, logicName, 'view_logic');
1178
1204
  }
1179
1205
 
1180
1206
  if (node.type === 'ExpressionStatement') {
@@ -1209,10 +1235,17 @@ function transformNode2ViewConstruct(node: babelTypes.Node): naslTypes.ViewEleme
1209
1235
  } else {
1210
1236
  properties?.[3].value.elements.forEach((element: any) => {
1211
1237
  let newNode = {} as any;
1238
+ const propertiesMap = ['BindDirective', 'BindStyle', 'BindAttribute'];
1212
1239
  if (properties?.[2].value.value === 'ViewElement') {
1213
1240
  newNode = transformNode2ViewConstruct(element);
1214
- } else if (properties?.[2].value.value === 'BindAttribute') {
1241
+ } else if (propertiesMap.includes(properties?.[2]?.value?.value)) {
1215
1242
  newNode = transformNode2Attribute({ key: element.left, value: element.right });
1243
+ } else if (properties?.[2]?.value?.value === 'BindEvent') {
1244
+ const eventName = element?.left?.name?.replace(/^on/, '')?.toLowerCase();
1245
+ const bindEvent = new naslTypes.BindEvent({ name: eventName });
1246
+ const logicName = bindEvent.getLogicUniqueName();
1247
+ bindEvent.addLogic(transformNode2Logic(element?.right?.elements[0], logicName, 'event_logic'));
1248
+ newNode = bindEvent;
1216
1249
  }
1217
1250
  const newNodeBackup = cloneDeep(newNode);
1218
1251
  (newNode as any).aiParams = {
@@ -1263,6 +1296,8 @@ function transformNode2View(node: babelTypes.FunctionDeclaration, root?: ParseRe
1263
1296
  if (item.type === 'ReturnStatement' && item?.argument?.type === 'ArrayExpression') {
1264
1297
  viewItem?.forEach((element: any) => {
1265
1298
  if (element.aiParams) json.push(element.aiParams);
1299
+ if (element?.concept === 'ViewElement')
1300
+ view.addViewElement(element);
1266
1301
  });
1267
1302
  }
1268
1303
  if (viewItem?.concept === 'Variable') {
@@ -429,7 +429,7 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
429
429
  });
430
430
  }
431
431
  if (callee.length === 2 && callee[0].type === 'Identifier' && callee[0].name.endsWith('Entity')) {
432
- const entityName = callee[0].name.replace(/Entity$/, '');
432
+ const entityName = callee[0].name.replace(/Entity/, '');
433
433
  return new naslTypes.CallLogic({
434
434
  calleeNamespace: `app.dataSources.defaultDS.entities.${entityName}.logics`,
435
435
  calleeName: (callee[1] as babelTypes.Identifier).name,
@@ -625,7 +625,7 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
625
625
  } else if (/^app.dataSources|app.logics/.test(calleeName)) {
626
626
  if (calleeName?.includes('.entities.')) {
627
627
  const calleeNamespace = generate((node?.callee as any)?.object?.object)?.code;
628
- const entityName = (node?.callee as any)?.object?.property?.name?.replace(/Entity$/, '');
628
+ const entityName = (node?.callee as any)?.object?.property?.name?.replace(/Entity/, '');
629
629
  return new naslTypes.CallLogic({
630
630
  calleeNamespace: `${calleeNamespace}.${entityName}.logics`,
631
631
  calleeName: (node?.callee as any)?.property?.name,
@@ -677,7 +677,10 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
677
677
  }))).flat() as naslTypes.Argument[],
678
678
  });
679
679
  } else if (/connector./.test(calleeName)) {
680
- const flatCalleeKey = generate(node?.callee as any)?.code;
680
+ let flatCalleeKey = generate(node?.callee as any)?.code;
681
+ if (flatCalleeKey?.startsWith('connector.')) {
682
+ flatCalleeKey = flatCalleeKey?.replace('connector.', '');
683
+ }
681
684
  const [, calleeConnectionName, calleeNamespace, calleeFunName] = flatCalleeKey?.match(/^(\w+)\.([\w.]+)\.(\w+)$/);
682
685
  return new naslTypes.CallConnector({
683
686
  calleeConnectionName,
@@ -972,20 +975,27 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
972
975
  }
973
976
  } else if (node.type === 'ReturnStatement') {
974
977
  if (node.argument) {
975
- if (type === 'expression') {
976
- return transformLogicNode(node.argument);
977
- }
978
- if (!logic.returns.length) {
979
- logic.returns.push(new naslTypes.Return({
980
- name: 'result',
981
- }));
978
+ if (node.argument?.type === 'Identifier') {
979
+ if (!logic.returns.length) {
980
+ const curVariable = logic?.variables?.find((item) => item.name === (node?.argument as any)?.name);
981
+ if (curVariable) {
982
+ logic.variables = logic?.variables?.filter((item) => item.name !== (node?.argument as any)?.name);
983
+ logic.addReturn(curVariable as any);
984
+ }
985
+ }
986
+ } else {
987
+ if (!logic.returns.length) {
988
+ logic.returns.push(new naslTypes.Return({
989
+ name: 'result',
990
+ }));
991
+ }
992
+ return new naslTypes.Assignment({
993
+ left: new naslTypes.Identifier({
994
+ name: logic.returns[0].name,
995
+ }),
996
+ right: transformLogicNode(node.argument),
997
+ });
982
998
  }
983
- return new naslTypes.Assignment({
984
- left: new naslTypes.Identifier({
985
- name: logic.returns[0].name,
986
- }),
987
- right: transformLogicNode(node.argument),
988
- });
989
999
  }
990
1000
  if ((node as any)?.ends) {
991
1001
  return new naslTypes.End();
@@ -416,6 +416,7 @@ class NaslServer {
416
416
 
417
417
  // 处理一堆api.ts的类型
418
418
  const convertTsCode = (code: string) => {
419
+ code = code || '';
419
420
  code = code.replace(/nasl.core.Integer/g, 'nasl.core.Long')
420
421
  // 匹配union类型的正则
421
422
  const unionReg = /\s*['"].*['"](\s*\|\s*['"].*['"])+/g;
@@ -258,7 +258,7 @@ export function transfromUnionTypeAnnotation(expTypeAnnotation: TypeAnnotation,
258
258
  export function createDescriptionComment<T extends BaseNode>(state: TranslatorState, node: T, properties: Array<keyof T>) {
259
259
  const content = properties.map((prop) => node[prop]).filter((value) => !!value).join(' ');
260
260
 
261
- return content.trim() ? `/** ${content} */\n${indent(state.tabSize)}` : '';
261
+ return content.trim() ? `/* ${content} */\n${indent(state.tabSize)}` : '';
262
262
  }
263
263
 
264
264
  export function createDecoratorCode<T extends BaseNode>(state: TranslatorState, node: T, properties: Array<keyof T>, options?: {