efront 3.34.11 → 3.35.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.
Files changed (76) hide show
  1. package/apps/moue/content//344/275/240/345/245/275/344/270/226/347/225/214.vue +21 -0
  2. package/apps/moue/content//344/275/240/345/245/275/345/274/200/345/217/221/350/200/205.html +1 -0
  3. package/apps/moue/{home/index.js → content//344/275/240/345/245/275/345/274/200/345/217/221/350/200/205.js} +4 -2
  4. package/apps/moue/content//344/275/240/345/245/275/345/274/200/345/217/221/350/200/205.less +4 -0
  5. package/apps/moue/home/index2.vue +97 -18
  6. package/apps/moue/index.html +1 -1
  7. package/coms/basic/ArrayFill.md +9 -0
  8. package/coms/basic/awaitable.md +10 -0
  9. package/coms/basic/backEach.md +7 -0
  10. package/coms/basic/combine.md +23 -0
  11. package/coms/basic/renderExpress.js +1 -1
  12. package/coms/basic/wait.js +5 -0
  13. package/coms/basic_/readme.md +27 -9
  14. package/coms/compile/#/350/257/264/346/230/216.md +1 -0
  15. package/coms/compile/Html.js +263 -0
  16. package/coms/compile/Html_test.js +5 -0
  17. package/coms/compile/Javascript.js +594 -0
  18. package/coms/compile/Program.js +664 -0
  19. package/coms/compile/autoenum.js +179 -0
  20. package/coms/compile/autoenum_test.js +17 -0
  21. package/coms/compile/autoeval.js +50 -0
  22. package/coms/compile/autoeval_test.js +28 -0
  23. package/coms/compile/autoiota.js +121 -0
  24. package/coms/compile/breakcode.js +83 -0
  25. package/coms/compile/common.js +1063 -0
  26. package/coms/compile/downLevel.js +901 -0
  27. package/coms/compile/downLevel_test.js +111 -0
  28. package/coms/compile/formatcode.js +57 -0
  29. package/coms/compile/iso8859.js +9 -0
  30. package/coms/compile/iso8859_test.js +2 -0
  31. package/coms/compile/keywords.js +6 -0
  32. package/coms/compile/namelist.js +154 -0
  33. package/coms/compile/namelist_test.js +7 -0
  34. package/coms/compile/polyfill.js +31 -0
  35. package/coms/compile/required.js +20 -0
  36. package/coms/compile/richcss.js +237 -0
  37. package/coms/compile/richcss_test.js +7 -0
  38. package/coms/compile/scanner.js +653 -0
  39. package/coms/compile/scanner2.js +202 -0
  40. package/coms/compile/scanner2_test.js +110 -0
  41. package/coms/compile/scanner_test.js +10 -0
  42. package/coms/compile/unstruct.js +712 -0
  43. package/coms/compile/unstruct_test.js +54 -0
  44. package/coms/compile/washcode.js +237 -0
  45. package/coms/compile/washcode_test.js +17 -0
  46. package/coms/docs/helps.js +71 -0
  47. package/coms/docs/markdown.js +248 -0
  48. package/coms/frame/route.js +1 -1
  49. package/coms/reptile/colored_console.js +2 -1
  50. package/coms/zimoli/cless.js +1 -0
  51. package/coms/zimoli/css.js +1 -9
  52. package/coms/zimoli/html.js +1 -1
  53. package/coms/zimoli/menu.js +1 -1
  54. package/coms/zimoli/menuItem.html +1 -1
  55. package/coms/zimoli/menuItem.js +1 -1
  56. package/coms/zimoli/render.js +14 -3
  57. package/coms/zimoli/text.js +1 -1
  58. package/coms/zimoli/transition.js +4 -4
  59. package/coms/zimoli/tree.js +2 -2
  60. package/coms/zimoli/zimoli.js +39 -12
  61. package/docs/compare.md +5 -5
  62. package/docs/components.jsp +17 -0
  63. package/docs/index.html +16 -26
  64. package/docs/main.xht +182 -0
  65. package/docs/mark.xht +166 -0
  66. package/docs/welcome.jsp +7 -0
  67. package/docs//345/221/275/344/273/244.xht +100 -0
  68. package/docs//347/211/210/346/234/254/350/257/264/346/230/216.md +9 -0
  69. package/docs//347/273/204/344/273/266.xht +87 -0
  70. package/package.json +1 -1
  71. package/public/efront.js +1 -1
  72. package/readme.md +6 -11
  73. package/apis/docs/getAllComponents.js +0 -69
  74. package/apps/moue/home/index.html +0 -1
  75. package/apps/moue/home/index.less +0 -0
  76. package/docs/main.js +0 -17
@@ -0,0 +1,594 @@
1
+ "use strict";
2
+ var strings = require("../basic/strings");
3
+ var Program = require("./Program");
4
+ var backEach = require("../basic/backEach");
5
+
6
+ const {
7
+ /* 1 */COMMENT,
8
+ /* 2 */SPACE,
9
+ /* 4 */STRAP,
10
+ /* 8 */STAMP,
11
+ /* 16 */VALUE,
12
+ /* 32 */QUOTED,
13
+ /* 64 */PIECE,
14
+ /* 128 */EXPRESS,
15
+ /* 256 */SCOPED,
16
+ /* 512 */LABEL,
17
+ /*1024 */PROPERTY,
18
+ createString,
19
+ getDeclared,
20
+ createScoped,
21
+ relink,
22
+ skipAssignment,
23
+ } = require("./common");
24
+ var straps = `if,in,do,as,of
25
+ var,for,new,try,let,get,set
26
+ else,case,void,with,enum,from,eval
27
+ async,while,break,catch,throw,const,yield,class,await,super
28
+ return,typeof,delete,switch,export,import,static
29
+ default,finally,extends
30
+ function,continue,debugger
31
+ instanceof`.trim().split(/[,\s]+/);
32
+ class Javascript extends Program {
33
+ straps = straps;
34
+ value_reg = /^(false|true|null|Infinity|NaN|undefined|arguments|this|eval|super)$/
35
+ transive_reg = /^(new|var|let|const|yield|void|in|of|typeof|delete|case|return|await|export|default|instanceof|throw|extends|import|from)$/
36
+ strapexp_reg = /^(new|void|typeof|delete|class|function|await)/;
37
+ forceend_reg = /^(return|yield|break|continue|debugger)$/;
38
+ classstrap_reg = /^(class|function|async)$/;
39
+ }
40
+ var propresolve_reg = /^(static|get|set|async)$/;
41
+
42
+ Javascript.prototype.isProperty = function (o) {
43
+ var queue = o.queue;
44
+ var prev = o.prev;
45
+ if (queue.isObject) {
46
+ if (!prev || prev.type === STAMP && prev.text === ",") return true;
47
+ if (prev.type === STAMP && prev.isprop) return true;
48
+ }
49
+ if (queue.isClass) {
50
+ if (!prev) return true;
51
+ if (prev.type === STAMP) {
52
+ if (prev.isprop) return true;
53
+ return /^(\+\+|\-\-|;)$/.test(prev.text);
54
+ }
55
+ if (prev.type === EXPRESS && !/\.$/.test(prev.text)) return true;
56
+ if (~[SCOPED, VALUE, QUOTED, PROPERTY].indexOf(prev.type)) return true;
57
+ }
58
+ if (!prev) return false;
59
+ if (prev.type === PROPERTY && propresolve_reg.test(prev.text)) {
60
+ return true;
61
+ }
62
+ if (queue.prev && queue.prev.type === STRAP && queue.prev.text === 'export') {
63
+ if (prev.type === STRAP && prev.text === "as") return true;
64
+ }
65
+ return false;
66
+ };
67
+ Javascript.prototype.fixType = function (o) {
68
+ var type = o.type;
69
+ var queue = o.queue;
70
+ var m = o.text;
71
+ var last = o.prev;
72
+ if (m === 'yield') {
73
+ var temp = queue;
74
+ var type = STRAP;
75
+ if (queue.entry === '[' || queue.isClass || queue.isObject || last && (last.type === STAMP && (
76
+ queue[queue.length - 1].type !== SPACE && /^(\+\+|\-\-)$/.test(last.text)
77
+ || !/^(>>>?=|<<=|[^><!=]=|[,;])/.test(last.text)
78
+ ) || last.type === STRAP)) {
79
+ type = EXPRESS;
80
+ }
81
+ if (type === STRAP) while (temp) {
82
+ if (temp.entry != "{" || !temp.prev || temp.prev.type !== SCOPED || temp.prev.entry !== '(') {
83
+ temp = temp.queue;
84
+ continue;
85
+ }
86
+ var pp = temp.prev.prev;
87
+ var isprop = pp.isprop;
88
+ if (pp && pp.type === EXPRESS || pp.isprop) pp = pp.prev;
89
+ if (!pp || pp.type === STRAP && pp.text !== 'function') {
90
+ temp = temp.queue;
91
+ continue;
92
+ }
93
+ if (pp.type === STAMP && pp.text === "*" && (pp.isprop || pp.prev && pp.prev.type === STRAP && pp.prev.text === "function")) {
94
+ type = STRAP;
95
+ break;
96
+ }
97
+ if (isprop || pp.type === STRAP && pp.text === "function") {
98
+ type = EXPRESS;
99
+ break;
100
+ }
101
+ temp = temp.queue;
102
+ }
103
+ }
104
+
105
+ switch (type) {
106
+ case QUOTED:
107
+ if (this.isProperty(o)) type = PROPERTY;
108
+ break;
109
+ case SCOPED:
110
+ if (o.entry === '(') {
111
+ if (last && last.type === STRAP && last.text === 'import') {
112
+ last.type = EXPRESS;
113
+ }
114
+ }
115
+ break;
116
+ case EXPRESS:
117
+ if ((!/^\./.test(m)) && this.isProperty(o)) type = PROPERTY;
118
+ break;
119
+ case STRAP:
120
+ case VALUE:
121
+ if (last && last.type === EXPRESS && /[^\.]\.$/.test(last.text)) {
122
+ type = EXPRESS;
123
+ }
124
+ else if (this.isProperty(o)) type = PROPERTY;
125
+ else if (m === 'from') {
126
+ if (!last || last.type === STRAP && !/^(im|ex)port$/.test(last.text)) {
127
+ type = EXPRESS;
128
+ break;
129
+ }
130
+ var temp = last;
131
+ while (temp.type === STAMP && temp.text === "*" || temp.type & (EXPRESS | VALUE | SCOPED)) {
132
+ var prev = temp.prev;
133
+ if (!prev) break;
134
+ if (prev.type === STRAP && prev.text === "as") {
135
+ temp = prev.prev;
136
+ continue;
137
+ }
138
+ if (prev.type !== STAMP || prev.text !== ',' && (prev.text !== "*" || !prev.prev || !((STRAP | STAMP) & prev.prev.type))) {
139
+ temp = prev;
140
+ break;
141
+ }
142
+ temp = prev.prev;
143
+ if (!temp) break;
144
+ }
145
+ if (!temp || temp.type !== STRAP || !/^(im|ex)port$/.test(temp.text)) {
146
+ type = EXPRESS;
147
+ }
148
+ }
149
+ else if (m === 'as') {
150
+ if (!last) {
151
+ type = EXPRESS;
152
+ break;
153
+ }
154
+ if (last.type & (PROPERTY | EXPRESS | VALUE)
155
+ || last.type === STAMP && last.text === "*" && last.prev && (STRAP | STAMP) & last.prev.type) {
156
+ } else {
157
+ type = EXPRESS;
158
+ }
159
+ }
160
+ break;
161
+ }
162
+ if (type === STRAP && m === "class" && !queue.classed) {
163
+ queue.classed = 1;
164
+ }
165
+ else if (queue.classed > 0) {
166
+ if (type === STRAP && /^(class|function)$/.test(m)) queue.classed++;
167
+ }
168
+ o.type = type;
169
+
170
+ };
171
+ var isShortMethodEnd = function (o) {
172
+ if (!o) return false;
173
+ if (o.type !== SCOPED || o.entry !== "{") return false;
174
+ o = o.prev;
175
+ if (!o) return false;
176
+ if (o.type !== SCOPED || o.entry !== "(") return false;
177
+ o = o.prev;
178
+ if (!o) return false;
179
+ return o.type === PROPERTY;
180
+ };
181
+
182
+ Javascript.prototype.setType = function (o) {
183
+ this.fixType(o);
184
+ var last = o.prev;
185
+ var queue = o.queue;
186
+ if (queue.isObject || queue.isClass) {
187
+ if (o.type & (VALUE | QUOTED | STRAP)) {
188
+ o.isprop = this.isProperty(o);
189
+ }
190
+ else if (o.type === SCOPED && o.entry === '[') {
191
+ if (queue.isObject) o.isprop = this.isProperty(o);
192
+ if (queue.isClass) o.isprop = !last || last.isprop || last.type === STAMP && last.text === ';';
193
+ }
194
+ else if (o.type === STAMP) {
195
+ o.isprop = o.text === "*" && (!last || /^[,;]$/.test(last.text) || queue.isClass && isShortMethodEnd(last));
196
+ }
197
+ else if (o.type === PROPERTY) {
198
+ o.isprop = true;
199
+ }
200
+ if (o.isprop) {
201
+ if (last && last.type === PROPERTY && propresolve_reg.test(last.text)) {
202
+ last.type = STRAP;
203
+ }
204
+ }
205
+ }
206
+ if (o.type === PROPERTY || o.isprop);
207
+ else if (o.type === STRAP && /^(get|set|static)/.test(o.text)) {
208
+ o.type = EXPRESS;
209
+ }
210
+ if (last) {
211
+ if (!o.isprop && last.type === STRAP) {
212
+ if (last.text === 'async' && o.text !== "function")
213
+ last.type = EXPRESS;
214
+ }
215
+ if (o.type === STAMP && o.text === "=>") {
216
+ var pp = last.prev;
217
+ if (pp && pp.type === EXPRESS && pp.text === 'async') {
218
+ pp.type = STRAP;
219
+ }
220
+ }
221
+ }
222
+ if (o.type === STAMP) {
223
+ if (!last || last.type & (STAMP | STRAP)) {
224
+ o.unary = /^[^=;,\*]$|.[^\=]$/.test(o.text);
225
+ }
226
+ }
227
+ };
228
+ var insertAfter = function (o) {
229
+ var queue = this || o.queue;
230
+ var index = queue.indexOf(o) + 1;
231
+ var os = [].slice.call(arguments, 1);
232
+ queue.splice.apply(queue, [index, 0].concat(os));
233
+ var prev = o, next = o && o.next;
234
+ for (var o of os) {
235
+ if (prev) prev.next = o;
236
+ o.prev = prev;
237
+ Object.defineProperty(o, 'queue', { value: queue });
238
+ prev = o;
239
+ }
240
+ o.next = next;
241
+ if (next) next.prev = o;
242
+ };
243
+ var js = new Javascript;
244
+ var scan = function (data) {
245
+ js.lastIndex = 0;
246
+ return js.exec(data);
247
+ };
248
+ var detourTemplate = function (raw, params) {
249
+ var spliter = { text: ",", type: STAMP };
250
+ var template = scan(`extend([],{["raw"]:[]})`);
251
+ var str0 = template[1].first;
252
+ var str1 = template[1][2][2];
253
+ for (var r of raw) {
254
+ str0.push({ text: strings.recode("`" + r.text + "`"), type: QUOTED }, spliter);
255
+ str1.push({ text: strings.encode(r.text), type: QUOTED }, spliter);
256
+ }
257
+ str0.pop();
258
+ str1.pop();
259
+ for (var p of params) template.push(spliter), hasComma(p) ? template.push(p) : template.push(...p);
260
+ return template;
261
+ };
262
+
263
+ var collectProperty = function (o, text) {
264
+ var q = o.queue;
265
+ if (!q.defined) q.defined = Object.create(null);
266
+ if (q.defined[text]) {
267
+ var t = q.defined[text];
268
+ var p = t.prev;
269
+ while (p && (p.type !== STAMP || p.text !== ',')) p = p.prev;
270
+ var start = p ? q.indexOf(p) + 1 : 0;
271
+ var n = t.next;
272
+ while (n && (n.type !== STAMP || n.text !== ',')) n = n.next;
273
+ var end = n ? q.indexOf(n) + 1 : q.length;
274
+ var s = q.splice(start, end - start);
275
+ if (s.length) console.info(`属性<green>${text}</green>被后文覆盖,已移除<yellow>${createString(s)}</yellow>\r\n`);
276
+ if (p && n) {
277
+ var pp = p.prev;
278
+ n.prev = pp;
279
+ if (pp) pp.next = n;
280
+ }
281
+ }
282
+ q.defined[text] = o;
283
+ };
284
+
285
+ var hasComma = function (c) {
286
+ for (var cc of c) {
287
+ if (cc.type === STAMP && cc.text === ',') return true;
288
+ }
289
+ return false;
290
+ }
291
+
292
+ var removeQoute = function (o, c, i) {
293
+ if (hasComma(c)) return;
294
+ if (!isFinite(i)) i = o.indexOf(c);
295
+ o.splice(i, 1, ...c);
296
+ var ch = c[0];
297
+ var cf = c[c.length - 1];
298
+ ch.prev = c.prev;
299
+ cf.next = c.next;
300
+ if (c.prev) c.prev.next = ch;
301
+ if (c.next) c.next.prev = cf;
302
+ }
303
+
304
+ Javascript.prototype.detour = function detour(o, ie) {
305
+ var avoidMap = this.avoidMap;
306
+ while (o) {
307
+ switch (o.type) {
308
+ case SCOPED:
309
+ this.detour(o.first, ie);
310
+ break;
311
+ case EXPRESS:
312
+ if (avoidMap) {
313
+ var m = /^[^\.\[\]]+/.exec(o.text.replace(/^\.\.\./, ''));
314
+ if (m) { avoidMap[m[0]] = true; }
315
+ }
316
+ if (!/^\.\.\.|\.\.\.$/.test(o.text)) {
317
+ o.text = o.text.replace(/\.([^\.\[]+)/g, (_, a) => ie === undefined || this.strap_reg.test(a) ? `[${strings.recode(a)}]` : _);
318
+ }
319
+ break;
320
+ case QUOTED:
321
+ if (o.length) {
322
+ if (!o.prev || o.prev.type & (STAMP | STRAP)) {
323
+ o.type = SCOPED;
324
+ o.entry = '[';
325
+ o.leave = `]["join"]('')`;
326
+ for (var cx = o.length - 1; cx >= 0; cx--) {
327
+ var c = o[cx];
328
+ if (c.type === PIECE) {
329
+ c.type = QUOTED;
330
+ c.text = strings.recode("`" + c.text + "`");
331
+ }
332
+ else {
333
+ insertAfter.call(o, c.prev, { type: STAMP, text: ',' });
334
+ c.entry = "(";
335
+ c.leave = ")";
336
+ this.detour(c.first, ie);
337
+ insertAfter.call(o, c, { type: STAMP, text: ',' });
338
+ removeQoute(o, c);
339
+ }
340
+ }
341
+ }
342
+ else {
343
+ var raw = [];
344
+ var params = [];
345
+
346
+ for (var c of o) {
347
+ if (c.type === PIECE) {
348
+ raw.push(c);
349
+ } else {
350
+ c.entry = '(';
351
+ c.leave = ")";
352
+ this.detour(c.first, ie);
353
+ params.push(c);
354
+ }
355
+ }
356
+ o.type = SCOPED;
357
+ o.entry = "(";
358
+ o.leave = ")";
359
+ var temp = detourTemplate(raw, params);
360
+ o.splice(0, o.length);
361
+ o.push.apply(o, temp);
362
+ }
363
+ break;
364
+ }
365
+ else if (!o.prev || o.prev.type & (STAMP | STRAP)) {
366
+ if (/^[`]/.test(o.text)) {
367
+ o.text = strings.recode(o.text);
368
+ }
369
+ }
370
+ else {
371
+ if (/^`/.test(o.text)) {
372
+ o.text = o.text.replace(/^`|`$/g, '');
373
+ var template = detourTemplate([o], []);
374
+ o.type = SCOPED;
375
+ o.entry = "(";
376
+ o.leave = ")";
377
+ delete o.text;
378
+ o.push.apply(o, template);
379
+ }
380
+ }
381
+ if (!o.isprop) break;
382
+ case PROPERTY:
383
+ if (/^(get|set|async|static)$/.test(o.text) && o.next && (o.next.type === PROPERTY || o.next.isprop)) break;
384
+ if (o.text === 'static' && o.next && o.next.type === SCOPED && o.next.entry === '{') break;
385
+ if (/^\[/.test(o.text)) break;
386
+ if (o.queue.isObject) {
387
+ var text = strings.recode(o.text);
388
+ if (ie === undefined || o.prev && (o.prev.type !== STAMP || o.prev.text !== ",") || this.strap_reg.test(o.text)) {
389
+ text = `[${text}]`;
390
+ }
391
+ else {
392
+ collectProperty(o, text);
393
+ }
394
+ if (o.short) {
395
+ insertAfter.call(o.queue, o.prev, { text: text, short: false, isprop: true, type: PROPERTY }, { text: ':', type: STAMP });
396
+ o.isprop = false;
397
+ o.type = EXPRESS;
398
+ delete o.short;
399
+ }
400
+ else {
401
+ o.text = text;
402
+ }
403
+ }
404
+ else if (o.queue.isClass) {
405
+ if (o.text === 'constructor') break;
406
+ var text = strings.recode(o.text);
407
+ if (o.prev) {
408
+ var prev = o.prev;
409
+ if (prev && prev.isprop && /^(get|set|static|async)$/.test(prev.text)) {
410
+ prev = prev.prev;
411
+ }
412
+ if (prev && prev.type === STAMP && prev.isprop) prev = prev.prev;
413
+ if (prev && (prev.type !== STAMP || prev.text !== ';')) insertAfter(prev, { text: ';', type: STAMP });
414
+ }
415
+ o.text = `[${text}]`;
416
+ if (o.next && o.next.type === SCOPED && o.next.entry === "(") { }
417
+ else if (!o.next || o.next.type !== STAMP || o.next.text !== "=") {
418
+ insertAfter(o, { text: "=", type: STAMP }, { text: "undefined", type: VALUE, isExpress: true });
419
+ }
420
+ }
421
+ break;
422
+ }
423
+ if (o) o = o.next;
424
+ }
425
+ };
426
+
427
+ var removeImport = function (c, i, code) {
428
+ var { used, envs } = code;
429
+ var [dec, map, o] = getDeclared(c.next);
430
+ if (dec.length !== 1 || !o) throw new Error("代码结构异常!");
431
+ if (o.type !== STRAP || o.text !== 'from') throw new Error("缺少from语句");
432
+ var n = o.next;
433
+ if (!n || n.type !== QUOTED) throw new Error("缺少导入路径!");
434
+ var oi = code.indexOf(o, i);
435
+ var ns = skipAssignment(n);
436
+ var nsi = code.indexOf(ns, i);
437
+ var q = scan(`require()`);
438
+ if (!used.require) used.require = [], envs.require = true;
439
+ used.require.push(q[0]);
440
+ var cs = code.splice(oi + 1, nsi - oi - 1, ...q);
441
+ q[1].push.apply(q[1], cs);
442
+ relink(q[1])
443
+ var name = dec[0];
444
+ var na = dec.attributes[0];
445
+ o.type = STAMP;
446
+ o.text = '=';
447
+ c.text = 'var';
448
+ if (typeof name === 'string' && name !== '*') {
449
+ if (na[0] !== '*') {
450
+ used[name].forEach(u => {
451
+ u.text = u.text.replace(/^[^\.\[]+/g, '$&.default');
452
+ });
453
+ }
454
+ }
455
+ else {
456
+ var name = strings.decode(q[1].last.text)
457
+ .replace(/\.[^\.\/\\]+$/, '')
458
+ .split(/[\/\\\:\{\}\[\]\.\+\-\*\/\!\~\|\:;,'"`\(\)\>\<\?\^%&\s]+/)
459
+ .filter(a => !!a).pop();
460
+ if (!this.express_reg.test(name)) name = "imported";
461
+ var id = 0;
462
+ while (this.strap_reg.test(name) || name in used) {
463
+ name = name.replace(/\d+$/, '') + ++id;
464
+ }
465
+ used[name] = [];
466
+ if (dec[0] !== "*") dec[0].forEach((dn, i) => {
467
+ var da = dec[0].attributes[i];
468
+ used[dn].forEach(u => {
469
+ u.text = name + da[0];
470
+ used[name].push(u);
471
+ });
472
+ delete used[dn];
473
+ });
474
+
475
+ }
476
+ var u = { type: EXPRESS, text: name };
477
+ code.splice(i + 1, oi - i - 1, u);
478
+ used[name].push(u);
479
+ return u;
480
+ };
481
+ var removeExport = function (c, i, code) {
482
+ var { envs, used } = code;
483
+ if (!used.exports) envs.exports = true, used.exports = [];
484
+ var n = c.next;
485
+ if (n.type === STAMP && n.text === '*') {
486
+ var u = removeImport.call(this, c, i, code);
487
+ if (!code.exportStars) code.exportStars = [];
488
+ code.exportStars.push(u);
489
+ return;
490
+ }
491
+ if (n.type === SCOPED) {
492
+ var o = n.first;
493
+ var allexports = [];
494
+ while (o) {
495
+ var name = o, prop = o.text;
496
+ var n = o.next;
497
+ if (n && n.type === STRAP && n.text === 'as') {
498
+ var nn = n.next;
499
+ if (!nn) throw new Error("缺少导出名!");
500
+ prop = nn.text;
501
+ o = nn;
502
+ n = o.next;
503
+ }
504
+ o = n && n.next;
505
+ var exp = scan(`\r\nexports.${prop}=`);
506
+ exp.push(name);
507
+ allexports.push(exp);
508
+ }
509
+ var ni = skipAssignment(code, i);
510
+ code.splice(i, ni - i);
511
+ for (var exp of allexports) {
512
+ code.splice(i, 0, ...exp);
513
+ }
514
+ return;
515
+ }
516
+ if (n.type !== STRAP) throw new Error("代码结构异常!");
517
+ if (n.text === 'default') {
518
+ n.text = '=';
519
+ n.type = STAMP;
520
+ c.text = `exports.default`;
521
+ code.exportDefault = true;
522
+ c.type = EXPRESS;
523
+ return;
524
+ }
525
+ var [dec, map, o] = getDeclared(n.next, 'export');
526
+ if (/^(class|function)$/.test(n.text)) {
527
+ c.text = `exports.${dec[0]}`;
528
+ c.type = EXPRESS;
529
+ code.splice(i + 1, 0, ...scan(`=${dec[0]}\r\n`));
530
+ return;
531
+ }
532
+ var nn = n.next;
533
+ if (!nn) throw new Error('缺少导出项!');
534
+ var oi = code.indexOf(nn, i);
535
+ if (!code.exportDecs) {
536
+ code.exportDecs = [];
537
+ }
538
+ dec.forEach((d, i) => {
539
+ for (var a of used[d]) {
540
+ if (a.kind && a.kind !== 'export') continue;
541
+ if (!a.export) code.exportDecs.push(a), a.export = true;
542
+ }
543
+ });
544
+ code.splice(i, oi - i);
545
+ };
546
+
547
+ Javascript.prototype.fix = function (code) {
548
+ backEach(code, function (o, i) {
549
+ if (o.type !== STRAP) return;
550
+ if (o.text === 'import') removeImport.call(this, o, i, code);
551
+ else if (o.text === 'export') removeExport.call(this, o, i, code);
552
+ }, this);
553
+ if (code.exportStars) {
554
+ var exportStars = code.exportStars;
555
+ if (!code.exportDefault) code.push(...scan(`\r\nexports.default=undefined`));
556
+ exportStars.forEach(u => {
557
+ code.push(...scan(`\r\nextendIfNeeded(exports,${u.text})`));
558
+ });
559
+ delete code.exportStars;
560
+ delete code.exportDefault;
561
+ }
562
+ var imports = code.used.import;
563
+ if (imports) {
564
+ if (!code.used.require) {
565
+ code.used.require = [];
566
+ code.envs.require = true;
567
+ }
568
+ var requires = code.used.require;
569
+ imports.forEach(m => {
570
+ m.text = 'require';
571
+ requires.push(m);
572
+ });
573
+ delete code.used.import;
574
+ delete code.envs.import;
575
+ }
576
+ if (code.exportDecs) {
577
+ var exportDecs = code.exportDecs;
578
+ delete code.exportDecs;
579
+ exportDecs.forEach(e => {
580
+ e.text = 'exports.' + e.text;
581
+ if (e.kind) {
582
+ var n = e.next;
583
+ if (!n || n.type !== STAMP || n.text !== '=') {
584
+ var i = code.indexOf(e);
585
+ code.splice(i + 1, 0, ...scan(`= undefined`));
586
+ }
587
+ }
588
+ });
589
+ }
590
+ relink(code);
591
+ }
592
+ Javascript.prototype.createString = createString;
593
+ Javascript.prototype.createScoped = createScoped;
594
+ module.exports = Javascript;