@lcap/nasl 2.18.0-beta.5 → 2.18.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/out/common/BaseNode.js +1 -0
  2. package/out/common/BaseNode.js.map +1 -1
  3. package/out/concepts/BatchAssignment__.js +63 -46
  4. package/out/concepts/BatchAssignment__.js.map +1 -1
  5. package/out/concepts/CallLogic__.d.ts +2 -1
  6. package/out/concepts/CallLogic__.js +26 -11
  7. package/out/concepts/CallLogic__.js.map +1 -1
  8. package/out/concepts/Destination__.d.ts +2 -1
  9. package/out/concepts/Destination__.js +90 -22
  10. package/out/concepts/Destination__.js.map +1 -1
  11. package/out/concepts/Logic__.js +6 -7
  12. package/out/concepts/Logic__.js.map +1 -1
  13. package/out/concepts/MatchExpression__.d.ts +97 -0
  14. package/out/concepts/MatchExpression__.js +281 -0
  15. package/out/concepts/MatchExpression__.js.map +1 -0
  16. package/out/concepts/ViewElement__.js +1 -1
  17. package/out/concepts/ViewElement__.js.map +1 -1
  18. package/out/concepts/View__.js +4 -0
  19. package/out/concepts/View__.js.map +1 -1
  20. package/out/generator/genBundleFiles.js +32 -182
  21. package/out/generator/genBundleFiles.js.map +1 -1
  22. package/out/generator/genMetaData.d.ts +1 -10
  23. package/out/generator/genMetaData.js +189 -50
  24. package/out/generator/genMetaData.js.map +1 -1
  25. package/out/generator/genReleaseBody.js +11 -2
  26. package/out/generator/genReleaseBody.js.map +1 -1
  27. package/out/server/extendBaseNode.js +4 -18
  28. package/out/server/extendBaseNode.js.map +1 -1
  29. package/out/server/formatTsUtils.d.ts +1 -2
  30. package/out/server/formatTsUtils.js +30 -47
  31. package/out/server/formatTsUtils.js.map +1 -1
  32. package/out/server/getProcesses.js +1 -1
  33. package/out/server/getProcesses.js.map +1 -1
  34. package/out/server/naslServer.js +8 -7
  35. package/out/server/naslServer.js.map +1 -1
  36. package/out/server/translator.js +19 -4
  37. package/out/server/translator.js.map +1 -1
  38. package/out/templator/sql-parser/index.d.ts +1 -0
  39. package/out/templator/sql-parser/index.js +228 -0
  40. package/out/templator/sql-parser/index.js.map +1 -0
  41. package/out/templator/sql-parser/parser.js +26664 -0
  42. package/out/templator/sql-parser/parser.js.map +1 -0
  43. package/package.json +2 -2
  44. package/sandbox/stdlib/dist/nasl.logging.js +0 -0
  45. package/sandbox/stdlib/nasl.util.ts +1 -1
  46. package/src/automate/engine/dist/index.dev.js +517 -0
  47. package/src/common/BaseNode.ts +1 -0
  48. package/src/common/dist/BaseNode.js +1101 -0
  49. package/src/concepts/BatchAssignment__.ts +66 -50
  50. package/src/concepts/CallLogic__.ts +26 -11
  51. package/src/concepts/Destination__.ts +92 -22
  52. package/src/concepts/Logic__.ts +6 -7
  53. package/src/concepts/ViewElement__.ts +8 -29
  54. package/src/concepts/View__.ts +4 -0
  55. package/src/concepts/basics/stdlib/dist/nasl.util.js +1503 -0
  56. package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +24 -0
  57. package/src/concepts/dist/Anchor__.js +179 -0
  58. package/src/concepts/dist/Assignment__.js +301 -0
  59. package/src/concepts/dist/CallFunction__.js +513 -0
  60. package/src/concepts/dist/CallInterface__.js +533 -0
  61. package/src/concepts/dist/CallLogic__.js +892 -0
  62. package/src/concepts/dist/ForEachStatement__.js +426 -0
  63. package/src/concepts/dist/MatchCase__.js +587 -0
  64. package/src/concepts/dist/Match__.js +631 -0
  65. package/src/concepts/dist/MemberExpression__.js +348 -0
  66. package/src/concepts/dist/Param__.js +538 -0
  67. package/src/concepts/dist/Return__.js +494 -0
  68. package/src/concepts/dist/Variable__.js +537 -0
  69. package/src/concepts/dist/ViewElement__.js +1680 -0
  70. package/src/generator/dist/genBundleFiles.js +261 -0
  71. package/src/generator/dist/genMetaData.js +249 -0
  72. package/src/generator/genBundleFiles.ts +34 -219
  73. package/src/generator/genMetaData.ts +182 -77
  74. package/src/generator/genReleaseBody.ts +10 -3
  75. package/src/server/dist/formatTsUtils.js +683 -0
  76. package/src/server/dist/naslServer.js +3474 -0
  77. package/src/server/extendBaseNode.ts +4 -19
  78. package/src/server/formatTsUtils.ts +30 -46
  79. package/src/server/getProcesses.ts +1 -1
  80. package/src/server/naslServer.ts +8 -7
  81. package/src/server/translator.ts +18 -4
  82. package/src/service/storage/dist/init.js +572 -0
  83. package/ts-worker/dist/webpack.config.dev.js +108 -0
  84. package/dist/bundle.js +0 -3962
  85. package/dist/bundle.js.LICENSE.txt +0 -16
  86. package/out/generator/release.d.ts +0 -1
  87. package/out/generator/release.js +0 -51
  88. package/out/generator/release.js.map +0 -1
