@lcap/nasl 4.3.0-rc.5 → 4.4.0-beta.3

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 (173) hide show
  1. package/out/generator/annotation/full.d.ts.map +1 -1
  2. package/out/generator/annotation/full.js +0 -32
  3. package/out/generator/annotation/full.js.map +1 -1
  4. package/out/generator/genBundleFiles.d.ts +3 -2
  5. package/out/generator/genBundleFiles.d.ts.map +1 -1
  6. package/out/generator/genBundleFiles.js +178 -140
  7. package/out/generator/genBundleFiles.js.map +1 -1
  8. package/out/generator/genSimpleBundleFile.d.ts +19 -0
  9. package/out/generator/genSimpleBundleFile.d.ts.map +1 -0
  10. package/out/generator/genSimpleBundleFile.js +114 -0
  11. package/out/generator/genSimpleBundleFile.js.map +1 -0
  12. package/out/generator/index.d.ts +1 -0
  13. package/out/generator/index.d.ts.map +1 -1
  14. package/out/generator/index.js +1 -0
  15. package/out/generator/index.js.map +1 -1
  16. package/out/generator/qiankun.d.ts +1 -1
  17. package/out/generator/qiankun.d.ts.map +1 -1
  18. package/out/generator/qiankun.js +4 -1
  19. package/out/generator/qiankun.js.map +1 -1
  20. package/out/generator/release-body/data.d.ts.map +1 -1
  21. package/out/generator/release-body/data.js +34 -1
  22. package/out/generator/release-body/data.js.map +1 -1
  23. package/out/generator/release-body/utils.d.ts +2 -6
  24. package/out/generator/release-body/utils.d.ts.map +1 -1
  25. package/out/generator/release-body/utils.js +101 -3
  26. package/out/generator/release-body/utils.js.map +1 -1
  27. package/out/generator/templates/chunk.d.ts +11 -0
  28. package/out/generator/templates/chunk.d.ts.map +1 -0
  29. package/out/generator/templates/chunk.js +29 -0
  30. package/out/generator/templates/chunk.js.map +1 -0
  31. package/out/generator/templates/runtime.d.ts +7 -0
  32. package/out/generator/templates/runtime.d.ts.map +1 -0
  33. package/out/generator/templates/runtime.js +409 -0
  34. package/out/generator/templates/runtime.js.map +1 -0
  35. package/out/generator/ui-library-declaration/basic.d.ts.map +1 -1
  36. package/out/generator/ui-library-declaration/basic.js +5 -5
  37. package/out/generator/ui-library-declaration/basic.js.map +1 -1
  38. package/out/generator/ui-library-declaration/dependency.d.ts.map +1 -1
  39. package/out/generator/ui-library-declaration/dependency.js +3 -3
  40. package/out/generator/ui-library-declaration/dependency.js.map +1 -1
  41. package/out/index.d.ts +1 -0
  42. package/out/index.d.ts.map +1 -1
  43. package/out/index.js +1 -0
  44. package/out/index.js.map +1 -1
  45. package/out/manager/diagnostic.d.ts.map +1 -1
  46. package/out/manager/diagnostic.js +0 -1
  47. package/out/manager/diagnostic.js.map +1 -1
  48. package/out/natural/getContext/nasl2Files.d.ts +15 -0
  49. package/out/natural/getContext/nasl2Files.d.ts.map +1 -0
  50. package/out/natural/getContext/nasl2Files.js +75 -0
  51. package/out/natural/getContext/nasl2Files.js.map +1 -0
  52. package/out/natural/index.d.ts +5 -1
  53. package/out/natural/index.d.ts.map +1 -1
  54. package/out/natural/index.js +7 -1
  55. package/out/natural/index.js.map +1 -1
  56. package/out/natural/parseNaturalTS.d.ts +6 -8
  57. package/out/natural/parseNaturalTS.d.ts.map +1 -1
  58. package/out/natural/parseNaturalTS.js +205 -54
  59. package/out/natural/parseNaturalTS.js.map +1 -1
  60. package/out/natural/parseNaturalTSXView.d.ts +7 -0
  61. package/out/natural/parseNaturalTSXView.d.ts.map +1 -0
  62. package/out/natural/parseNaturalTSXView.js +722 -0
  63. package/out/natural/parseNaturalTSXView.js.map +1 -0
  64. package/out/natural/transform2BatchActions.d.ts +96 -0
  65. package/out/natural/transform2BatchActions.d.ts.map +1 -0
  66. package/out/natural/transform2BatchActions.js +387 -0
  67. package/out/natural/transform2BatchActions.js.map +1 -0
  68. package/out/natural/transformTS2UI.d.ts.map +1 -1
  69. package/out/natural/transformTS2UI.js +16 -25
  70. package/out/natural/transformTS2UI.js.map +1 -1
  71. package/out/natural/transformTSCode.d.ts +2 -2
  72. package/out/natural/transformTSCode.d.ts.map +1 -1
  73. package/out/natural/transformTSCode.js +19 -11
  74. package/out/natural/transformTSCode.js.map +1 -1
  75. package/out/natural/transforms/transform2Entity.d.ts +2 -2
  76. package/out/natural/transforms/transform2Entity.d.ts.map +1 -1
  77. package/out/natural/transforms/transform2Entity.js +31 -7
  78. package/out/natural/transforms/transform2Entity.js.map +1 -1
  79. package/out/natural/transforms/transform2Enum.d.ts +2 -2
  80. package/out/natural/transforms/transform2Enum.d.ts.map +1 -1
  81. package/out/natural/transforms/transform2Enum.js +20 -4
  82. package/out/natural/transforms/transform2Enum.js.map +1 -1
  83. package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts +2 -2
  84. package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts.map +1 -1
  85. package/out/natural/transforms/transform2GlobalLogicDeclaration.js +4 -4
  86. package/out/natural/transforms/transform2GlobalLogicDeclaration.js.map +1 -1
  87. package/out/natural/transforms/transform2Logic.d.ts +4 -2
  88. package/out/natural/transforms/transform2Logic.d.ts.map +1 -1
  89. package/out/natural/transforms/transform2Logic.js +46 -8
  90. package/out/natural/transforms/transform2Logic.js.map +1 -1
  91. package/out/natural/transforms/transform2LogicItem.d.ts +65 -30
  92. package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
  93. package/out/natural/transforms/transform2LogicItem.js +502 -222
  94. package/out/natural/transforms/transform2LogicItem.js.map +1 -1
  95. package/out/natural/transforms/transform2MetadataType.d.ts +3 -0
  96. package/out/natural/transforms/transform2MetadataType.d.ts.map +1 -0
  97. package/out/natural/transforms/transform2MetadataType.js +14 -0
  98. package/out/natural/transforms/transform2MetadataType.js.map +1 -0
  99. package/out/natural/transforms/transform2Structure.d.ts +2 -2
  100. package/out/natural/transforms/transform2Structure.d.ts.map +1 -1
  101. package/out/natural/transforms/transform2Structure.js +5 -5
  102. package/out/natural/transforms/transform2Structure.js.map +1 -1
  103. package/out/natural/transforms/transform2TypeAnnotation.d.ts +2 -2
  104. package/out/natural/transforms/transform2TypeAnnotation.d.ts.map +1 -1
  105. package/out/natural/transforms/transform2TypeAnnotation.js +10 -14
  106. package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -1
  107. package/out/natural/transforms/transform2ValidationRule.d.ts +3 -0
  108. package/out/natural/transforms/transform2ValidationRule.d.ts.map +1 -0
  109. package/out/natural/transforms/transform2ValidationRule.js +24 -0
  110. package/out/natural/transforms/transform2ValidationRule.js.map +1 -0
  111. package/out/natural/transforms/transform2Variable.d.ts +3 -2
  112. package/out/natural/transforms/transform2Variable.d.ts.map +1 -1
  113. package/out/natural/transforms/transform2Variable.js +30 -6
  114. package/out/natural/transforms/transform2Variable.js.map +1 -1
  115. package/out/natural/transforms/transformThemeAndStyle.d.ts +24 -0
  116. package/out/natural/transforms/transformThemeAndStyle.d.ts.map +1 -0
  117. package/out/natural/transforms/transformThemeAndStyle.js +269 -0
  118. package/out/natural/transforms/transformThemeAndStyle.js.map +1 -0
  119. package/out/natural/transforms/utils.d.ts +37 -3
  120. package/out/natural/transforms/utils.d.ts.map +1 -1
  121. package/out/natural/transforms/utils.js +95 -13
  122. package/out/natural/transforms/utils.js.map +1 -1
  123. package/out/server/OQL/oql-cache.js +1 -1
  124. package/out/server/OQL/oql-cache.js.map +1 -1
  125. package/out/server/OQL/sqlCategory.json +410 -0
  126. package/out/server/OQL/sqlFunctions.json +695 -7
  127. package/out/server/OQL/utils.d.ts +1 -0
  128. package/out/server/OQL/utils.d.ts.map +1 -1
  129. package/out/server/OQL/utils.js +1 -0
  130. package/out/server/OQL/utils.js.map +1 -1
  131. package/out/server/index.d.ts +1 -0
  132. package/out/server/index.d.ts.map +1 -1
  133. package/out/server/index.js +1 -0
  134. package/out/server/index.js.map +1 -1
  135. package/out/server/naslServer.d.ts +5 -2
  136. package/out/server/naslServer.d.ts.map +1 -1
  137. package/out/server/naslServer.js +62 -34
  138. package/out/server/naslServer.js.map +1 -1
  139. package/out/service/initial/form-designer.d.ts +1 -1
  140. package/out/service/initial/form-designer.d.ts.map +1 -1
  141. package/out/service/initial/form-designer.js +4 -1
  142. package/out/service/initial/form-designer.js.map +1 -1
  143. package/out/service/initial/processV2.d.ts +1 -1
  144. package/out/service/initial/processV2.d.ts.map +1 -1
  145. package/out/service/initial/processV2.js +4 -1
  146. package/out/service/initial/processV2.js.map +1 -1
  147. package/out/service/initial/types.d.ts +1 -0
  148. package/out/service/initial/types.d.ts.map +1 -1
  149. package/out/service/storage/api.d.ts +9 -0
  150. package/out/service/storage/api.js +8 -0
  151. package/out/service/storage/api.js.map +1 -1
  152. package/out/service/storage/service.d.ts +3 -0
  153. package/out/service/storage/service.d.ts.map +1 -1
  154. package/out/service/storage/service.js +11 -0
  155. package/out/service/storage/service.js.map +1 -1
  156. package/out/service/storage/specTools.d.ts +34 -0
  157. package/out/service/storage/specTools.d.ts.map +1 -0
  158. package/out/service/storage/specTools.js +52 -0
  159. package/out/service/storage/specTools.js.map +1 -0
  160. package/out/utils/json-schema-to-nasl-type.d.ts +37 -0
  161. package/out/utils/json-schema-to-nasl-type.d.ts.map +1 -0
  162. package/out/utils/json-schema-to-nasl-type.js +195 -0
  163. package/out/utils/json-schema-to-nasl-type.js.map +1 -0
  164. package/package.json +12 -10
  165. package/sandbox/stdlib/nasl.oql.ts +1 -0
  166. package/out/generator/ui-library-declaration/utils.d.ts +0 -3
  167. package/out/generator/ui-library-declaration/utils.d.ts.map +0 -1
  168. package/out/generator/ui-library-declaration/utils.js +0 -20
  169. package/out/generator/ui-library-declaration/utils.js.map +0 -1
  170. package/out/natural/transforms/registerTransform.d.ts +0 -8
  171. package/out/natural/transforms/registerTransform.d.ts.map +0 -1
  172. package/out/natural/transforms/registerTransform.js +0 -24
  173. package/out/natural/transforms/registerTransform.js.map +0 -1
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nasl2Files = void 0;
4
+ const index_1 = require("../../index");
5
+ /**
6
+ * 将 NASL 对象转换为文件
7
+ * @param params - 包含 NASL 应用对象的参数
8
+ * @param params.app - NASL 应用实例
9
+ * @returns 生成的文件列表,每个文件包含路径和内容
10
+ */
11
+ const nasl2Files = ({ app }) => {
12
+ const result = [];
13
+ const state = (0, index_1.createCompilerState)('', { descriptionComment: true });
14
+ try {
15
+ // 处理枚举
16
+ if (app.enums && app.enums.length > 0) {
17
+ app.enums.forEach((item) => {
18
+ const path = `app.enums.${item.name}.ts`;
19
+ const content = item.toNaturalTS((0, index_1.shiftState)(state, '', { tabSize: 0 }));
20
+ result.push({ path, content });
21
+ });
22
+ }
23
+ // 处理结构体
24
+ if (app.structures && app.structures.length > 0) {
25
+ app.structures.forEach((item) => {
26
+ const path = `app.structures.${item.name}.ts`;
27
+ const content = item.toNaturalTS((0, index_1.shiftState)(state, '', { tabSize: 0 }));
28
+ result.push({ path, content });
29
+ });
30
+ }
31
+ // 处理数据源实体
32
+ if (app.dataSources && app.dataSources.length > 0 && app.dataSources[0]?.entities) {
33
+ app.dataSources[0].entities.forEach((item) => {
34
+ const path = `app.dataSources.defaultDS.entities.${item.name}.ts`;
35
+ const content = item.toNaturalTS((0, index_1.shiftState)(state, '', { tabSize: 0 }));
36
+ result.push({ path, content });
37
+ });
38
+ }
39
+ // 处理逻辑
40
+ if (app.logics && app.logics.length > 0) {
41
+ app.logics.forEach((item) => {
42
+ const path = `app.logics.${item.name}.ts`;
43
+ const content = item.toNaturalTS((0, index_1.shiftState)(state, '', { tabSize: 0, functionPrefix: 'export' }));
44
+ result.push({ path, content });
45
+ });
46
+ }
47
+ // 处理前端视图
48
+ if (app.frontendTypes?.[0]?.frontends[0]?.views) {
49
+ // 递归处理视图及其子视图的函数
50
+ const processView = (view, pathPrefix) => {
51
+ const path = `${pathPrefix}.${view.name}.tsx`;
52
+ const content = view.toNaturalTSX((0, index_1.shiftState)(state, '', { tabSize: 0 }));
53
+ result.push({ path, content });
54
+ // 如果视图有 children,递归处理子视图
55
+ if (view.children && view.children.length > 0) {
56
+ view.children.forEach((childView) => {
57
+ processView(childView, `${pathPrefix}.${view.name}.views`);
58
+ });
59
+ }
60
+ };
61
+ app.frontendTypes[0].frontends[0].views.forEach((item) => {
62
+ processView(item, 'app.frontendTypes.pc.frontends.pc.views');
63
+ });
64
+ }
65
+ }
66
+ catch (error) {
67
+ console.error('Error in nasl2File:', error);
68
+ return [];
69
+ }
70
+ // 输出结果
71
+ console.log('Generated files count:', result.length);
72
+ return result;
73
+ };
74
+ exports.nasl2Files = nasl2Files;
75
+ //# sourceMappingURL=nasl2Files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nasl2Files.js","sourceRoot":"","sources":["../../../src/natural/getContext/nasl2Files.ts"],"names":[],"mappings":";;;AAAA,uCAA8D;AAO9D;;;;;GAKG;AACI,MAAM,UAAU,GAAG,CAAC,EAAE,GAAG,EAAgB,EAAmB,EAAE;IACnE,MAAM,MAAM,GAA6C,EAAE,CAAC;IAC5D,MAAM,KAAK,GAAG,IAAA,2BAAmB,EAAC,EAAE,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC;IACpE,IAAI,CAAC;QACH,OAAO;QACP,IAAI,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAS,EAAE,EAAE;gBAC9B,MAAM,IAAI,GAAG,aAAa,IAAI,CAAC,IAAI,KAAK,CAAC;gBACzC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,IAAA,kBAAU,EAAC,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;gBACxE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;YACjC,CAAC,CAAC,CAAC;QACL,CAAC;QAED,QAAQ;QACR,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChD,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAS,EAAE,EAAE;gBACnC,MAAM,IAAI,GAAG,kBAAkB,IAAI,CAAC,IAAI,KAAK,CAAC;gBAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,IAAA,kBAAU,EAAC,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;gBACxE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;YACjC,CAAC,CAAC,CAAC;QACL,CAAC;QAED,UAAU;QACV,IAAI,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;YAClF,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAS,EAAE,EAAE;gBAChD,MAAM,IAAI,GAAG,sCAAsC,IAAI,CAAC,IAAI,KAAK,CAAC;gBAClE,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,IAAA,kBAAU,EAAC,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;gBACxE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;YACjC,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO;QACP,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAS,EAAE,EAAE;gBAC/B,MAAM,IAAI,GAAG,cAAc,IAAI,CAAC,IAAI,KAAK,CAAC;gBAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAC9B,IAAA,kBAAU,EAAC,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,CAChE,CAAC;gBACF,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;YACjC,CAAC,CAAC,CAAC;QACL,CAAC;QAED,SAAS;QACT,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;YAChD,iBAAiB;YACjB,MAAM,WAAW,GAAG,CAAC,IAAS,EAAE,UAAkB,EAAE,EAAE;gBACpD,MAAM,IAAI,GAAG,GAAG,UAAU,IAAI,IAAI,CAAC,IAAI,MAAM,CAAC;gBAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,IAAA,kBAAU,EAAC,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;gBACzE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;gBAE/B,yBAAyB;gBACzB,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC9C,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,SAAc,EAAE,EAAE;wBACvC,WAAW,CAAC,SAAS,EAAE,GAAG,UAAU,IAAI,IAAI,CAAC,IAAI,QAAQ,CAAC,CAAC;oBAC7D,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC;YAEF,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAS,EAAE,EAAE;gBAC5D,WAAW,CAAC,IAAI,EAAE,yCAAyC,CAAC,CAAC;YAC/D,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;QAC5C,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO;IACP,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAtEW,QAAA,UAAU,cAsErB"}
@@ -3,7 +3,11 @@ export * from './genTextualNASL';
3
3
  export * from './transformTSCode';
