efront 3.24.2 → 3.24.7

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