@lcap/nasl 4.4.0-beta.9 → 4.4.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 (204) hide show
  1. package/out/generator/genBundleFiles.d.ts.map +1 -1
  2. package/out/generator/genBundleFiles.js +32 -3
  3. package/out/generator/genBundleFiles.js.map +1 -1
  4. package/out/generator/qiankun.d.ts +1 -1
  5. package/out/generator/qiankun.d.ts.map +1 -1
  6. package/out/generator/qiankun.js +4 -0
  7. package/out/generator/qiankun.js.map +1 -1
  8. package/out/generator/release-body/body.d.ts +0 -1
  9. package/out/generator/release-body/body.d.ts.map +1 -1
  10. package/out/generator/release-body/body.js +1 -390
  11. package/out/generator/release-body/body.js.map +1 -1
  12. package/out/generator/release-body/data.d.ts.map +1 -1
  13. package/out/generator/release-body/data.js +1 -10
  14. package/out/generator/release-body/data.js.map +1 -1
  15. package/out/generator/release-body/share-content.js.map +1 -1
  16. package/out/generator/release-body/types.d.ts +1 -0
  17. package/out/generator/release-body/types.d.ts.map +1 -1
  18. package/out/generator/templates/chunk.js +1 -1
  19. package/out/generator/templates/runtime.js +2 -2
  20. package/out/natural/exports/nasl2Files.d.ts.map +1 -0
  21. package/out/natural/{getContext → exports}/nasl2Files.js +4 -4
  22. package/out/natural/exports/nasl2Files.js.map +1 -0
  23. package/out/natural/{transform2BatchActions.d.ts → exports/transform2BatchActions.d.ts} +1 -1
  24. package/out/natural/exports/transform2BatchActions.d.ts.map +1 -0
  25. package/out/natural/{transform2BatchActions.js → exports/transform2BatchActions.js} +68 -19
  26. package/out/natural/exports/transform2BatchActions.js.map +1 -0
  27. package/out/natural/index.d.ts +12 -12
  28. package/out/natural/index.d.ts.map +1 -1
  29. package/out/natural/index.js +12 -14
  30. package/out/natural/index.js.map +1 -1
  31. package/out/natural/{genNaturalTS.d.ts → old/getContext/genNaturalTS.d.ts} +12 -12
  32. package/out/natural/old/getContext/genNaturalTS.d.ts.map +1 -0
  33. package/out/natural/{genNaturalTS.js → old/getContext/genNaturalTS.js} +65 -65
  34. package/out/natural/old/getContext/genNaturalTS.js.map +1 -0
  35. package/out/natural/old/getContext/genTextualNASL.d.ts.map +1 -0
  36. package/out/natural/old/getContext/genTextualNASL.js.map +1 -0
  37. package/out/natural/{getContext → old/getContext}/getUILib.d.ts +1 -1
  38. package/out/natural/old/getContext/getUILib.d.ts.map +1 -0
  39. package/out/natural/{getContext → old/getContext}/getUILib.js +14 -14
  40. package/out/natural/old/getContext/getUILib.js.map +1 -0
  41. package/out/natural/{getContext → old/getContext}/index.d.ts +3 -3
  42. package/out/natural/old/getContext/index.d.ts.map +1 -0
  43. package/out/natural/{getContext → old/getContext}/index.js +4 -4
  44. package/out/natural/old/getContext/index.js.map +1 -0
  45. package/out/natural/old/getContext/naslStdlibMap.d.ts.map +1 -0
  46. package/out/natural/{getContext → old/getContext}/naslStdlibMap.js +10 -10
  47. package/out/natural/old/getContext/naslStdlibMap.js.map +1 -0
  48. package/out/natural/{transformTS2UI.d.ts → old/parser/transformTS2UI.d.ts} +2 -2
  49. package/out/natural/old/parser/transformTS2UI.d.ts.map +1 -0
  50. package/out/natural/{transformTS2UI.js → old/parser/transformTS2UI.js} +12 -13
  51. package/out/natural/old/parser/transformTS2UI.js.map +1 -0
  52. package/out/natural/{transformTSCode.d.ts → old/parser/transformTSCode.d.ts} +1 -1
  53. package/out/natural/old/parser/transformTSCode.d.ts.map +1 -0
  54. package/out/natural/{transformTSCode.js → old/parser/transformTSCode.js} +6 -6
  55. package/out/natural/old/parser/transformTSCode.js.map +1 -0
  56. package/out/natural/{tools.d.ts → old/tools.d.ts} +0 -4
  57. package/out/natural/old/tools.d.ts.map +1 -0
  58. package/out/natural/{tools.js → old/tools.js} +7 -25
  59. package/out/natural/old/tools.js.map +1 -0
  60. package/out/natural/{parseNaturalTS.d.ts → parser/parseNaturalTS.d.ts} +1 -1
  61. package/out/natural/parser/parseNaturalTS.d.ts.map +1 -0
  62. package/out/natural/{parseNaturalTS.js → parser/parseNaturalTS.js} +14 -10
  63. package/out/natural/parser/parseNaturalTS.js.map +1 -0
  64. package/out/natural/{parseNaturalTSXView.d.ts → parser/parseNaturalTSXView.d.ts} +1 -2
  65. package/out/natural/parser/parseNaturalTSXView.d.ts.map +1 -0
  66. package/out/natural/{parseNaturalTSXView.js → parser/parseNaturalTSXView.js} +51 -58
  67. package/out/natural/parser/parseNaturalTSXView.js.map +1 -0
  68. package/out/natural/transforms/checker/checkDataQueryCalleeNameOrder.d.ts +7 -0
  69. package/out/natural/transforms/checker/checkDataQueryCalleeNameOrder.d.ts.map +1 -0
  70. package/out/natural/transforms/checker/checkDataQueryCalleeNameOrder.js +38 -0
  71. package/out/natural/transforms/checker/checkDataQueryCalleeNameOrder.js.map +1 -0
  72. package/out/natural/transforms/checker/checkDefaultValue.d.ts +13 -0
  73. package/out/natural/transforms/checker/checkDefaultValue.d.ts.map +1 -0
  74. package/out/natural/transforms/checker/checkDefaultValue.js +33 -0
  75. package/out/natural/transforms/checker/checkDefaultValue.js.map +1 -0
  76. package/out/natural/transforms/checker/checkViewElement.d.ts +29 -0
  77. package/out/natural/transforms/checker/checkViewElement.d.ts.map +1 -0
  78. package/out/natural/transforms/checker/checkViewElement.js +422 -0
  79. package/out/natural/transforms/checker/checkViewElement.js.map +1 -0
  80. package/out/natural/transforms/checker/index.d.ts +17 -0
  81. package/out/natural/transforms/checker/index.d.ts.map +1 -0
  82. package/out/natural/transforms/checker/index.js +26 -0
  83. package/out/natural/transforms/checker/index.js.map +1 -0
  84. package/out/natural/transforms/transform2Entity.d.ts +8 -1
  85. package/out/natural/transforms/transform2Entity.d.ts.map +1 -1
  86. package/out/natural/transforms/transform2Entity.js +88 -18
  87. package/out/natural/transforms/transform2Entity.js.map +1 -1
  88. package/out/natural/transforms/transform2Enum.d.ts +1 -1
  89. package/out/natural/transforms/transform2Enum.d.ts.map +1 -1
  90. package/out/natural/transforms/transform2Enum.js +5 -1
  91. package/out/natural/transforms/transform2Enum.js.map +1 -1
  92. package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts +1 -1
  93. package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts.map +1 -1
  94. package/out/natural/transforms/transform2GlobalLogicDeclaration.js +3 -3
  95. package/out/natural/transforms/transform2GlobalLogicDeclaration.js.map +1 -1
  96. package/out/natural/transforms/transform2Logic.d.ts +1 -1
  97. package/out/natural/transforms/transform2Logic.d.ts.map +1 -1
  98. package/out/natural/transforms/transform2Logic.js +4 -4
  99. package/out/natural/transforms/transform2Logic.js.map +1 -1
  100. package/out/natural/transforms/transform2LogicItem.d.ts +6 -3
  101. package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
  102. package/out/natural/transforms/transform2LogicItem.js +99 -110
  103. package/out/natural/transforms/transform2LogicItem.js.map +1 -1
  104. package/out/natural/transforms/transform2MetadataType.d.ts +1 -1
  105. package/out/natural/transforms/transform2MetadataType.d.ts.map +1 -1
  106. package/out/natural/transforms/transform2MetadataType.js +1 -1
  107. package/out/natural/transforms/transform2MetadataType.js.map +1 -1
  108. package/out/natural/transforms/transform2Param.d.ts +4 -0
  109. package/out/natural/transforms/transform2Param.d.ts.map +1 -0
  110. package/out/natural/transforms/transform2Param.js +114 -0
  111. package/out/natural/transforms/transform2Param.js.map +1 -0
  112. package/out/natural/transforms/transform2Structure.d.ts +1 -1
  113. package/out/natural/transforms/transform2Structure.d.ts.map +1 -1
  114. package/out/natural/transforms/transform2Structure.js +13 -2
  115. package/out/natural/transforms/transform2Structure.js.map +1 -1
  116. package/out/natural/transforms/transform2TypeAnnotation.d.ts +1 -1
  117. package/out/natural/transforms/transform2TypeAnnotation.d.ts.map +1 -1
  118. package/out/natural/transforms/transform2TypeAnnotation.js +2 -2
  119. package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -1
  120. package/out/natural/transforms/transform2ValidationRule.d.ts +1 -1
  121. package/out/natural/transforms/transform2ValidationRule.d.ts.map +1 -1
  122. package/out/natural/transforms/transform2ValidationRule.js +1 -1
  123. package/out/natural/transforms/transform2ValidationRule.js.map +1 -1
  124. package/out/natural/transforms/transform2Variable.d.ts +2 -1
  125. package/out/natural/transforms/transform2Variable.d.ts.map +1 -1
  126. package/out/natural/transforms/transform2Variable.js +22 -2
  127. package/out/natural/transforms/transform2Variable.js.map +1 -1
  128. package/out/natural/transforms/transformThemeAndStyle.d.ts +1 -1
  129. package/out/natural/transforms/transformThemeAndStyle.d.ts.map +1 -1
  130. package/out/natural/transforms/transformThemeAndStyle.js +1 -1
  131. package/out/natural/transforms/transformThemeAndStyle.js.map +1 -1
  132. package/out/natural/transforms/utils/fetchFromComments.d.ts +3 -0
  133. package/out/natural/transforms/utils/fetchFromComments.d.ts.map +1 -0
  134. package/out/natural/transforms/utils/fetchFromComments.js +10 -0
  135. package/out/natural/transforms/utils/fetchFromComments.js.map +1 -0
  136. package/out/natural/transforms/utils/misc.d.ts +16 -0
  137. package/out/natural/transforms/utils/misc.d.ts.map +1 -0
  138. package/out/natural/transforms/utils/misc.js +240 -0
  139. package/out/natural/transforms/utils/misc.js.map +1 -0
  140. package/out/natural/transforms/utils/parseDecorator.d.ts +46 -0
  141. package/out/natural/transforms/utils/parseDecorator.d.ts.map +1 -0
  142. package/out/natural/transforms/utils/parseDecorator.js +180 -0
  143. package/out/natural/transforms/utils/parseDecorator.js.map +1 -0
  144. package/out/natural/utils/index.d.ts +59 -0
  145. package/out/natural/utils/index.d.ts.map +1 -0
  146. package/out/natural/utils/index.js +168 -0
  147. package/out/natural/utils/index.js.map +1 -0
  148. package/out/server/extendBaseNode.js +14 -0
  149. package/out/server/extendBaseNode.js.map +1 -1
  150. package/out/server/findReference.js +1 -1
  151. package/out/server/findReference.js.map +1 -1
  152. package/out/server/naslServer.d.ts.map +1 -1
  153. package/out/server/naslServer.js +33 -17
  154. package/out/server/naslServer.js.map +1 -1
  155. package/out/server/translator.js.map +1 -1
  156. package/out/service/autofix/rules/rule-convert-incompatible-assignment-to-union.js.map +1 -1
  157. package/out/service/storage/init.d.ts.map +1 -1
  158. package/out/service/storage/init.js +9 -2
  159. package/out/service/storage/init.js.map +1 -1
  160. package/out/templator/block2nasl/transformBlock2Nasl.js +2 -2
  161. package/out/templator/block2nasl/transformBlock2Nasl.js.map +1 -1
  162. package/out/utils/can-i-use.d.ts.map +1 -1
  163. package/out/utils/can-i-use.js +1 -0
  164. package/out/utils/can-i-use.js.map +1 -1
  165. package/package.json +9 -9
  166. package/sandbox/stdlib/nasl.core.ts +2 -0
  167. package/sandbox/stdlib/nasl.io.ts +1 -1
  168. package/sandbox/stdlib/nasl.oql.ts +2 -0
  169. package/out/natural/genNaturalTS.d.ts.map +0 -1
  170. package/out/natural/genNaturalTS.js.map +0 -1
  171. package/out/natural/genTextualNASL.d.ts.map +0 -1
  172. package/out/natural/genTextualNASL.js.map +0 -1
  173. package/out/natural/getContext/getUILib.d.ts.map +0 -1
  174. package/out/natural/getContext/getUILib.js.map +0 -1
  175. package/out/natural/getContext/index.d.ts.map +0 -1
  176. package/out/natural/getContext/index.js.map +0 -1
  177. package/out/natural/getContext/nasl2Files.d.ts.map +0 -1
  178. package/out/natural/getContext/nasl2Files.js.map +0 -1
  179. package/out/natural/getContext/naslStdlibMap.d.ts.map +0 -1
  180. package/out/natural/getContext/naslStdlibMap.js.map +0 -1
  181. package/out/natural/parseNaturalTS.d.ts.map +0 -1
  182. package/out/natural/parseNaturalTS.js.map +0 -1
  183. package/out/natural/parseNaturalTSXView.d.ts.map +0 -1
  184. package/out/natural/parseNaturalTSXView.js.map +0 -1
  185. package/out/natural/tools.d.ts.map +0 -1
  186. package/out/natural/tools.js.map +0 -1
  187. package/out/natural/transform2BatchActions.d.ts.map +0 -1
  188. package/out/natural/transform2BatchActions.js.map +0 -1
  189. package/out/natural/transformTS2UI.d.ts.map +0 -1
  190. package/out/natural/transformTS2UI.js.map +0 -1
  191. package/out/natural/transformTSCode.d.ts.map +0 -1
  192. package/out/natural/transformTSCode.js.map +0 -1
  193. package/out/natural/transforms/checkViewElement.d.ts +0 -12
  194. package/out/natural/transforms/checkViewElement.d.ts.map +0 -1
  195. package/out/natural/transforms/checkViewElement.js +0 -143
  196. package/out/natural/transforms/checkViewElement.js.map +0 -1
  197. package/out/natural/transforms/utils.d.ts +0 -137
  198. package/out/natural/transforms/utils.d.ts.map +0 -1
  199. package/out/natural/transforms/utils.js +0 -714
  200. package/out/natural/transforms/utils.js.map +0 -1
  201. /package/out/natural/{getContext → exports}/nasl2Files.d.ts +0 -0
  202. /package/out/natural/{genTextualNASL.d.ts → old/getContext/genTextualNASL.d.ts} +0 -0
  203. /package/out/natural/{genTextualNASL.js → old/getContext/genTextualNASL.js} +0 -0
  204. /package/out/natural/{getContext → old/getContext}/naslStdlibMap.d.ts +0 -0
