efront 3.22.10 → 3.24.3

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 (39) hide show
  1. package/coms/basic/BigNumber.js +28 -5
  2. package/coms/basic/BigNumber_test.js +14 -1
  3. package/coms/basic/[]map.js +18 -13
  4. package/coms/basic/assert.js +10 -2
  5. package/coms/basic/extends_.js +13 -0
  6. package/coms/basic/loader.js +47 -28
  7. package/coms/basic/mark.js +155 -0
  8. package/coms/basic/queue.js +11 -14
  9. package/coms/basic/rest_.js +27 -0
  10. package/coms/kugou/parseSongsList.js +1 -1
  11. package/coms/kugou/player.js +3 -2
  12. package/coms/zimoli/Promise.js +84 -133
  13. package/coms/zimoli/appendChild.js +4 -14
  14. package/coms/zimoli/cless.js +11 -5
  15. package/coms/zimoli/color.js +0 -1
  16. package/coms/zimoli/compile.js +64 -1
  17. package/coms/{compile → zimoli}/compile_test.js +0 -0
  18. package/coms/zimoli/cross.js +1 -1
  19. package/coms/zimoli/data.js +6 -2
  20. package/coms/zimoli/dispatch.js +1 -1
  21. package/coms/zimoli/on.js +64 -47
  22. package/coms/zimoli/remove.js +0 -9
  23. package/coms/zimoli/render.js +2 -2
  24. package/coms/zimoli/zimoli.js +2 -2
  25. package/package.json +1 -1
  26. package/public/efront.js +1 -1
  27. package/coms/compile/breakcode.js +0 -78
  28. package/coms/compile/common.js +0 -683
  29. package/coms/compile/compile.js +0 -64
  30. package/coms/compile/keywords.js +0 -6
  31. package/coms/compile/namelist.js +0 -142
  32. package/coms/compile/namelist_test.js +0 -7
  33. package/coms/compile/required.js +0 -20
  34. package/coms/compile/scanner.js +0 -653
  35. package/coms/compile/scanner2.js +0 -909
  36. package/coms/compile/scanner2_test.js +0 -85
  37. package/coms/compile/scanner_test.js +0 -10
  38. package/coms/compile/washcode.js +0 -313
  39. package/coms/zimoli/mark.js +0 -70
