efront 3.34.12 → 3.35.1

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