@lcap/nasl 2.18.0-beta.4 → 2.18.0
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.
- package/out/concepts/MatchExpression__.d.ts +97 -0
- package/out/concepts/MatchExpression__.js +281 -0
- package/out/concepts/MatchExpression__.js.map +1 -0
- package/out/concepts/Param__.js +1 -1
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/Return__.js +1 -1
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/Variable__.js +1 -1
- package/out/concepts/Variable__.js.map +1 -1
- package/out/server/naslServer.js +27 -31
- package/out/server/naslServer.js.map +1 -1
- package/out/templator/sql-parser/index.d.ts +1 -0
- package/out/templator/sql-parser/index.js +228 -0
- package/out/templator/sql-parser/index.js.map +1 -0
- package/out/templator/sql-parser/parser.js +26664 -0
- package/out/templator/sql-parser/parser.js.map +1 -0
- package/package.json +2 -2
- package/src/automate/engine/dist/index.dev.js +517 -0
- package/src/common/dist/BaseNode.js +1101 -0
- package/src/concepts/Param__.ts +1 -1
- package/src/concepts/Return__.ts +1 -1
- package/src/concepts/Variable__.ts +1 -1
- package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +24 -0
- package/src/concepts/dist/Anchor__.js +179 -0
- package/src/concepts/dist/Assignment__.js +301 -0
- package/src/concepts/dist/CallFunction__.js +473 -0
- package/src/concepts/dist/CallInterface__.js +533 -0
- package/src/concepts/dist/CallLogic__.js +864 -0
- package/src/concepts/dist/ForEachStatement__.js +426 -0
- package/src/concepts/dist/MatchCase__.js +587 -0
- package/src/concepts/dist/MemberExpression__.js +348 -0
- package/src/concepts/dist/Param__.js +537 -0
- package/src/concepts/dist/Return__.js +493 -0
- package/src/generator/dist/genBundleFiles.js +414 -0
- package/src/server/dist/formatTsUtils.js +683 -0
- package/src/server/dist/naslServer.js +3396 -0
- package/src/server/naslServer.ts +28 -31
- package/src/service/storage/dist/init.js +541 -0
- package/ts-worker/dist/webpack.config.dev.js +104 -0
- package/ts-worker/lib/dist/tsserver.dev.js +22953 -0
- package/ts-worker/sources/lib/dist/tsserver.dev.js +22912 -0
- package/dist/bundle.js +0 -3962
- package/dist/bundle.js.LICENSE.txt +0 -16
- package/out/generator/release.d.ts +0 -1
- package/out/generator/release.js +0 -51
- package/out/generator/release.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lcap/nasl",
|
|
3
3
|
"description": "NetEase Application Specific Language",
|
|
4
|
-
"version": "2.18.0
|
|
4
|
+
"version": "2.18.0",
|
|
5
5
|
"author": "Forrest <rainforest92@126.com>",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "tsc -watch -p ./",
|
|
@@ -67,4 +67,4 @@
|
|
|
67
67
|
"typedoc": "^0.22.17",
|
|
68
68
|
"typescript": "^4.1.3"
|
|
69
69
|
}
|
|
70
|
-
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.autoTemplate = autoTemplate;
|
|
7
|
+
exports.getRoles = getRoles;
|
|
8
|
+
exports.applyTemplate = applyTemplate;
|
|
9
|
+
exports.applyDropComponent = applyDropComponent;
|
|
10
|
+
|
|
11
|
+
var _lodash = require("lodash");
|
|
12
|
+
|
|
13
|
+
var _BaseNode = require("../../common/BaseNode");
|
|
14
|
+
|
|
15
|
+
var _utils = require("./utils");
|
|
16
|
+
|
|
17
|
+
var _index = require("../../decorators/index");
|
|
18
|
+
|
|
19
|
+
var _uniqueName = require("./uniqueName");
|
|
20
|
+
|
|
21
|
+
var _operators = require("./operators");
|
|
22
|
+
|
|
23
|
+
var _myProcess = require("../template/myProcess");
|
|
24
|
+
|
|
25
|
+
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
26
|
+
|
|
27
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
28
|
+
|
|
29
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
30
|
+
|
|
31
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
32
|
+
|
|
33
|
+
var id = 0;
|
|
34
|
+
|
|
35
|
+
var TemplateMeta =
|
|
36
|
+
/*#__PURE__*/
|
|
37
|
+
function () {
|
|
38
|
+
function TemplateMeta(node) {
|
|
39
|
+
_classCallCheck(this, TemplateMeta);
|
|
40
|
+
|
|
41
|
+
// this.name = `t_${uuidv4().replace(/-/g, '')}`;
|
|
42
|
+
this.name = "t_".concat(node.concept, "_").concat(node.name ? node.name.replace(/[-\.]/g, '') : 'unknown', "_").concat(id++);
|
|
43
|
+
this.node = node;
|
|
44
|
+
this.isRoot = false;
|
|
45
|
+
this.rootBinds = [];
|
|
46
|
+
this.binds = [];
|
|
47
|
+
this.callees = [];
|
|
48
|
+
this.modules = [];
|
|
49
|
+
this.rolebinds = [];
|
|
50
|
+
this.templatebinds = []; // 前端全局变量
|
|
51
|
+
|
|
52
|
+
this.frontendVariables = [];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
_createClass(TemplateMeta, [{
|
|
56
|
+
key: "addRootBinds",
|
|
57
|
+
value: function addRootBinds(propertyName, templateMeta) {
|
|
58
|
+
// App.[propertyName].push(templateMeta.name)
|
|
59
|
+
if (!this.rootBinds.find(function (b) {
|
|
60
|
+
return b.propertyName === propertyName;
|
|
61
|
+
})) {
|
|
62
|
+
this.rootBinds.push({
|
|
63
|
+
propertyName: propertyName,
|
|
64
|
+
value: templateMeta.name
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}, {
|
|
69
|
+
key: "addBinds",
|
|
70
|
+
value: function addBinds(type, propertyName, templateMeta) {
|
|
71
|
+
// this.node.[propertyName] = templateMeta.name
|
|
72
|
+
// this.node.[propertyName].push(templateMeta.name)
|
|
73
|
+
this.binds.push({
|
|
74
|
+
type: type,
|
|
75
|
+
propertyName: propertyName,
|
|
76
|
+
value: templateMeta.name
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
key: "addPlainBinds",
|
|
81
|
+
value: function addPlainBinds(propertyName, value) {
|
|
82
|
+
// this.node.[propertyName] = value
|
|
83
|
+
if (typeof value === 'string') {
|
|
84
|
+
value = value.split(/\r?\n/).map(function (c) {
|
|
85
|
+
return "\"".concat(c.replace(/\\/g, '\\\\').replace(/"/g, '\\"'), "\"");
|
|
86
|
+
}) // .map((c) => `"${c.replace(/([^\\])"/g, '$1\\"')}"`)
|
|
87
|
+
// .map((c) => `decodeURIComponent("${c.encodeURIComponent}")`)
|
|
88
|
+
.join(' + "\\n" +\n');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (_typeof(value) === 'object') {
|
|
92
|
+
value = JSON.stringify(value);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.binds.push({
|
|
96
|
+
type: _utils.TRACK_TYPE.PLAIN,
|
|
97
|
+
propertyName: propertyName,
|
|
98
|
+
value: value
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}, {
|
|
102
|
+
key: "addModule",
|
|
103
|
+
value: function addModule(m) {
|
|
104
|
+
this.modules.push({
|
|
105
|
+
name: m.name,
|
|
106
|
+
belongs: m.parentKey,
|
|
107
|
+
data: m._toJSON(function (source) {
|
|
108
|
+
return (0, _lodash.omit)(source, _utils.IGNORE_PROPERTY);
|
|
109
|
+
})
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}, {
|
|
113
|
+
key: "addCallee",
|
|
114
|
+
value: function addCallee(propertyName, relatedPropertyName, templateMeta) {
|
|
115
|
+
// this.node.[propertyName] = [targetVar].getNamespace();
|
|
116
|
+
// this.node.[relatedPropertyName] = [targetVar].name;
|
|
117
|
+
this.callees.push({
|
|
118
|
+
propertyName: propertyName,
|
|
119
|
+
relatedPropertyName: relatedPropertyName,
|
|
120
|
+
targetVar: templateMeta.name
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}, {
|
|
124
|
+
key: "addCalleeTemplate",
|
|
125
|
+
value: function addCalleeTemplate(propertyName, relatedPropertyName, nstemplate, nametemplate, arguVars) {
|
|
126
|
+
// this.node.[propertyName] = nstemplate([arguVars]);
|
|
127
|
+
// this.node.[relatedPropertyName] = nametemplate([arguVars]);
|
|
128
|
+
this.callees.push({
|
|
129
|
+
propertyName: propertyName,
|
|
130
|
+
relatedPropertyName: relatedPropertyName,
|
|
131
|
+
nstemplate: nstemplate,
|
|
132
|
+
nametemplate: nametemplate,
|
|
133
|
+
arguVars: arguVars
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}, {
|
|
137
|
+
key: "addRoleTemplate",
|
|
138
|
+
value: function addRoleTemplate(propertyName, arguVars) {
|
|
139
|
+
this.rolebinds.push({
|
|
140
|
+
propertyName: propertyName,
|
|
141
|
+
arguVars: arguVars
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}, {
|
|
145
|
+
key: "addTemplateBind",
|
|
146
|
+
value: function addTemplateBind(propertyName, relatedVar, relatedProperty) {
|
|
147
|
+
this.templatebinds.push({
|
|
148
|
+
propertyName: propertyName,
|
|
149
|
+
relatedVar: relatedVar,
|
|
150
|
+
relatedProperty: relatedProperty
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}, {
|
|
154
|
+
key: "genComment",
|
|
155
|
+
value: function genComment(part) {
|
|
156
|
+
return "/*---------".concat(this.node.concept, " ").concat(this.node.name, " ").concat(part, " -----------*/");
|
|
157
|
+
}
|
|
158
|
+
}, {
|
|
159
|
+
key: "genCreate",
|
|
160
|
+
value: function genCreate() {
|
|
161
|
+
// [this.name] = create[this.node.concept]();
|
|
162
|
+
// return `${this.genComment('create')}
|
|
163
|
+
// _tempConstructor = getConceptConstructor("${this.node.concept}");
|
|
164
|
+
// const ${this.name} = new _tempConstructor();`
|
|
165
|
+
return "".concat(this.genComment('create'), "\n let ").concat(this.name, " = _create(\"").concat(this.node.concept, "\");\n _templateObjects.push(").concat(this.name, ")");
|
|
166
|
+
}
|
|
167
|
+
}, {
|
|
168
|
+
key: "genBind",
|
|
169
|
+
value: function genBind() {
|
|
170
|
+
var _this = this;
|
|
171
|
+
|
|
172
|
+
return this.binds.map(function (bind) {
|
|
173
|
+
var type = bind.type,
|
|
174
|
+
propertyName = bind.propertyName,
|
|
175
|
+
value = bind.value;
|
|
176
|
+
|
|
177
|
+
switch (type) {
|
|
178
|
+
case _utils.TRACK_TYPE.PROPERTY:
|
|
179
|
+
return "_set(".concat(_this.name, ", \"").concat(propertyName, "\", ").concat(value, ", (updatedObj) => { ").concat(value, " = updatedObj; })");
|
|
180
|
+
|
|
181
|
+
case _utils.TRACK_TYPE.PLAIN:
|
|
182
|
+
return "_set(".concat(_this.name, ", \"").concat(propertyName, "\", ").concat(value, ");");
|
|
183
|
+
|
|
184
|
+
case _utils.TRACK_TYPE.ARRAY:
|
|
185
|
+
return "_push(".concat(_this.name, ", \"").concat(propertyName, "\", ").concat(value, ");");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return '';
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}, {
|
|
192
|
+
key: "genRootBind",
|
|
193
|
+
value: function genRootBind() {
|
|
194
|
+
return this.rootBinds.map(function (bind) {
|
|
195
|
+
var propertyName = bind.propertyName,
|
|
196
|
+
value = bind.value;
|
|
197
|
+
|
|
198
|
+
if (propertyName === 'roles') {
|
|
199
|
+
return "\n if(roleCallback) {\n ".concat(value, " = roleCallback(").concat(value, ")\n } else {\n _push(app, \"roles\", ").concat(value, ");\n }");
|
|
200
|
+
} // return `app.${propertyName}.push(${value});
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
return "_push(app, \"".concat(propertyName, "\", ").concat(value, ");");
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}, {
|
|
207
|
+
key: "genEntryBind",
|
|
208
|
+
value: function genEntryBind() {
|
|
209
|
+
if (this.isRoot) {
|
|
210
|
+
return "rootBindCallback(".concat(this.name, ")");
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return '';
|
|
214
|
+
}
|
|
215
|
+
}, {
|
|
216
|
+
key: "genRootReturn",
|
|
217
|
+
value: function genRootReturn() {
|
|
218
|
+
if (this.isRoot) {
|
|
219
|
+
return "return ".concat(this.name, ";");
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return '';
|
|
223
|
+
}
|
|
224
|
+
}, {
|
|
225
|
+
key: "genName",
|
|
226
|
+
value: function genName() {
|
|
227
|
+
// [this.name].name = this.parent.genUniqueXXXName();
|
|
228
|
+
// return `${this.name}.name = (${this.name}.parentNode.gen${this.node.concept}UniqueName ? ${this.name}.parentNode.gen${this.node.concept}UniqueName() : ${this.name}.name)`
|
|
229
|
+
if (this.node.concept === 'Role') {
|
|
230
|
+
return '';
|
|
231
|
+
} // if (this.node.concept === 'Entity') {
|
|
232
|
+
// return `_set(${this.name}, "name", getGenUniqNameFunctionName(${this.name}, "${this.node.concept}"));`;
|
|
233
|
+
// _setTableName(${this.name}, ${this.name}.name + '_' + app.id.slice(0,6));`;
|
|
234
|
+
// }
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
return "_set(".concat(this.name, ", \"name\", _uniqueName.getGenUniqNameFunctionName(").concat(this.name, ", \"").concat(this.node.concept, "\", app), (updatedObj) => { ").concat(this.name, " = updatedObj; })");
|
|
238
|
+
}
|
|
239
|
+
}, {
|
|
240
|
+
key: "genRoleBind",
|
|
241
|
+
value: function genRoleBind() {
|
|
242
|
+
var _this2 = this;
|
|
243
|
+
|
|
244
|
+
return this.rolebinds.map(function (role) {
|
|
245
|
+
var propertyName = role.propertyName,
|
|
246
|
+
arguVars = role.arguVars;
|
|
247
|
+
return "_set(".concat(_this2.name, ", \"").concat(propertyName, "\", _bindRoles(").concat(arguVars, "), (updatedObj) => { ").concat(_this2.name, " = updatedObj; });");
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}, {
|
|
251
|
+
key: "genCallee",
|
|
252
|
+
value: function genCallee() {
|
|
253
|
+
var _this3 = this;
|
|
254
|
+
|
|
255
|
+
return this.callees.map(function (callee) {
|
|
256
|
+
var propertyName = callee.propertyName,
|
|
257
|
+
relatedPropertyName = callee.relatedPropertyName,
|
|
258
|
+
targetVar = callee.targetVar,
|
|
259
|
+
nstemplate = callee.nstemplate,
|
|
260
|
+
nametemplate = callee.nametemplate,
|
|
261
|
+
arguVars = callee.arguVars;
|
|
262
|
+
|
|
263
|
+
if (arguVars && nstemplate && nametemplate) {
|
|
264
|
+
// return `${this.name}.${propertyName} = (${nstemplate}(${arguVars}));
|
|
265
|
+
// ${this.name}.${relatedPropertyName} = (${nametemplate}(${arguVars}))`
|
|
266
|
+
return "_set(".concat(_this3.name, ", \"").concat(propertyName, "\", (").concat(nstemplate, "(").concat(arguVars, ")));\n _set(").concat(_this3.name, ", \"").concat(relatedPropertyName, "\", (").concat(nametemplate, "(").concat(arguVars, ")))");
|
|
267
|
+
} else {
|
|
268
|
+
// return `${this.name}.${propertyName} = ${targetVar}.getNamespace();
|
|
269
|
+
// ${this.name}.${relatedPropertyName} = ${targetVar}.name;`
|
|
270
|
+
return "_set(".concat(_this3.name, ", \"").concat(propertyName, "\", ").concat(targetVar, ".getNamespace(), (updatedObj) => { ").concat(_this3.name, " = updatedObj; });\n _set(").concat(_this3.name, ", \"").concat(relatedPropertyName, "\", ").concat(targetVar, ".name, (updatedObj) => { ").concat(_this3.name, " = updatedObj; });");
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}, {
|
|
275
|
+
key: "genModule",
|
|
276
|
+
value: function genModule() {
|
|
277
|
+
return this.modules.map(function (meta) {
|
|
278
|
+
var name = meta.name,
|
|
279
|
+
belongs = meta.belongs,
|
|
280
|
+
data = meta.data;
|
|
281
|
+
return "_addModule(app, \"".concat(name, "\", \"").concat(belongs, "\", ").concat(JSON.stringify(data), ");");
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}, {
|
|
285
|
+
key: "genTemplateBind",
|
|
286
|
+
value: function genTemplateBind() {
|
|
287
|
+
var _this4 = this;
|
|
288
|
+
|
|
289
|
+
return this.templatebinds.map(function (meta) {
|
|
290
|
+
var propertyName = meta.propertyName,
|
|
291
|
+
relatedVar = meta.relatedVar,
|
|
292
|
+
relatedProperty = meta.relatedProperty;
|
|
293
|
+
return "_set(".concat(_this4.name, ", \"").concat(propertyName, "\", ").concat(relatedVar, ".").concat(relatedProperty, ")");
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}]);
|
|
297
|
+
|
|
298
|
+
return TemplateMeta;
|
|
299
|
+
}();
|
|
300
|
+
|
|
301
|
+
function autoScript(stack) {
|
|
302
|
+
var createBlock = [];
|
|
303
|
+
var rootBindBlock = [];
|
|
304
|
+
var bindBlock = [];
|
|
305
|
+
var rolebindBlock = [];
|
|
306
|
+
var appBindBlock = [];
|
|
307
|
+
var nameBlock = [];
|
|
308
|
+
var calleeBlock = [];
|
|
309
|
+
var moduleBlock = [];
|
|
310
|
+
var returnBlock = [];
|
|
311
|
+
var roleNASL = [];
|
|
312
|
+
var templateBlock = [];
|
|
313
|
+
stack.forEach(function (temp) {
|
|
314
|
+
createBlock.push(temp.genCreate());
|
|
315
|
+
|
|
316
|
+
if (temp.isRoot) {
|
|
317
|
+
rootBindBlock = rootBindBlock.concat(temp.genEntryBind());
|
|
318
|
+
returnBlock = returnBlock.concat(temp.genRootReturn());
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (temp.node.concept === 'Role') {
|
|
322
|
+
roleNASL = roleNASL.concat(temp.node._toJSON(function (source) {
|
|
323
|
+
return (0, _lodash.omit)(source, _utils.IGNORE_PROPERTY);
|
|
324
|
+
}));
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
rolebindBlock = rolebindBlock.concat(temp.genRoleBind());
|
|
328
|
+
bindBlock = bindBlock.concat(temp.genBind());
|
|
329
|
+
appBindBlock = (0, _lodash.uniq)(appBindBlock.concat(temp.genRootBind()));
|
|
330
|
+
nameBlock.push(temp.genName());
|
|
331
|
+
calleeBlock = calleeBlock.concat(temp.genCallee());
|
|
332
|
+
moduleBlock = moduleBlock.concat(temp.genModule());
|
|
333
|
+
templateBlock = templateBlock.concat(temp.genTemplateBind());
|
|
334
|
+
});
|
|
335
|
+
var ideVersion = window.globalData.ideVersion;
|
|
336
|
+
return "\n(function () {\n const injectModule = {};\n \n const exportRoles = function() {\n return ".concat(JSON.stringify(roleNASL), ";\n }\n\n const execTemplate = function(app, getCtor, getCMeta, base, rootBindCallback, roleCallback, finalCallback) {\n let _templateObjects = [];\n const {\n _set,\n _push,\n _create,\n _addModule,\n _bindRoles,\n } = injectModule.operators;\n const _uniqueName = new injectModule.uniqueName();\n\n _uniqueName.initAppUniqueNames(app);\n\n app.emit('collect:start', {\n actionMsg: ' \u521B\u5EFA\u9875\u9762'\n });\n /*---- create ---- */\n ").concat(createBlock.join('\n\t\t'), "\n\n /*---- bind ---- */\n ").concat(bindBlock.join('\n\t\t'), "\n\n /*---- reset name ---- */\n ").concat(nameBlock.join('\n\t\t'), "\n\n /*--- root bind ---*/\n ").concat(rootBindBlock.join('\n\t\t'), "\n\n /*---- appbind ---- */\n ").concat(appBindBlock.join('\n\t\t'), "\n\n /*--- role bind ---*/\n ").concat(rolebindBlock.join('\n\t\t'), "\n\n /*---- reset callee ---- */\n ").concat(calleeBlock.join('\n\t\t'), "\n\n /*--- template bind ---- */\n ").concat(templateBlock.join('\n\t\t'), "\n\n /*---- add module ----*/\n ").concat(moduleBlock.join('\n\t\t'), "\n\n /*--- final callback ---*/\n if(finalCallback) {\n finalCallback(_templateObjects)\n }\n app.emit('collect:end');\n\n /*---- return root -----*/\n ").concat(returnBlock.join('\n\t\t'), "\n }\n\n return {\n version: '").concat(ideVersion, "',\n execTemplate,\n exportRoles,\n importModule(key, m) {\n injectModule[key] = m;\n injectModule[key].templateVersion = '").concat(ideVersion, "'\n },\n }\n})();");
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
var i = 0;
|
|
340
|
+
|
|
341
|
+
function autoTemplate(node) {
|
|
342
|
+
console.log(node);
|
|
343
|
+
var visitedMap = new WeakMap();
|
|
344
|
+
var stack = [];
|
|
345
|
+
var startNode = node;
|
|
346
|
+
var rootNode = true;
|
|
347
|
+
var finalOps = [];
|
|
348
|
+
|
|
349
|
+
function iterator(node) {
|
|
350
|
+
if (node && !visitedMap.has(node)) {
|
|
351
|
+
var meta = new TemplateMeta(node);
|
|
352
|
+
|
|
353
|
+
if (rootNode) {
|
|
354
|
+
meta.isRoot = true;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
rootNode = false;
|
|
358
|
+
stack.push(meta);
|
|
359
|
+
visitedMap.set(node, meta);
|
|
360
|
+
(0, _utils.tracking)(node, startNode, function (type, propertyName, property) {
|
|
361
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
362
|
+
var rootNode = options.rootNode,
|
|
363
|
+
calleeNode = options.calleeNode,
|
|
364
|
+
relatedPropertyName = options.relatedPropertyName,
|
|
365
|
+
AppPropertyName = options.AppPropertyName,
|
|
366
|
+
metaNodes = options.metaNodes;
|
|
367
|
+
|
|
368
|
+
switch (type) {
|
|
369
|
+
case _utils.TRACK_TYPE.PLAIN:
|
|
370
|
+
meta.addPlainBinds(propertyName, property);
|
|
371
|
+
break;
|
|
372
|
+
|
|
373
|
+
case _utils.TRACK_TYPE.PROPERTY:
|
|
374
|
+
case _utils.TRACK_TYPE.ARRAY:
|
|
375
|
+
iterator(property);
|
|
376
|
+
var pmeta = visitedMap.get(property);
|
|
377
|
+
meta.addBinds(type, propertyName, pmeta);
|
|
378
|
+
break;
|
|
379
|
+
|
|
380
|
+
case _utils.TRACK_TYPE.ARRAY_NO_FURTHER:
|
|
381
|
+
finalOps.push(function () {
|
|
382
|
+
var pmeta = visitedMap.get(property);
|
|
383
|
+
|
|
384
|
+
if (pmeta) {
|
|
385
|
+
meta.addBinds(_utils.TRACK_TYPE.ARRAY, propertyName, pmeta);
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
break;
|
|
389
|
+
|
|
390
|
+
case _utils.TRACK_TYPE.CALLEE:
|
|
391
|
+
iterator(rootNode);
|
|
392
|
+
iterator(calleeNode);
|
|
393
|
+
var cmeta = visitedMap.get(calleeNode);
|
|
394
|
+
|
|
395
|
+
if (AppPropertyName) {
|
|
396
|
+
meta.addRootBinds(AppPropertyName, visitedMap.get(rootNode));
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
meta.addCallee(propertyName, relatedPropertyName, cmeta);
|
|
400
|
+
break;
|
|
401
|
+
|
|
402
|
+
case _utils.TRACK_TYPE.MODULE:
|
|
403
|
+
meta.addModule(property);
|
|
404
|
+
break;
|
|
405
|
+
|
|
406
|
+
case _utils.TRACK_TYPE.CALLEE_TEMPLATE:
|
|
407
|
+
var nstemplate = options.nstemplate,
|
|
408
|
+
nametemplate = options.nametemplate;
|
|
409
|
+
metaNodes.forEach(function (n) {
|
|
410
|
+
iterator(n);
|
|
411
|
+
});
|
|
412
|
+
var arguVars = metaNodes.map(function (n) {
|
|
413
|
+
return visitedMap.get(n).name;
|
|
414
|
+
}).join(',');
|
|
415
|
+
|
|
416
|
+
if (AppPropertyName) {
|
|
417
|
+
meta.addRootBinds(AppPropertyName, visitedMap.get(rootNode));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
meta.addCalleeTemplate(propertyName, relatedPropertyName, nstemplate, nametemplate, arguVars);
|
|
421
|
+
break;
|
|
422
|
+
|
|
423
|
+
case _utils.TRACK_TYPE.ROLE_TEMPLATE:
|
|
424
|
+
var roleMetaNames = [];
|
|
425
|
+
metaNodes.forEach(function (node) {
|
|
426
|
+
iterator(node);
|
|
427
|
+
var m = visitedMap.get(node);
|
|
428
|
+
m.addRootBinds('roles', m);
|
|
429
|
+
roleMetaNames.push(m.name);
|
|
430
|
+
});
|
|
431
|
+
meta.addRoleTemplate(propertyName, roleMetaNames);
|
|
432
|
+
break;
|
|
433
|
+
|
|
434
|
+
case _utils.TRACK_TYPE.PROPERTY_TEMPLATE:
|
|
435
|
+
var relatedProperty = options.relatedProperty;
|
|
436
|
+
var getRelatedVar = options.getRelatedVar;
|
|
437
|
+
var t = getRelatedVar();
|
|
438
|
+
|
|
439
|
+
if (t) {
|
|
440
|
+
iterator(t);
|
|
441
|
+
var relatedMeta = visitedMap.get(t);
|
|
442
|
+
meta.addTemplateBind(propertyName, relatedMeta.name, relatedProperty);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
break;
|
|
446
|
+
|
|
447
|
+
default:
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
return meta;
|
|
452
|
+
} else if (node) {
|
|
453
|
+
return visitedMap.get(node);
|
|
454
|
+
} else {
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
iterator(node);
|
|
460
|
+
finalOps.forEach(function (f) {
|
|
461
|
+
f();
|
|
462
|
+
});
|
|
463
|
+
return autoScript(stack);
|
|
464
|
+
}
|
|
465
|
+
/* 使用模板的代码 */
|
|
466
|
+
|
|
467
|
+
/*
|
|
468
|
+
const view = this.view;
|
|
469
|
+
const app = view.rootNode;
|
|
470
|
+
applyTemplate(script, app, (rootNode) => {
|
|
471
|
+
const names = app.getViewExistingNames();
|
|
472
|
+
if(names.includes(rootNode.name)) {
|
|
473
|
+
const name = app.getViewUniqueName();
|
|
474
|
+
rootNode.name = name;
|
|
475
|
+
}
|
|
476
|
+
app.addView(rootNode);
|
|
477
|
+
})
|
|
478
|
+
*/
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
function getRoles(script) {
|
|
482
|
+
var _eval = eval(script),
|
|
483
|
+
exportRoles = _eval.exportRoles;
|
|
484
|
+
|
|
485
|
+
return exportRoles();
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function applyTemplate(script, app, rootBindCallback, roleCallback, finalCallback) {
|
|
489
|
+
_operators.ops.upgraders.forEach(function (upgrader) {
|
|
490
|
+
return upgrader.replace && (script = upgrader.replace(script));
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
var _eval2 = eval(script),
|
|
494
|
+
execTemplate = _eval2.execTemplate,
|
|
495
|
+
importModule = _eval2.importModule; // 为了兼容 2.11 老模板
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
if (importModule) {
|
|
499
|
+
importModule('operators', _operators.ops);
|
|
500
|
+
importModule('uniqueName', _uniqueName.uniqueName);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
execTemplate(app, _index.getConceptConstructor, _index.getConceptMeta, _BaseNode.BaseNode, rootBindCallback, roleCallback, finalCallback);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function applyDropComponent(app, view, element) {
|
|
507
|
+
var execTemplate = _myProcess.processComponent.execTemplate,
|
|
508
|
+
importModule = _myProcess.processComponent.importModule; // 为了兼容 2.11 老模板
|
|
509
|
+
|
|
510
|
+
if (importModule) {
|
|
511
|
+
importModule('operators', _operators.ComponentOps);
|
|
512
|
+
importModule('uniqueName', _uniqueName.componentUniqueName);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
view.collectExistingViewElementName();
|
|
516
|
+
return execTemplate(app, view, element);
|
|
517
|
+
}
|