4
4
  export * from './transformTS2UI';
5
5
  export * from './parseNaturalTS';
6
- export * from './getContext/getUILib';
6
+ export * from './parseNaturalTSXView';
7
7
  export * from './getContext';
8
+ export * from './getContext/getUILib';
9
+ export * from './getContext/nasl2Files';
8
10
  export * from './tools';
11
+ export * from './transform2BatchActions';
12
+ export { parseNaturalTSErrorMap } from './transforms/utils';
9
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/natural/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/natural/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,SAAS,CAAC;AACxB,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -14,12 +14,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.parseNaturalTSErrorMap = void 0;
17
18
  __exportStar(require("./genNaturalTS"), exports);
18
19
  __exportStar(require("./genTextualNASL"), exports);
19
20
  __exportStar(require("./transformTSCode"), exports);
20
21
  __exportStar(require("./transformTS2UI"), exports);
21
22
  __exportStar(require("./parseNaturalTS"), exports);
22
- __exportStar(require("./getContext/getUILib"), exports);
23
+ __exportStar(require("./parseNaturalTSXView"), exports);
23
24
  __exportStar(require("./getContext"), exports);
25
+ __exportStar(require("./getContext/getUILib"), exports);
26
+ __exportStar(require("./getContext/nasl2Files"), exports);
24
27
  __exportStar(require("./tools"), exports);