@@ -1,909 +0,0 @@
1
- var createNamelist = require("./namelist");
2
-
3
- const {
4
- /*-1 */COMMENT,
5
- /* 0 */SPACE,
6
- /* 1 */STRAP,
7
- /* 2 */STAMP,
8
- /* 3 */VALUE,
9
- /* 4 */QUOTED,
10
- /* 5 */PIECE,
11
- /* 6 */EXPRESS,
12
- /* 7 */SCOPED,
13
- /* 8 */LABEL,
14
- /* 9 */PROPERTY,
15
- number_reg,
16
- skipAssignment,
17
- createScoped,
18
- createString,
19
- } = require("./common");
20
-
21
-
22
-
23
-
24
-
25
- var compress = function (scoped, maped) {
26
- var { lets, vars, used } = scoped;
27
- var map = lets || vars;
28
- var __prevent = Object.create(null);
29
- maped = Object.create(maped || null);
30
- for (var k in used) {
31
- if (!(k in map)) {
32
- if (k in maped) {
33
- k = maped[k];
34
- }
35
- else {
36
- maped[k] = true;
37
- }
38
- __prevent[k] = true;
39
- }
40
- }
41
- var keys = Object.keys(map);
42
- keys.sort((a, b) => used[b].length - used[a].length);
43
- if (keys.length) {
44
- var names = createNamelist(keys.length, __prevent);
45
- for (var cx = 0, dx = keys.length; cx < dx; cx++) {
46
- var k = keys[cx];
47
- var name = names[cx];
48
- map[k] = name;
49
- var list = used[k];
50
- if (list) for (var u of list) {
51
- if (!u) continue;
52
- var text = u.text;
53
- var doted = /^\.\.\./.test(text);
54
- if (doted) text = text.slice(3);
55
- text = name + text.replace(/^[^\.\:]+/i, "");
56
- if (doted) text = "..." + text;
57
- u.text = text;
58
- }
59
- }
60
- }
61
- if (scoped.length) {
62
- for (var cx = 0, dx = keys.length; cx < dx; cx++) {
63
- var k = keys[cx];
64
- maped[k] = names[cx];
65
- }
66
- scoped.forEach(s => compress(s, maped));
67
- }
68
- };
69
-
70
- var strings = require("../basic/strings");
71
-
72
- var insertAfter = function (o) {
73
- var queue = o.queue || this;
74
- var index = queue.indexOf(o) + 1;
75
- var os = [].slice.call(arguments, 1);
76
- queue.splice.apply(queue, [index, 0].concat(os));
77
- var prev = o, next = o.next;
78
- for (var o of os) {
79
- prev.next = o;
80
- o.prev = prev;
81
- Object.defineProperty(o, 'queue', { value: queue });
82
- prev = o;
83
- }
84
- if (next) {
85
- o.next = next;
86
- next.prev = o;
87
- }
88
- };
89
- var detourTemplate = function (raw, params) {
90
- var spliter = { text: ",", type: STAMP };
91
- var template = scan(`extend([],{["raw"]:[]})`);
92
- var str0 = template[1].first;
93
- var str1 = template[1][2][2];
94
- for (var r of raw) {
95
- str0.push({ text: strings.encode(strings.decode("`" + r.text + "`")), type: QUOTED }, spliter);
96
- str1.push({ text: strings.encode(r.text), type: QUOTED }, spliter);
97
- }
98
- str0.pop();
99
- str1.pop();
100
- for (var p of params) template.push(spliter, p);
101
- return template;
102
- };
103
-
104
- var detour = function (o, ie) {
105
- while (o) {
106
- switch (o.type) {
107
- case SCOPED:
108
- detour(o.first, ie);
109
- break;
110
- case EXPRESS:
111
- if (!/^\.\.\.|\.\.\.$/.test(o.text)) {
112
- var ot = o.text;
113
- o.text = o.text.replace(/\.([^\.\[]+)/g, (_, a) => ie === undefined || program.strap_reg.test(a) ? `[${strings.encode(strings.decode(a))}]` : _);
114
- }
115
- break;
116
- case QUOTED:
117
- if (o.length) {
118
- if (!o.prev || o.prev.type === STAMP || o.prev.type === STRAP) {
119
- o.type = SCOPED;
120
- o.entry = '[';
121
- o.leave = `]["join"]('')`;
122
- for (var cx = o.length - 1; cx >= 0; cx--) {
123
- var c = o[cx];
124
- if (c.type === PIECE) {
125
- c.type = QUOTED;
126
- c.text = strings.encode(strings.decode("`" + c.text + "`"));
127
- }
128
- else {
129
- insertAfter.call(o, c.prev, { type: STAMP, text: ',' });
130
- c.entry = "(";
131
- c.leave = ")";
132
- insertAfter.call(o, c, { type: STAMP, text: ',' });
133
- detour(c.first, ie);
134
- }
135
- }
136
- }
137
- else {
138
- var raw = [];
139
- var params = [];
140
-
141
- for (var c of o) {
142
- if (c.type === PIECE) {
143
- raw.push(c);
144
- } else {
145
- c.entry = '(';
146
- c.leave = ")";
147
- detour(c, ie);
148
- params.push(c.length === 1 ? c[0] : c);
149
- }
150
- }
151
- o.type = SCOPED;
152
- o.entry = "(";
153
- o.leave = ")";
154
- var temp = detourTemplate(raw, params);
155
- o.splice(0, o.length);
156
- o.push.apply(o, temp);
157
- }
158
- break;
159
- }
160
- else if (!o.prev || o.prev.type === STAMP || o.prev.type === STRAP) {
161
- if (/^[`]/.test(o.text)) {
162
- o.text = strings.encode(strings.decode(o.text));
163
- }
164
- }
165
- else {
166
- if (/^`/.test(o.text)) {
167
- o.text = o.text.replace(/^`|`$/g, '');
168
- var template = detourTemplate([o], []);
169
- o.type = SCOPED;
170
- o.entry = "(";
171
- o.leave = ")";
172
- delete o.text;
173
- o.push.apply(o, template);
174
- }
175
- }
176
- if (!o.isprop) break;
177
- case PROPERTY:
178
- if (/^(get|set|async|static)$/.test(o.text) && o.next && (o.next.type === PROPERTY || o.next.isprop)) break;
179
- if (o.text === 'static' && o.next && o.next.type === SCOPED && o.next.entry === '{') break;
180
- if (ie === undefined || program.strap_reg.test(o.text)) {
181
- if (!/^\[/.test(o.text) && o.queue.isObject) {
182
- if (o.short) {
183
- insertAfter(o, { text: ':', type: STAMP }, { text: o.text, type: EXPRESS, isExpress: true });
184
- o.short = false;
185
- }
186
- var text = strings.encode(strings.decode(o.text));
187
- o.text = ie !== undefined ? text : `[${text}]`;
188
- }
189
- if (!/^\[/.test(o.text) && o.queue.isClass) {
190
- if (o.text === 'constructor') break;
191
- var text = strings.encode(strings.decode(o.text));
192
- if (o.prev) {
193
- var prev = o.prev;
194
- if (prev && prev.type === PROPERTY && /^(get|set|static|async)$/.test(prev.text)) {
195
- prev = prev.prev;
196
- }
197
- if (prev && prev.type === STAMP && prev.isprop) prev = prev.prev;
198
- if (prev && (prev.type !== STAMP || prev.text !== ';')) insertAfter(prev, { text: ';', type: STAMP });
199
- }
200
- o.text = `[${text}]`;
201
- if (o.next && o.next.type === SCOPED && o.next.entry === "(") { }
202
- else if (!o.next || o.next.type !== STAMP || o.next.text !== "=") {
203
- insertAfter(o, { text: "=", type: STAMP }, { text: "undefined", type: VALUE, isExpress: true });
204
- }
205
- }
206
- }
207
- break;
208
- }
209
- if (o) o = o.next;
210
- }
211
- };
212
-
213
- class Program extends Array {
214
- COMMENT = COMMENT
215
- SPACE = SPACE
216
- STRAP = STRAP
217
- STAMP = STAMP
218
- VALUE = VALUE
219
- QUOTED = QUOTED
220
- PIECE = PIECE
221
- EXPRESS = EXPRESS
222
- SCOPED = SCOPED
223
- LABEL = LABEL
224
- PROPERTY = PROPERTY
225
- pressed = false
226
- _scoped = null;
227
- isExpress() {
228
- if (!this.first) return false;
229
- var first = this.first;
230
- if (first.type === SCOPED) {
231
- if (first.entry === '{') return false;
232
- }
233
- else if (first.type === STRAP) {
234
- if (!/^(new|void|typeof|delete|class|function|await)/.test(first.text)) return false;
235
- }
236
- else if (!~[EXPRESS, STAMP, QUOTED, SCOPED, VALUE].indexOf(first.type)) return false;
237
- var last = skipAssignment(this.first);
238
- return this.lastUncomment === last || !last;
239
- }
240
-
241
- toString() {
242
- return createString(this);
243
- }
244
- get envs() {
245
- return this.scoped.envs;
246
- }
247
- get vars() {
248
- return this.scoped.vars;
249
- }
250
- get used() {
251
- return this.scoped.used;
252
- }
253
- get yield() {
254
- return this.scoped.yield;
255
- }
256
- get async() {
257
- return this.scoped.async;
258
- }
259
- get await() {
260
- return this.scoped.await;
261
- }
262
- get return() {
263
- return this.scoped.return;
264
- }
265
- get scoped() {
266
- if (this._scoped) return this._scoped;
267
- return this._scoped = createScoped(this);
268
- }
269
- getUndecleared() {
270
- return this.envs;
271
- }
272
- // 提前处理属性
273
- break() {
274
- detour(this.first);
275
- return this;
276
- }
277
- // 绕开低版本ie的异常属性
278
- detour(ie) {
279
- detour(this.first, !!ie);
280
- return this;
281
- }
282
- // 压缩
283
- press() {
284
- this.pressed = true;
285
- compress(this.scoped);
286
- return this;
287
- }
288
- }
289
-
290
- var isShortMethodEnd = function (o) {
291
- if (!o) return false;
292
- if (o.type !== SCOPED || o.entry !== "{") return false;
293
- o = o.prev;
294
- if (!o) return false;
295
- if (o.type !== SCOPED || o.entry !== "(") return false;
296
- o = o.prev;
297
- if (!o) return false;
298
- return o.type === PROPERTY;
299
- };
300
-
301
- class Javascript {
302
- quotes = [
303
- [/'/, /'/, /\\[\s\S]/],
304
- [/"/, /"/, /\\[\s\S]/],
305
- ["/", /\/[imgyu]*/, /\\[\s\S]|\[(\\[\s\S]|[^\]])+\]/],
306
- ["`", "`", /\\[\s\S]/, ["${", "}"]],
307
- ]
308
- comments = [
309
- ["//", /(?=[\r\n\u2028\u2029])/],
310
- ["/*", "*/"],
311
- ]
312
- scopes = [
313
- ["(", ")"],
314
- ["[", "]"],
315
- ["{", "}"],
316
- ]
317
- stamps = "/=+;|:?<>-!~@#%^&*,".split("")
318
- value_reg = /^(false|true|null|Infinity|NaN|undefined|arguments|this|eval|super)$/
319
- number_reg = number_reg;
320
- transive = /^(new|var|let|const|yield|void|in|of|typeof|delete|case|return|await|export|default|instanceof|throw|extends|import|from)$/
321
- straps = `if,in,do,as,of
322
- var,for,new,try,let,get,set
323
- else,case,void,with,enum,from,eval
324
- async,while,break,catch,throw,const,yield,class,await,super
325
- return,typeof,delete,switch,export,import,static
326
- default,finally,extends
327
- function,continue,debugger
328
- instanceof`.trim().split(/[\r\n,\s]+/)
329
- spaces = ["\\u00a0", " ", "\\t", "\\v", "\\b", "\\r", "\\n", "\\u2028", "\\u2029", "\\u3000"]
330
- nocase = false
331
- lastIndex = 0
332
- compile(s) {
333
- return s.replace(/\\[\s\S]|[\[\]\(\)\{\}\+\-\*\?\:\$\^\!\|\>\<\\\/]/g, function (m) {
334
- if (m.length > 1) {
335
- return m;
336
- }
337
- return "\\" + m;
338
- });
339
- }
340
- createRegExp(source, g) {
341
- source = source.map(s => s instanceof RegExp ? s.source : this.compile(s));
342
- var flag = this.nocase ? "i" : "";
343
- var s = source.join("|");
344
- if (g) return new RegExp(`${s}`, "g" + flag);
345
- if (source.length > 1) return new RegExp(`^(${s})$`, flag);
346
- return new RegExp(`^${s}$`, flag);
347
- }
348
-
349
- exec(text) {
350
- if (!this.entry_reg) this.commit();
351
- var index = this.lastIndex;
352
- var parents = [];
353
- var lasttype;
354
- var queue = new Program();
355
- queue.__proto__ = Program.prototype;
356
- var origin = queue;
357
- var queue_push = function (scope) {
358
- var last = queue.lastUncomment;
359
- if (queue.isObject || queue.isClass) {
360
- if (~[VALUE, QUOTED].indexOf(scope.type)) {
361
- scope.isprop = isProperty();
362
- }
363
- else if (scope.type === SCOPED && scope.entry === '[') {
364
- if (queue.isObject) scope.isprop = isProperty();
365
- if (queue.isClass) scope.isprop = !last || last.isprop || last.type === STAMP && last.text === ';';
366
- }
367
- else if (scope.type === STAMP) {
368
- scope.isprop = scope.text === "*" && (!queue.lastUncomment || /^[,;]$/.test(queue.lastUncomment.text) || queue.isClass && isShortMethodEnd(queue.lastUncomment));
369
- }
370
- else if (scope.type === PROPERTY) {
371
- scope.isprop = true;
372
- }
373
- }
374
- if (scope.type !== COMMENT && scope.type !== SPACE) {
375
- Object.defineProperty(scope, 'queue', { value: queue });
376
- if (scope.type === PROPERTY || scope.isprop);
377
- else if (scope.type === STRAP && /^(get|set|static)$/.test(scope.text)) {
378
- scope.type = EXPRESS;
379
- }
380
- if (last) {
381
- scope.prev = last;
382
- last.next = scope;
383
- if (!scope.isprop && last.type === STRAP) {
384
- if (last.text === 'async' && scope.text !== "function")
385
- last.type = EXPRESS;
386
- }
387
- }
388
- if (!queue.first) queue.first = scope;
389
- queue.lastUncomment = scope;
390
- for (var cx = queue.length - 1; cx >= 0; cx--) {
391
- var q = queue[cx];
392
- if (q === last) break;
393
- q.next = scope;
394
- }
395
- }
396
- else {
397
- scope.prev = last;
398
- }
399
- scope.row = row;
400
- scope.col = scope.start - colstart;
401
- queue.push(scope);
402
- };
403
- var row = 1, colstart = -1;
404
- var save = (type) => {
405
- if (lasttype === STAMP && type === STAMP && !/[,;\:\?]/.test(m)) {
406
- var scope = queue[queue.length - 1];
407
- if (/=>$/i.test(scope.text) || /=$/.test(scope.text) && /[^>=]/.test(m) || scope.end !== start) {
408
- } else {
409
- scope.end = end;
410
- scope.text = text.slice(scope.start, scope.end);
411
- if (scope.text === '=>') {
412
- if (scope.prev && scope.prev.prev) {
413
- var pp = scope.prev.prev;
414
- if (pp.type === EXPRESS && pp.text === 'async') {
415
- pp.type = STRAP;
416
- }
417
- }
418
- }
419
- queue.inExpress = true;
420
- return;
421
- }
422
- }
423
- var last = queue.lastUncomment;
424
- switch (type) {
425
- case QUOTED:
426
- if (isProperty()) type = PROPERTY;
427
- break;
428
- case SPACE:
429
- if (last && last.type === STRAP && last.text === 'retrun') {
430
- queue.inExpress = false;
431
- }
432
- break;
433
- case EXPRESS:
434
- if (!/^\./.test(m) && isProperty()) type = PROPERTY;
435
- else if (this.number_reg.test(m)) type = VALUE;
436
- break;
437
- case STRAP:
438
- case VALUE:
439
- if (last && last.type === EXPRESS && /\.$/.test(last.text)) {
440
- type = EXPRESS;
441
- }
442
- else if (isProperty()) type = PROPERTY;
443
- else if (m === 'from') {
444
- if (!last || last.type === STRAP && !/^(im|ex)port$/.test(last.text)) {
445
- type = EXPRESS;
446
- break;
447
- }
448
- var temp = last;
449
- while (temp.type === STAMP && temp.text === "*" || temp.type === EXPRESS || temp.type === VALUE || temp.type === SCOPED) {
450
- var prev = temp.prev;
451
- if (!prev) break;
452
- if (prev.type === STRAP && prev.text === "as") {
453
- temp = prev.prev;
454
- continue;
455
- }
456
- if (prev.type !== STAMP || prev.text !== ',' && (prev.text !== "*" || !prev.prev || !~[STRAP, STAMP].indexOf(prev.prev.type))) {
457
- temp = prev;
458
- break;
459
- }
460
- temp = prev.prev;
461
- if (!temp) break;
462
- }
463
- if (!temp || temp.type !== STRAP || !/^(im|ex)port$/.test(temp.text)) {
464
- type = EXPRESS;
465
- }
466
- }
467
- else if (m === 'as') {
468
- if (!last) {
469
- type = EXPRESS;
470
- break;
471
- }
472
- if (~[PROPERTY, EXPRESS, VALUE].indexOf(last.type)
473
- || last.type === STAMP && last.text === "*" && last.prev && ~[STRAP, STAMP].indexOf(last.prev.type)) {
474
- Object.defineProperty(last, 'queue', { value: queue });
475
- } else {
476
- type = EXPRESS;
477
- }
478
- }
479
- break;
480
- case STAMP:
481
- if (m === ";") queue.inExpress = false;
482
- else if (last) check: switch (m) {
483
- case "?":
484
- queue.inExpress = true;
485
- if (!queue.question) queue.question = 1;
486
- else queue.question++;
487
- break;
488
- case ",":
489
- case "=":
490
- if (queue.isObject) {
491
- if (last.type === PROPERTY) {
492
- last.short = true;
493
- }
494
- }
495
- queue.inExpress = true;
496
- break;
497
- case ":":
498
- if (queue.question) {
499
- queue.question--;
500
- queue.inExpress = true;
501
- break;
502
- }
503
- if (queue.isObject) {
504
- if (last.type === PROPERTY || last.isprop) {
505
- queue.inExpress = true;
506
- break;
507
- }
508
- if (last.type === SCOPED && (!last.prev || !last.prev.type === STAMP && last.prev.text === ",")) {
509
- queue.inExpress = true;
510
- }
511
- break;
512
- }
513
- var temp = last;
514
- while (temp) {
515
- if (temp.type === STRAP && /^(case|default)$/.test(temp.text)) {
516
- queue.inExpress = false;
517
- break check;
518
- }
519
- if (!temp.isExpress) break;
520
- temp = temp.prev;
521
- }
522
- queue.inExpress = false;
523
- if (last.type === EXPRESS) {
524
- // label
525
- last.type = LABEL;
526
- last.text += ":";
527
- last.end = end;
528
- return;
529
- }
530
- break;
531
- default:
532
- queue.inExpress = true;
533
- }
534
- else {
535
- queue.inExpress = true;
536
- }
537
- break;
538
- }
539
- if (type === STRAP && m === "class" && !queue.classed) {
540
- queue.classed = 1;
541
- }
542
- else if (queue.classed > 0) {
543
- if (type === STRAP && /^(class|function)$/.test(m)) queue.classed++;
544
- }
545
- var scope = {
546
- type,
547
- start,
548
- end,
549
- isExpress: queue.inExpress,
550
- text: m
551
- }
552
- lasttype = type;
553
- queue_push(scope);
554
- };
555
- var push_quote = function () {
556
- var scope = [];
557
- scope.entry = m;
558
- scope.type = SCOPED;
559
- scope.inExpress = true;
560
- scope.leave_map = quote.leave;
561
- end = match.index;
562
- m = text.slice(start, end);
563
- save(PIECE);
564
- queue_push(scope);
565
- parents.push(queue);
566
- lasttype = scope.type;
567
- queue = scope;
568
- };
569
- var isProperty = function () {
570
- var prev = queue.lastUncomment;
571
- if (queue.isObject) {
572
- if (!prev || prev.type === STAMP && prev.text === ",") return true;
573
- if (prev.type === STAMP && prev.isprop) return true;
574
- }
575
- if (queue.isClass) {
576
- if (!prev) return true;
577
- if (prev.type === STAMP) {
578
- if (prev.isprop) return true;
579
- return /^(\+\+|\-\-|;)$/.test(prev.text);
580
- }
581
- if (prev.type === EXPRESS && !/\.$/.test(prev.text)) return true;
582
- if (~[SCOPED, VALUE, QUOTED, PROPERTY].indexOf(prev.type)) return true;
583
- }
584
- if (!prev) return false;
585
- if (prev.type === PROPERTY && /^(get|set|async|static)$/.test(prev.text)) {
586
- return true;
587
- }
588
- if (queue.prev && queue.prev.type === STRAP && queue.prev.text === 'export') {
589
- if (prev.type === STRAP && prev.text === "as") return true;
590
- }
591
- return false;
592
- };
593
-
594
- loop: while (index < text.length) {
595
- if (queue.type === QUOTED) {
596
- var quote = this.quote_map[queue.entry];
597
- var reg = quote.reg;
598
- start = index;
599
- while (index < text.length) {
600
- reg.lastIndex = index;
601
- var match = reg.exec(text);
602
- if (!match) {
603
- index = text.length;
604
- break;
605
- }
606
- var m = match[0];
607
- index = match.index + m.length;
608
- if (quote.end.test(m)) {
609
- end = match.index;
610
- queue.leave = m;
611
- m = text.slice(start, end);
612
- save(PIECE);
613
- break;
614
- }
615
- if (m in quote.entry) {
616
- push_quote();
617
- start = index;
618
- continue loop;
619
- }
620
- }
621
- queue.end = match.index;
622
- queue = parents.pop();
623
- lasttype = queue.type;
624
- continue;
625
- }
626
- var reg = this.entry_reg;
627
- var start = reg.lastIndex = index;
628
- var match = reg.exec(text);
629
- if (!match) return null;
630
- var end = match[0].length + match.index;
631
- this.lastIndex = index = end;
632
- var m = match[0];
633
- test: if (this.quote_map.hasOwnProperty(m)) {
634
- var last = queue.lastUncomment;
635
- if (this.stamp_reg.test(m) && last) {
636
- if ([VALUE, EXPRESS, QUOTED].indexOf(last.type) >= 0) break test;
637
- if (last.type === SCOPED && queue.inExpress) break test;
638
- }
639
- var scope = [];
640
- var quote = this.quote_map[m];
641
- scope.type = this.comment_entry.test(m) ? COMMENT : QUOTED;
642
- scope.start = start;
643
- queue_push(scope);
644
- parents.push(queue);
645
- queue = scope;
646
- lasttype = scope.type;
647
- var m0 = m;
648
- while (index < text.length) {
649
- var reg = quote.reg;
650
- reg.lastIndex = index;
651
- var match = reg.exec(text);
652
- if (!match) {
653
- index = text.length;
654
- break;
655
- }
656
- var m = match[0];
657
- index = this.lastIndex = match.index + m.length;
658
- if (quote.length === 2) {
659
- break;
660
- }
661
- if (quote.end.test(m)) {
662
- break;
663
- }
664
- if (quote.length === 3) {
665
- continue;
666
- }
667
- if (quote.length >= 4 && m in quote.entry) {
668
- queue.entry = m0;
669
- start += m0.length;
670
- push_quote();
671
- continue loop;
672
- }
673
- }
674
- queue.inExpress = true;
675
- queue.end = index;
676
- queue.text = text.slice(queue.start, index);
677
- queue = parents.pop();
678
- lasttype = queue.type;
679
- continue;
680
- }
681
- var parent = parents[parents.length - 1];
682
- if (parent && this.quote_map[parent.entry] && queue.leave_map[m] === queue.entry) {
683
- delete queue.leave_map;
684
- queue.end = end;
685
- queue.leave = m;
686
- queue = parents.pop();
687
- lasttype = queue.type;
688
- continue;
689
- }
690
- if (this.space_reg.test(m)) {
691
- if (/[\r\n\u2028\u2029]/.test(m)) {
692
- colstart = match.index + 1;
693
- m = m.replace(/^[^\r\n\u2028\u2029]+/, '').replace(/\r\n|\r|\n|\u2028|\u2029/g, "\r\n");
694
- row += m.replace(/[^\r\n]+/, '').length >> 1;
695
- save(SPACE);
696
- }
697
- lasttype = SPACE;
698
- continue;
699
- }
700
- if (this.strap_reg.test(m)) {
701
- if (!/^(async|function|class)$/.test(m)) queue.inExpress = this.transive.test(m);
702
- else {
703
- var last = queue.lastUncomment;
704
- if (!last) queue.inExpress = false;
705
- else if (last.type === STAMP) {
706
- queue.inExpress = !/^(;|\+\+|\-\-)$/.test(last.text);
707
- }
708
- else if (last.type !== STRAP) {
709
- queue.inExpress = false;
710
- }
711
- }
712
- if (m === 'yield') {
713
- var temp = queue;
714
- var type = STRAP;
715
- var last = queue.lastUncomment;
716
- if (queue.entry === '[' || queue.isClass || queue.isObject || last && (last.type === STAMP && (
717
- queue[queue.length - 1].type !== SPACE && /^(\+\+|\-\-)$/.test(last.text)
718
- || !/^(>>>?=|<<=|[^><!=]=|[,;])/.test(last.text)
719
- ) || last.type === STRAP)) {
720
- type = EXPRESS;
721
- }
722
- if (type === STRAP) while (temp) {
723
- if (temp.entry != "{" || !temp.prev || temp.prev.type !== SCOPED || temp.prev.entry !== '(') {
724
- temp = temp.queue;
725
- continue;
726
- }
727
- var pp = temp.prev.prev;
728
- var isprop = pp.isprop;
729
- if (pp && pp.type === EXPRESS || pp.isprop) pp = pp.prev;
730
- if (!pp || pp.type === STRAP && !/^function$/.test(pp.text)) {
731
- temp = temp.queue;
732
- continue;
733
- }
734
- if (pp.type === STAMP && pp.text === "*" && (pp.isprop || pp.prev && pp.prev.type === STRAP && pp.prev.text === "function")) {
735
- type = STRAP;
736
- break;
737
- }
738
- if (isprop || pp.type === STRAP && pp.text === "function") {
739
- type = EXPRESS;
740
- break;
741
- }
742
- temp = temp.queue;
743
- }
744
- save(type);
745
- }
746
- else {
747
- save(STRAP);
748
- }
749
- continue;
750
- }
751
- if (this.value_reg.test(m) || this.number_reg.test(m)) {
752
- save(VALUE);
753
- queue.inExpress = true;
754
- continue;
755
- }
756
- if (this.express_reg.test(m)) {
757
- save(EXPRESS);
758
- queue.inExpress = true;
759
- continue;
760
- }
761
-
762
- if (this.scope_entry[m]) {
763
- var scope = [];
764
- scope.entry = m;
765
- scope.type = SCOPED;
766
- var last = queue.lastUncomment;
767
- if (m === "{") {
768
- if (!last) {
769
- scope.isObject = queue.inExpress;
770
- }
771
- else if (queue.classed > 0) {
772
- if (last.type !== STAMP || last.text !== "=>") {
773
- queue.classed--;
774
- scope.isClass = true;
775
- scope.extend += last.text === "extends";
776
- scope.inExpress = false;
777
- }
778
- }
779
- else if (last.type === STAMP) {
780
- if (last.text === ':') {
781
- scope.isObject = queue.inExpress;
782
- }
783
- else scope.isObject = !/^(;|\+\+|\-\-|=>)$/.test(last.text);
784
- }
785
- else if (last.type === STRAP) {
786
- if (queue[queue.length - 1].type === SPACE && /^(return|yield)$/.test(last.text));
787
- else if (/^export$/.test(last.text));
788
- else scope.isObject = queue.inExpress;
789
- }
790
- }
791
- else {
792
- scope.isExpress = queue.inExpress;
793
- scope.inExpress = true;
794
- }
795
-
796
- queue_push(scope);
797
- parents.push(queue);
798
- queue = scope;
799
- scope.start = match.index;
800
- lasttype = scope.type;
801
- continue;
802
- }
803
- if (this.scope_leave[m] && queue.entry === this.scope_leave[m]) {
804
- var lastUncomment = queue.lastUncomment;
805
- if (lastUncomment) {
806
- if (lastUncomment.type === PROPERTY) {
807
- lastUncomment.short = true;
808
- }
809
- }
810
-
811
- queue.end = end;
812
- queue.leave = m;
813
- queue = parents.pop();
814
- lasttype = queue.type;
815
- continue;
816
- }
817
-
818
- if (this.stamp_reg.test(m)) {
819
- save(STAMP);
820
- }
821
-
822
- }
823
- if (queue !== origin) throw new Error("代码异常结束");
824
- return queue;
825
- }
826
- commit() {
827
- this.strap_reg = this.createRegExp(this.straps);
828
- this.comment_entry = this.createRegExp(this.comments.map(m => m[0]));
829
- var stamps = this.stamps.join("");
830
- stamps = this.compile(stamps);
831
- this.stamp_reg = new RegExp(`^[${stamps}]$`);
832
- var tokens = {};
833
- var quote_map = {};
834
- this.quote_map = quote_map;
835
- var quoteslike = this.comments.concat(this.quotes);
836
- quoteslike.forEach(q => {
837
- var a = q[0];
838
- if (a instanceof RegExp) a = a.source;
839
- if (a.length === 1) tokens[a] = true;
840
- var r = q.slice(2).concat(q[1]).map(q => {
841
- if (q instanceof Array) {
842
- return this.compile(q[0]);
843
- }
844
- if (q instanceof RegExp) {
845
- return q.source;
846
- }
847
- return this.compile(q);
848
- }).join("|");
849
- q.reg = new RegExp(r, 'g');
850
- q.end = this.createRegExp([q[1]]);
851
- if (q.length >= 4) {
852
- var map = q.entry = {};
853
- var end = q.leave = {};
854
- q.slice(3).forEach(k => {
855
- var [a, b] = k;
856
- map[a] = b;
857
- end[b] = a;
858
- // tokens[b] = true;
859
- // tokens[a] = true;
860
- });
861
- }
862
- quote_map[a] = q;
863
- });
864
- var scope_entry = {};
865
- this.scope_entry = scope_entry;
866
- this.scope_leave = {};
867
- var scope_leave = this.scope_leave;
868
- this.scopes.forEach(s => {
869
- var [a, b] = s;
870
- scope_entry[a] = b;
871
- scope_leave[b] = a;
872
- tokens[a] = true;
873
- tokens[b] = true;
874
- });
875
- this.stamps.forEach(s => {
876
- tokens[s] = true;
877
- });
878
- this.spaces.forEach(s => {
879
- tokens[s] = true;
880
- });
881
- var keys = Object.keys(tokens).join("");
882
- keys = this.compile(keys);
883
- var express = `[^${keys}]+`;
884
- this.express_reg = new RegExp(`^${express}$`);
885
- var scopes = this.scopes.map(a => a.join("")).join("");
886
- scopes = this.compile(scopes);
887
- var spaces = this.spaces.join("");
888
- spaces = this.compile(spaces);
889
- this.space_reg = new RegExp(`^[${spaces}]+$`);
890
- var quotes = this.createRegExp(quoteslike.map(q => q[0]), true).source;
891
- this.entry_reg = new RegExp([`[${spaces}]+|${quotes}|[${scopes}]|${this.number_reg.source.replace(/^\^|\$$/g, "")}|${express}|[${stamps}]`], "gi");
892
- }
893
-
894
-
895
- }
896
-
897
- var program = new Javascript;
898
- function javascript(text, lastIndex = 0) {
899
- program.lastIndex = lastIndex;
900
- return program.exec(text);
901
- }
902
-
903
- function scan(text) {
904
- var res = javascript(text, 0);
905
- return res;
906
- }
907
-
908
-
909
- module.exports = scan;