efront 4.35.5 → 4.35.6

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 (79) hide show
  1. package/apps/_index.html +41 -41
  2. package/apps/blank/index.html +20 -20
  3. package/apps/noice/index.html +42 -42
  4. package/apps/pay/paypal.jsp +0 -0
  5. package/apps/pay/wxpay.jsp +32 -0
  6. package/apps/pivot/dht/rent.html +14 -0
  7. package/apps/pivot/dht/rent.js +148 -0
  8. package/apps/pivot/dht/rent.less +46 -0
  9. package/apps/pivot/home/desktop.xht +0 -0
  10. package/apps/pivot/menu.yml +6 -1
  11. package/apps/pivot/shop/goods/list.xht +183 -0
  12. package/apps/pivot/shop/home.xht +20 -0
  13. package/apps/pivot/shop/mind/list.xht +1 -0
  14. package/apps/pivot/shop/order/create.xht +49 -0
  15. package/apps/pivot/shop/order/list.xht +1 -0
  16. package/apps/pivot/shop/paypal.jsp +23 -0
  17. package/apps/pivot/soft/list.html +0 -0
  18. package/apps/pivot/soft/list.js +9 -0
  19. package/apps/pivot/soft/list.less +0 -0
  20. package/apps/pivot//344/270/273/351/241/265.html +42 -42
  21. package/coms/7z_temp/Java.js +93 -0
  22. package/coms/7z_temp/LzmaBench.java +392 -0
  23. package/coms/7z_temp/read-from-java-code.js +28 -0
  24. package/coms/7z_temp//350/257/264/346/230/216.md +1 -0
  25. package/coms/basic/JSAM.js +259 -259
  26. package/coms/basic/JSAM_test.js +3 -5
  27. package/coms/basic/check.js +42 -42
  28. package/coms/basic/color.js +696 -696
  29. package/coms/basic/crc.js +39 -39
  30. package/coms/basic/getIndexFromOrderedArray.js +39 -39
  31. package/coms/basic/isObject.js +3 -3
  32. package/coms/basic/keys.js +4 -4
  33. package/coms/basic/lazy.js +78 -78
  34. package/coms/basic/refilm.js +96 -96
  35. package/coms/basic/saveToOrderedArray.js +11 -11
  36. package/coms/basic/strings.js +0 -1
  37. package/coms/basic_/&pget.js +1 -0
  38. package/coms/basic_/&pset.js +1 -0
  39. package/coms/basic_/Proxy.js +6 -0
  40. package/coms/basic_/Reflect.js +55 -0
  41. package/coms/compile/autoeval.js +24 -5
  42. package/coms/compile/autoeval_test.js +5 -1
  43. package/coms/compile/bracket.js +51 -0
  44. package/coms/compile/bracket_test.js +9 -0
  45. package/coms/compile/createvm.js +35 -0
  46. package/coms/compile/createvm_test.js +7 -0
  47. package/coms/compile/scanner.js +653 -653
  48. package/coms/compile/scanner2.js +23 -0
  49. package/coms/docs/getMimeData_test.js +19 -19
  50. package/coms/docs/md5.js +173 -173
  51. package/coms/frame/top.less +190 -190
  52. package/coms/pivot/DB.js +9 -0
  53. package/coms/pivot/paypal-var.js +1 -0
  54. package/coms/pivot//345/225/206/345/223/201.js +1 -0
  55. package/coms/zimoli/AudioContext_test.html +5 -5
  56. package/coms/zimoli/AudioContext_test.js +92 -92
  57. package/coms/zimoli/AudioContext_test.less +114 -114
  58. package/coms/zimoli/alert_test.js +11 -11
  59. package/coms/zimoli/dispatch.js +50 -50
  60. package/coms/zimoli/extendTouchEvent.js +8 -8
  61. package/coms/zimoli/fullscreen.js +52 -52
  62. package/coms/zimoli/gallery.less +13 -13
  63. package/coms/zimoli/gallery_test.html +2 -2
  64. package/coms/zimoli/gallery_test.js +14 -14
  65. package/coms/zimoli/gallery_test.less +17 -17
  66. package/coms/zimoli/getChanged.js +7 -7
  67. package/coms/zimoli/getChanges.js +13 -13
  68. package/coms/zimoli/lattice.js +109 -109
  69. package/coms/zimoli/lattice_test.less +23 -23
  70. package/coms/zimoli/picture.less +71 -71
  71. package/coms/zimoli/refilm_test.html +41 -41
  72. package/coms/zimoli/refilm_test.less +102 -102
  73. package/coms/zimoli/xml.js +131 -131
  74. package/data/keystore/cross-cert.pem +21 -21
  75. package/data/keystore/cross-key.pem +27 -27
  76. package/package.json +1 -1
  77. package/public/efront.js +1 -1
  78. package/public//346/226/207/344/273/266/347/263/273/347/273/237//344/270/273/351/241/265.jsp +2 -2
  79. /package/apps/pivot/{tick → ticket}/list.js +0 -0
