efront 3.37.0 → 3.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coms/basic/#loader.js +3 -2
- package/coms/basic/assert.js +21 -9
- package/coms/basic_/Array2.js +2 -1
- package/coms/basic_/JSON.js +5 -5
- package/coms/basic_/Symbol.js +4 -1
- package/coms/basic_/exec_.js +21 -10
- package/coms/basic_/extends_.js +1 -0
- package/coms/compile/Javascript.js +36 -12
- package/coms/compile/Program.js +11 -4
- package/coms/compile/common.js +170 -51
- package/coms/compile/downLevel.js +727 -275
- package/coms/compile/downLevel_test.js +195 -53
- package/coms/compile/powermap.js +2 -2
- package/coms/compile/scanner2.js +5 -2
- package/coms/compile/translate.js +45 -19
- package/coms/compile/unstruct.js +506 -280
- package/coms/compile/unstruct_test.js +66 -40
- package/coms/reptile/colored_console.js +2 -2
- package/coms/zimoli/appendChild.js +1 -1
- package/coms/zimoli/css.js +1 -0
- package/coms/zimoli/zimoli.js +1 -0
- package/package.json +1 -1
- package/public/efront.js +1 -1
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
var downLevel = require("./downLevel");
|
|
2
|
+
var _asert = assert, i = 10;
|
|
3
|
+
assert = function (a, b) {
|
|
4
|
+
var d = 1;
|
|
5
|
+
b = b.split(/(?<!\r)\n/), d = b.length, b = b.join("\r\n");
|
|
6
|
+
_asert(a, b, i);
|
|
7
|
+
i += d;
|
|
8
|
+
}
|
|
2
9
|
// 声明及解构
|
|
3
|
-
assert(downLevel(`
|
|
4
|
-
assert(downLevel(`
|
|
5
|
-
assert(downLevel(`
|
|
10
|
+
assert(downLevel(`var [name, type, options] = piece, key, repeat;`), 'var name = piece[0], type = piece[1], options = piece[2], key, repeat;');
|
|
11
|
+
assert(downLevel(`const`), '');
|
|
12
|
+
assert(downLevel(`let`), '');
|
|
13
|
+
assert(downLevel(`var`), '');
|
|
14
|
+
assert(downLevel(`{let a; function b(){a};return;}`), `if (tmp = 0, tmp0 =function (a) { a; function b() { a }; return tmp = 1, void 0; }(a)) { if (tmp === 1) return tmp0; }
|
|
15
|
+
var tmp, a, tmp0`);
|
|
6
16
|
assert(downLevel(`const a,b,c`), 'var a, b, c');
|
|
7
17
|
assert(downLevel(`let a,b,c`), 'var a, b, c');
|
|
8
|
-
assert(downLevel(`var a;{let a,b,c}`), 'var a; { var a0
|
|
18
|
+
assert(downLevel(`var a;{let a,b,c}`), 'var a; { var a0, b, c }');
|
|
9
19
|
assert(downLevel(`var {a,b,c}`), 'var a, b, c');
|
|
10
20
|
assert(downLevel(`let {a,b,c}`), 'var a, b, c');
|
|
11
21
|
assert(downLevel(`const {a,b,c}`), 'var a, b, c');
|
|
@@ -29,9 +39,10 @@ assert(downLevel(`var {a}=a`), 'var a = a.a');
|
|
|
29
39
|
assert(downLevel(`var {a,b}=a`), 'var _ = a, a = a.a, b = _.b');
|
|
30
40
|
assert(downLevel(`var {a:{a:{a}}}=b`), 'var a = b.a.a.a');
|
|
31
41
|
assert(downLevel(`var {a,[a]:c}={}`), 'var _ = {}, a = _.a, c = _[a]');
|
|
32
|
-
assert(downLevel(`={a,[a]:c}={}`), '= _ = {}, a = _.a, c = _[a]');
|
|
42
|
+
assert(downLevel(`={a,[a]:c}={}`), '= _ = {}, a = _.a, c = _[a]\r\nvar _');
|
|
43
|
+
var tmp = scanner2(`var {window}=this`); tmp.helpcode = false; tmp.detour(); assert(downLevel.code(tmp).toString(), `var window = this["window"]`);
|
|
33
44
|
assert(downLevel(`function (){var [a]=a;}`), "function () { var a = a[0]; }")
|
|
34
|
-
|
|
45
|
+
i++// 参数解构
|
|
35
46
|
assert(downLevel(`function ([a]){}`), "function (arg) { var a = arg[0]; }")
|
|
36
47
|
assert(downLevel(`function ([a],b){}`), "function (arg0, b) { var a = arg0[0]; }")
|
|
37
48
|
assert(downLevel(`function ([a],{b}){}`), "function (arg0, arg1) { var a = arg0[0], b = arg1.b; }")
|
|
@@ -40,76 +51,207 @@ assert(downLevel(`function (){var {a}=a,{b}=a;}`), "function () { var a = a.a, b
|
|
|
40
51
|
assert(downLevel(`function (a=b){}`), "function (a) { if (a === undefined) a = b; }")
|
|
41
52
|
assert(downLevel(`function (a=b,[c],d,e=f){}`), "function (a, arg1, d, e) { if (a === undefined) a = b; var c = arg1[0]; if (e === undefined) e = f; }")
|
|
42
53
|
assert(downLevel(`function (arg1=b,[c],d,e=f){}`), "function (arg1, arg2, d, e) { if (arg1 === undefined) arg1 = b; var c = arg2[0]; if (e === undefined) e = f; }")
|
|
43
|
-
|
|
54
|
+
i++// class降级
|
|
44
55
|
assert(downLevel(`class a {}`), "function a() {}")
|
|
45
56
|
assert(downLevel(`class a {a=1}`), "function a() { this.a = 1 }")
|
|
46
57
|
assert(downLevel(`class a {a=1; b(){}}`), "function a() { this.a = 1; }; a.prototype.b = function () {}")
|
|
47
|
-
assert(downLevel(`=class a {a=1; b(){}}`), "= function (a) { a.prototype.b = function () {}
|
|
58
|
+
assert(downLevel(`=class a {a=1; b(){}}`), "= function (a) { a.prototype.b = function () {}\r\nreturn a }(function a() { this.a = 1; })")
|
|
59
|
+
assert(downLevel(`var a=class {a=1; static b=2 b(){}};`), "var a = function (cls0) { cls0.b = 2\r\ncls0.prototype.b = function () {}\r\nreturn cls0 }(function () { this.a = 1; });")
|
|
60
|
+
assert(downLevel(`var a=class { constructor(){this.a=1}; static b=2 b(){}};`), "var a = function (cls0) { cls0.b = 2\r\ncls0.prototype.b = function () {}\r\nreturn cls0 }(function () { this.a = 1 });")
|
|
48
61
|
assert(downLevel(`class a {static b(){}}`), "function a() {}; a.b = function () {}")
|
|
49
|
-
assert(downLevel(`class a extends b{}`),
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
assert(downLevel(`class a
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
assert(downLevel(
|
|
58
|
-
|
|
59
|
-
assert(downLevel(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
assert(downLevel(`class a extends b{}`), `function a() {
|
|
63
|
+
var this_ = b.apply(this, arguments) || this;
|
|
64
|
+
return this_ }; extends_(a, b)`);
|
|
65
|
+
assert(downLevel(`class a extends class b{}{}`), `var a = function (b, a) { extends_(a, b)\r\nreturn a }(function b() {}, function a() {
|
|
66
|
+
var this_ = b.apply(this, arguments) || this;
|
|
67
|
+
return this_ })`);
|
|
68
|
+
assert(downLevel(`class a {get a(){}}`), `function a() {};
|
|
69
|
+
Object.defineProperty(a.prototype, "a", { get: function () {} })`);
|
|
70
|
+
assert(downLevel(`class a {set a(){}}`), `function a() {};
|
|
71
|
+
Object.defineProperty(a.prototype, "a", { set: function () {} })`);
|
|
72
|
+
assert(downLevel(`class a {get a(){}; get b(){}; set a(){}}`), `function a() {};
|
|
73
|
+
Object.defineProperty(a.prototype, "a", { get: function () {}, set: function () {} });
|
|
74
|
+
Object.defineProperty(a.prototype, "b", { get: function () {} });`);
|
|
75
|
+
assert(downLevel(`class a {set a(){}; get b(){}; set a(){}}`), `function a() {};
|
|
76
|
+
Object.defineProperty(a.prototype, "a", { set: function () {}, set: function () {} });
|
|
77
|
+
Object.defineProperty(a.prototype, "b", { get: function () {} });`);
|
|
78
|
+
i++// 属性降级
|
|
79
|
+
assert(downLevel(`return ({b,async a(){}})`), `return ((_ = {},
|
|
80
|
+
_.b = b,
|
|
81
|
+
_.a = function () { return async_() }, _))\r\nvar _`);
|
|
82
|
+
assert(downLevel(`var a={b,async a(){}}`), `var a = (_ = {},
|
|
83
|
+
_.b = b,
|
|
84
|
+
_.a = function () { return async_() }, _)\r\nvar _`);
|
|
85
|
+
assert(downLevel(`var a={b:a=>b,c}`), `var a = (_ = {},
|
|
86
|
+
_.b = function (a) { return b },
|
|
87
|
+
_.c = c, _)\r\nvar _`);
|
|
88
|
+
assert(downLevel(`={b,async a(){}}`), `= (_ = {},
|
|
89
|
+
_.b = b,
|
|
90
|
+
_.a = function () { return async_() }, _)\r\nvar _`);
|
|
91
|
+
assert(downLevel(`={async [a](){}}`), `= (_ = {},
|
|
92
|
+
_[a] = function () { return async_() }, _)\r\nvar _`);
|
|
93
|
+
assert(downLevel(`={[a]:b}`), `= (_ = {},
|
|
94
|
+
_[a] = b, _)\r\nvar _`);
|
|
95
|
+
assert(downLevel(`={a:1,[a]:1}`), `= (_ = { a: 1 },
|
|
96
|
+
_[a] = 1, _)\r\nvar _`);
|
|
97
|
+
assert(downLevel(`={a,[a]:1}`), `= (_ = {},
|
|
98
|
+
_.a = a,
|
|
99
|
+
_[a] = 1, _)\r\nvar _`);
|
|
100
|
+
assert(downLevel(`={[a]:{[b]:1}}`), `= (_ = {},
|
|
101
|
+
_[a] = (_0 = {},
|
|
102
|
+
_0[b] = 1, _0), _)\r\nvar _, _0`);
|
|
103
|
+
assert(downLevel(`={[a]:{[b]:{[c]:1}}}`), `= (_ = {},
|
|
104
|
+
_[a] = (_0 = {},
|
|
105
|
+
_0[b] = (_1 = {},
|
|
106
|
+
_1[c] = 1, _1), _0), _)\r\nvar _, _0, _1`);
|
|
107
|
+
assert(downLevel(`={[a]:{[b]:{[c]:1}},[b]:{[a]:1}}`), `= (_ = {},
|
|
108
|
+
_[a] = (_0 = {},
|
|
109
|
+
_0[b] = (_1 = {},
|
|
110
|
+
_1[c] = 1, _1), _0),
|
|
111
|
+
_[b] = (_0 = {},
|
|
112
|
+
_0[a] = 1, _0), _)\r\nvar _, _0, _1`);
|
|
113
|
+
i++// 对象展开
|
|
114
|
+
assert(downLevel(`={ok:ok}`), `= { ok: ok }`);
|
|
63
115
|
assert(downLevel(`={...a}`), `= extend({}, a)`);
|
|
116
|
+
assert(downLevel(`={...a&&b}`), `= extend({}, a && b)`);
|
|
117
|
+
assert(downLevel(`()=>({\r\nfileName: entry.fileName,\r\ntextSpan: highlightSpan.textSpan,\r\nisWriteAccess: highlightSpan.kind === "writtenReference" /* writtenReference */,\r\n...highlightSpan.isInString && { isInString: true },\r\n...highlightSpan.contextSpan && { contextSpan: highlightSpan.contextSpan }})`), `function () { return (extend({
|
|
118
|
+
fileName: entry.fileName,
|
|
119
|
+
textSpan: highlightSpan.textSpan,
|
|
120
|
+
isWriteAccess: highlightSpan.kind === "writtenReference" /* writtenReference */ }, highlightSpan.isInString && { isInString: true }, highlightSpan.contextSpan && { contextSpan: highlightSpan.contextSpan })) }`);
|
|
64
121
|
assert(downLevel(`={...{a:1}}`), `= extend({}, { a: 1 })`);
|
|
65
122
|
assert(downLevel(`={...a,...c}`), `= extend({}, a, c)`);
|
|
66
|
-
assert(downLevel(`={
|
|
67
|
-
assert(downLevel(`={...
|
|
68
|
-
assert(downLevel(`={...a
|
|
69
|
-
|
|
70
|
-
assert(downLevel(`={a
|
|
123
|
+
assert(downLevel(`={a:a,...b,c}`), `= (_ = extend({ a: a }, b),\r\n_.c = c, _)\r\nvar _`);
|
|
124
|
+
assert(downLevel(`={...b,c,...d,e}`), `= (_ = extend({}, b),\r\n_.c = c, extend(_, d),\r\n_.e = e, _)\r\nvar _`);
|
|
125
|
+
assert(downLevel(`={...a,b}`), `= (_ = extend({}, a),
|
|
126
|
+
_.b = b, _)\r\nvar _`);
|
|
127
|
+
assert(downLevel(`={...a,b,...c}`), `= (_ = extend({}, a),
|
|
128
|
+
_.b = b, extend(_, c), _)\r\nvar _`);
|
|
129
|
+
assert(downLevel(`={...a,...c,b}`), `= (_ = extend({}, a, c),
|
|
130
|
+
_.b = b, _)\r\nvar _`);
|
|
131
|
+
assert(downLevel(`={...{},...c,b}`), `= (_ = extend({}, {}, c),
|
|
132
|
+
_.b = b, _)\r\nvar _`);
|
|
133
|
+
assert(downLevel(`={a(){},get c(){},b}`), `= (_ = {},
|
|
134
|
+
_.a = function () {},
|
|
135
|
+
Object.defineProperty(_, "c", { get: function () {} }),
|
|
136
|
+
_.b = b, _)\r\nvar _`);
|
|
71
137
|
assert(downLevel(`=[...a]`), `= Array.prototype.slice.call(a)`)
|
|
72
|
-
assert(downLevel(
|
|
138
|
+
assert(downLevel(`let a = [...a,...a()];`), `var a = (slice_ = Array.prototype.slice).call(a).concat(slice_.call(a()));
|
|
139
|
+
var slice_`)
|
|
140
|
+
assert(downLevel(`=[...a,...b]`), `= (slice_ = Array.prototype.slice).call(a).concat(slice_.call(b))\r\nvar slice_`)
|
|
73
141
|
assert(downLevel(`=[a,...b]`), `= [a].concat(Array.prototype.slice.call(b))`)
|
|
74
|
-
assert(downLevel(`=[a,...b,...c]`), `= [a].concat((slice_ = Array.prototype.slice).call(b), slice_.call(c))`)
|
|
142
|
+
assert(downLevel(`=[a,...b,...c]`), `= [a].concat((slice_ = Array.prototype.slice).call(b), slice_.call(c))\r\nvar slice_`)
|
|
75
143
|
assert(downLevel(`=[a,b,...c]`), `= [a, b].concat(Array.prototype.slice.call(c))`)
|
|
76
144
|
assert(downLevel(`=[a,b,...c,d]`), `= [a, b].concat(Array.prototype.slice.call(c), [d])`)
|
|
77
145
|
assert(downLevel(`=[a,b,...c,d,e,f]`), `= [a, b].concat(Array.prototype.slice.call(c), [d, e, f])`)
|
|
78
|
-
assert(downLevel(`=[a,b,...c,d,e,f,...g]`), `= [a, b].concat((slice_ = Array.prototype.slice).call(c), [d, e, f], slice_.call(g))`)
|
|
79
|
-
assert(downLevel(`=[a,b,...c,d,...e]`), `= [a, b].concat((slice_ = Array.prototype.slice).call(c), [d], slice_.call(e))`)
|
|
146
|
+
assert(downLevel(`=[a,b,...c,d,e,f,...g]`), `= [a, b].concat((slice_ = Array.prototype.slice).call(c), [d, e, f], slice_.call(g))\r\nvar slice_`)
|
|
147
|
+
assert(downLevel(`=[a,b,...c,d,...e]`), `= [a, b].concat((slice_ = Array.prototype.slice).call(c), [d], slice_.call(e))\r\nvar slice_`)
|
|
80
148
|
assert(downLevel(`a(...b)`), `a.apply(null, b)`)
|
|
81
|
-
assert(downLevel(`a(...
|
|
149
|
+
assert(downLevel(`a(c,d,e,...b(...c))`), `a.apply(null, [c, d, e].concat(Array.prototype.slice.call(b.apply(null, c))))`)
|
|
150
|
+
assert(downLevel(`a(c,d,e,...b.a(...c))`), `a.apply(null, [c, d, e].concat(Array.prototype.slice.call(b.a.apply(b, c))))`)
|
|
151
|
+
assert(downLevel(`a(c,d,e,...b.a.c(...c))`), `a.apply(null, [c, d, e].concat(Array.prototype.slice.call((_ = b.a).c.apply(_, c))))\r\nvar _`)
|
|
152
|
+
assert(downLevel(`a(...b,...c)`), `a.apply(null, (slice_ = Array.prototype.slice).call(b).concat(slice_.call(c)))\r\nvar slice_`)
|
|
82
153
|
assert(downLevel(`a(...b,c)`), `a.apply(null, Array.prototype.slice.call(b).concat([c]))`)
|
|
154
|
+
assert(downLevel(`getPendingExpressions()[_push](...flattenCommaList(expr));`), `(_ = getPendingExpressions())[_push].apply(_, flattenCommaList(expr));\r\nvar _`)
|
|
83
155
|
assert(downLevel(`a(b,...c)`), `a.apply(null, [b].concat(Array.prototype.slice.call(c)))`)
|
|
84
|
-
assert(downLevel(`a(a,b,...c,d,...e)`), `a.apply(null, [a, b].concat((slice_ = Array.prototype.slice).call(c), [d], slice_.call(e)))`)
|
|
85
|
-
assert(downLevel(`a.call(a,b,...c,d,...e)`), `a.call.apply(a, [a, b].concat((slice_ = Array.prototype.slice).call(c), [d], slice_.call(e)))`)
|
|
86
|
-
assert(downLevel(`a.b(a,b,...c,d,...e)`), `a.b.apply(a, [a, b].concat((slice_ = Array.prototype.slice).call(c), [d], slice_.call(e)))`)
|
|
87
|
-
assert(downLevel(`[].b(a,b,...c,d,...e)`), `(_ = []).b.apply(_, [a, b].concat((slice_ = Array.prototype.slice).call(c), [d], slice_.call(e)))`)
|
|
88
|
-
assert(downLevel(`a(...b).c(...d)`), `(_ = a.apply(null, b)).c.apply(_, d)`)
|
|
89
|
-
assert(downLevel(`a(...b).c(...d).e(...f)`), `(_ = (_ = a.apply(null, b)).c.apply(_, d)).e.apply(_, f)`)
|
|
90
|
-
|
|
156
|
+
assert(downLevel(`a(a,b,...c,d,...e)`), `a.apply(null, [a, b].concat((slice_ = Array.prototype.slice).call(c), [d], slice_.call(e)))\r\nvar slice_`)
|
|
157
|
+
assert(downLevel(`a.call(a,b,...c,d,...e)`), `a.call.apply(a, [a, b].concat((slice_ = Array.prototype.slice).call(c), [d], slice_.call(e)))\r\nvar slice_`)
|
|
158
|
+
assert(downLevel(`a.b(a,b,...c,d,...e)`), `a.b.apply(a, [a, b].concat((slice_ = Array.prototype.slice).call(c), [d], slice_.call(e)))\r\nvar slice_`)
|
|
159
|
+
assert(downLevel(`[].b(a,b,...c,d,...e)`), `(_ = []).b.apply(_, [a, b].concat((slice_ = Array.prototype.slice).call(c), [d], slice_.call(e)))\r\nvar _, slice_`)
|
|
160
|
+
assert(downLevel(`a(...b).c(...d)`), `(_ = a.apply(null, b)).c.apply(_, d)\r\nvar _`)
|
|
161
|
+
assert(downLevel(`a(...b).c(...d).e(...f)`), `(_ = (_ = a.apply(null, b)).c.apply(_, d)).e.apply(_, f)\r\nvar _`)
|
|
162
|
+
assert(downLevel(`diagnostic.relatedInformation.push(...relatedInformation);`), `(_ = diagnostic.relatedInformation).push.apply(_, relatedInformation);\r\nvar _`);
|
|
163
|
+
assert(downLevel(`const typeNames = [79 /* Identifier */, ...typeKeywords];`), `var typeNames = [79 /* Identifier */].concat(Array.prototype.slice.call(typeKeywords));`);
|
|
164
|
+
i++// 箭头函数
|
|
165
|
+
assert(downLevel(`a=>k`), "function (a) { return k }")
|
|
166
|
+
assert(downLevel(`function (a,...b,b){}`), "function (a, b) { b = arguments.length > 1 ? arguments[arguments.length - 1] : undefined; }")
|
|
167
|
+
assert(downLevel(`(a)=>k`), "function (a) { return k }")
|
|
168
|
+
assert(downLevel(`(a=1)=>k`), "function (a) { if (a === undefined) a = 1; return k }")
|
|
169
|
+
assert(downLevel(`([a])=>b`), "function (arg) { var a = arg[0]; return b }")
|
|
170
|
+
assert(downLevel(`map(([a])=>a)`), "map(function (arg) { var a = arg[0]; return a })")
|
|
171
|
+
assert(downLevel(`var [_, R, G, B, A] = rgbHex.exec(color).map(a => parseInt(a + a, 16));`), "var _0 = rgbHex.exec(color).map(function (a) { return parseInt(a + a, 16) }), _ = _0[0], R = _0[1], G = _0[2], B = _0[3], A = _0[4];")
|
|
172
|
+
assert(downLevel(`if (/^(?:select|input|textarea)$/i.test(initialEvent.target.tagName) || getTargetIn(a => a.nodrag || a.hasAttribute('nodrag'), initialEvent.target)) return;`), "if (/^(?:select|input|textarea)$/i.test(initialEvent.target.tagName) || getTargetIn(function (a) { return a.nodrag || a.hasAttribute('nodrag') }, initialEvent.target)) return;")
|
|
173
|
+
i++// 对象收集
|
|
91
174
|
assert(downLevel(`function (a,...b){}`), "function (a) { var b = Array.prototype.slice.call(arguments, 1); }")
|
|
92
175
|
assert(downLevel(`function (a,...b,c){}`), "function (a, c) { var b = Array.prototype.slice.call(arguments, 1, -1); c = arguments.length > 1 ? arguments[arguments.length - 1] : undefined; }")
|
|
93
176
|
assert(downLevel(`function (a,...,c){}`), "function (a, c) { c = arguments.length > 1 ? arguments[arguments.length - 1] : undefined; }")
|
|
94
|
-
assert(downLevel(`function (a,...b,b){}`), "function (a, b) { b = arguments.length > 1 ? arguments[arguments.length - 1] : undefined; }")
|
|
95
|
-
assert(downLevel(`(a)=>k`), "function (a) { return k }")
|
|
96
177
|
assert(downLevel(`(...a) => k`), "function () { var a = Array.prototype.slice.call(arguments, 0); return k }")
|
|
97
|
-
assert(downLevel(`for(
|
|
98
|
-
assert(downLevel(`for(var o of
|
|
99
|
-
assert(downLevel(`for(var
|
|
100
|
-
assert(downLevel(`for(var
|
|
178
|
+
assert(downLevel(`for(o of os) noSymbol`), "for (_ = 0, _0 = os.length; _ < _0 && (o = os[_], true); _++) noSymbol\r\nvar _, _0")
|
|
179
|
+
assert(downLevel(`for(var o of os) Symbol`), "for (var o, _0 = os[Symbol.iterator] || os[Symbol.asyncIterator] || Array.prototype[Symbol.iterator], _0 = _0.call(os), _ = _0.next(); !_.done && (o = _.value, true); _ = _0.next()) Symbol\r\nvar _, _0")
|
|
180
|
+
assert(downLevel(`for(var o of os) Symbol`), "for (var o, _0 = os[Symbol.iterator] || os[Symbol.asyncIterator] || Array.prototype[Symbol.iterator], _0 = _0.call(os), _ = _0.next(); !_.done && (o = _.value, true); _ = _0.next()) Symbol\r\nvar _, _0")
|
|
181
|
+
assert(downLevel(`for(var o of o)Symbol`), "for (var o, _1 = o, _0 = _1[Symbol.iterator] || _1[Symbol.asyncIterator] || Array.prototype[Symbol.iterator], _0 = _0.call(_1), _ = _0.next(); !_.done && (o = _.value, true); _ = _0.next()) Symbol\r\nvar _, _0, _1")
|
|
182
|
+
assert(downLevel(`for(var [a] of os)Symbol`), "for (var a, _0 = os[Symbol.iterator] || os[Symbol.asyncIterator] || Array.prototype[Symbol.iterator], _0 = _0.call(os), _ = _0.next(); !_.done && (a = _.value[0], true); _ = _0.next()) Symbol\r\nvar _, _0")
|
|
183
|
+
assert(downLevel(`for(var [a,b] of os)Symbol`), "for (var a, b, _0 = os[Symbol.iterator] || os[Symbol.asyncIterator] || Array.prototype[Symbol.iterator], _0 = _0.call(os), _ = _0.next(); !_.done && (_1 = _.value, a = _1[0], b = _1[1], true); _ = _0.next()) Symbol\r\nvar _, _0, _1")
|
|
101
184
|
assert(downLevel(`[...a]=a`), "a = Array.prototype.slice.call(a, 0)")
|
|
102
185
|
assert(downLevel(`[c,...a]=a`), "c = a[0], a = Array.prototype.slice.call(a, 1)")
|
|
103
186
|
assert(downLevel(`[...a]=a`), "a = Array.prototype.slice.call(a, 0)")
|
|
104
|
-
assert(downLevel(`[...a,c]=a`), "_ = a, a = Array.prototype.slice.call(a, 0, -1), c = _.length > 1 ? _[_.length - 1] : undefined")
|
|
187
|
+
assert(downLevel(`[...a,c]=a`), "_ = a, a = Array.prototype.slice.call(a, 0, -1), c = _.length > 1 ? _[_.length - 1] : undefined\r\nvar _")
|
|
105
188
|
assert(downLevel(`{...a,c}=a`), `c = a.c, a = rest_(a, ["c"])`)
|
|
106
189
|
assert(downLevel(`{c,...a}=a`), `c = a.c, a = rest_(a, ["c"])`)
|
|
190
|
+
assert(downLevel("if(a){}[r, g, b] = rgb4s(r, g, b, s)"), "if (a) {} _ = rgb4s(r, g, b, s), r = _[0], g = _[1], b = _[2]\r\nvar _", true);
|
|
107
191
|
assert(downLevel(`{c,[c]:b,...a}=a`), `c = a.c, b = a[c], a = rest_(a, ["c", c])`)
|
|
192
|
+
i++//异步或步进函数
|
|
193
|
+
assert(downLevel(`function *(){yield *a}`), `function () { return aster_(
|
|
194
|
+
function () {
|
|
195
|
+
_; _0 = 0; _3 = a.length; _1 = _3; return [1, 0]
|
|
196
|
+
},
|
|
197
|
+
function () {
|
|
198
|
+
_3 = _0 < _1; if (!_3) return [1, 0]; _4 = a[_0]; _ = _4; _3 = (_4, true)
|
|
199
|
+
},
|
|
200
|
+
function () {
|
|
201
|
+
if (!_3) return [2, 0]; return [_, 3]
|
|
202
|
+
},
|
|
203
|
+
function () {
|
|
204
|
+
_3 = _0++; return [-2, 0]
|
|
205
|
+
})
|
|
206
|
+
var _, _0, _1, _3, _4 }`)
|
|
108
207
|
assert(downLevel(`async function(){}`), `function () { return async_() }`)
|
|
109
|
-
assert(downLevel(`async function(){
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
208
|
+
assert(downLevel(`async function(){for(var a of b){Symbol}}`), `function () { return async_(
|
|
209
|
+
function () {
|
|
210
|
+
a; _3 = Symbol.iterator; _2 = b[_3]; if (_2) return [1, 0]; _3 = Symbol.asyncIterator; _2 = b[_3]; if (_2) return [1, 0]; _3 = Symbol.iterator; _2 = Array.prototype[_3]
|
|
211
|
+
},
|
|
212
|
+
function () {
|
|
213
|
+
_0 = _2; _2 = _0.call(b); _0 = _2; _2 = _0.next(); _ = _2; return [1, 0]
|
|
214
|
+
},
|
|
215
|
+
function () {
|
|
216
|
+
_2 = !_.done; if (!_2) return [1, 0]; _3 = _.value; a = _3; _2 = (_3, true)
|
|
217
|
+
},
|
|
218
|
+
function () {
|
|
219
|
+
if (!_2) return [1, 0]; Symbol; _2 = _0.next(); _ = _2; return [-1, 0]
|
|
220
|
+
})
|
|
221
|
+
var a, _, _0, _2, _3 }`)
|
|
222
|
+
assert(downLevel(`a={async a(){var b =c;return 1}}`), `a = (_ = {},
|
|
223
|
+
_.a = function () { return async_(\r\nfunction () {\r\nb = c; return [1, 2]\r\n})\r\nvar b }, _)\r\nvar _`)
|
|
224
|
+
assert(downLevel(`async function(){return 1}`), `function () { return async_(\r\nfunction () {\r\nreturn [1, 2]\r\n}) }`)
|
|
225
|
+
assert(downLevel(`async function(a){await a}`), `function (a) { return async_(\r\nfunction () {\r\n_0 = a; return [_0, 1]\r\n})\r\nvar _0 }`)
|
|
226
|
+
assert(downLevel(`async function(a){return await a}`), `function (a) { return async_(\r\nfunction () {\r\n_0 = a; return [_0, 1]\r\n},\r\nfunction (_) {\r\n_0 = _; return [_0, 2]\r\n})\r\nvar _0 }`)
|
|
227
|
+
assert(downLevel(`async function(a){await a,await b}`), `function (a) { return async_(\r\nfunction () {\r\n_0 = a; return [_0, 1]\r\n},\r\nfunction (_) {\r\n_0 = _; _0 = b; return [_0, 1]\r\n})\r\nvar _0 }`)
|
|
228
|
+
assert(downLevel(`async function(){await a,await b}`), `function () { return async_(\r\nfunction () {\r\n_0 = a; return [_0, 1]\r\n},\r\nfunction (_) {\r\n_0 = _; _0 = b; return [_0, 1]\r\n})\r\nvar _0 }`)
|
|
229
|
+
assert(downLevel(`async function(a){ if(c)await a,await b;else if(s) await c;}`), `function (a) { return async_(
|
|
230
|
+
function () {
|
|
231
|
+
if (!c) return [3, 0]; _0 = a; return [_0, 1]
|
|
232
|
+
},
|
|
233
|
+
function (_) {
|
|
234
|
+
_0 = _; _0 = b; return [_0, 1]
|
|
235
|
+
},
|
|
236
|
+
function (_) {
|
|
237
|
+
_0 = _; return [3, 0]
|
|
238
|
+
},
|
|
239
|
+
function () {
|
|
240
|
+
if (!s) return [2, 0]; _0 = c; return [_0, 1]
|
|
241
|
+
},
|
|
242
|
+
function (_) {
|
|
243
|
+
_0 = _; return [1, 0]
|
|
244
|
+
})
|
|
245
|
+
var _0 }`)
|
|
246
|
+
assert(downLevel(`async function(a){ for(var i=1;i<2;i++) await 1 }`), `function (a) { return async_(\r\nfunction () {\r\ni = 1; return [1, 0]\r\n},\r\nfunction () {\r\n_0 = i < 2; if (!_0) return [2, 0]; _0 = 1; return [_0, 1]\r\n},\r\nfunction (_) {\r\n_0 = _; _0 = i++; return [-1, 0]\r\n})\r\nvar i, _0 }`)
|
|
247
|
+
assert(downLevel('async function(){ if(b); else {if (a){}else{location = getRequestProtocol(url) + "//" + location;}}}'), `function () { return async_(
|
|
248
|
+
function () {
|
|
249
|
+
if (!b) return [1, 0]; return [3, 0]
|
|
250
|
+
},
|
|
251
|
+
function () {
|
|
252
|
+
if (!a) return [1, 0]; return [2, 0]
|
|
253
|
+
},
|
|
254
|
+
function () {
|
|
255
|
+
_0 = getRequestProtocol(url) + "//", _0 = _0 + location; location = _0; return [1, 0]
|
|
256
|
+
})
|
|
257
|
+
var _0 }`);
|
package/coms/compile/powermap.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var powermap = {};
|
|
2
2
|
[
|
|
3
3
|
'=,+=,-=,*=,/=,%=,|=,&=,^=,**=,~=,?,:,=>'/* 1 */,
|
|
4
|
-
'
|
|
4
|
+
'&&,||,^^,??'/* 4 */, '&,|,^'/* 5 */,
|
|
5
5
|
'instanceof,in,==,>=,<=,>,<,!=,!==,===,!in,!instanceof'/* 6 */,
|
|
6
6
|
'>>,>>>,<<'/* 7 */, '+,-'/* 8 */, '*,/,%'/* 9 */, '**'/* 10 */,
|
|
7
|
-
'typeof,await,
|
|
7
|
+
'typeof,await,new,delete,void,!,~'/* 11 */, '++,--'/* 12 */,
|
|
8
8
|
].forEach((pp, i) => {
|
|
9
9
|
pp.split(",").forEach(p => {
|
|
10
10
|
powermap[p] = i + 1;
|
package/coms/compile/scanner2.js
CHANGED
|
@@ -17,6 +17,7 @@ const {
|
|
|
17
17
|
skipSentenceQueue,
|
|
18
18
|
rename,
|
|
19
19
|
relink,
|
|
20
|
+
setqueue
|
|
20
21
|
} = require("./common");
|
|
21
22
|
|
|
22
23
|
|
|
@@ -141,7 +142,7 @@ class Code extends Array {
|
|
|
141
142
|
// 绕开低版本ie的异常属性
|
|
142
143
|
detour(ie) {
|
|
143
144
|
this.program.avoidMap = avoidMap;
|
|
144
|
-
this.program.detour(this.first,
|
|
145
|
+
this.program.detour(this.first, ie !== false);
|
|
145
146
|
return this;
|
|
146
147
|
}
|
|
147
148
|
// 压缩
|
|
@@ -153,7 +154,9 @@ class Code extends Array {
|
|
|
153
154
|
return this;
|
|
154
155
|
}
|
|
155
156
|
relink(list = this) {
|
|
156
|
-
|
|
157
|
+
relink(list);
|
|
158
|
+
setqueue(list);
|
|
159
|
+
return list;
|
|
157
160
|
}
|
|
158
161
|
}
|
|
159
162
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var scanner2 = require("./scanner2");
|
|
2
|
-
var { SCOPED, QUOTED, SCOPED, PIECE, number_reg, replace, createString } = require("./common");
|
|
2
|
+
var { SCOPED, QUOTED, SCOPED, PROPERTY, STAMP, PIECE, setqueue, splice, relink, number_reg, replace, createString } = require("./common");
|
|
3
3
|
var strings = require("../basic/strings");
|
|
4
4
|
var program = null;
|
|
5
5
|
var patchTranslate = function (c) {
|
|
@@ -63,7 +63,23 @@ function getI18nPrefixedText(code, dist = []) {
|
|
|
63
63
|
}, 字段名);
|
|
64
64
|
return dist;
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
var ctn = function (tt, t) {
|
|
67
|
+
var tn = scanner2(tt.replace(/[\$#]+(\d+)/g, (_, i) => {
|
|
68
|
+
var a = (i << 1) - 1;
|
|
69
|
+
if (a in t) return `\${${a}}`;
|
|
70
|
+
return _;
|
|
71
|
+
}));
|
|
72
|
+
tn[tn.length - 1].forEach(n => {
|
|
73
|
+
if (n.type !== QUOTED || !n.length) return;
|
|
74
|
+
n.forEach((a, i) => {
|
|
75
|
+
if (a.type !== SCOPED) return;
|
|
76
|
+
var e = a[0].text;
|
|
77
|
+
if (e in t) n[i] = t[e];
|
|
78
|
+
});
|
|
79
|
+
relink(n);
|
|
80
|
+
})
|
|
81
|
+
return tn;
|
|
82
|
+
}
|
|
67
83
|
function translate([imap, supports], code) {
|
|
68
84
|
var texts = getI18nPrefixedText(code);
|
|
69
85
|
texts.sort((a, b) => {
|
|
@@ -88,11 +104,8 @@ function translate([imap, supports], code) {
|
|
|
88
104
|
p.leave = ")";
|
|
89
105
|
}
|
|
90
106
|
var tt = t.translate;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (a in t) return `\${${createString(t[a])}}`;
|
|
94
|
-
return _;
|
|
95
|
-
})));
|
|
107
|
+
var tn = ctn(`(${getm(tt)})`, t);
|
|
108
|
+
replace(t, tn[0]);
|
|
96
109
|
}
|
|
97
110
|
else if (t.transtype === 字段名) {
|
|
98
111
|
var i = t.queue.indexOf(t.prev);
|
|
@@ -103,19 +116,32 @@ function translate([imap, supports], code) {
|
|
|
103
116
|
used.i18n = [];
|
|
104
117
|
code.envs.i18n = true;
|
|
105
118
|
}
|
|
106
|
-
|
|
107
|
-
|
|
119
|
+
var tn = scanner2("[]")[0];
|
|
120
|
+
t.fields.forEach(f => {
|
|
121
|
+
var o = scanner2('={}')[1];
|
|
122
|
+
Object.keys(f).forEach(k => {
|
|
108
123
|
var v = f[k];
|
|
109
|
-
if (/[\$#]\d+/.test(v))
|
|
110
|
-
var a = (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
else v =
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
124
|
+
if (/[\$#]\d+/.test(v)) {
|
|
125
|
+
var a = v.replace(/^[\$#]+/, '');
|
|
126
|
+
var a = (a << 1) - 1;
|
|
127
|
+
if (a in t) v = t[a];
|
|
128
|
+
else v = scanner2(JSON.stringify(v));
|
|
129
|
+
}
|
|
130
|
+
else if (k === 'name') v = ctn(`i18n(${getm(v)})`, t);
|
|
131
|
+
else v = scanner2(JSON.stringify(v));
|
|
132
|
+
o.push({ type: PROPERTY, isprop: true, text: JSON.stringify(k) }, { type: STAMP, text: ':' }, ...v, { type: STAMP, text: ',' });
|
|
133
|
+
})
|
|
134
|
+
o.pop();
|
|
135
|
+
setqueue(o);
|
|
136
|
+
relink(o);
|
|
137
|
+
tn.push(o);
|
|
138
|
+
tn.push({ type: STAMP, text: ',' });
|
|
139
|
+
});
|
|
140
|
+
tn.pop();
|
|
141
|
+
setqueue(tn);
|
|
142
|
+
relink(tn);
|
|
143
|
+
Object.defineProperty(tn, 'queue', { value: t.queue });
|
|
144
|
+
splice(t.queue, i, e + 1 - i, tn);
|
|
119
145
|
}
|
|
120
146
|
}
|
|
121
147
|
if (used.refilm && !used.refilm.length) {
|