@@ -1,714 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.addLint = exports.validateParentConstraints = exports.parseParentAcceptDescription = exports.validateComponentFeature = exports.getComponentInfo = exports.getComponentSlot = exports.getComponentEvent = exports.getComponentProp = exports.pickDecoratorObject = exports.checkOQLCalleeNameOrder = exports.fetchFromComments = exports.handleListSort = exports.upgradeListSort = exports.replaceCallFunctionMap = exports.callFunctionMap = exports.tryParseTS = exports.throwWarning = exports.throwError = exports.ParseNaturalTSError = exports.parseNaturalTSErrorMap = exports.DEBUG = exports.generate = exports.naslTypes = exports.babelTypes = void 0;
30
- const babel = __importStar(require("@babel/core"));
31
- const babelTypes = __importStar(require("@babel/types"));
32
- exports.babelTypes = babelTypes;
33
- const naslTypes = __importStar(require("../../concepts"));
34
- exports.naslTypes = naslTypes;
35
- const generator_1 = __importDefault(require("@babel/generator"));
36
- exports.generate = generator_1.default;
37
- // Dynamic DEBUG function to allow runtime environment variable changes
38
- function DEBUG() {
39
- return process.env.NATURAL_TS_THROW_ERROR === 'true';
40
- }
41
- exports.DEBUG = DEBUG;
42
- exports.parseNaturalTSErrorMap = {};
43
- class ParseNaturalTSError extends Error {
44
- constructor(message) {
45
- super(message);
46
- this.name = 'ParseNaturalTSError';
47
- }
48
- }
49
- exports.ParseNaturalTSError = ParseNaturalTSError;
50
- /**
51
- * 抛出错误
52
- * @param message 错误信息
53
- * @param babelNode babel节点,用于便捷生成代码片段信息
54
- * @param babelNode2 babel节点,用于便捷生成代码片段信息
55
- */
56
- function throwError(state, message, babelNode, babelNode2) {
57
- if (state.nodeNamespace) {
58
- let namespaceAndName = `${state.nodeNamespace}.${state.nodeName ? state.nodeName : '*'}`;
59
- if (state.nodeName && state.appendExtName) {
60
- namespaceAndName += state.nodeNamespace.includes('.views.') ? '.tsx' : '.ts';
61
- }
62
- message += '\n**可能的位置**: ' + namespaceAndName;
63
- }
64
- if (babelNode) {
65
- let code = typeof babelNode === 'string' ? babelNode : (0, generator_1.default)(babelNode).code;
66
- const truncatedCode = code.slice(0, 1000);
67
- if (code.length > 1000) {
68
- message += '\n**相关代码片段**: ' + truncatedCode + `...(omit ${code.length - 1000} char)`;
69
- }
70
- else {
71
- message += '\n**相关代码片段**: ' + truncatedCode;
72
- }
73
- }
74
- if (babelNode2) {
75
- let code = typeof babelNode2 === 'string' ? babelNode2 : (0, generator_1.default)(babelNode2).code;
76
- const truncatedCode = code.slice(0, 1000);
77
- if (code.length > 1000) {
78
- message += '\n**更多代码片段**: ' + truncatedCode + `...(omit ${code.length - 1000} char)`;
79
- }
80
- else {
81
- message += '\n**更多代码片段**: ' + truncatedCode;
82
- }
83
- }
84
- if (!state.parsingId) {
85
- throw new ParseNaturalTSError(message);
86
- }
87
- else {
88
- const keys = Object.keys(exports.parseNaturalTSErrorMap).map(Number).sort();
89
- keys.forEach((key) => {
90
- if (state.parsingId - key > 1000 * 60 * 60)
91
- delete exports.parseNaturalTSErrorMap[key];
92
- });
93
- const errors = exports.parseNaturalTSErrorMap[state.parsingId] = exports.parseNaturalTSErrorMap[state.parsingId] || [];
94
- // 相同错误过滤:避免重复的错误信息
95
- if (!errors.includes(message)) {
96
- errors.push(message);
97
- }
98
- }
99
- }
100
- exports.throwError = throwError;
101
- /**
102
- * 抛出警告,在 DEBUG 模式下不抛出这类错误
103
- * @param message 错误信息
104
- * @param babelNode babel节点,用于便捷生成代码片段信息
105
- * @param babelNode2 babel节点,用于便捷生成代码片段信息
106
- */
107
- function throwWarning(message, babelNode, babelNode2) {
108
- if (DEBUG())
109
- return;
110
- if (babelNode) {
111
- let code = typeof babelNode === 'string' ? babelNode : (0, generator_1.default)(babelNode).code;
112
- message += ':' + code.slice(0, 1000);
113
- }
114
- if (babelNode2) {
115
- let code = typeof babelNode2 === 'string' ? babelNode2 : (0, generator_1.default)(babelNode2).code;
116
- message += '\n' + code.slice(0, 1000);
117
- }
118
- throw new Error(message);
119
- }
120
- exports.throwWarning = throwWarning;
121
- function tryParseTS(tsCode) {
122
- try {
123
- const root = babel.parseSync(tsCode, {
124
- filename: 'result.ts',
125
- presets: [require('@babel/preset-typescript')],
126
- });
127
- // console.log((root as any).program.body[0].body.body.map((item) => item.trailingComments));
128
- return root;
129
- }
130
- catch (e) {
131
- return null;
132
- }
133
- }
134
- exports.tryParseTS = tryParseTS;
135
- exports.callFunctionMap = [
136
- 'Convert',
137
- 'FormatNumber',
138
- 'FormatDateTime',
139
- 'FormatDate',
140
- 'FromString',
141
- 'ToString',
142
- 'Length',
143
- 'IndexOf',
144
- 'Join',
145
- 'LastIndexOf',
146
- 'Replace',
147
- 'Split',
148
- 'SubString',
149
- 'ToLower',
150
- 'ToUpper',
151
- 'Trim',
152
- 'CurrDate',
153
- 'CurrDateTime',
154
- 'CurrTime',
155
- 'DateDiff',
156
- 'AlterDateTime',
157
- 'GetDateCount',
158
- 'GetSpecificDaysOfWeek',
159
- 'ListAdd',
160
- 'ListAddAll',
161
- 'ListContains',
162
- 'ListInsert',
163
- 'ListDistinct',
164
- 'ListDistinctBy',
165
- 'ListFilter',
166
- 'ListFind',
167
- 'ListFindIndex',
168
- 'ListFlatten',
169
- 'ListGroupBy',
170
- 'ListHead',
171
- 'ListLast',
172
- 'ListMax',
173
- 'ListMin',
174
- 'ListReverse',
175
- 'ListSlice',
176
- 'ListSort',
177
- 'ListSum',
178
- 'ListToMap',
179
- 'ListTransform',
180
- 'ListGet',
181
- 'ListRemove',
182
- 'ListRemoveAt',
183
- 'ListSet',
184
- 'ListRange',
185
- 'ListRepeat',
186
- 'MapContains',
187
- 'MapGet',
188
- 'MapPut',
189
- 'MapKeys',
190
- 'MapRemove',
191
- 'MapValues',
192
- 'EnumToList',
193
- 'EnumItemToText',
194
- 'Round',
195
- 'Clear',
196
- 'Clone',
197
- 'HasValue',
198
- 'RandomInt',
199
- 'NewList',
200
- 'NewMap',
201
- 'NewEntity',
202
- 'NewStructure',
203
- 'NewAnonymousStructure',
204
- 'jsonSerialize',
205
- 'jsonDeserialize',
206
- "Add",
207
- "AddAll",
208
- "Contains",
209
- "Insert",
210
- "Get",
211
- "Remove",
212
- "RemoveAt",
213
- "Set",
214
- "Ceil",
215
- "Floor",
216
- "Trunc",
217
- "TruncDivide",
218
- "Abs",
219
- "Pow",
220
- "Sqrt",
221
- "Cbrt",
222
- "Log",
223
- "PadStart",
224
- "PadEnd",
225
- "TrimStart",
226
- "TrimEnd",
227
- ];
228
- exports.replaceCallFunctionMap = {
229
- "ListAdd": "Add",
230
- "ListAddAll": "AddAll",
231
- "ListContains": "Contains",
232
- "ListInsert": "Insert",
233
- "ListGet": "Get",
234
- "ListRemove": "Remove",
235
- "ListRemoveAt": "RemoveAt",
236
- "ListSet": "Set",
237
- "COUNTD": "COUNT",
238
- };
239
- function upgradeListSort(node) {
240
- const asc = node?.arguments?.[2]?.expression;
241
- const by = node?.arguments?.[1]?.expression;
242
- const newArgument = [
243
- {
244
- ...node.arguments[0]
245
- },
246
- {
247
- concept: 'Argument',
248
- keyword: 'fn1',
249
- expression: {
250
- concept: 'AnonymousFunction',
251
- body: {
252
- concept: 'NewComposite',
253
- typeAnnotation: {
254
- concept: 'TypeAnnotation',
255
- typeKind: 'anonymousStructure',
256
- properties: [
257
- {
258
- concept: 'StructureProperty',
259
- name: 'asc',
260
- typeAnnotation: {
261
- concept: 'TypeAnnotation',
262
- typeKind: 'primitive',
263
- typeNamespace: 'nasl.core',
264
- typeName: 'Boolean'
265
- }
266
- },
267
- {
268
- concept: 'StructureProperty',
269
- name: 'by',
270
- typeAnnotation: null
271
- }
272
- ]
273
- },
274
- properties: [
275
- {
276
- concept: 'Identifier',
277
- name: 'asc',
278
- folded: false,
279
- typeAnnotation: null
280
- },
281
- {
282
- concept: 'Identifier',
283
- name: 'by',
284
- folded: false,
285
- typeAnnotation: null
286
- }
287
- ],
288
- rights: [
289
- {
290
- concept: 'SelectMembers',
291
- hideMembers: false,
292
- expression: asc,
293
- members: []
294
- }
295
- ],
296
- assignmentLines: [
297
- {
298
- concept: 'AssignmentLine',
299
- leftIndex: [0, 0],
300
- rightIndex: [0]
301
- }
302
- ]
303
- },
304
- params: by?.params
305
- }
306
- }
307
- ];
308
- if (by?.body) {
309
- newArgument[1].expression.body.rights.push({
310
- concept: 'SelectMembers',
311
- hideMembers: false,
312
- expression: by.body,
313
- members: []
314
- });
315
- newArgument[1].expression.body.assignmentLines.push({
316
- concept: 'AssignmentLine',
317
- leftIndex: [0, 1],
318
- rightIndex: [1]
319
- });
320
- }
321
- node.arguments = newArgument;
322
- return node;
323
- }
324
- exports.upgradeListSort = upgradeListSort;
325
- function handleListSort(node, parseState) {
326
- const args = node?.arguments;
327
- let hasErrorArg = false;
328
- if (args?.[args?.length - 1]?.expression?.concept === 'BooleanLiteral') {
329
- if (DEBUG)
330
- return throwError(parseState, '调用 ListSort 函数需要使用最新的写法');
331
- // 老的 ListSort 结构'nasl.util.ListSort(variable1, (item) => item, true)',要升级成新的
332
- return upgradeListSort(node);
333
- }
334
- else {
335
- args?.forEach((arg, index) => {
336
- // 新的 ListSort: nasl.util.ListSort(list, (item) => ({ asc: true, by: item.name}))
337
- if (index !== 0) {
338
- const argExpression = arg?.expression;
339
- if (argExpression?.concept === 'AnonymousFunction' && argExpression?.body?.concept === 'NewComposite') {
340
- // 做下特殊处理
341
- if (argExpression?.body?.rights[1] && argExpression?.body?.rights[1]?.members[0]) {
342
- argExpression.body.rights[1].expression = argExpression?.body?.rights[1]?.members[0];
343
- argExpression.body.rights[1].members = [];
344
- argExpression.body.assignmentLines[1].rightIndex = [1];
345
- }
346
- if (!argExpression?.params?.length) {
347
- argExpression.params = [
348
- {
349
- concept: 'Param',
350
- name: 'item',
351
- typeAnnotation: null
352
- }
353
- ];
354
- }
355
- }
356
- else if (argExpression?.concept === 'SubLogic') {
357
- hasErrorArg = false;
358
- }
359
- else {
360
- hasErrorArg = true;
361
- }
362
- }
363
- });
364
- if (hasErrorArg)
365
- return null;
366
- return node;
367
- }
368
- }
369
- exports.handleListSort = handleListSort;
370
- function fetchFromComments(comments) {
371
- if (!comments || comments.length === 0)
372
- return;
373
- return comments[0].value.trim();
374
- }
375
- exports.fetchFromComments = fetchFromComments;
376
- const expectedOrder = [
377
- "FROM",
378
- "JOIN",
379
- "WHERE",
380
- "GROUP_BY",
381
- "SELECT",
382
- "HAVING",
383
- "ORDER_BY",
384
- ];
385
- function checkOQLCalleeNameOrder(calleeNames) {
386
- let currentIndex = -1;
387
- for (const name of calleeNames) {
388
- const expectedIndex = expectedOrder.findIndex((item) => name?.includes(item));
389
- if (expectedIndex === -1) {
390
- // 如果名称不在期望顺序中,返回 false
391
- return false;
392
- }
393
- if (expectedIndex < currentIndex) {
394
- // 如果当前名称的索引小于前一个名称的索引,返回 false
395
- return false;
396
- }
397
- currentIndex = expectedIndex;
398
- }
399
- return true;
400
- }
401
- exports.checkOQLCalleeNameOrder = checkOQLCalleeNameOrder;
402
- function pickDecoratorObject(objectExpression, keys, parseState) {
403
- const result = {};
404
- objectExpression.properties.forEach((item) => {
405
- if (item.type === 'ObjectProperty' && item.key.type === 'Identifier' && keys.has(item.key.name)) {
406
- let value;
407
- if (item.value.type === 'NullLiteral') {
408
- value = null;
409
- }
410
- else if (item.value.type === 'BooleanLiteral') {
411
- value = item.value.value;
412
- }
413
- else if (item.value.type === 'StringLiteral') {
414
- value = item.value.value;
415
- }
416
- else if (item.value.type === 'NumericLiteral') {
417
- value = item.value.value;
418
- }
419
- else {
420
- return throwError(parseState, '不支持的装饰器对象属性值:' + (0, generator_1.default)(item).code);
421
- }
422
- result[item.key.name] = value;
423
- }
424
- else {
425
- return throwError(parseState, '不支持的装饰器对象属性:' + (0, generator_1.default)(item).code);
426
- }
427
- });
428
- return result;
429
- }
430
- exports.pickDecoratorObject = pickDecoratorObject;
431
- /**
432
- * 检查组件是否有指定的prop配置
433
- * @param tagName 组件标签名
434
- * @param propName 属性名
435
- * @param lookupMap 查找Map
436
- * @returns 返回 true 或 false
437
- */
438
- function getComponentProp(tagName, propName, lookupMap) {
439
- const componentInfo = lookupMap.get(tagName);
440
- if (!componentInfo) {
441
- // 组件不存在不校验
442
- return true;
443
- }
444
- return !!componentInfo.propsMap.get(propName) || false;
445
- }
446
- exports.getComponentProp = getComponentProp;
447
- /**
448
- * 检查组件是否有指定的事件配置
449
- * @param tagName 组件标签名
450
- * @param eventName 事件名
451
- * @param lookupMap 查找Map
452
- * @returns 返回 true 或 false
453
- */
454
- function getComponentEvent(tagName, eventName, lookupMap) {
455
- const componentInfo = lookupMap.get(tagName);
456
- if (!componentInfo) {
457
- // 组件不存在不校验
458
- return true;
459
- }
460
- return !!componentInfo.eventsMap.get(eventName) || false;
461
- }
462
- exports.getComponentEvent = getComponentEvent;
463
- /**
464
- * 检查组件是否有指定的slot配置
465
- * @param tagName 组件标签名
466
- * @param slotName 插槽名
467
- * @param lookupMap 查找Map
468
- * @returns 返回 true 或 false
469
- */
470
- function getComponentSlot(tagName, slotName, lookupMap) {
471
- const componentInfo = lookupMap.get(tagName);
472
- if (!componentInfo) {
473
- // 组件不存在不校验
474
- return true;
475
- }
476
- return !!componentInfo.slotsMap.get(slotName) || false;
477
- }
478
- exports.getComponentSlot = getComponentSlot;
479
- /**
480
- * 获取组件的完整配置信息
481
- * @param tagName 组件标签名
482
- * @param type 查找类型
483
- * @param lookupMap 查找Map
484
- * @returns 返回组件配置或null
485
- */
486
- function getComponentInfo(tagName, lookupMap, type) {
487
- if (type === 'prop') {
488
- return lookupMap.get(tagName)?.component?.propsNames || null;
489
- }
490
- else if (type === 'event') {
491
- return lookupMap.get(tagName)?.component?.eventNames || null;
492
- }
493
- else if (type === 'slot') {
494
- return lookupMap.get(tagName)?.component?.slotNames || null;
495
- }
496
- return lookupMap.get(tagName)?.component || null;
497
- }
498
- exports.getComponentInfo = getComponentInfo;
499
- // 通用白名单
500
- const COMMON_WHITE_LIST = new Set(['_if', 'destination', 'style', 'class', 'ref', 'widthStretch', 'heightStretch']);
501
- /**
502
- * 组件特性校验函数
503
- * @param tag 组件标签名
504
- * @param featureType 特性类型
505
- * @param featureName 特性名称
506
- * @param attrName 属性名
507
- * @param options 解析状态选项
508
- * @param attr JSX属性节点
509
- */
510
- function validateComponentFeature(tag, featureType, featureName, options, attr) {
511
- if (!options?.componentsMap)
512
- return;
513
- if (COMMON_WHITE_LIST.has(featureName))
514
- return; // 在白名单中,不报错
515
- const featureMap = {
516
- event: getComponentEvent,
517
- slot: getComponentSlot,
518
- prop: getComponentProp,
519
- };
520
- const getFeatureInfo = featureMap[featureType];
521
- const hasFeature = getFeatureInfo(tag, featureName, options.componentsMap);
522
- if (!hasFeature) {
523
- const supportFeatures = getComponentInfo(tag, options.componentsMap, featureType);
524
- const featureTypeMap = {
525
- event: '事件',
526
- slot: '插槽',
527
- prop: '属性',
528
- };
529
- const typeText = featureTypeMap[featureType];
530
- const prefix = featureType === 'slot' ? '插槽有:' : featureType === 'prop' ? '属性有:' : '事件列表如下:';
531
- // 非严格模式下
532
- if (!options.strictForTraining) {
533
- // 白名单检查:某些特定组件的特定属性不进行验证
534
- if (featureType === 'prop') {
535
- const propWhitelist = new Set(['el-table-column:width']);
536
- const whitelistKey = `${tag}:${featureName}`;
537
- if (propWhitelist.has(whitelistKey)) {
538
- return; // 在白名单中,不报错
539
- }
540
- }
541
- }
542
- let explain = '';
543
- if (featureType === 'prop' && ['title', 'label'].includes(featureName)) {
544
- explain = `, 可能需要使用 slot${naslTypes.firstUpperCase(featureName)}`;
545
- }
546
- return throwError(options, `组件 ${tag} 不支持${typeText} ${featureName},当前支持的${prefix}${supportFeatures}${explain}`, attr);
547
- }
548
- }
549
- exports.validateComponentFeature = validateComponentFeature;
550
- /**
551
- * 解析 parentAccept 表达式,生成友好的错误描述
552
- * @param parentAccept parentAccept 表达式字符串
553
- * @returns 友好的错误描述字符串
554
- */
555
- function parseParentAcceptDescription(parentAccept) {
556
- try {
557
- // 处理数组的 includes 方法:['el-table'].includes(target.tag)
558
- const arrayIncludesMatch = parentAccept.match(/\[([^\]]+)\]\.includes\(target\.tag\)/);
559
- if (arrayIncludesMatch) {
560
- const items = arrayIncludesMatch[1]
561
- .split(',')
562
- .map((item) => item.trim().replace(/['"]/g, ''))
563
- .filter(Boolean);
564
- return items.join(' 或 ');
565
- }
566
- // 处理单个 endsWith:target.tag.endsWith('el-select')
567
- const endsWithMatch = parentAccept.match(/target\.tag\.endsWith\(['"]([^'"]*)['"]\)/);
568
- if (endsWithMatch && !parentAccept.includes('||')) {
569
- return `以 ${endsWithMatch[1]} 结尾的组件`;
570
- }
571
- // 处理多个条件用 || 连接的情况
572
- if (parentAccept.includes('||')) {
573
- const conditions = parentAccept.split('||').map((condition) => condition.trim());
574
- const tags = [];
575
- for (const condition of conditions) {
576
- // 精确匹配:target.tag === 'el-menu'
577
- const exactMatch = condition.match(/target\.tag\s*===\s*['"]([^'"]*)['"]/);
578
- if (exactMatch) {
579
- tags.push(exactMatch[1]);
580
- continue;
581
- }
582
- // endsWith 匹配:target.tag.endsWith('el-select')
583
- const endsWithMatch = condition.match(/target\.tag\.endsWith\(['"]([^'"]*)['"]\)/);
584
- if (endsWithMatch) {
585
- tags.push(`以 ${endsWithMatch[1]} 结尾的组件`);
586
- continue;
587
- }
588
- // 如果无法解析,添加通用描述
589
- tags.push('符合条件的组件');
590
- }
591
- return tags.join(' 或 ');
592
- }
593
- // 处理单个精确匹配:target.tag === 'el-carousel'
594
- const exactMatch = parentAccept.match(/target\.tag\s*===\s*['"]([^'"]*)['"]/);
595
- if (exactMatch) {
596
- return exactMatch[1];
597
- }
598
- // 处理 includes 方法但不是数组形式
599
- if (parentAccept.includes('includes(target.tag)')) {
600
- return '指定列表中的组件';
601
- }
602
- // 兜底返回通用描述
603
- return '符合条件的父组件';
604
- }
605
- catch (error) {
606
- return '符合条件的父组件';
607
- }
608
- }
609
- exports.parseParentAcceptDescription = parseParentAcceptDescription;
610
- // 表单组件变形映射表
611
- const formComponentMap = {
612
- 'el-input': 'el-form-input',
613
- 'el-select': 'el-form-select',
614
- 'el-cascader': 'el-form-cascader',
615
- 'el-checkbox-group': 'el-form-checkbox-group',
616
- 'el-input-number': 'el-form-input-number',
617
- 'el-input-tag': 'el-form-input-tag',
618
- 'el-rate': 'el-form-rate',
619
- 'el-switch': 'el-form-switch',
620
- 'el-tree-select': 'el-form-tree-select',
621
- 'el-slider': 'el-form-slider',
622
- 'el-upload': 'el-form-upload',
623
- 'el-time-picker': 'el-form-time-picker',
624
- 'el-time-select': 'el-form-time-select',
625
- 'el-mention': 'el-form-mention',
626
- 'el-date-picker': 'el-form-date-picker',
627
- 'el-transfer': 'el-form-transfer',
628
- 'el-radio-group': 'el-form-radio-group',
629
- };
630
- // 反向映射表,用于从表单组件名获取原始组件名
631
- const reverseFormComponentMap = {};
632
- Object.entries(formComponentMap).forEach(([original, form]) => {
633
- reverseFormComponentMap[form] = original;
634
- });
635
- /**
636
- * 验证父组件约束
637
- * @param tag 当前组件标签
638
- * @param options 解析状态选项
639
- * @param node JSX节点
640
- * @returns 如果违反约束则返回错误,否则返回 undefined
641
- */
642
- function validateParentConstraints(tag, options, node) {
643
- // 检查组件库中的父组件约束
644
- if (options.componentsMap) {
645
- const componentInfo = getComponentInfo(tag, options.componentsMap);
646
- const parentAccept = componentInfo?.ideusage?.parentAccept;
647
- if (parentAccept && parentAccept?.includes('target.tag')) {
648
- const parentTag = options.parentTag;
649
- try {
650
- // 创建验证函数来检查父组件是否符合要求
651
- const createValidator = (expression, actualParentTag) => {
652
- // 将所有 target.tag 替换为实际的父组件标签
653
- const code = expression.replace(/target\.tag/g, JSON.stringify(actualParentTag || ''));
654
- // 使用 Function 构造器创建验证函数
655
- return new Function('return ' + code)();
656
- };
657
- let isValidParent = false;
658
- let actualParentTag = parentTag;
659
- if (parentTag) {
660
- // 首先尝试用原始父组件标签验证
661
- isValidParent = createValidator(parentAccept, parentTag);
662
- // 如果验证失败,尝试使用对应的表单组件或原始组件进行验证
663
- if (!isValidParent) {
664
- // 如果当前父组件是表单组件,尝试用对应的原始组件验证
665
- if (reverseFormComponentMap[parentTag]) {
666
- const originalParentTag = reverseFormComponentMap[parentTag];
667
- isValidParent = createValidator(parentAccept, originalParentTag);
668
- if (isValidParent) {
669
- actualParentTag = originalParentTag;
670
- }
671
- }
672
- // 如果当前父组件是原始组件,尝试用对应的表单组件验证
673
- else if (formComponentMap[parentTag]) {
674
- const formParentTag = formComponentMap[parentTag];
675
- isValidParent = createValidator(parentAccept, formParentTag);
676
- if (isValidParent) {
677
- actualParentTag = formParentTag;
678
- }
679
- }
680
- }
681
- }
682
- else {
683
- isValidParent = false;
684
- }
685
- if (parentTag && !isValidParent) {
686
- // 解析 parentAccept 来生成更友好的错误信息
687
- const expectedDescription = parseParentAcceptDescription(parentAccept);
688
- return throwError(options, `组件 ${tag} 必须放在 ${expectedDescription} 内部,但当前父组件是 ${parentTag}`, node);
689
- }
690
- else if (!parentTag) {
691
- return throwError(options, `组件 ${tag} 必须放在指定的父组件内部`, node);
692
- }
693
- }
694
- catch (error) {
695
- console.log(`组件 ${tag} 的 parentAccept 表达式无效: ${parentAccept}`);
696
- }
697
- }
698
- }
699
- }
700
- exports.validateParentConstraints = validateParentConstraints;
701
- /**
702
- * 在 strictForTraining 模式下执行 lint 检查逻辑
703
- * 当 options.strictForTraining 为 true 时,执行传入的检查函数
704
- * @param rule LintRule 对象,包含 name 和可选的 description
705
- * @param options 解析状态选项
706
- * @param lintFn 需要执行的 lint 检查函数
707
- */
708
- function addLint(options, rule, lintFn) {
709
- if (options.strictForTraining) {
710
- lintFn(rule);
711
- }
712
- }
713
- exports.addLint = addLint;
714
- //# sourceMappingURL=utils.js.map