@@ -1,654 +1,654 @@
1
- "use strict";
2
- function test(test, count) {
3
- var time = +new Date;
4
- if (test instanceof Function) {
5
- while (count-- > 0) {
6
- test();
7
- }
8
- }
9
- return new Date - time;
10
- }
11
- // - function () {
12
- // single_comment_scanner.call("'", 0) === 1;
13
- // single_comment_scanner.call(" ", 0) === 1;
14
- // single_comment_scanner.call("' ", 0) === 1;
15
- // single_comment_scanner.call("\\'", 0) === 2;
16
- // single_comment_scanner.call(" ' ", 0) === 2;
17
- // single_comment_scanner.call("\\''", 0) === 3;
18
- // single_comment_scanner.call("\\'' ", 0) === 3;
19
- // // var t1=test(function(){
20
- // // /[\r\n\u2028\u2029]/.exec(" ");
21
- // // },10000000);//300+
22
- // // var t2=test(function(){
23
- // // "\r\n\u2028\u2029".indexOf(" ");
24
- // // },10000000);//700+
25
- // // console.log(t1,t2);
26
- // }();
27
- // console.log(single_quote_scanner.call("''", 0))
28
-
29
-
30
-
31
- /**
32
- * 单引号字符串扫描
33
- * @param {Inteter} index
34
- */
35
- // var count = 1000000;
36
- // var string=" '"
37
- // var t1 = test(function () {
38
- // single_quote_scanner.call(string,0);
39
- // }, count);//240+
40
- // var t2 = test(function () {
41
- // single_quote_scanner2.call(string,0)
42
- // }, count);//1202+
43
- // console.log(t1, t2);
44
- function single_quote_scanner(index) {
45
- var reg = /\\[\s\S]|'/g;
46
- reg.lastIndex = index + 1;
47
- do {
48
- var res = reg.exec(this);
49
- } while (res && res[0].length > 1);
50
- return res ? res.index + 1 : this.length;
51
- }
52
-
53
- function single_quote_scanner2(index) {
54
- // var x = "'".codePointAt(0); //39
55
- // var u = "\\".codePointAt(0);//92
56
-
57
- var length = this.length;
58
- while (++index < length) {
59
- // 字符的速度比codePointAt快点
60
- if (this[index] === "'" && this[index - 1] !== "\\") return index + 1;
61
- // if (this.codePointAt(index) === 39 && this.codePointAt(index - 1) !== 92) return index + 1;
62
- }
63
- return index;
64
- }
65
-
66
-
67
- /**
68
- * 双引号字符串扫描
69
- * @param {Integer} index
70
- */
71
- // var count = 1000000;
72
- // var string=" '"
73
- // var t1 = test(function () {
74
- // double_quote_scanner.call(string,0);
75
- // }, count);//240+
76
- // var t2 = test(function () {
77
- // double_quote_scanner2.call(string,0)
78
- // }, count);//1128+
79
- // console.log(t1, t2);
80
- function double_quote_scanner(index) {
81
- var reg = /\\[\s\S]|"/g;
82
- reg.lastIndex = index + 1;
83
- do {
84
- var res = reg.exec(this);
85
- } while (res && res[0].length > 1);
86
- return res ? res.index + 1 : this.length;
87
- }
88
-
89
- function double_quote_scanner2(index) {
90
- // var x = "\"".codePointAt(0);//34
91
- // var u = "\\".codePointAt(0);//92
92
- var length = this.length;
93
- while (++index < length) {
94
- // 字符的速度比codePointAt快点
95
- // if (this.codePointAt(index) === 34 && this.codePointAt(index - 1) !== 92) return index + 1;
96
- if (this[index] === "\"" && this[index - 1] !== "\\") return index + 1;
97
- }
98
- return index;
99
- }
100
-
101
-
102
-
103
- /**
104
- * 正则表达式扫描
105
- * @param {Integer} index
106
- */
107
- // var count = 1000000;
108
- // var string=" '"
109
- // var t1 = test(function () {
110
- // regexp_quote_scanner.call(string,0);
111
- // }, count);//220+
112
- // var t2 = test(function () {
113
- // regexp_quote_scanner2.call(string,0)
114
- // }, count);//1200+
115
- // console.log(t1, t2);
116
- function regexp_quote_scanner(index) {
117
- var reg = /\\[\s\S]|\[(\\[\s\S]|[^\]])+\]|\/[\w]*/g;
118
- reg.lastIndex = index + 1;
119
- do {
120
- var res = reg.exec(this);
121
- } while (res && res[0][0] !== "/");
122
- return res ? res.index + res[0].length : this.length;
123
- }
124
-
125
- function regexp_quote_scanner2(index) {
126
- // var x="/".codePointAt(0);//47
127
- // var u = "\\".codePointAt(0);//92
128
- while (++index < this.length) {
129
- // if (this.codePointAt(index) === 47 && this.codePointAt(index - 1) !== 92) return index + 1;
130
- // 字符的速度比codePointAt快点
131
- if (this[index] === "/" && this[index - 1] !== "\\") return index + 1;
132
- }
133
- return index;
134
- }
135
-
136
- /**
137
- * 模版字符串扫描
138
- * @param {Integer} index
139
- * @param {Array} blocks
140
- */
141
- // var count = 1000000;
142
- // var string = " ${`"
143
- // var t1 = test(function () {
144
- // template_quote_scanner.call(string, 0);
145
- // }, count); //610+
146
- // var t2 = test(function () {
147
- // template_quote_scanner2.call(string, 0)
148
- // }, count); //2500+
149
- // console.log(t1, t2);
150
-
151
- function template_quote_scanner(index, blocks) {
152
- index++;
153
- while (index < this.length) {
154
- var reg = /\\[\s\S]|`|\$\{/g;
155
- reg.lastIndex = index;
156
- var res = reg.exec(this);
157
- if (!res) {
158
- return this.length;
159
- }
160
- if (res[0] === "${") {
161
- index = block_code_scanner.call(this, res.index + 2, blocks);
162
- } else if (res[0].length === 1) {
163
- return res.index + 1;
164
- } else {
165
- index = reg.lastIndex;
166
- }
167
- }
168
- return index;
169
- }
170
-
171
- function template_quote_scanner2(index, blocks) {
172
- // var x1 = "`".codePointAt(0);//96
173
- // var x2 = "{".codePointAt(0);//123
174
- // var u1 = "\\".codePointAt(0);//92
175
- // var u2 = "$".codePointAt(0);//36
176
- var length = this.length;
177
- while (++index < length) {
178
- // if (this.codePointAt(index) === 96 && this.codePointAt(index - 1) !== 92) return index + 1;
179
- // if (this.codePointAt(index) === 92 && this.codePointAt(index - 1) === 36) {
180
- // index = block_code_scanner.call(this, index, blocks);
181
- // }
182
- if (this[index] === "`" && this[index - 1] !== "\\") return index + 1;
183
- if (this[index] === "{" && this[index - 1] === "$") {
184
- index = block_code_scanner.call(this, index + 1, blocks);
185
- }
186
- }
187
- return index;
188
- };
189
- /**
190
- * 多行注释扫描
191
- * @param {Integer} index
192
- */
193
- // var count = 1000000;
194
- // var string = " ${`";
195
- // var t1 = test(function () {
196
- // multi_comment_scanner.call(string, 0);
197
- // }, count); //266+
198
- // var t2 = test(function () {
199
- // multi_comment_scanner2.call(string, 0);
200
- // }, count); //266+
201
- // console.log(t1, t2);
202
- function multi_comment_scanner(index) {
203
- var reg = /\*\//g;
204
- reg.lastIndex = index + 1;
205
- var res = reg.exec(this);
206
- return res ? res.index + 2 : this.length;
207
- }
208
-
209
- function multi_comment_scanner2(index) {
210
- var index = this.indexOf("*/", index + 1);
211
- if (index > 0) {
212
- return index + 2;
213
- }
214
- return this.length;
215
- // var x="/".codePointAt(0);//47
216
- // var x="*".codePointAt(0);//42
217
- // 一般多行注释有更多的星号
218
- // index++;
219
- // while(++index<this.length){
220
- // if(this.codePointAt(index)===47&&this.charCodeAt(index-1)===42)break;
221
- // }
222
- }
223
- /**
224
- * 单行注释扫描
225
- * @param {Integer} index
226
- */
227
- // var count = 1000000;
228
- // var string = " ${`";
229
- // var t1 = test(function () {
230
- // single_comment_scanner.call(string, 0);
231
- // }, count); //233+
232
- // var t2 = test(function () {
233
- // single_comment_scanner2.call(string, 0);
234
- // }, count); //3340+
235
- // console.log(t1, t2);
236
- function single_comment_scanner(index) {
237
- var reg = /[\r\n\u2028\u2029]/g;
238
- reg.lastIndex = index + 1;
239
- var res = reg.exec(this);
240
- index = res ? res.index : this.length;
241
- if (this[index] === "\r" && this[index + 1] == "\n") {
242
- index++;
243
- }
244
- return index + 1;
245
- }
246
-
247
- function single_comment_scanner2(index) {
248
- var c;
249
- var length = this.length;
250
- while (++index < length) {
251
- /**
252
- * 这里switch case 与if的速度相当,但当使用双字节换行时有较大的风险,所以这里使用if+codePointAt
253
- */
254
- // switch (this[index]) {
255
- // case "\r":
256
- // if (this[index + 1] === "\n") return index + 2;
257
- // return index + 1;
258
- // case "\n":
259
- // case "\u2028":
260
- // case "\u2029":
261
- // return index+1;
262
- // }
263
- c = this.charCodeAt(index);
264
- if (c < 0xff) {
265
- if (c === 13) {
266
- if (this.charCodeAt(index + 1) === 10) {
267
- return index + 2;
268
- }
269
- return index + 1;
270
- } else if (c === 10) {
271
- return index + 1;
272
- }
273
- } else {
274
- if (c === 2028 || c === 2029) {
275
- return index + 1;
276
- }
277
- }
278
- }
279
- return index;
280
- }
281
- //var declareReg=/(var|const|let)\s+([A-Za-z\$_][\w$_]*(?:\s*,\s*[A-Za-z\$_][\w$_]*)*)/g;
282
- /**
283
- * 代码块扫描
284
- * @param {Integer} index
285
- * @param {Array} blocks
286
- */
287
- // var count = 1000000;
288
- // var string = " ${`";
289
- // var t1 = test(function () {
290
- // single_comment_scanner.call(string, 0);
291
- // }, count); //317+
292
- // var t2 = test(function () {
293
- // single_comment_scanner2.call(string, 0);
294
- // }, count); //3354+
295
- // console.log(t1, t2);
296
- function block_code_scanner(index, blocks = [], keepdeep = Infinity) {
297
- var save = (blocks instanceof Array) ? function (scanner, children) {
298
- if (deep < keepdeep && saved_index < index) {
299
- blocks.push(new Block(scanner, saved_index, index, children));
300
- saved_index = index;
301
- }
302
- } : function () { };
303
- var lookback = function (tempIndex) {
304
- while (tempIndex >= saved_index && /\s/.test(this[tempIndex])) tempIndex--;
305
- if (tempIndex < saved_index) {
306
- var blockIndex = blocks.length;
307
- while (blockIndex-- > 0) {
308
- var tempBlock = blocks[blockIndex];
309
- var type = tempBlock.type;
310
- if (type === single_comment_scanner || type === multi_comment_scanner) continue;
311
- if (type !== block_code_scanner) break;
312
- var tempLastIndex = tempBlock.start;
313
- tempIndex = Math.min(tempBlock.end, tempIndex);
314
- while (tempIndex >= tempLastIndex && /\s/.test(this[tempIndex])) tempIndex--;
315
- if (tempIndex > tempLastIndex) break;
316
- }
317
- if (blockIndex < 0) tempIndex = blockIndex;
318
- }
319
- return tempIndex;
320
- };
321
- var saved_index = index;
322
- var start_index = index;
323
- var c, deep = 0;
324
- var length = this.length;
325
- var reg = /[\/\{\}'"`]/g;
326
- while (index < length) {
327
- reg.lastIndex = index;
328
- var res = reg.exec(this);
329
- index = res ? res.index : this.length;
330
- //直接用字符表示比用数字快一倍,用的时间是用codePointAt的一半
331
- var c = this[index];
332
- switch (c) {
333
- case "/": // /
334
- save(block_code_scanner);
335
- var d = this[index + 1];
336
- //内部的d 数字与字符的速度差别不大
337
- if (d === "*") { // u /* */
338
- index = multi_comment_scanner.call(this, index + 1);
339
- save(multi_comment_scanner);
340
- } else if (d === "/") { // x3 //
341
- index = single_comment_scanner.call(this, index + 1);
342
- save(single_comment_scanner);
343
- } else { // /reg/
344
- var isReg = false;
345
- // do{break 8
346
- // for(;;)break 12
347
- // while(0)break 13
348
- // switch(a){case 1:break
349
- // return/a/
350
- //switch case break,while continue,break abcd;
351
- var tempIndex = lookback.call(this, index - 1);
352
- isReg = tempIndex <= start_index || /[[|,+=*~?:&\^{\(\/><;%\-!]/.test(this[tempIndex]);
353
- if (!isReg && tempIndex >= start_index + 5) {
354
- var last_pice = this.slice(Math.max(tempIndex - 50, 0), tempIndex + 1);
355
- isReg = /return\s*$|([)};:{]|[^\.\s]\s+)(continue|break|case)\s*$/.test(last_pice);
356
- isReg = isReg || /([)};:{]|[^\.\s]\s+)(?:continue|break)\s+([\w\u0100-\u2027\u2030-\uffff]+?)$/.test(last_pice);
357
- if (!isReg && !/\r\n\u2028\u2029/.test(last_pice)) {
358
- var variabled_name_reg = /\w\u0100-\u2027\u2030-\uffff/;
359
- if (variabled_name_reg.test(this[tempIndex])) {
360
- while (tempIndex > 8 && variabled_name_reg.test(this[tempIndex])) tempIndex--;
361
- var tempIndex2 = lookback.call(this, tempIndex);
362
- if (tempIndex2 >= 8 && !/\r\n\u2028\u2029/.test(this.slice(tempIndex2, tempIndex))) {
363
- isReg = /([)};:{]|[^\.\s]\b\s*)(continue|break)$/.test(this.slice(tempIndex2 - 8, tempIndex2 + 1));
364
- }
365
- }
366
- }
367
- }
368
- if (isReg) {
369
- index = regexp_quote_scanner.call(this, index);
370
- save(regexp_quote_scanner);
371
- } else {
372
- index++;
373
- }
374
- }
375
- break;
376
- case "`": // `
377
- save(block_code_scanner);
378
- var children = [];
379
- index = template_quote_scanner.call(this, index, children);
380
- save(template_quote_scanner, children);
381
- break;
382
- case "'": // '
383
- save(block_code_scanner);
384
- index = single_quote_scanner.call(this, index);
385
- save(single_quote_scanner);
386
- break;
387
- case "\"": // "
388
- save(block_code_scanner);
389
- index = double_quote_scanner.call(this, index);
390
- save(double_quote_scanner);
391
- break;
392
- case "}": // }
393
- if (deep === 0) {
394
- save(block_code_scanner);
395
- return index + 1;
396
- }
397
- deep--;
398
- index++;
399
- break;
400
- case "{": // {
401
- deep++;
402
- index++;
403
- break;
404
- }
405
- }
406
- if (saved_index < length) save(block_code_scanner);
407
- return index;
408
- }
409
-
410
- function block_code_scanner2(index, blocks) {
411
- var save = (blocks instanceof Array) ? function (scanner) {
412
- if (saved_index < index) {
413
- blocks.push(new Block(scanner, saved_index, index));
414
- saved_index = index;
415
- }
416
- } : function () { };
417
- //for(){block} while(){block} function(){block} switch(){block} ()=>{block} {simple block}
418
- //{object block} /var|let|const\s*{block}/
419
- // "\"'/`{}".split("").sort().map(a=>a.codePointAt(0));
420
- // 字节顺序,x1,x2,x3,x4,x5,x6从小到大排列
421
- // var x1 = "\"".codePointAt(0);//34
422
- // var x2 = "'".codePointAt(0);//39
423
- // var x3 = "/".codePointAt(0);//47
424
- // var x4 = "`".codePointAt(0);//96
425
- // var x5 = "{".codePointAt(0);//123
426
- // var x6 = "}".codePointAt(0);//125
427
- // var u = "*".codePointAt(0);//42
428
- var saved_index = index;
429
- var c, deep = 0;
430
- var length = this.length;
431
- while (index < length) {
432
- //直接用字符表示比用数字快一倍,用的时间是用codePointAt的一半
433
- var c = this[index];
434
- switch (c) {
435
- case "/": // /
436
- save(block_code_scanner);
437
- var d = this[index + 1];
438
- //内部的d 数字与字符的速度差别不大
439
- if (d === "*") { // u /* */
440
- index = multi_comment_scanner.call(this, index + 1);
441
- save(multi_comment_scanner);
442
- } else if (d === "/") { // x3 //
443
- index = single_comment_scanner.call(this, index + 1);
444
- save(single_comment_scanner);
445
- } else { // /reg/
446
- index = regexp_quote_scanner.call(this, index);
447
- save(regexp_quote_scanner);
448
- }
449
- // var d = this.codePointAt(index + 1);
450
- // save(block_code_scanner);
451
- // if (d === 42) { // u /* */
452
- // index = multi_comment_scanner.call(this, index + 1);
453
- // save(multi_comment_scanner);
454
- // } else if (d === 47) { // x3 //
455
- // index = single_comment_scanner.call(this, index + 1);
456
- // save(single_comment_scanner);
457
- // } else { // /reg/
458
- // index = regexp_quote_scanner.call(this, index);
459
- // save(regexp_quote_scanner);
460
- // }
461
- break;
462
- case "`": // `
463
- save(block_code_scanner);
464
- index = template_quote_scanner.call(this, index, blocks);
465
- save(template_quote_scanner);
466
- break;
467
- case "'": // '
468
- save(block_code_scanner);
469
- index = single_quote_scanner.call(this, index);
470
- save(single_quote_scanner);
471
- break;
472
- case "\"": // "
473
- save(block_code_scanner);
474
- index = double_quote_scanner.call(this, index);
475
- save(double_quote_scanner);
476
- break;
477
- case "}": // }
478
- if (deep === 0) {
479
- save(block_code_scanner);
480
- return index + 1;
481
- }
482
- deep--;
483
- index++;
484
- break;
485
- case "{": // {
486
- deep++;
487
- default:
488
- index++;
489
- }
490
- // c = this.codePointAt(index);
491
- // switch (c) {
492
- // case 47:// /
493
- // var d = this.codePointAt(index + 1);
494
- // save(block_code_scanner);
495
- // /** 嵌在内部的情况较少的switch(d),速度与来没有差别*/
496
- // // switch (d) {
497
- // // case 42:
498
- // // index = multi_comment_scanner.call(this, index + 1);
499
- // // save(multi_comment_scanner);
500
- // // break;
501
- // // case 47:
502
- // // index = single_comment_scanner.call(this, index + 1);
503
- // // save(single_comment_scanner);
504
- // // break;
505
- // // default:
506
- // // index = regexp_quote_scanner.call(this, index);
507
- // // save(regexp_quote_scanner);
508
- // // }
509
- // if (d === 42) { // u /* */
510
- // index = multi_comment_scanner.call(this, index + 1);
511
- // save(multi_comment_scanner);
512
- // } else if (d === 47) { // x3 //
513
- // index = single_comment_scanner.call(this, index + 1);
514
- // save(single_comment_scanner);
515
- // } else { // /reg/
516
- // index = regexp_quote_scanner.call(this, index);
517
- // save(regexp_quote_scanner);
518
- // }
519
- // break;
520
- // case 96:// `
521
- // save(block_code_scanner);
522
- // index = template_quote_scanner.call(this, index);
523
- // save(template_quote_scanner);
524
- // break;
525
- // case 39: // '
526
- // save(block_code_scanner);
527
- // index = single_quote_scanner.call(this, index);
528
- // save(single_quote_scanner);
529
- // break;
530
- // case 34:// "
531
- // save(block_code_scanner);
532
- // index = double_quote_scanner.call(this, index);
533
- // save(double_quote_scanner);
534
- // break;
535
- // case 125:// }
536
- // if (deep === 0) {
537
- // save(block_code_scanner);
538
- // return index + 1;
539
- // }
540
- // deep--;
541
- // case 123:// {
542
- // deep++;
543
- // default:
544
- // index++;
545
- // }
546
-
547
- /**
548
- * if else有明显的速度下降
549
- * 扫描angular.js的源码100次,ifelse用时8500左右
550
- * 其他条件不变时,switch case用时7600毫秒
551
- */
552
-
553
- // if (123 > c) { //x5
554
- // if (47 > c) { //x3
555
- // if (39 === c) { //x1 39 '
556
- // save(block_code_scanner);
557
- // index = single_quote_scanner.call(this, index);
558
- // save(single_quote_scanner);
559
- // } else if (34 === c) { //x2 " 34
560
- // save(block_code_scanner);
561
- // index = double_quote_scanner.call(this, index);
562
- // save(double_quote_scanner);
563
- // }else{
564
- // index++;
565
- // }
566
- // } else {
567
- // if (47 === c) { //x3 /
568
- // var d = this.codePointAt(index + 1);
569
- // save(block_code_scanner);
570
- // if (d === 42) { // u /* */
571
- // index = multi_comment_scanner.call(this, index + 1);
572
- // save(multi_comment_scanner);
573
- // } else if (d === 47) { // x3 //
574
- // index = single_comment_scanner.call(this, index + 1);
575
- // save(single_comment_scanner);
576
- // } else { // /reg/
577
- // index = regexp_quote_scanner.call(this, index);
578
- // save(regexp_quote_scanner);
579
- // }
580
- // } else if (96 === c) { //x4 ` 96
581
- // save(block_code_scanner);
582
- // index = template_quote_scanner.call(this, index);
583
- // save(template_quote_scanner);
584
- // }else{
585
- // index++;
586
- // }
587
- // }
588
- // } else {
589
- // if (123 === c) { //x5 { 123
590
- // deep++;
591
- // } else if (125 === c) { //x6 } 125
592
- // if (deep === 0) {
593
- // save(block_code_scanner);
594
- // return index + 1;
595
- // }
596
- // deep--;
597
- // }
598
- // index++;
599
- // }
600
- }
601
- if (saved_index < length) save(block_code_scanner);
602
- return index;
603
- };
604
-
605
- function lookback_scanner(blockIndex, blocks) {
606
- if (!blocks.length || blockIndex >= blocks.length) return -1;
607
- var tempIndex = blocks[blockIndex].end;
608
- while (blockIndex-- > 0) {
609
- var tempBlock = blocks[blockIndex];
610
- var type = tempBlock.type;
611
- if (type === single_comment_scanner || type === multi_comment_scanner) continue;
612
- if (type !== block_code_scanner) break;
613
- var tempLastIndex = tempBlock.start;
614
- tempIndex = Math.min(tempBlock.end, tempIndex);
615
- while (tempIndex >= tempLastIndex && /\s/.test(this[tempIndex])) tempIndex--;
616
- if (tempIndex > tempLastIndex) break;
617
- }
618
- if (blockIndex < 0) tempIndex = blockIndex;
619
- return tempIndex;
620
- }
621
-
622
- var scanner = module.exports = function (s, keepdeep) {
623
- var blocks = [];
624
- var s = String(s);
625
- // var time = +new Date;
626
- // for (var i = 0; i < 1000; i++) {
627
- // block_code_scanner.call(s, 0, blocks);
628
- // }//angular 1.5.3 x1000 7.0s
629
- // console.log(+new Date - time);
630
- block_code_scanner.call(s, 0, blocks, keepdeep);
631
- // console.log(blocks.map(a => s.slice(a.start, a.end)).join())
632
- return blocks;
633
- };
634
- scanner.autoskip = function (code, start) {
635
- return block_code_scanner.call(code, start, null);
636
- };
637
- function Block(scanner, start, end, children) {
638
- this.type = scanner;
639
- this.start = start;
640
- if (children) this.children = children;
641
- this.end = end;
642
- }
643
- Block.prototype = {
644
- lookback_scanner,
645
- block_code_scanner,
646
- double_quote_scanner,
647
- regexp_quote_scanner,
648
- single_quote_scanner,
649
- multi_comment_scanner,
650
- single_comment_scanner,
651
- template_quote_scanner
652
- };
653
- // module.exports(require("fs").readFileSync("./apps/x6/js/angular.js"))
1
+ "use strict";
2
+ function test(test, count) {
3
+ var time = +new Date;
4
+ if (test instanceof Function) {
5
+ while (count-- > 0) {
6
+ test();
7
+ }
8
+ }
9
+ return new Date - time;
10
+ }
11
+ // - function () {
12
+ // single_comment_scanner.call("'", 0) === 1;
13
+ // single_comment_scanner.call(" ", 0) === 1;
14
+ // single_comment_scanner.call("' ", 0) === 1;
15
+ // single_comment_scanner.call("\\'", 0) === 2;
16
+ // single_comment_scanner.call(" ' ", 0) === 2;
17
+ // single_comment_scanner.call("\\''", 0) === 3;
18
+ // single_comment_scanner.call("\\'' ", 0) === 3;
19
+ // // var t1=test(function(){
20
+ // // /[\r\n\u2028\u2029]/.exec(" ");
21
+ // // },10000000);//300+
22
+ // // var t2=test(function(){
23
+ // // "\r\n\u2028\u2029".indexOf(" ");
24
+ // // },10000000);//700+
25
+ // // console.log(t1,t2);
26
+ // }();
27
+ // console.log(single_quote_scanner.call("''", 0))
28
+
29
+
30
+
31
+ /**
32
+ * 单引号字符串扫描
33
+ * @param {Inteter} index
34
+ */
35
+ // var count = 1000000;
36
+ // var string=" '"
37
+ // var t1 = test(function () {
38
+ // single_quote_scanner.call(string,0);
39
+ // }, count);//240+
40
+ // var t2 = test(function () {
41
+ // single_quote_scanner2.call(string,0)
42
+ // }, count);//1202+
43
+ // console.log(t1, t2);
44
+ function single_quote_scanner(index) {
45
+ var reg = /\\[\s\S]|'/g;
46
+ reg.lastIndex = index + 1;
47
+ do {
48
+ var res = reg.exec(this);
49
+ } while (res && res[0].length > 1);
50
+ return res ? res.index + 1 : this.length;
51
+ }
52
+
53
+ function single_quote_scanner2(index) {
54
+ // var x = "'".codePointAt(0); //39
55
+ // var u = "\\".codePointAt(0);//92
56
+
57
+ var length = this.length;
58
+ while (++index < length) {
59
+ // 字符的速度比codePointAt快点
60
+ if (this[index] === "'" && this[index - 1] !== "\\") return index + 1;
61
+ // if (this.codePointAt(index) === 39 && this.codePointAt(index - 1) !== 92) return index + 1;
62
+ }
63
+ return index;
64
+ }
65
+
66
+
67
+ /**
68
+ * 双引号字符串扫描
69
+ * @param {Integer} index
70
+ */
71
+ // var count = 1000000;
72
+ // var string=" '"
73
+ // var t1 = test(function () {
74
+ // double_quote_scanner.call(string,0);
75
+ // }, count);//240+
76
+ // var t2 = test(function () {
77
+ // double_quote_scanner2.call(string,0)
78
+ // }, count);//1128+
79
+ // console.log(t1, t2);
80
+ function double_quote_scanner(index) {
81
+ var reg = /\\[\s\S]|"/g;
82
+ reg.lastIndex = index + 1;
83
+ do {
84
+ var res = reg.exec(this);
85
+ } while (res && res[0].length > 1);
86
+ return res ? res.index + 1 : this.length;
87
+ }
88
+
89
+ function double_quote_scanner2(index) {
90
+ // var x = "\"".codePointAt(0);//34
91
+ // var u = "\\".codePointAt(0);//92
92
+ var length = this.length;
93
+ while (++index < length) {
94
+ // 字符的速度比codePointAt快点
95
+ // if (this.codePointAt(index) === 34 && this.codePointAt(index - 1) !== 92) return index + 1;
96
+ if (this[index] === "\"" && this[index - 1] !== "\\") return index + 1;
97
+ }
98
+ return index;
99
+ }
100
+
101
+
102
+
103
+ /**
104
+ * 正则表达式扫描
105
+ * @param {Integer} index
106
+ */
107
+ // var count = 1000000;
108
+ // var string=" '"
109
+ // var t1 = test(function () {
110
+ // regexp_quote_scanner.call(string,0);
111
+ // }, count);//220+
112
+ // var t2 = test(function () {
113
+ // regexp_quote_scanner2.call(string,0)
114
+ // }, count);//1200+
115
+ // console.log(t1, t2);
116
+ function regexp_quote_scanner(index) {
117
+ var reg = /\\[\s\S]|\[(\\[\s\S]|[^\]])+\]|\/[\w]*/g;
118
+ reg.lastIndex = index + 1;
119
+ do {
120
+ var res = reg.exec(this);
121
+ } while (res && res[0][0] !== "/");
122
+ return res ? res.index + res[0].length : this.length;
123
+ }
124
+
125
+ function regexp_quote_scanner2(index) {
126
+ // var x="/".codePointAt(0);//47
127
+ // var u = "\\".codePointAt(0);//92
128
+ while (++index < this.length) {
129
+ // if (this.codePointAt(index) === 47 && this.codePointAt(index - 1) !== 92) return index + 1;
130
+ // 字符的速度比codePointAt快点
131
+ if (this[index] === "/" && this[index - 1] !== "\\") return index + 1;
132
+ }
133
+ return index;
134
+ }
135
+
136
+ /**
137
+ * 模版字符串扫描
138
+ * @param {Integer} index
139
+ * @param {Array} blocks
140
+ */
141
+ // var count = 1000000;
142
+ // var string = " ${`"
143
+ // var t1 = test(function () {
144
+ // template_quote_scanner.call(string, 0);
145
+ // }, count); //610+
146
+ // var t2 = test(function () {
147
+ // template_quote_scanner2.call(string, 0)
148
+ // }, count); //2500+
149
+ // console.log(t1, t2);
150
+
151
+ function template_quote_scanner(index, blocks) {
152
+ index++;
153
+ while (index < this.length) {
154
+ var reg = /\\[\s\S]|`|\$\{/g;
155
+ reg.lastIndex = index;
156
+ var res = reg.exec(this);
157
+ if (!res) {
158
+ return this.length;
159
+ }
160
+ if (res[0] === "${") {
161
+ index = block_code_scanner.call(this, res.index + 2, blocks);
162
+ } else if (res[0].length === 1) {
163
+ return res.index + 1;
164
+ } else {
165
+ index = reg.lastIndex;
166
+ }
167
+ }
168
+ return index;
169
+ }
170
+
171
+ function template_quote_scanner2(index, blocks) {
172
+ // var x1 = "`".codePointAt(0);//96
173
+ // var x2 = "{".codePointAt(0);//123
174
+ // var u1 = "\\".codePointAt(0);//92
175
+ // var u2 = "$".codePointAt(0);//36
176
+ var length = this.length;
177
+ while (++index < length) {
178
+ // if (this.codePointAt(index) === 96 && this.codePointAt(index - 1) !== 92) return index + 1;
179
+ // if (this.codePointAt(index) === 92 && this.codePointAt(index - 1) === 36) {
180
+ // index = block_code_scanner.call(this, index, blocks);
181
+ // }
182
+ if (this[index] === "`" && this[index - 1] !== "\\") return index + 1;
183
+ if (this[index] === "{" && this[index - 1] === "$") {
184
+ index = block_code_scanner.call(this, index + 1, blocks);
185
+ }
186
+ }
187
+ return index;
188
+ };
189
+ /**
190
+ * 多行注释扫描
191
+ * @param {Integer} index
192
+ */
193
+ // var count = 1000000;
194
+ // var string = " ${`";
195
+ // var t1 = test(function () {
196
+ // multi_comment_scanner.call(string, 0);
197
+ // }, count); //266+
198
+ // var t2 = test(function () {
199
+ // multi_comment_scanner2.call(string, 0);
200
+ // }, count); //266+
201
+ // console.log(t1, t2);
202
+ function multi_comment_scanner(index) {
203
+ var reg = /\*\//g;
204
+ reg.lastIndex = index + 1;
205
+ var res = reg.exec(this);
206
+ return res ? res.index + 2 : this.length;
207
+ }
208
+
209
+ function multi_comment_scanner2(index) {
210
+ var index = this.indexOf("*/", index + 1);
211
+ if (index > 0) {
212
+ return index + 2;
213
+ }
214
+ return this.length;
215
+ // var x="/".codePointAt(0);//47
216
+ // var x="*".codePointAt(0);//42
217
+ // 一般多行注释有更多的星号
218
+ // index++;
219
+ // while(++index<this.length){
220
+ // if(this.codePointAt(index)===47&&this.charCodeAt(index-1)===42)break;
221
+ // }
222
+ }
223
+ /**
224
+ * 单行注释扫描
225
+ * @param {Integer} index
226
+ */
227
+ // var count = 1000000;
228
+ // var string = " ${`";
229
+ // var t1 = test(function () {
230
+ // single_comment_scanner.call(string, 0);
231
+ // }, count); //233+
232
+ // var t2 = test(function () {
233
+ // single_comment_scanner2.call(string, 0);
234
+ // }, count); //3340+
235
+ // console.log(t1, t2);
236
+ function single_comment_scanner(index) {
237
+ var reg = /[\r\n\u2028\u2029]/g;
238
+ reg.lastIndex = index + 1;
239
+ var res = reg.exec(this);
240
+ index = res ? res.index : this.length;
241
+ if (this[index] === "\r" && this[index + 1] == "\n") {
242
+ index++;
243
+ }
244
+ return index + 1;
245
+ }
246
+
247
+ function single_comment_scanner2(index) {
248
+ var c;
249
+ var length = this.length;
250
+ while (++index < length) {
251
+ /**
252
+ * 这里switch case 与if的速度相当,但当使用双字节换行时有较大的风险,所以这里使用if+codePointAt
253
+ */
254
+ // switch (this[index]) {
255
+ // case "\r":
256
+ // if (this[index + 1] === "\n") return index + 2;
257
+ // return index + 1;
258
+ // case "\n":
259
+ // case "\u2028":
260
+ // case "\u2029":
261
+ // return index+1;
262
+ // }
263
+ c = this.charCodeAt(index);
264
+ if (c < 0xff) {
265
+ if (c === 13) {
266
+ if (this.charCodeAt(index + 1) === 10) {
267
+ return index + 2;
268
+ }
269
+ return index + 1;
270
+ } else if (c === 10) {
271
+ return index + 1;
272
+ }
273
+ } else {
274
+ if (c === 2028 || c === 2029) {
275
+ return index + 1;
276
+ }
277
+ }
278
+ }
279
+ return index;
280
+ }
281
+ //var declareReg=/(var|const|let)\s+([A-Za-z\$_][\w$_]*(?:\s*,\s*[A-Za-z\$_][\w$_]*)*)/g;
282
+ /**
283
+ * 代码块扫描
284
+ * @param {Integer} index
285
+ * @param {Array} blocks
286
+ */
287
+ // var count = 1000000;
288
+ // var string = " ${`";
289
+ // var t1 = test(function () {
290
+ // single_comment_scanner.call(string, 0);
291
+ // }, count); //317+
292
+ // var t2 = test(function () {
293
+ // single_comment_scanner2.call(string, 0);
294
+ // }, count); //3354+
295
+ // console.log(t1, t2);
296
+ function block_code_scanner(index, blocks = [], keepdeep = Infinity) {
297
+ var save = (blocks instanceof Array) ? function (scanner, children) {
298
+ if (deep < keepdeep && saved_index < index) {
299
+ blocks.push(new Block(scanner, saved_index, index, children));
300
+ saved_index = index;
301
+ }
302
+ } : function () { };
303
+ var lookback = function (tempIndex) {
304
+ while (tempIndex >= saved_index && /\s/.test(this[tempIndex])) tempIndex--;
305
+ if (tempIndex < saved_index) {
306
+ var blockIndex = blocks.length;
307
+ while (blockIndex-- > 0) {
308
+ var tempBlock = blocks[blockIndex];
309
+ var type = tempBlock.type;
310
+ if (type === single_comment_scanner || type === multi_comment_scanner) continue;
311
+ if (type !== block_code_scanner) break;
312
+ var tempLastIndex = tempBlock.start;
313
+ tempIndex = Math.min(tempBlock.end, tempIndex);
314
+ while (tempIndex >= tempLastIndex && /\s/.test(this[tempIndex])) tempIndex--;
315
+ if (tempIndex > tempLastIndex) break;
316
+ }
317
+ if (blockIndex < 0) tempIndex = blockIndex;
318
+ }
319
+ return tempIndex;
320
+ };
321
+ var saved_index = index;
322
+ var start_index = index;
323
+ var c, deep = 0;
324
+ var length = this.length;
325
+ var reg = /[\/\{\}'"`]/g;
326
+ while (index < length) {
327
+ reg.lastIndex = index;
328
+ var res = reg.exec(this);
329
+ index = res ? res.index : this.length;
330
+ //直接用字符表示比用数字快一倍,用的时间是用codePointAt的一半
331
+ var c = this[index];
332
+ switch (c) {
333
+ case "/": // /
334
+ save(block_code_scanner);
335
+ var d = this[index + 1];
336
+ //内部的d 数字与字符的速度差别不大
337
+ if (d === "*") { // u /* */
338
+ index = multi_comment_scanner.call(this, index + 1);
339
+ save(multi_comment_scanner);
340
+ } else if (d === "/") { // x3 //
341
+ index = single_comment_scanner.call(this, index + 1);
342
+ save(single_comment_scanner);
343
+ } else { // /reg/
344
+ var isReg = false;
345
+ // do{break 8
346
+ // for(;;)break 12
347
+ // while(0)break 13
348
+ // switch(a){case 1:break
349
+ // return/a/
350
+ //switch case break,while continue,break abcd;
351
+ var tempIndex = lookback.call(this, index - 1);
352
+ isReg = tempIndex <= start_index || /[[|,+=*~?:&\^{\(\/><;%\-!]/.test(this[tempIndex]);
353
+ if (!isReg && tempIndex >= start_index + 5) {
354
+ var last_pice = this.slice(Math.max(tempIndex - 50, 0), tempIndex + 1);
355
+ isReg = /return\s*$|([)};:{]|[^\.\s]\s+)(continue|break|case)\s*$/.test(last_pice);
356
+ isReg = isReg || /([)};:{]|[^\.\s]\s+)(?:continue|break)\s+([\w\u0100-\u2027\u2030-\uffff]+?)$/.test(last_pice);
357
+ if (!isReg && !/\r\n\u2028\u2029/.test(last_pice)) {
358
+ var variabled_name_reg = /\w\u0100-\u2027\u2030-\uffff/;
359
+ if (variabled_name_reg.test(this[tempIndex])) {
360
+ while (tempIndex > 8 && variabled_name_reg.test(this[tempIndex])) tempIndex--;
361
+ var tempIndex2 = lookback.call(this, tempIndex);
362
+ if (tempIndex2 >= 8 && !/\r\n\u2028\u2029/.test(this.slice(tempIndex2, tempIndex))) {
363
+ isReg = /([)};:{]|[^\.\s]\b\s*)(continue|break)$/.test(this.slice(tempIndex2 - 8, tempIndex2 + 1));
364
+ }
365
+ }
366
+ }
367
+ }
368
+ if (isReg) {
369
+ index = regexp_quote_scanner.call(this, index);
370
+ save(regexp_quote_scanner);
371
+ } else {
372
+ index++;
373
+ }
374
+ }
375
+ break;
376
+ case "`": // `
377
+ save(block_code_scanner);
378
+ var children = [];
379
+ index = template_quote_scanner.call(this, index, children);
380
+ save(template_quote_scanner, children);
381
+ break;
382
+ case "'": // '
383
+ save(block_code_scanner);
384
+ index = single_quote_scanner.call(this, index);
385
+ save(single_quote_scanner);
386
+ break;
387
+ case "\"": // "
388
+ save(block_code_scanner);
389
+ index = double_quote_scanner.call(this, index);
390
+ save(double_quote_scanner);
391
+ break;
392
+ case "}": // }
393
+ if (deep === 0) {
394
+ save(block_code_scanner);
395
+ return index + 1;
396
+ }
397
+ deep--;
398
+ index++;
399
+ break;
400
+ case "{": // {
401
+ deep++;
402
+ index++;
403
+ break;
404
+ }
405
+ }
406
+ if (saved_index < length) save(block_code_scanner);
407
+ return index;
408
+ }
409
+
410
+ function block_code_scanner2(index, blocks) {
411
+ var save = (blocks instanceof Array) ? function (scanner) {
412
+ if (saved_index < index) {
413
+ blocks.push(new Block(scanner, saved_index, index));
414
+ saved_index = index;
415
+ }
416
+ } : function () { };
417
+ //for(){block} while(){block} function(){block} switch(){block} ()=>{block} {simple block}
418
+ //{object block} /var|let|const\s*{block}/
419
+ // "\"'/`{}".split("").sort().map(a=>a.codePointAt(0));
420
+ // 字节顺序,x1,x2,x3,x4,x5,x6从小到大排列
421
+ // var x1 = "\"".codePointAt(0);//34
422
+ // var x2 = "'".codePointAt(0);//39
423
+ // var x3 = "/".codePointAt(0);//47
424
+ // var x4 = "`".codePointAt(0);//96
425
+ // var x5 = "{".codePointAt(0);//123
426
+ // var x6 = "}".codePointAt(0);//125
427
+ // var u = "*".codePointAt(0);//42
428
+ var saved_index = index;
429
+ var c, deep = 0;
430
+ var length = this.length;
431
+ while (index < length) {
432
+ //直接用字符表示比用数字快一倍,用的时间是用codePointAt的一半
433
+ var c = this[index];
434
+ switch (c) {
435
+ case "/": // /
436
+ save(block_code_scanner);
437
+ var d = this[index + 1];
438
+ //内部的d 数字与字符的速度差别不大
439
+ if (d === "*") { // u /* */
440
+ index = multi_comment_scanner.call(this, index + 1);
441
+ save(multi_comment_scanner);
442
+ } else if (d === "/") { // x3 //
443
+ index = single_comment_scanner.call(this, index + 1);
444
+ save(single_comment_scanner);
445
+ } else { // /reg/
446
+ index = regexp_quote_scanner.call(this, index);
447
+ save(regexp_quote_scanner);
448
+ }
449
+ // var d = this.codePointAt(index + 1);
450
+ // save(block_code_scanner);
451
+ // if (d === 42) { // u /* */
452
+ // index = multi_comment_scanner.call(this, index + 1);
453
+ // save(multi_comment_scanner);
454
+ // } else if (d === 47) { // x3 //
455
+ // index = single_comment_scanner.call(this, index + 1);
456
+ // save(single_comment_scanner);
457
+ // } else { // /reg/
458
+ // index = regexp_quote_scanner.call(this, index);
459
+ // save(regexp_quote_scanner);
460
+ // }
461
+ break;
462
+ case "`": // `
463
+ save(block_code_scanner);
464
+ index = template_quote_scanner.call(this, index, blocks);
465
+ save(template_quote_scanner);
466
+ break;
467
+ case "'": // '
468
+ save(block_code_scanner);
469
+ index = single_quote_scanner.call(this, index);
470
+ save(single_quote_scanner);
471
+ break;
472
+ case "\"": // "
473
+ save(block_code_scanner);
474
+ index = double_quote_scanner.call(this, index);
475
+ save(double_quote_scanner);
476
+ break;
477
+ case "}": // }
478
+ if (deep === 0) {
479
+ save(block_code_scanner);
480
+ return index + 1;
481
+ }
482
+ deep--;
483
+ index++;
484
+ break;
485
+ case "{": // {
486
+ deep++;
487
+ default:
488
+ index++;
489
+ }
490
+ // c = this.codePointAt(index);
491
+ // switch (c) {
492
+ // case 47:// /
493
+ // var d = this.codePointAt(index + 1);
494
+ // save(block_code_scanner);
495
+ // /** 嵌在内部的情况较少的switch(d),速度与来没有差别*/
496
+ // // switch (d) {
497
+ // // case 42:
498
+ // // index = multi_comment_scanner.call(this, index + 1);
499
+ // // save(multi_comment_scanner);
500
+ // // break;
501
+ // // case 47:
502
+ // // index = single_comment_scanner.call(this, index + 1);
503
+ // // save(single_comment_scanner);
504
+ // // break;
505
+ // // default:
506
+ // // index = regexp_quote_scanner.call(this, index);
507
+ // // save(regexp_quote_scanner);
508
+ // // }
509
+ // if (d === 42) { // u /* */
510
+ // index = multi_comment_scanner.call(this, index + 1);
511
+ // save(multi_comment_scanner);
512
+ // } else if (d === 47) { // x3 //
513
+ // index = single_comment_scanner.call(this, index + 1);
514
+ // save(single_comment_scanner);
515
+ // } else { // /reg/
516
+ // index = regexp_quote_scanner.call(this, index);
517
+ // save(regexp_quote_scanner);
518
+ // }
519
+ // break;
520
+ // case 96:// `
521
+ // save(block_code_scanner);
522
+ // index = template_quote_scanner.call(this, index);
523
+ // save(template_quote_scanner);
524
+ // break;
525
+ // case 39: // '
526
+ // save(block_code_scanner);
527
+ // index = single_quote_scanner.call(this, index);
528
+ // save(single_quote_scanner);
529
+ // break;
530
+ // case 34:// "
531
+ // save(block_code_scanner);
532
+ // index = double_quote_scanner.call(this, index);
533
+ // save(double_quote_scanner);
534
+ // break;
535
+ // case 125:// }
536
+ // if (deep === 0) {
537
+ // save(block_code_scanner);
538
+ // return index + 1;
539
+ // }
540
+ // deep--;
541
+ // case 123:// {
542
+ // deep++;
543
+ // default:
544
+ // index++;
545
+ // }
546
+
547
+ /**
548
+ * if else有明显的速度下降
549
+ * 扫描angular.js的源码100次,ifelse用时8500左右
550
+ * 其他条件不变时,switch case用时7600毫秒
551
+ */
552
+
553
+ // if (123 > c) { //x5
554
+ // if (47 > c) { //x3
555
+ // if (39 === c) { //x1 39 '
556
+ // save(block_code_scanner);
557
+ // index = single_quote_scanner.call(this, index);
558
+ // save(single_quote_scanner);
559
+ // } else if (34 === c) { //x2 " 34
560
+ // save(block_code_scanner);
561
+ // index = double_quote_scanner.call(this, index);
562
+ // save(double_quote_scanner);
563
+ // }else{
564
+ // index++;
565
+ // }
566
+ // } else {
567
+ // if (47 === c) { //x3 /
568
+ // var d = this.codePointAt(index + 1);
569
+ // save(block_code_scanner);
570
+ // if (d === 42) { // u /* */
571
+ // index = multi_comment_scanner.call(this, index + 1);
572
+ // save(multi_comment_scanner);
573
+ // } else if (d === 47) { // x3 //
574
+ // index = single_comment_scanner.call(this, index + 1);
575
+ // save(single_comment_scanner);
576
+ // } else { // /reg/
577
+ // index = regexp_quote_scanner.call(this, index);
578
+ // save(regexp_quote_scanner);
579
+ // }
580
+ // } else if (96 === c) { //x4 ` 96
581
+ // save(block_code_scanner);
582
+ // index = template_quote_scanner.call(this, index);
583
+ // save(template_quote_scanner);
584
+ // }else{
585
+ // index++;
586
+ // }
587
+ // }
588
+ // } else {
589
+ // if (123 === c) { //x5 { 123
590
+ // deep++;
591
+ // } else if (125 === c) { //x6 } 125
592
+ // if (deep === 0) {
593
+ // save(block_code_scanner);
594
+ // return index + 1;
595
+ // }
596
+ // deep--;
597
+ // }
598
+ // index++;
599
+ // }
600
+ }
601
+ if (saved_index < length) save(block_code_scanner);
602
+ return index;
603
+ };
604
+
605
+ function lookback_scanner(blockIndex, blocks) {
606
+ if (!blocks.length || blockIndex >= blocks.length) return -1;
607
+ var tempIndex = blocks[blockIndex].end;
608
+ while (blockIndex-- > 0) {
609
+ var tempBlock = blocks[blockIndex];
610
+ var type = tempBlock.type;
611
+ if (type === single_comment_scanner || type === multi_comment_scanner) continue;
612
+ if (type !== block_code_scanner) break;
613
+ var tempLastIndex = tempBlock.start;
614
+ tempIndex = Math.min(tempBlock.end, tempIndex);
615
+ while (tempIndex >= tempLastIndex && /\s/.test(this[tempIndex])) tempIndex--;
616
+ if (tempIndex > tempLastIndex) break;
617
+ }
618
+ if (blockIndex < 0) tempIndex = blockIndex;
619
+ return tempIndex;
620
+ }
621
+
622
+ var scanner = module.exports = function (s, keepdeep) {
623
+ var blocks = [];
624
+ var s = String(s);
625
+ // var time = +new Date;
626
+ // for (var i = 0; i < 1000; i++) {
627
+ // block_code_scanner.call(s, 0, blocks);
628
+ // }//angular 1.5.3 x1000 7.0s
629
+ // console.log(+new Date - time);
630
+ block_code_scanner.call(s, 0, blocks, keepdeep);
631
+ // console.log(blocks.map(a => s.slice(a.start, a.end)).join())
632
+ return blocks;
633
+ };
634
+ scanner.autoskip = function (code, start) {
635
+ return block_code_scanner.call(code, start, null);
636
+ };
637
+ function Block(scanner, start, end, children) {
638
+ this.type = scanner;
639
+ this.start = start;
640
+ if (children) this.children = children;
641
+ this.end = end;
642
+ }
643
+ Block.prototype = {
644
+ lookback_scanner,
645
+ block_code_scanner,
646
+ double_quote_scanner,
647
+ regexp_quote_scanner,
648
+ single_quote_scanner,
649
+ multi_comment_scanner,
650
+ single_comment_scanner,
651
+ template_quote_scanner
652
+ };
653
+ // module.exports(require("fs").readFileSync("./apps/x6/js/angular.js"))
654
654
  // module.exports(require("fs").readFileSync("./main.js"))