28
+ __exportStar(require("./transform2BatchActions"), exports);
29
+ var utils_1 = require("./transforms/utils");
30
+ Object.defineProperty(exports, "parseNaturalTSErrorMap", { enumerable: true, get: function () { return utils_1.parseNaturalTSErrorMap; } });
25
31
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/natural/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,mDAAiC;AACjC,oDAAkC;AAClC,mDAAiC;AACjC,mDAAiC;AACjC,wDAAsC;AACtC,+CAA6B;AAC7B,0CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/natural/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,mDAAiC;AACjC,oDAAkC;AAClC,mDAAiC;AACjC,mDAAiC;AACjC,wDAAsC;AACtC,+CAA6B;AAC7B,wDAAsC;AACtC,0DAAwC;AACxC,0CAAwB;AACxB,2DAAyC;AACzC,4CAA4D;AAAnD,+GAAA,sBAAsB,OAAA"}
@@ -1,15 +1,13 @@
1
1
  import { naslTypes } from './transforms/utils';
2
- interface PartialAppInfo {
3
- name?: string;
4
- title?: string;
5
- ideVersion?: string;
6
- }
7
2
  type HeadNamespace = 'app' | 'extensions' | 'apis' | 'connectors';
8
- type TypeInNamespace = 'structures' | 'enums' | 'logics' | 'interfaces';
3
+ type TypeInNamespace = 'structures' | 'enums' | 'metadataTypes' | 'logics' | 'interfaces';
9
4
  /**
10
5
  * 添加到指定命名空间中
11
6
  */