@@ -0,0 +1,631 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __assign = (this && this.__assign) || function () {
16
+ __assign = Object.assign || function(t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
+ t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
27
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
28
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
29
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
30
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
31
+ };
32
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
33
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
+ return new (P || (P = Promise))(function (resolve, reject) {
35
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
39
+ });
40
+ };
41
+ var __generator = (this && this.__generator) || function (thisArg, body) {
42
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
43
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
44
+ function verb(n) { return function (v) { return step([n, v]); }; }
45
+ function step(op) {
46
+ if (f) throw new TypeError("Generator is already executing.");
47
+ while (_) try {
48
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
49
+ if (y = 0, t) op = [op[0] & 2, t.value];
50
+ switch (op[0]) {
51
+ case 0: case 1: t = op; break;
52
+ case 4: _.label++; return { value: op[1], done: false };
53
+ case 5: _.label++; y = op[1]; op = [0]; continue;
54
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
55
+ default:
56
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
57
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
58
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
59
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
60
+ if (t[2]) _.ops.pop();
61
+ _.trys.pop(); continue;
62
+ }
63
+ op = body.call(thisArg, _);
64
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
65
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
66
+ }
67
+ };
68
+ exports.__esModule = true;
69
+ exports.Match = void 0;
70
+ var translator_1 = require("../translator");
71
+ var TypeAnnotation__1 = require("./TypeAnnotation__");
72
+ var BooleanLiteral__1 = require("./BooleanLiteral__");
73
+ var MemberExpression__1 = require("./MemberExpression__");
74
+ var getMemberIdentifier_1 = require("../server/getMemberIdentifier");
75
+ var Identifier__1 = require("./Identifier__");
76
+ var decorators_1 = require("../decorators");
77
+ var classMap_1 = require("../common/classMap");
78
+ var LogicItem__1 = require("./LogicItem__");
79
+ var MatchCase__1 = require("./MatchCase__");
80
+ /**
81
+ * 匹配
82
+ */
83
+ var Match = /** @class */ (function (_super) {
84
+ __extends(Match, _super);
85
+ /**
86
+ * @param source 需要合并的部分参数
87
+ */
88
+ function Match(source) {
89
+ var _this = this;
90
+ source = Object.assign({}, Match_1.getDefaultOptions(), source);
91
+ _this = _super.call(this, source) || this;
92
+ /**
93
+ * 产品概念
94
+ */
95
+ _this.concept = 'Match';
96
+ /**
97
+ * 逻辑项
98
+ */
99
+ _this.expression = undefined;
100
+ /**
101
+ * 是否表达式形态
102
+ */
103
+ _this.isExpression = false;
104
+ /**
105
+ * 匹配分支列表
106
+ */
107
+ _this.cases = [];
108
+ _super.prototype.subConstructor.call(_this, source);
109
+ return _this;
110
+ }
111
+ Match_1 = Match;
112
+ Match.from = function (source, parentNode, parentKey) {
113
+ return _super.from.call(this, source, parentNode, parentKey);
114
+ };
115
+ Match.prototype._insertMatchCaseAt = function (options, index) {
116
+ var matchCaseOptions = {};
117
+ var relationOptions = { parentNode: this, parentKey: 'cases' };
118
+ var matchCase;
119
+ if (options instanceof MatchCase__1["default"]) {
120
+ options.ensureDelete(); // 同一实例不支持多处存在
121
+ matchCase = options;
122
+ Object.assign(matchCase, relationOptions);
123
+ }
124
+ else {
125
+ matchCase = MatchCase__1["default"].from(__assign(__assign({}, matchCaseOptions), options), this, 'cases');
126
+ }
127
+ this.cases.splice(index, 0, matchCase);
128
+ return matchCase;
129
+ };
130
+ Match.prototype.insertMatchCaseAt = function (options, index) {
131
+ var node = this._insertMatchCaseAt(options, index);
132
+ node.create({
133
+ index: index,
134
+ parentNode: this,
135
+ parentKey: 'cases'
136
+ });
137
+ return node;
138
+ };
139
+ Match.prototype._addMatchCase = function (options) {
140
+ var index = this.cases.length;
141
+ return this._insertMatchCaseAt(options, index);
142
+ };
143
+ Match.prototype.addMatchCase = function (options) {
144
+ var node = this._addMatchCase(options);
145
+ var index = this.cases.indexOf(node);
146
+ node.create({
147
+ index: index,
148
+ parentNode: this,
149
+ parentKey: 'cases'
150
+ });
151
+ return node;
152
+ };
153
+ Match.prototype.removeExpression = function (options) {
154
+ var expression;
155
+ if (typeof options === 'string') {
156
+ expression = this.expression;
157
+ if (!expression) {
158
+ throw new Error('找不到逻辑项 ' + options);
159
+ }
160
+ }
161
+ else {
162
+ expression = options;
163
+ }
164
+ return expression["delete"]();
165
+ };
166
+ Match.prototype.removeMatchCaseInCases = function (options) {
167
+ var matchCase = options;
168
+ return matchCase["delete"]();
169
+ };
170
+ Match.prototype.__removeLogicItem = function (logicItem) {
171
+ var parentKey = logicItem.parentKey;
172
+ var params = {
173
+ parentNode: this,
174
+ parentKey: parentKey,
175
+ index: -1,
176
+ object: null,
177
+ oldObject: logicItem
178
+ };
179
+ if (parentKey) {
180
+ params.parentKey = parentKey;
181
+ if (Array.isArray(this[parentKey])) {
182
+ var index = this[parentKey].indexOf(logicItem);
183
+ ~index && this[parentKey].splice(index, 1);
184
+ params.index = index;
185
+ }
186
+ else if (this[parentKey] === logicItem) {
187
+ params.index = 0;
188
+ this[parentKey] = undefined;
189
+ }
190
+ }
191
+ return params;
192
+ };
193
+ Object.defineProperty(Match.prototype, "isEnumerable", {
194
+ get: function () {
195
+ var _a;
196
+ return !!((_a = this.enumerableItems) === null || _a === void 0 ? void 0 : _a.length);
197
+ },
198
+ enumerable: false,
199
+ configurable: true
200
+ });
201
+ Match.prototype.cacheStatus = function () {
202
+ return __awaiter(this, void 0, void 0, function () {
203
+ var _a;
204
+ return __generator(this, function (_b) {
205
+ switch (_b.label) {
206
+ case 0:
207
+ console.log(111);
208
+ _a = this;
209
+ return [4 /*yield*/, this.getEnumerableItems()];
210
+ case 1:
211
+ _a.enumerableItems = _b.sent();
212
+ console.log(222);
213
+ return [2 /*return*/];
214
+ }
215
+ });
216
+ });
217
+ };
218
+ Object.defineProperty(Match.prototype, "canAddCase", {
219
+ /**
220
+ * 是否允许新建case
221
+ */
222
+ get: function () {
223
+ var cases = this === null || this === void 0 ? void 0 : this.cases;
224
+ if (Array.isArray(cases) && cases.length > 1) {
225
+ var enumerableItems = this.enumerableItems;
226
+ if (Array.isArray(enumerableItems)) {
227
+ var map_1 = {};
228
+ cases.forEach(function (caseItem) {
229
+ var patterns = (caseItem || {}).patterns;
230
+ if (Array.isArray(patterns)) {
231
+ patterns.forEach(function (pattern) {
232
+ if (pattern instanceof TypeAnnotation__1["default"]) {
233
+ var patternTypeKey = pattern.typeKey;
234
+ map_1[patternTypeKey] = true;
235
+ }
236
+ else if (pattern instanceof MemberExpression__1["default"] || pattern instanceof BooleanLiteral__1["default"]) {
237
+ var patternValue = pattern.getValue();
238
+ map_1[patternValue] = true;
239
+ }
240
+ });
241
+ }
242
+ });
243
+ var enumerableKeys = Object.keys(map_1);
244
+ if (enumerableKeys.length === enumerableItems.length) {
245
+ return false;
246
+ }
247
+ }
248
+ }
249
+ return true;
250
+ },
251
+ enumerable: false,
252
+ configurable: true
253
+ });
254
+ // 获取可枚举项
255
+ Match.prototype.getEnumerableItems = function (typeAnnotation) {
256
+ return __awaiter(this, void 0, void 0, function () {
257
+ var expression, currTypeAnnotation, _a, typeKind, typeNamespace, typeName, typeArguments, nameArr, typeNode, enums, children;
258
+ return __generator(this, function (_b) {
259
+ switch (_b.label) {
260
+ case 0:
261
+ expression = this.expression;
262
+ currTypeAnnotation = typeAnnotation;
263
+ if (!!currTypeAnnotation) return [3 /*break*/, 2];
264
+ return [4 /*yield*/, (expression === null || expression === void 0 ? void 0 : expression.getCurrentTypeAnnotation())];
265
+ case 1:
266
+ currTypeAnnotation = _b.sent();
267
+ _b.label = 2;
268
+ case 2:
269
+ _a = currTypeAnnotation || {}, typeKind = _a.typeKind, typeNamespace = _a.typeNamespace, typeName = _a.typeName, typeArguments = _a.typeArguments;
270
+ if (typeKind === 'union' && Array.isArray(typeArguments)) {
271
+ return [2 /*return*/, typeArguments.map(function (typeArg) {
272
+ var typeArgJson = typeArg;
273
+ if (typeArg instanceof TypeAnnotation__1["default"]) {
274
+ typeArgJson = typeArg.toJSON();
275
+ }
276
+ return new TypeAnnotation__1["default"](typeArgJson);
277
+ })];
278
+ }
279
+ else if (typeKind === 'reference') {
280
+ nameArr = [typeName];
281
+ if (typeNamespace) {
282
+ nameArr.unshift(typeNamespace);
283
+ }
284
+ typeNode = this.app.findNodeByCompleteName(nameArr.join('.')) || {};
285
+ if (typeNode.concept === 'Enum') {
286
+ enums = getMemberIdentifier_1.formatEnums([typeNode]);
287
+ children = ((enums === null || enums === void 0 ? void 0 : enums[0]) || {}).children;
288
+ if (Array.isArray(children)) {
289
+ return [2 /*return*/, children.map(function (child) { return child === null || child === void 0 ? void 0 : child.expression; })];
290
+ }
291
+ }
292
+ }
293
+ else if (typeKind === 'primitive' && typeNamespace === 'nasl.core' && typeName === 'Boolean') {
294
+ return [2 /*return*/, [
295
+ new BooleanLiteral__1["default"]({
296
+ value: 'true'
297
+ }),
298
+ new BooleanLiteral__1["default"]({
299
+ value: 'false'
300
+ }),
301
+ ]];
302
+ }
303
+ return [2 /*return*/];
304
+ }
305
+ });
306
+ });
307
+ };
308
+ Match.prototype.setIsExpression = function (isExpression) {
309
+ var object = {
310
+ isExpression: isExpression
311
+ };
312
+ this.update(__assign({}, object));
313
+ };
314
+ /**
315
+ * 设置逻辑项
316
+ */
317
+ Match.prototype.setExpression = function (expression) {
318
+ if (expression) {
319
+ expression._delete();
320
+ var relationOptions = { parentNode: this, parentKey: 'expression' };
321
+ Object.assign(expression, relationOptions);
322
+ }
323
+ var object = {
324
+ expression: expression
325
+ };
326
+ this.update(__assign({}, object));
327
+ };
328
+ // 设置 expression ,如果 expression 是可枚举类型,加上默认匹配条件
329
+ Match.prototype.setExpressionWitchCase = function (expression) {
330
+ var _a;
331
+ return __awaiter(this, void 0, void 0, function () {
332
+ return __generator(this, function (_b) {
333
+ switch (_b.label) {
334
+ case 0:
335
+ this.app.emit('collect:start', {
336
+ actionMsg: "\u4FEE\u6539" + ((this === null || this === void 0 ? void 0 : this.name) || (this === null || this === void 0 ? void 0 : this.label) || ((_a = this === null || this === void 0 ? void 0 : this.constructor) === null || _a === void 0 ? void 0 : _a.nodeTitle))
337
+ });
338
+ this.setExpression(expression);
339
+ // expression切换并且自动生成分支
340
+ return [4 /*yield*/, this.autoGenCases()];
341
+ case 1:
342
+ // expression切换并且自动生成分支
343
+ _b.sent();
344
+ this.app.emit('collect:end');
345
+ return [2 /*return*/];
346
+ }
347
+ });
348
+ });
349
+ };
350
+ // 自动生成分支
351
+ Match.prototype.autoGenCases = function () {
352
+ return __awaiter(this, void 0, void 0, function () {
353
+ var expression, currTypeAnnotation, cases, isMatchedTypeEnumable, enumerableItems, bodys;
354
+ return __generator(this, function (_a) {
355
+ switch (_a.label) {
356
+ case 0:
357
+ expression = this.expression;
358
+ console.log(222);
359
+ return [4 /*yield*/, (expression === null || expression === void 0 ? void 0 : expression.getCurrentTypeAnnotation())];
360
+ case 1:
361
+ currTypeAnnotation = _a.sent();
362
+ console.log(333);
363
+ cases = [];
364
+ isMatchedTypeEnumable = false;
365
+ if (!currTypeAnnotation) return [3 /*break*/, 3];
366
+ cases = [new MatchCase__1["default"]()];
367
+ console.log(333);
368
+ return [4 /*yield*/, this.getEnumerableItems()];
369
+ case 2:
370
+ enumerableItems = _a.sent();
371
+ console.log(333);
372
+ if (Array.isArray(enumerableItems) && enumerableItems.length) {
373
+ isMatchedTypeEnumable = true;
374
+ cases = enumerableItems.map(function (enumerableItem) { return new MatchCase__1["default"]({
375
+ patterns: [enumerableItem],
376
+ isMatchedTypeEnumable: isMatchedTypeEnumable
377
+ }); });
378
+ }
379
+ _a.label = 3;
380
+ case 3:
381
+ bodys = [];
382
+ if (Array.isArray(this.cases) && this.cases.length) {
383
+ this.cases.forEach(function (caseItem) {
384
+ var body = (caseItem || {}).body;
385
+ if (Array.isArray(body) && body.length) {
386
+ bodys.push({
387
+ body: body,
388
+ isMatchedTypeEnumable: currTypeAnnotation ? isMatchedTypeEnumable : true
389
+ });
390
+ }
391
+ });
392
+ bodys.forEach(function (_a, index) {
393
+ var body = _a.body, isMatchedTypeEnumable = _a.isMatchedTypeEnumable;
394
+ var caseItem = cases[index];
395
+ if (!caseItem) {
396
+ caseItem = new MatchCase__1["default"]({
397
+ isMatchedTypeEnumable: isMatchedTypeEnumable
398
+ });
399
+ cases.push(caseItem);
400
+ }
401
+ caseItem.update({
402
+ body: body
403
+ });
404
+ });
405
+ }
406
+ if (cases.length) {
407
+ cases.push(new MatchCase__1["default"]());
408
+ }
409
+ this.update({
410
+ cases: cases
411
+ });
412
+ return [2 /*return*/];
413
+ }
414
+ });
415
+ });
416
+ };
417
+ Match.getDefaultOptions = function () {
418
+ return {
419
+ label: '匹配'
420
+ };
421
+ };
422
+ Match.prototype.isTypeMatching = function () {
423
+ return __awaiter(this, void 0, void 0, function () {
424
+ var typeAnnotation, _a, typeKind, typeArguments;
425
+ return __generator(this, function (_b) {
426
+ switch (_b.label) {
427
+ case 0:
428
+ if (!this.expression) return [3 /*break*/, 2];
429
+ return [4 /*yield*/, this.expression.getCurrentTypeAnnotation()];
430
+ case 1:
431
+ typeAnnotation = _b.sent();
432
+ _a = typeAnnotation || {}, typeKind = _a.typeKind, typeArguments = _a.typeArguments;
433
+ if (typeKind === 'union' && Array.isArray(typeArguments)) {
434
+ return [2 /*return*/, true];
435
+ }
436
+ _b.label = 2;
437
+ case 2: return [2 /*return*/, false];
438
+ }
439
+ });
440
+ });
441
+ };
442
+ Object.defineProperty(Match.prototype, "inViewName", {
443
+ // 获取在页面中的名字
444
+ get: function () {
445
+ var nameList = [];
446
+ var node = this;
447
+ while (node) {
448
+ if (node === this) {
449
+ nameList.unshift('viewMatchExpression');
450
+ }
451
+ else {
452
+ nameList.unshift(node.name);
453
+ }
454
+ if (node.concept === 'ViewElement') {
455
+ node = null;
456
+ }
457
+ else {
458
+ nameList.unshift(node.parentKey);
459
+ node = node.parentNode;
460
+ }
461
+ }
462
+ return nameList.join('_').replace(/-/g, '_');
463
+ },
464
+ enumerable: false,
465
+ configurable: true
466
+ });
467
+ Match.prototype.getViewMatchExpressionBuilder = function () {
468
+ return "gen" + this.inViewName;
469
+ };
470
+ Match.prototype.getInViewMethod = function (state) {
471
+ var _this = this;
472
+ var viewElement = this === null || this === void 0 ? void 0 : this.getAncestor('ViewElement');
473
+ var argsList = [];
474
+ var parent = viewElement === null || viewElement === void 0 ? void 0 : viewElement.parentNode;
475
+ var index = 0;
476
+ while (parent && parent.concept !== 'View') {
477
+ if (parent.slotScope) {
478
+ argsList.unshift(index === 0 ? 'current' : 'current' + index);
479
+ index++;
480
+ }
481
+ parent = parent.parentNode;
482
+ }
483
+ var code = '';
484
+ code += this.getViewMatchExpressionBuilder() + " (" + argsList.join(', ') + ") {\n";
485
+ if (this.expression && Array.isArray(this.cases)) {
486
+ this.cases.forEach(function (item, index) {
487
+ var _a;
488
+ code += (_a = item === null || item === void 0 ? void 0 : item.toJS) === null || _a === void 0 ? void 0 : _a.call(item, _this.expression, index, _this.cases.length);
489
+ });
490
+ }
491
+ code += ";\n";
492
+ code += '}';
493
+ return code;
494
+ };
495
+ Match.prototype.onChange = function ($event) {
496
+ var _a, _b;
497
+ var _c = $event || {}, action = _c.action, object = _c.object, eventList = _c.eventList;
498
+ // expression修改时,通知tsserver,让tsserver重新生成ts文件,为了后续能获取expression的类型
499
+ if (action === 'update' && object.hasOwnProperty('expression')) {
500
+ (_b = (_a = this.app) === null || _a === void 0 ? void 0 : _a.naslServer) === null || _b === void 0 ? void 0 : _b.embeddedTSEmitter.emit('change', {
501
+ value: eventList
502
+ });
503
+ }
504
+ this.emit('change', $event);
505
+ };
506
+ Match.prototype.toVue = function (state) {
507
+ if ((state === null || state === void 0 ? void 0 : state.finalCode) === false) {
508
+ return this.toUI();
509
+ }
510
+ else {
511
+ var viewElement = this === null || this === void 0 ? void 0 : this.getAncestor('ViewElement');
512
+ var argsList = [];
513
+ var parent = viewElement === null || viewElement === void 0 ? void 0 : viewElement.parentNode;
514
+ var index = 0;
515
+ while (parent && parent.concept !== 'View') {
516
+ if (parent.slotScope) {
517
+ argsList.unshift(index === 0 ? 'current' : 'current' + index);
518
+ index++;
519
+ }
520
+ parent = parent.parentNode;
521
+ }
522
+ return this.getViewMatchExpressionBuilder() + "(" + argsList.join(', ') + ")";
523
+ }
524
+ };
525
+ Match.prototype.toUI = function (state) {
526
+ var _a, _b;
527
+ var code = '匹配 ';
528
+ if (this.expression) {
529
+ code += (_b = (_a = this.expression).toUI) === null || _b === void 0 ? void 0 : _b.call(_a);
530
+ }
531
+ if (Array.isArray(this.cases)) {
532
+ code += ' { ';
533
+ this.cases.forEach(function (item, index) {
534
+ var _a;
535
+ code += (_a = item === null || item === void 0 ? void 0 : item.toUI) === null || _a === void 0 ? void 0 : _a.call(item);
536
+ });
537
+ code += '}';
538
+ }
539
+ return code;
540
+ };
541
+ Match.prototype.toJS = function (state) {
542
+ var _this = this;
543
+ var code = 'await (async () => {\n';
544
+ if (this.expression && Array.isArray(this.cases)) {
545
+ this.cases.forEach(function (item, index) {
546
+ var _a;
547
+ code += (_a = item === null || item === void 0 ? void 0 : item.toJS) === null || _a === void 0 ? void 0 : _a.call(item, _this.expression, index, _this.cases.length);
548
+ });
549
+ }
550
+ code += "})()";
551
+ return code;
552
+ };
553
+ Match.prototype.toEmbeddedTS = function (state) {
554
+ var code = '';
555
+ if (this.parentNode.concept === 'Logic') {
556
+ code += '\n';
557
+ }
558
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0));
559
+ code += '(() => { \n';
560
+ var parentCode;
561
+ if (this.expression) {
562
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0));
563
+ // Identifier会使用自己本身的类型,来推导,因为右侧放的内容关系关系到内部类型推断
564
+ if ((this.expression instanceof Identifier__1["default"]) || (this.expression instanceof MemberExpression__1["default"])) {
565
+ code += parentCode = this.expression.toEmbeddedTS(translator_1.shiftState(state, code));
566
+ }
567
+ else {
568
+ parentCode = '__matchExpression';
569
+ code += "let " + parentCode + " = ";
570
+ code += this.expression.toEmbeddedTS(translator_1.shiftState(state, code));
571
+ }
572
+ code += ';\n';
573
+ }
574
+ else {
575
+ code += '__IDENTIFIER__;\n';
576
+ }
577
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) + 1 || 0));
578
+ code += ' function __MatchExpressionFuntion() {\n';
579
+ // 最后一项是else
580
+ this.cases.forEach(function (item, index) {
581
+ // 如果是最后一项
582
+ code += item.toEmbeddedTS(translator_1.shiftState(state, code, { tabSize: ((state === null || state === void 0 ? void 0 : state.tabSize) || 0) }), index, parentCode);
583
+ });
584
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0));
585
+ code += '};\n';
586
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0));
587
+ code += 'return __MatchExpressionFuntion();\n';
588
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0));
589
+ code += '})()';
590
+ if (this.parentNode.concept !== 'Argument'
591
+ && this.parentKey !== 'test'
592
+ && this.parentKey !== 'patterns'
593
+ && this.parentNode.concept !== 'Assignment'
594
+ && this.parentNode.concept !== 'ForEachStatement'
595
+ && this.parentNode.concept !== 'SelectMembers'
596
+ && this.parentNode.concept !== 'BinaryExpression'
597
+ && this.parentNode.concept !== 'StringInterpolation'
598
+ && this.parentNode.concept !== 'MemberExpression') {
599
+ code += ';\n';
600
+ }
601
+ return code;
602
+ };
603
+ var Match_1;
604
+ __decorate([
605
+ decorators_1.property()
606
+ ], Match.prototype, "concept");
607
+ __decorate([
608
+ decorators_1.property('LogicItem')
609
+ ], Match.prototype, "expression");
610
+ __decorate([
611
+ decorators_1.property()
612
+ ], Match.prototype, "isExpression");
613
+ __decorate([
614
+ decorators_1.property('MatchCase')
615
+ ], Match.prototype, "cases");
616
+ __decorate([
617
+ translator_1.withSourceMap()
618
+ ], Match.prototype, "toEmbeddedTS");
619
+ Match = Match_1 = __decorate([
620
+ decorators_1.concept('匹配')
621
+ ], Match);
622
+ return Match;
623
+ }(LogicItem__1["default"]));
624
+ exports.Match = Match;
625
+ classMap_1["default"].Match = Match;
626
+ exports["default"] = Match;
627
+ //================================================================================
628
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
629
+ // 自动生成的代码已结束。下面可以手动编写。
630
+ //================================================================================
631
+ // @ts-check