12
- export declare function addType2Namespace(app: naslTypes.App, node: any, namespacePrefix: HeadNamespace, type: TypeInNamespace, options?: any): void;
13
- export declare function parseNaturalTS(tsCode: string, appInfo?: PartialAppInfo): naslTypes.App;
7
+ export declare function addType2Namespace(app: naslTypes.App, node: any, namespacePrefix: HeadNamespace, type: TypeInNamespace, opts?: any): void;
8
+ export declare function parseNaturalTS(tsCode: string, options?: {
9
+ parsingId?: number;
10
+ source?: string;
11
+ }): naslTypes.App;
14
12
  export {};
15
13
  //# sourceMappingURL=parseNaturalTS.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseNaturalTS.d.ts","sourceRoot":"","sources":["../../src/natural/parseNaturalTS.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,SAAS,EAA2C,MAAM,oBAAoB,CAAC;AAQpG,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAyGD,KAAK,aAAa,GAAG,KAAK,GAAG,YAAY,GAAG,MAAM,GAAG,YAAY,CAAC;AAClE,KAAK,eAAe,GAAG,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,YAAY,CAAC;AAIxE;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,eAAe,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,GAAG,QA+BpI;AASD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,iBA4H1E"}
1
+ {"version":3,"file":"parseNaturalTS.d.ts","sourceRoot":"","sources":["../../src/natural/parseNaturalTS.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,SAAS,EAAiF,MAAM,oBAAoB,CAAC;AA4H1I,KAAK,aAAa,GAAG,KAAK,GAAG,YAAY,GAAG,MAAM,GAAG,YAAY,CAAC;AAClE,KAAK,eAAe,GAAG,YAAY,GAAG,OAAO,GAAG,eAAe,GAAG,QAAQ,GAAG,YAAY,CAAC;AAI1F;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,eAAe,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,CAAC,EAAE,GAAG,QA+BjI;AASD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAA0B,iBAkQtH"}
@@ -32,8 +32,12 @@ const transform2GlobalLogicDeclaration_1 = require("./transforms/transform2Globa
32
32
  const transform2Enum_1 = require("./transforms/transform2Enum");
33
33
  const transform2Logic_1 = require("./transforms/transform2Logic");
34
34
  const transform2Variable_1 = require("./transforms/transform2Variable");
35
+ const parseNaturalTSXView_1 = require("./parseNaturalTSXView");
36
+ const transform2MetadataType_1 = require("./transforms/transform2MetadataType");
37
+ const transformThemeAndStyle_1 = require("./transforms/transformThemeAndStyle");
35
38
  /**
36
39
  * 铺平命名空间
40
+ * 会将连续嵌套的命令空间铺平
37
41
  */
38
42
  function flatNamespace(node) {
39
43
  const sub = node.body;
@@ -55,22 +59,24 @@ function flatNamespace(node) {
55
59
  * ids: apis.myInterface.interfaces statement: TSDeclareFunction
56
60
  * ids: apis.myInterface.interfaces statement: FunctionDeclaration
57
61
  */
58
- function flatMapNamespaceStatements(nodes, isInner = false) {
62
+ function flatMapNamespaceStatements(nodes, isInner = false, parseState) {
59
63
  const result = [];
60
64
  nodes.forEach((node) => {
61
65
  let statement = node;
62
66
  if (node.type === 'ExportNamedDeclaration') {
63
- // if (!isInner) throwError('顶层不应该导出:' + node.declaration.type);
67
+ // if (!isInner) return throwError(options?.parsingId, '顶层不应该导出:' + node.declaration.type);
64
68
  statement = node.declaration;
65
69
  statement.leadingComments = node.leadingComments;
66
70
  }
67
71
  else {
68
- if (isInner)
69
- (0, utils_1.throwError)('内层必须使用导出:' + node.type);
72
+ if (isInner && !(node.type === 'ExpressionStatement' && ['CallExpression', 'TaggedTemplateExpression'].includes(node.expression.type))) // && node.expression.callee.type === 'Identifier' && /^[@$]/.test(node.expression.callee.name)))
73
+ return (0, utils_1.throwError)(parseState, '必须使用 export', node.type, node);
70
74
  }
71
75
  if (statement.type === 'TSModuleDeclaration') {
72
76
  const curr = flatNamespace(statement);
73
- const subResult = flatMapNamespaceStatements(curr.block.body, true);
77
+ const nodeNamespace = curr.ids.map((id) => id.name).join('.');
78
+ // console.log('nodeNamespace in flatMapNamespaceStatements:', nodeNamespace);
79
+ const subResult = flatMapNamespaceStatements(curr.block.body, true, { ...parseState, nodeNamespace });
74
80
  subResult.forEach((item) => {
75
81
  result.push({ ids: [...curr.ids, ...item.ids], statement: item.statement });
76
82
  });
@@ -81,19 +87,19 @@ function flatMapNamespaceStatements(nodes, isInner = false) {
81
87
  });
82
88
  return result;
83
89
  }
84
- function handleDependency({ dependencies, moduleType, listName, options, node }) {
85
- let dependency = dependencies.find((d) => d.name === options?.moduleName);
90
+ function handleDependency({ dependencies, moduleType, listName, opts, node }) {
91
+ let dependency = dependencies.find((d) => d.name === opts?.moduleName);
86
92
  if (!dependency) {
87
93
  if (moduleType === 'connector') {
88
94
  dependency = new utils_1.naslTypes.Connector({
89
95
  type: moduleType,
90
- name: options.moduleName,
96
+ name: opts.moduleName,
91
97
  });
92
98
  }
93
99
  else {
94
100
  dependency = new utils_1.naslTypes.Module({
95
101
  type: moduleType,
96
- name: options.moduleName,
102
+ name: opts.moduleName,
97
103
  });
98
104
  }
99
105
  dependencies.push(dependency);
@@ -118,13 +124,13 @@ function handleDependency({ dependencies, moduleType, listName, options, node })
118
124
  }
119
125
  }
120
126
  const hasLogicIndex = logicList.findIndex((item) => item.name === node.name);
121
- if (options.logicType === 'declare') {
127
+ if (opts.logicKind === 'declare') {
122
128
  // 逻辑不存在时添加
123
129
  if (hasLogicIndex === -1) {
124
130
  logicList.push(node);
125
131
  }
126
132
  }
127
- else if (options.logicType === 'export') {
133
+ else if (opts.logicKind === 'export') {
128
134
  if (hasLogicIndex !== -1) {
129
135
  // 覆盖
130
136
  logicList[hasLogicIndex] = node;
@@ -137,19 +143,19 @@ function handleDependency({ dependencies, moduleType, listName, options, node })
137
143
  }
138
144
  }
139
145
  const HEAD_NAMESPACES = ['app', 'extensions', 'apis', 'connectors'];
140
- const TYPE_IN_NAMESPACES = ['structures', 'enums', 'logics', 'interfaces'];
146
+ const TYPE_IN_NAMESPACES = ['structures', 'enums', 'metadataTypes', 'logics', 'interfaces'];
141
147
  /**
142
148
  * 添加到指定命名空间中
143
149
  */
144
- function addType2Namespace(app, node, namespacePrefix, type, options) {
150
+ function addType2Namespace(app, node, namespacePrefix, type, opts) {
145
151
  if (namespacePrefix === 'app') {
146
152
  app[type].push(node);
147
153
  }
148
154
  if (namespacePrefix === 'extensions') {
149
- handleDependency({ dependencies: app.dependencies, moduleType: 'extension', listName: type, options, node });
155
+ handleDependency({ dependencies: app.dependencies, moduleType: 'extension', listName: type, opts, node });
150
156
  }
151
157
  else if (namespacePrefix === 'connectors') {
152
- handleDependency({ dependencies: app.connectorDependencies, moduleType: 'connector', listName: type, options, node });
158
+ handleDependency({ dependencies: app.connectorDependencies, moduleType: 'connector', listName: type, opts, node });
153
159
  }
154
160
  else if (namespacePrefix === 'apis') {
155
161
  if (type === 'interfaces') {
@@ -172,7 +178,7 @@ function addType2Namespace(app, node, namespacePrefix, type, options) {
172
178
  params: interfaceParams
173
179
  });
174
180
  }
175
- handleDependency({ dependencies: app.interfaceDependencies, moduleType: 'interface', listName: type, options, node });
181
+ handleDependency({ dependencies: app.interfaceDependencies, moduleType: 'interface', listName: type, opts, node });
176
182
  }
177
183
  }
178
184
  exports.addType2Namespace = addType2Namespace;
@@ -182,23 +188,32 @@ function addConnectionByName(app, connectionName, connectorName) {
182
188
  namespace: `connector.${connectorName}`,
183
189
  }));
184
190
  }
185
- function parseNaturalTS(tsCode, appInfo = {}) {
191
+ function parseNaturalTS(tsCode, options = { source: 'creator' }) {
186
192
  const plugins = [
187
- ['@babel/plugin-proposal-decorators', { legacy: true }],
188
- '@babel/plugin-proposal-class-properties'
193
+ [require('@babel/plugin-proposal-decorators'), { legacy: true }],
194
+ require('@babel/plugin-proposal-class-properties'),
189
195
  ];
190
196
  const root = babel.parseSync(tsCode, {
191
- filename: 'result.ts',
197
+ filename: 'result.tsx',
192
198
  presets: [require('@babel/preset-typescript')],
193
199
  plugins
194
200
  });
195
201
  const app = new utils_1.naslTypes.App();
196
- const namespaceStatements = flatMapNamespaceStatements(root.program.body);
197
- namespaceStatements.forEach(({ ids: _ids, statement }) => {
202
+ const namespaceStatements = flatMapNamespaceStatements(root.program.body, false, { $$beacon: true, parsingId: options?.parsingId });
203
+ let viewCacheMap = {};
204
+ namespaceStatements.forEach(({ ids: _ids, statement }, index) => {
198
205
  const idNames = _ids.map((id) => id.name);
199
206
  const idNamesStr = idNames.join('.');
207
+ // console.log('nodeNamespace in namespaceStatements:', idNamesStr);
208
+ const parseState = {
209
+ $$beacon: true,
210
+ parsingId: options?.parsingId,
211
+ nodeNamespace: idNamesStr,
212
+ nodeName: '',
213
+ appendExtName: true,
214
+ };
200
215
  if (!HEAD_NAMESPACES.includes(idNames[0]))
201
- (0, utils_1.throwError)(`不支持命名空间以${idNames[0]}开头`);
216
+ return (0, utils_1.throwError)(parseState, `不支持命名空间以${idNames[0]}开头`);
202
217
  let headNamespace = idNames[0];
203
218
  let typeInNamespace;
204
219
  if (headNamespace === 'app') {
@@ -214,16 +229,16 @@ function parseNaturalTS(tsCode, appInfo = {}) {
214
229
  return;
215
230
  }
216
231
  else if (paramType.type !== 'TSUnionType')
217
- (0, utils_1.throwError)('连接必须使用字符串联合类型');
232
+ return (0, utils_1.throwError)(parseState, '连接必须使用字符串联合类型');
218
233
  else {
219
234
  const connectionNames = paramType.types.map((type) => {
220
235
  if (type.type === 'TSLiteralType' && type.literal.type === 'StringLiteral') {
221
236
  return type.literal.value;
222
237
  }
223
238
  else {
224
- (0, utils_1.throwError)('连接必须使用字符串字面量');
239
+ return (0, utils_1.throwError)(parseState, '连接必须使用字符串字面量');
225
240
  }
226
- });
241
+ }).filter(Boolean);
227
242
  connectionNames.forEach((connectionName) => {
228
243
  addConnectionByName(app, connectionName, idNames[1]);
229
244
  });
@@ -231,7 +246,7 @@ function parseNaturalTS(tsCode, appInfo = {}) {
231
246
  }
232
247
  }
233
248
  else {
234
- (0, utils_1.throwError)(`不支持的命名空间:${idNamesStr}`);
249
+ return (0, utils_1.throwError)(parseState, `不支持的命名空间:${idNamesStr}`);
235
250
  }
236
251
  }
237
252
  else {
@@ -239,13 +254,12 @@ function parseNaturalTS(tsCode, appInfo = {}) {
239
254
  }
240
255
  }
241
256
  let tailNamespace = idNames[idNames.length - 1];
242
- let moduleName = headNamespace === 'app' ? '' : idNames[1];
243
- const options = { moduleName };
257
+ parseState.moduleName = headNamespace === 'app' ? '' : idNames[1];
244
258
  if (idNames[1] === 'dataSources' && idNames[3] === 'entities') {
245
259
  let dataSource = app.dataSources[0];
246
260
  if (dataSource) {
247
261
  if (dataSource.name !== idNames[2])
248
- (0, utils_1.throwError)(`暂时不支持多数据源${dataSource.name},${idNames[2]}`);
262
+ return (0, utils_1.throwError)(parseState, `暂时不支持多数据源${dataSource.name},${idNames[2]}`);
249
263
  }
250
264
  else {
251
265
  dataSource = new utils_1.naslTypes.DataSource({
@@ -254,63 +268,82 @@ function parseNaturalTS(tsCode, appInfo = {}) {
254
268
  app.dataSources.push(dataSource);
255
269
  }
256
270
  if (statement.type === 'ClassDeclaration') {
257
- dataSource.entities.push((0, transform2Entity_1.transform2Entity)(statement));
271
+ dataSource.entities.push((0, transform2Entity_1.transform2Entity)(statement, { ...parseState }));
258
272
  }
259
273
  else if (statement.type === 'VariableDeclaration') { }
274
+ else if (statement.type === 'ExpressionStatement' && statement.expression.type === 'CallExpression' && statement.expression.callee.type === 'MemberExpression' && statement.expression.callee.property.type === 'Identifier' && statement.expression.callee.property.name === '$mockData') {
275
+ if (statement.expression.arguments.length > 0) {
276
+ const firstArg = statement.expression.arguments[0];
277
+ try {
278
+ const argCode = (0, utils_1.generate)(firstArg).code;
279
+ JSON.parse(argCode);
280
+ }
281
+ catch (error) {
282
+ return (0, utils_1.throwError)({ ...parseState, nodeName: dataSource.entities[dataSource.entities.length - 1]?.name }, '$mockData的参数不是有效的JSON格式', firstArg.type, statement);
283
+ }
284
+ }
285
+ }
260
286
  else
261
- (0, utils_1.throwError)('实体命名空间中不支持的节点类型:' + statement.type);
287
+ return (0, utils_1.throwError)(parseState, '实体命名空间中不支持的节点类型', statement.type, statement);
262
288
  }
263
289
  else if (typeInNamespace === 'structures') {
264
290
  if (statement.type === 'ClassDeclaration') {
265
- addType2Namespace(app, (0, transform2Structure_1.transform2Structure)(statement), headNamespace, typeInNamespace, options);
291
+ addType2Namespace(app, (0, transform2Structure_1.transform2Structure)(statement, { ...parseState }), headNamespace, typeInNamespace, { ...parseState });
266
292
  }
267
293
  else
268
- (0, utils_1.throwError)('数据结构命名空间中不支持的节点类型:' + statement.type);
294
+ return (0, utils_1.throwError)(parseState, '数据结构命名空间中不支持的节点类型', statement.type, statement);
269
295
  }
270
296
  else if (typeInNamespace === 'enums') {
271
297
  if (statement.type === 'ClassDeclaration') {
272
- addType2Namespace(app, (0, transform2Enum_1.transform2Enum)(statement, statement.leadingComments), headNamespace, typeInNamespace, options);
298
+ addType2Namespace(app, (0, transform2Enum_1.transform2Enum)(statement, statement.leadingComments, { ...parseState }), headNamespace, typeInNamespace, { ...parseState });
273
299
  }
274
300
  else
275
- (0, utils_1.throwError)('枚举命名空间中不支持的节点类型:' + statement.type);
301
+ return (0, utils_1.throwError)(parseState, '枚举命名空间中不支持的节点类型', statement.type, statement);
302
+ }
303
+ else if (typeInNamespace === 'metadataTypes') {
304
+ if (statement.type === 'TSTypeAliasDeclaration') {
305
+ addType2Namespace(app, (0, transform2MetadataType_1.transform2MetadataType)(statement, statement.leadingComments, { ...parseState }), headNamespace, typeInNamespace, { ...parseState });
306
+ }
307
+ else
308
+ return (0, utils_1.throwError)(parseState, '元数据类型命名空间中不支持的节点类型', statement.type, statement);
276
309
  }
277
310
  else if (typeInNamespace === 'logics') {
278
- options.logicType = statement.type === 'TSDeclareFunction' ? 'declare' : 'export';
311
+ const logicParseState = { ...parseState, logicKind: statement.type === 'TSDeclareFunction' ? 'declare' : 'export' };
279
312
  if (statement.type === 'TSDeclareFunction') {
280
- addType2Namespace(app, (0, transform2GlobalLogicDeclaration_1.transform2GlobalLogicDeclaration)(statement), headNamespace, typeInNamespace, options);
313
+ addType2Namespace(app, (0, transform2GlobalLogicDeclaration_1.transform2GlobalLogicDeclaration)(statement, { ...parseState }), headNamespace, typeInNamespace, logicParseState);
281
314
  }
282
315
  else if (statement.type === 'FunctionDeclaration') {
283
- addType2Namespace(app, (0, transform2Logic_1.transform2Logic)(statement), headNamespace, typeInNamespace, options);
316
+ addType2Namespace(app, (0, transform2Logic_1.transform2Logic)(statement, undefined, { ...parseState }), headNamespace, typeInNamespace, logicParseState);
284
317
  }
285
318
  else
286
- (0, utils_1.throwError)('逻辑命名空间中不支持的节点类型:' + statement.type);
319
+ return (0, utils_1.throwError)(parseState, '逻辑命名空间中不支持的节点类型', statement.type, statement);
287
320
  }
288
321
  else if (['apis', 'extensions', 'connectors'].includes(headNamespace)) {
289
322
  // logics / interfaces
290
323
  if (tailNamespace === 'logics' || tailNamespace === 'interfaces') {
291
- options.logicType = statement.type === 'TSDeclareFunction' ? 'declare' : 'export';
292
- const logic = (0, transform2Logic_1.transform2Logic)(statement);
293
- if (options.logicType === 'declare') {
324
+ const logicParseState = { ...parseState, logicKind: statement.type === 'TSDeclareFunction' ? 'declare' : 'export' };
325
+ const logic = (0, transform2Logic_1.transform2Logic)(statement, undefined, logicParseState);
326
+ if (logicParseState.logicKind === 'declare') {
294
327
  logic.body = [];
295
328
  }
296
- addType2Namespace(app, logic, headNamespace, tailNamespace, options);
329
+ addType2Namespace(app, logic, headNamespace, tailNamespace, logicParseState);
297
330
  }
298
331
  else if (tailNamespace === 'enums' && statement.type === 'ClassDeclaration') {
299
- addType2Namespace(app, (0, transform2Enum_1.transform2Enum)(statement, statement.leadingComments), headNamespace, tailNamespace, options);
332
+ addType2Namespace(app, (0, transform2Enum_1.transform2Enum)(statement, statement.leadingComments, { ...parseState }), headNamespace, tailNamespace, parseState);
300
333
  }
301
334
  else if (tailNamespace === 'structures' && statement.type === 'ClassDeclaration') {
302
- addType2Namespace(app, (0, transform2Structure_1.transform2Structure)(statement), headNamespace, tailNamespace, options);
335
+ addType2Namespace(app, (0, transform2Structure_1.transform2Structure)(statement, { ...parseState }), headNamespace, tailNamespace, parseState);
303
336
  }
304
337
  else if (headNamespace === 'connectors') {
305
- options.logicType = statement.type === 'TSDeclareFunction' ? 'declare' : 'export';
306
- const logic = (0, transform2Logic_1.transform2Logic)(statement);
307
- if (options.logicType === 'declare') {
338
+ const logicParseState = { ...parseState, logicKind: statement.type === 'TSDeclareFunction' ? 'declare' : 'export' };
339
+ const logic = (0, transform2Logic_1.transform2Logic)(statement, undefined, logicParseState);
340
+ if (logicParseState.logicKind === 'declare') {
308
341
  logic.body = [];
309
342
  }
310
- addType2Namespace(app, logic, headNamespace, tailNamespace, options);
343
+ addType2Namespace(app, logic, headNamespace, tailNamespace, logicParseState);
311
344
  }
312
345
  else {
313
- (0, utils_1.throwError)('不支持的命名空间:' + idNamesStr);
346
+ return (0, utils_1.throwError)(parseState, '不支持的命名空间:' + idNamesStr);
314
347
  }
315
348
  }
316
349
  else if (idNamesStr === 'app.backend.variables') {
@@ -318,13 +351,131 @@ function parseNaturalTS(tsCode, appInfo = {}) {
318
351
  if (!app.backend) {
319
352
  app.backend = new utils_1.naslTypes.Backend();
320
353
  }
321
- app.backend.variables.push((0, transform2Variable_1.transform2BackendVariable)(statement));
354
+ const variable = (0, transform2Variable_1.transform2BackendVariable)(statement, { ...parseState });
355
+ variable && app.backend.variables.push(variable);
322
356
  }
323
357
  else
324
- (0, utils_1.throwError)('变量命名空间中不支持的节点类型:' + statement.type);
358
+ return (0, utils_1.throwError)(parseState, '变量命名空间中不支持的节点类型', statement.type, statement);
359
+ }
360
+ else if (idNames[1] === 'frontendTypes' && idNames[3] === 'frontends') {
361
+ let frontendType = app.frontendTypes.find((item) => item.name === idNames[2]);
362
+ if (!frontendType) {
363
+ frontendType = new utils_1.naslTypes.FrontendType({
364
+ name: idNames[2],
365
+ kind: idNames[2],
366
+ frameworkKind: "vue3",
367
+ frameworkUI: "ElementPlus",
368
+ });
369
+ app.frontendTypes.push(frontendType);
370
+ }
371
+ let frontend = frontendType.frontends.find((item) => item.name === idNames[4]);
372
+ if (!frontend) {
373
+ frontend = new utils_1.naslTypes.Frontend({
374
+ type: idNames[2],
375
+ name: idNames[4],
376
+ title: idNames[4].toUpperCase() + '端',
377
+ path: '/',
378
+ theme: new utils_1.naslTypes.Theme({
379
+ name: 'default',
380
+ title: '默认主题样式',
381
+ })
382
+ });
383
+ frontendType.frontends.push(frontend);
384
+ }
385
+ if (idNames[5] === 'variables') {
386
+ if (statement.type === 'VariableDeclaration') {
387
+ const variable = (0, transform2Variable_1.transform2FrontendVariable)(statement, { ...parseState });
388
+ variable && frontend.variables.push(variable);
389
+ }
390
+ else
391
+ return (0, utils_1.throwError)(parseState, '前端变量命名空间中不支持的节点类型', statement.type, statement);
392
+ }
393
+ else if (idNames[5] === 'views') {
394
+ if (statement.type === 'FunctionDeclaration' || statement.type === 'TSDeclareFunction') {
395
+ let decorator;
396
+ let prevStatement = namespaceStatements[index - 1]?.statement;
397
+ if (prevStatement?.type === 'ExpressionStatement' && prevStatement.expression.type === 'CallExpression' && prevStatement.expression.callee.type === 'Identifier' && prevStatement.expression.callee.name === '$View') {
398
+ decorator = prevStatement.expression;
399
+ }
400
+ const newOptions = { ...parseState, isInFrontend: true };
401
+ const view = statement.type === 'FunctionDeclaration' ? (0, parseNaturalTSXView_1.transform2View)(statement, decorator, newOptions) : (0, parseNaturalTSXView_1.transformTSDeclareFunction2View)(statement, decorator, newOptions);
402
+ newOptions.nodeName = view.name;
403
+ const parentPathSegments = []; // ['dashboard', 'abc']
404
+ for (let i = 6; i < idNames.length - 1; i += 2) {
405
+ if (idNames[i + 1] === 'views') {
406
+ parentPathSegments.push(idNames[i]);
407
+ }
408
+ else {
409
+ return (0, utils_1.throwError)(newOptions, `页面没有按 .views. 间隔,不支持的命名空间:${idNamesStr}`);
410
+ }
411
+ }
412
+ // 现在传过来时,需要先排序了,不然可能找不到父页面
413
+ function findViewByPath(views, pathSegments) {
414
+ if (pathSegments.length === 0)
415
+ return null;
416
+ const targetName = pathSegments[0];
417
+ const foundView = views.find(v => v.name === targetName);
418
+ if (!foundView)
419
+ return null;
420
+ if (pathSegments.length === 1)
421
+ return foundView;
422
+ return findViewByPath(foundView.children || [], pathSegments.slice(1));
423
+ }
424
+ let parentViewList;
425
+ if (parentPathSegments.length === 0) {
426
+ parentViewList = frontend.views;
427
+ }
428
+ else {
429
+ let parentView = viewCacheMap[parentPathSegments.join('/')];
430
+ if (!parentView)
431
+ parentView = findViewByPath(frontend.views, parentPathSegments);
432
+ if (!parentView)
433
+ return (0, utils_1.throwError)(newOptions, `找不到父级页面:${idNames.slice(0, -1).join('.')}`);
434
+ parentViewList = parentView.children;
435
+ }
436
+ if (view) {
437
+ const existingView = parentViewList.find((item) => item.name === view.name);
438
+ if (existingView) {
439
+ if (utils_1.DEBUG) {
440
+ return (0, utils_1.throwError)(newOptions, `${idNamesStr} 中存在同名页面:${view.name}`);
441
+ }
442
+ else { // 存在则保留原来页面的子页面,其他内容覆盖
443
+ delete view.children;
444
+ Object.assign(existingView, view);
445
+ }
446
+ }
447
+ else {
448
+ parentViewList.push(view);
449
+ viewCacheMap[[...parentPathSegments, view.name].join('/')] = view;
450
+ }
451
+ }
452
+ }
453
+ }
454
+ else if (statement.type === 'ExpressionStatement' && statement.expression.type === 'TaggedTemplateExpression') {
455
+ const expression = statement.expression;
456
+ if (expression.tag.type === 'Identifier' && expression.tag.name === '$theme') {
457
+ if (expression.quasi.expressions.length > 0) {
458
+ return (0, utils_1.throwError)(parseState, '不支持在 $theme 中使用动态表达式');
459
+ }
460
+ const css = expression.quasi.quasis[0].value.raw;
461
+ const variableMap = (0, transformThemeAndStyle_1.transformTheme)(css, { ...parseState });
462
+ frontend.theme.scopeVariableMap = variableMap;
463
+ }
464
+ else if (expression.tag.type === 'Identifier' && expression.tag.name === '$extraStyle') {
465
+ if (expression.quasi.expressions.length > 0) {
466
+ return (0, utils_1.throwError)(parseState, '不支持在 $style 中使用动态表达式');
467
+ }
468
+ const css = expression.quasi.quasis[0].value.raw;
469
+ const cssRules = (0, transformThemeAndStyle_1.transformStyle)(css, { ...parseState });
470
+ frontend.theme.cssRules = cssRules;
471
+ }
472
+ }
473
+ else {
474
+ return (0, utils_1.throwError)(parseState, '不支持的命名空间:' + idNamesStr);
475
+ }
325
476
  }
326
477
  else {
327
- (0, utils_1.throwError)('不支持的命名空间:' + idNamesStr);
478
+ return (0, utils_1.throwError)(parseState, '不支持的命名空间:' + idNamesStr);
328
479
  }
329
480
  });
330
481
  return app;