efront 3.7.9 → 3.8.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.
- package/coms/basic/loader.js +7 -5
- package/coms/basic/strings.js +1 -1
- package/coms/compile/common.js +76 -10
- package/coms/compile/downLevel.js +11 -0
- package/coms/compile/scanner2.js +192 -34
- package/coms/zimoli/createElement.js +1 -1
- package/package.json +2 -2
- package/public/efront.js +1 -1
package/coms/basic/loader.js
CHANGED
|
@@ -154,8 +154,8 @@ var readFile = function (names, then) {
|
|
|
154
154
|
tryload();
|
|
155
155
|
|
|
156
156
|
};
|
|
157
|
-
var createFunction = function (name, body, args) {
|
|
158
|
-
return window.eval(`[function/*${name}*/(${args || ''}){\r\n${body}\r\n}][0]`);
|
|
157
|
+
var createFunction = function (name, body, args, isAsync, isYield) {
|
|
158
|
+
return window.eval(`[${isAsync ? 'async ' : ''}function${isYield ? "*" : ""}/*${name}*/(${args || ''}){\r\n${body}\r\n}][0]`);
|
|
159
159
|
};
|
|
160
160
|
|
|
161
161
|
var FILE_NAME_REG = /^https?\:|\.(html?|css|asp|jsp|php)$/i;
|
|
@@ -269,13 +269,13 @@ var loadModule = function (name, then, prebuilds = {}) {
|
|
|
269
269
|
flushTree(loadedModules, key);
|
|
270
270
|
return;
|
|
271
271
|
}
|
|
272
|
-
var [argNames, body, args, required, strs] = getArgs(data);
|
|
272
|
+
var [argNames, body, args, required, strs, isAsync, isYield] = getArgs(data);
|
|
273
273
|
if (isProduction) {
|
|
274
274
|
strs = strs.map ? strs.map(toRem) : strs;
|
|
275
275
|
} else {
|
|
276
276
|
body = toRem(body);
|
|
277
277
|
}
|
|
278
|
-
var mod = createFunction(name, body, argNames);
|
|
278
|
+
var mod = createFunction(name, body, argNames, isAsync, isYield);
|
|
279
279
|
if (!mod) console.log(name, mod);
|
|
280
280
|
mod.args = args;
|
|
281
281
|
mod.argNames = argNames;
|
|
@@ -399,8 +399,10 @@ var getArgs = function (text) {
|
|
|
399
399
|
} else {
|
|
400
400
|
functionBody = text;
|
|
401
401
|
}
|
|
402
|
+
var [, isAsync, isYield] = /^(@?)(\*?)/.exec(functionBody);
|
|
403
|
+
if (isAsync || isYield) functionBody = functionBody.slice(+!!isAsync + +!!isYield);
|
|
402
404
|
functionBody = functionBody.replace(/^(?:\s*(["'])user? strict\1;?[\r\n]*)*/i, "\"use strict\";\r\n");
|
|
403
|
-
return [argNames || [], functionBody, args || [], required || '', strs || []];
|
|
405
|
+
return [argNames || [], functionBody, args || [], required || '', strs || [], !!isAsync, !!isYield];
|
|
404
406
|
};
|
|
405
407
|
var get_relatives = function (name, required, prefix = "") {
|
|
406
408
|
var required_base = name.replace(/[^\/\$]+$/, "");
|
package/coms/basic/strings.js
CHANGED
|
@@ -25,7 +25,7 @@ function encode(str) {
|
|
|
25
25
|
}) + "\"";
|
|
26
26
|
}
|
|
27
27
|
function decode(s) {
|
|
28
|
-
var r = /^(['"])([\s\S]*)\1$/.exec(s);
|
|
28
|
+
var r = /^(['"`])([\s\S]*)\1$/.exec(s);
|
|
29
29
|
if (!r) return s;
|
|
30
30
|
return r[2].replace(/\\u[0-9a-f]{4}|\\x[0-9a-f]{2}|\\([\s\S])/ig, (a, b) => {
|
|
31
31
|
if (!b) {
|
package/coms/compile/common.js
CHANGED
|
@@ -91,6 +91,7 @@ var skipAssignment = function (o) {
|
|
|
91
91
|
}
|
|
92
92
|
else if (o.text === "function") {
|
|
93
93
|
o = o.next;
|
|
94
|
+
if (o && o.type === STAMP) o = o.next;
|
|
94
95
|
if (o && o.type === EXPRESS) o = o.next;
|
|
95
96
|
if (o) o = o.next;
|
|
96
97
|
if (o) o = o.next;
|
|
@@ -111,13 +112,16 @@ var skipAssignment = function (o) {
|
|
|
111
112
|
};
|
|
112
113
|
var createScoped = function (parsed) {
|
|
113
114
|
var used = Object.create(null); var vars = Object.create(null), lets = vars;
|
|
114
|
-
var scoped = [];
|
|
115
|
+
var scoped = [], funcbody = scoped;
|
|
116
|
+
scoped.isfunc = true;
|
|
115
117
|
var run = function (o, id) {
|
|
116
118
|
loop: while (o) {
|
|
117
119
|
var isCatch = false;
|
|
118
120
|
var isFunction = false;
|
|
119
121
|
var isScope = false;
|
|
120
122
|
var isArrow = false;
|
|
123
|
+
var isDeclare = false;
|
|
124
|
+
var isYield = false;
|
|
121
125
|
switch (o.type) {
|
|
122
126
|
case QUOTED:
|
|
123
127
|
if (o.length) {
|
|
@@ -130,14 +134,20 @@ var createScoped = function (parsed) {
|
|
|
130
134
|
if (o.next) {
|
|
131
135
|
if (o.next.type !== STAMP || o.next.text !== ",") break;
|
|
132
136
|
}
|
|
137
|
+
if (o.prev && o.prev.type === STRAP && o.prev.text === 'as') {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
133
140
|
case VALUE:
|
|
134
141
|
if (number_reg.test(o.text)) break;
|
|
135
142
|
case EXPRESS:
|
|
136
143
|
if (o.prev && o.prev.type === EXPRESS) {
|
|
137
144
|
if (/\.$/.test(o.prev.text)) break;
|
|
138
145
|
}
|
|
139
|
-
var u = o.text
|
|
146
|
+
var u = o.text;
|
|
147
|
+
if (/^\.\.\./.test(u)) u = u.slice(3);
|
|
148
|
+
var u = u.replace(/^([^\.\[]*)[\s\S]*$/, '$1');
|
|
140
149
|
if (!u) break;
|
|
150
|
+
if (u === 'yield') funcbody.yield = false;
|
|
141
151
|
if (o.next && o.next.type === STAMP && o.next.text === "=>") {
|
|
142
152
|
isScope = true;
|
|
143
153
|
isArrow = true;
|
|
@@ -157,6 +167,27 @@ var createScoped = function (parsed) {
|
|
|
157
167
|
case STRAP:
|
|
158
168
|
var s = o.text;
|
|
159
169
|
switch (s) {
|
|
170
|
+
case "await":
|
|
171
|
+
funcbody.async = funcbody.await = true;
|
|
172
|
+
break;
|
|
173
|
+
case "yield":
|
|
174
|
+
if (!funcbody.yield) {
|
|
175
|
+
var next = o.next;
|
|
176
|
+
if (next) {
|
|
177
|
+
|
|
178
|
+
if (next.type === STAMP && !/[~!,;:]+$/.test(next.text)
|
|
179
|
+
|| next.type === STRAP && /in|of|as|from|instanceof/.test(next.text)
|
|
180
|
+
|| next.type === EXPRESS && /^\./.test(next.text)
|
|
181
|
+
) {
|
|
182
|
+
funcbody.yield = false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
saveTo(used, 'yield', o);
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
case "as":
|
|
189
|
+
case "from":
|
|
190
|
+
break;
|
|
160
191
|
case "var":
|
|
161
192
|
case "import":
|
|
162
193
|
var m = vars;
|
|
@@ -176,6 +207,10 @@ var createScoped = function (parsed) {
|
|
|
176
207
|
continue loop;
|
|
177
208
|
case "function":
|
|
178
209
|
isFunction = true;
|
|
210
|
+
if (o.next.type === STAMP) {
|
|
211
|
+
isYield = true;
|
|
212
|
+
o = o.next;
|
|
213
|
+
}
|
|
179
214
|
case "catch":
|
|
180
215
|
isCatch = true;
|
|
181
216
|
case "class":
|
|
@@ -184,6 +219,7 @@ var createScoped = function (parsed) {
|
|
|
184
219
|
|
|
185
220
|
if (o.type === EXPRESS) {
|
|
186
221
|
vars[o.text] = true;
|
|
222
|
+
isDeclare = true;
|
|
187
223
|
o.kind = isFunction ? 'function' : 'class';
|
|
188
224
|
saveTo(used, o.text, o);
|
|
189
225
|
|
|
@@ -197,11 +233,18 @@ var createScoped = function (parsed) {
|
|
|
197
233
|
break;
|
|
198
234
|
case SCOPED:
|
|
199
235
|
if (o.entry === "(") {
|
|
200
|
-
if (o.next && o.next.type === STAMP && o.next.text === "=>"
|
|
201
|
-
|| o.prev && (o.prev.type === PROPERTY || o.prev.isprop)) {
|
|
236
|
+
if (o.next && o.next.type === STAMP && o.next.text === "=>") {
|
|
202
237
|
isArrow = true;
|
|
203
238
|
isScope = true;
|
|
204
239
|
}
|
|
240
|
+
else if (o.prev && (o.prev.type === PROPERTY || o.prev.isprop)) {
|
|
241
|
+
isFunction = true;
|
|
242
|
+
isScope = true;
|
|
243
|
+
var pp = o.prev.prev;
|
|
244
|
+
if (pp && pp.type === STAMP && pp.isprop) {
|
|
245
|
+
isYield = true;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
205
248
|
else {
|
|
206
249
|
run(o.first);
|
|
207
250
|
}
|
|
@@ -229,15 +272,20 @@ var createScoped = function (parsed) {
|
|
|
229
272
|
scoped.used = used;
|
|
230
273
|
scoped.vars = vars;
|
|
231
274
|
lets = vars;
|
|
232
|
-
if (isFunction)
|
|
275
|
+
if (isFunction) {
|
|
276
|
+
vars.this = true, vars.arguments = true;
|
|
277
|
+
scoped.yield = isYield;
|
|
278
|
+
}
|
|
279
|
+
scoped.isfunc = true;
|
|
233
280
|
isFunction = true;
|
|
281
|
+
funcbody = scoped;
|
|
234
282
|
} else {
|
|
235
283
|
vars = _vars;
|
|
236
284
|
scoped.lets = lets;
|
|
237
285
|
scoped.used = used;
|
|
238
286
|
}
|
|
239
287
|
if (isArrow);
|
|
240
|
-
else if (o.isExpress && o.type !== SCOPED) {
|
|
288
|
+
else if (o.isExpress && o.type !== SCOPED && !isDeclare) {
|
|
241
289
|
o = o.next;
|
|
242
290
|
if (o.type === EXPRESS) {
|
|
243
291
|
vars[o.text] = true;
|
|
@@ -323,6 +371,10 @@ var createScoped = function (parsed) {
|
|
|
323
371
|
delete vars.this;
|
|
324
372
|
delete vars.arguments;
|
|
325
373
|
}
|
|
374
|
+
if (_scoped.isfunc && !funcbody.yield) {
|
|
375
|
+
if (used.yield) _scoped.yield = false;
|
|
376
|
+
funcbody = _scoped;
|
|
377
|
+
}
|
|
326
378
|
used = _used;
|
|
327
379
|
lets = _lets;
|
|
328
380
|
vars = _vars;
|
|
@@ -342,6 +394,12 @@ var createScoped = function (parsed) {
|
|
|
342
394
|
if (!/^(true|false|null|this|arguments)$/.test(u)) envs[u] = true;
|
|
343
395
|
}
|
|
344
396
|
}
|
|
397
|
+
if (vars.yield) scoped.yield = false;
|
|
398
|
+
if (scoped.yield !== false && envs.yield) {
|
|
399
|
+
scoped.yield = true;
|
|
400
|
+
delete envs.yield;
|
|
401
|
+
delete used.yield;
|
|
402
|
+
}
|
|
345
403
|
scoped.envs = envs;
|
|
346
404
|
return scoped;
|
|
347
405
|
};
|
|
@@ -358,10 +416,19 @@ var getDeclared = function (o, kind) {
|
|
|
358
416
|
}
|
|
359
417
|
}
|
|
360
418
|
switch (o.type) {
|
|
419
|
+
case STAMP:
|
|
420
|
+
if (o.text === "*" && o.next) {
|
|
421
|
+
if (o.next.type === STRAP && o.next.text === 'as') {
|
|
422
|
+
o = o.next.next;
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
361
426
|
case PROPERTY:
|
|
362
|
-
if (o.next
|
|
363
|
-
o
|
|
364
|
-
|
|
427
|
+
if (o.next) {
|
|
428
|
+
if (o.next.type === STAMP && o.next.text === ":" || o.next.type === STRAP && o.next.text === "as") {
|
|
429
|
+
o = o.next.next;
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
365
432
|
}
|
|
366
433
|
case STRAP:
|
|
367
434
|
case VALUE:
|
|
@@ -379,7 +446,6 @@ var getDeclared = function (o, kind) {
|
|
|
379
446
|
Object.assign(declared, d);
|
|
380
447
|
o = o.next;
|
|
381
448
|
break;
|
|
382
|
-
|
|
383
449
|
default:
|
|
384
450
|
console.log(o);
|
|
385
451
|
throw new Error("代码结构异常");
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var typescript = require("../typescript");
|
|
2
|
+
module.exports = function (data, isAsync, isYield) {
|
|
3
|
+
if (isYield || isAsync) {
|
|
4
|
+
data = `${isAsync ? "async " : ""}function${isYield ? "*" : ""}(){${data}}`;
|
|
5
|
+
}
|
|
6
|
+
data = typescript.transpile(data, { noEmitHelpers: true });
|
|
7
|
+
if (isYield || isAsync) {
|
|
8
|
+
data = data.replace(/^\s*function\s*\(\s*\)\s*\{\s*([\s\S]*?)\s*\}\s*$/, "$1");
|
|
9
|
+
}
|
|
10
|
+
return data;
|
|
11
|
+
}
|
package/coms/compile/scanner2.js
CHANGED
|
@@ -26,6 +26,7 @@ var needBreak = function (prev, next) {
|
|
|
26
26
|
if (prev.type === EXPRESS && /\.$/.test(prev.text)) return;
|
|
27
27
|
if (next.type === EXPRESS && /^\./.test(next.text)) return;
|
|
28
28
|
if (next.type === PROPERTY) return ";";
|
|
29
|
+
if (next.type === STAMP && next.text === "*") return ";";
|
|
29
30
|
if (
|
|
30
31
|
[EXPRESS, VALUE, QUOTED].indexOf(prev.type) >= 0
|
|
31
32
|
|| prev.type === STAMP && /^(\+\+|\-\-)$/.test(prev.text)
|
|
@@ -95,8 +96,8 @@ var compress = function (scoped, maped) {
|
|
|
95
96
|
|
|
96
97
|
var strings = require("../basic/strings");
|
|
97
98
|
|
|
98
|
-
var insertAfter = function (o
|
|
99
|
-
var queue = o.queue;
|
|
99
|
+
var insertAfter = function (o) {
|
|
100
|
+
var queue = o.queue || this;
|
|
100
101
|
var index = queue.indexOf(o) + 1;
|
|
101
102
|
var os = [].slice.call(arguments, 1);
|
|
102
103
|
queue.splice.apply(queue, [index, 0].concat(os));
|
|
@@ -104,6 +105,7 @@ var insertAfter = function (o,) {
|
|
|
104
105
|
for (var o of os) {
|
|
105
106
|
prev.next = o;
|
|
106
107
|
o.prev = prev;
|
|
108
|
+
Object.defineProperty(o, 'queue', { value: queue });
|
|
107
109
|
prev = o;
|
|
108
110
|
}
|
|
109
111
|
if (next) {
|
|
@@ -111,6 +113,20 @@ var insertAfter = function (o,) {
|
|
|
111
113
|
next.prev = o;
|
|
112
114
|
}
|
|
113
115
|
};
|
|
116
|
+
var detourTemplate = function (raw, params) {
|
|
117
|
+
var spliter = { text: ",", type: STAMP };
|
|
118
|
+
var template = scan(`extend([],{["raw"]:[]})`);
|
|
119
|
+
var str0 = template[1].first;
|
|
120
|
+
var str1 = template[1][2][2];
|
|
121
|
+
for (var r of raw) {
|
|
122
|
+
str0.push({ text: strings.encode(strings.decode("`" + r.text + "`")), type: QUOTED }, spliter);
|
|
123
|
+
str1.push({ text: strings.encode(r.text), type: QUOTED }, spliter);
|
|
124
|
+
}
|
|
125
|
+
str0.pop();
|
|
126
|
+
str1.pop();
|
|
127
|
+
for (var p of params) template.push(spliter, p);
|
|
128
|
+
return template;
|
|
129
|
+
};
|
|
114
130
|
|
|
115
131
|
var detour = function (o, ie) {
|
|
116
132
|
while (o) {
|
|
@@ -121,31 +137,103 @@ var detour = function (o, ie) {
|
|
|
121
137
|
case EXPRESS:
|
|
122
138
|
if (!/^\.\.\.|\.\.\.$/.test(o.text)) {
|
|
123
139
|
var ot = o.text;
|
|
124
|
-
o.text = o.text.replace(/\.([^\.\[]+)/g, (_, a) =>
|
|
140
|
+
o.text = o.text.replace(/\.([^\.\[]+)/g, (_, a) => ie === undefined || program.strap_reg.test(a) ? `[${strings.encode(strings.decode(a))}]` : _);
|
|
125
141
|
}
|
|
126
142
|
break;
|
|
127
143
|
case QUOTED:
|
|
128
144
|
if (o.length) {
|
|
129
|
-
|
|
145
|
+
if (!o.prev || o.prev.type === STAMP || o.prev.type === STRAP) {
|
|
146
|
+
o.type = SCOPED;
|
|
147
|
+
o.entry = '[';
|
|
148
|
+
o.leave = `]["join"]('')`;
|
|
149
|
+
for (var cx = o.length - 1; cx >= 0; cx--) {
|
|
150
|
+
var c = o[cx];
|
|
151
|
+
if (c.type === PIECE) {
|
|
152
|
+
c.type = QUOTED;
|
|
153
|
+
c.text = strings.encode(strings.decode("`" + c.text + "`"));
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
insertAfter.call(o, c.prev, { type: STAMP, text: ',' });
|
|
157
|
+
c.entry = "(";
|
|
158
|
+
c.leave = ")";
|
|
159
|
+
insertAfter.call(o, c, { type: STAMP, text: ',' });
|
|
160
|
+
detour(c.first, ie);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
var raw = [];
|
|
166
|
+
var params = [];
|
|
167
|
+
|
|
168
|
+
for (var c of o) {
|
|
169
|
+
if (c.type === PIECE) {
|
|
170
|
+
raw.push(c);
|
|
171
|
+
} else {
|
|
172
|
+
c.entry = '(';
|
|
173
|
+
c.leave = ")";
|
|
174
|
+
detour(c, ie);
|
|
175
|
+
params.push(c.length === 1 ? c[0] : c);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
o.type = SCOPED;
|
|
179
|
+
o.entry = "(";
|
|
180
|
+
o.leave = ")";
|
|
181
|
+
var temp = detourTemplate(raw, params);
|
|
182
|
+
o.splice(0, o.length);
|
|
183
|
+
o.push.apply(o, temp);
|
|
184
|
+
}
|
|
130
185
|
break;
|
|
131
186
|
}
|
|
187
|
+
else if (!o.prev || o.prev.type === STAMP || o.prev.type === STRAP) {
|
|
188
|
+
if (/^[`]/.test(o.text)) {
|
|
189
|
+
o.text = strings.encode(strings.decode(o.text));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
if (/^`/.test(o.text)) {
|
|
194
|
+
o.text = o.text.replace(/^`|`$/g, '');
|
|
195
|
+
var template = detourTemplate([o], []);
|
|
196
|
+
o.type = SCOPED;
|
|
197
|
+
o.entry = "(";
|
|
198
|
+
o.leave = ")";
|
|
199
|
+
delete o.text;
|
|
200
|
+
o.push.apply(o, template);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
132
203
|
if (!o.isprop) break;
|
|
133
204
|
case PROPERTY:
|
|
134
205
|
if (/^(get|set|async|static)$/.test(o.text) && o.next && (o.next.type === PROPERTY || o.next.isprop)) break;
|
|
135
206
|
if (o.text === 'static' && o.next && o.next.type === SCOPED && o.next.entry === '{') break;
|
|
136
|
-
if (
|
|
207
|
+
if (ie === undefined || program.strap_reg.test(o.text)) {
|
|
137
208
|
if (!/^\[/.test(o.text) && o.queue.isObject) {
|
|
138
209
|
if (o.short) {
|
|
139
210
|
insertAfter(o, { text: ':', type: STAMP }, { text: o.text, type: EXPRESS, isExpress: true });
|
|
140
211
|
o.short = false;
|
|
141
212
|
}
|
|
142
213
|
var text = strings.encode(strings.decode(o.text));
|
|
143
|
-
o.text = ie ? text : `[${text}]`;
|
|
214
|
+
o.text = ie !== undefined ? text : `[${text}]`;
|
|
215
|
+
}
|
|
216
|
+
if (!/^\[/.test(o.text) && o.queue.isClass) {
|
|
217
|
+
if (o.text === 'constructor') break;
|
|
218
|
+
var text = strings.encode(strings.decode(o.text));
|
|
219
|
+
if (o.prev) {
|
|
220
|
+
var prev = o.prev;
|
|
221
|
+
if (prev && prev.type === PROPERTY && /^(get|set|static|async)$/.test(prev.text)) {
|
|
222
|
+
prev = prev.prev;
|
|
223
|
+
}
|
|
224
|
+
if (prev && prev.type === STAMP && prev.isprop) prev = prev.prev;
|
|
225
|
+
if (prev && (prev.type !== STAMP || prev.text !== ';')) insertAfter(prev, { text: ';', type: STAMP });
|
|
226
|
+
}
|
|
227
|
+
o.text = `[${text}]`;
|
|
228
|
+
if (o.next && o.next.type === SCOPED && o.next.entry === "(") { }
|
|
229
|
+
else if (!o.next || o.next.type !== STAMP || o.next.text !== "=") {
|
|
230
|
+
insertAfter(o, { text: "=", type: STAMP }, { text: "undefined", type: VALUE, isExpress: true });
|
|
231
|
+
}
|
|
144
232
|
}
|
|
145
233
|
}
|
|
146
234
|
break;
|
|
147
235
|
}
|
|
148
|
-
o = o.next;
|
|
236
|
+
if (o) o = o.next;
|
|
149
237
|
}
|
|
150
238
|
};
|
|
151
239
|
|
|
@@ -215,7 +303,7 @@ class Program extends Array {
|
|
|
215
303
|
break;
|
|
216
304
|
}
|
|
217
305
|
case SCOPED:
|
|
218
|
-
if (!this.pressed && (lasttype === STRAP || lasttype === SCOPED && o.entry === "{") && o.type !== QUOTED) result.push(" ");
|
|
306
|
+
if (!this.pressed && (lasttype === STRAP || lasttype === STAMP || lasttype === SCOPED && o.entry === "{") && o.type !== QUOTED) result.push(" ");
|
|
219
307
|
result.push(o.entry);
|
|
220
308
|
if (o.length > 0) {
|
|
221
309
|
if (o.entry === "{" && result[0].type !== SPACE) {
|
|
@@ -229,7 +317,7 @@ class Program extends Array {
|
|
|
229
317
|
if (!o.prev || o.prev.text !== 'for') result.pop();
|
|
230
318
|
}
|
|
231
319
|
if (o.leave === "}" && (!o.next || o.next.type !== PIECE) && o[o.length - 1].type !== SPACE) {
|
|
232
|
-
result.push(" ");
|
|
320
|
+
if (!this.pressed) result.push(" ");
|
|
233
321
|
}
|
|
234
322
|
}
|
|
235
323
|
result.push(o.leave);
|
|
@@ -253,7 +341,7 @@ class Program extends Array {
|
|
|
253
341
|
) result.push(";");
|
|
254
342
|
}
|
|
255
343
|
else if (!/^(\+\+|\-\-)$/.test(o.text)) {
|
|
256
|
-
if (!this.pressed) result.push(" ");
|
|
344
|
+
if (!this.pressed && lasttype !== SPACE) result.push(" ");
|
|
257
345
|
}
|
|
258
346
|
}
|
|
259
347
|
result.push(o.text);
|
|
@@ -277,6 +365,15 @@ class Program extends Array {
|
|
|
277
365
|
get used() {
|
|
278
366
|
return this.scoped.used;
|
|
279
367
|
}
|
|
368
|
+
get yield() {
|
|
369
|
+
return this.scoped.yield;
|
|
370
|
+
}
|
|
371
|
+
get async() {
|
|
372
|
+
return this.scoped.async;
|
|
373
|
+
}
|
|
374
|
+
get await() {
|
|
375
|
+
return this.scoped.await;
|
|
376
|
+
}
|
|
280
377
|
get scoped() {
|
|
281
378
|
if (this._scoped) return this._scoped;
|
|
282
379
|
return this._scoped = createScoped(this);
|
|
@@ -290,8 +387,8 @@ class Program extends Array {
|
|
|
290
387
|
return this;
|
|
291
388
|
}
|
|
292
389
|
// 绕开低版本ie的异常属性
|
|
293
|
-
detour() {
|
|
294
|
-
detour(this.first,
|
|
390
|
+
detour(ie) {
|
|
391
|
+
detour(this.first, !!ie);
|
|
295
392
|
return this;
|
|
296
393
|
}
|
|
297
394
|
// 压缩
|
|
@@ -319,7 +416,7 @@ class Javascript {
|
|
|
319
416
|
["{", "}"],
|
|
320
417
|
]
|
|
321
418
|
stamps = "/=+;|:?<>-!~@#%^&*,".split("")
|
|
322
|
-
value_reg = /^(false|true|null|Infinity|NaN|undefined|arguments|this|eval)$/
|
|
419
|
+
value_reg = /^(false|true|null|Infinity|NaN|undefined|arguments|this|eval|super)$/
|
|
323
420
|
number_reg = number_reg;
|
|
324
421
|
transive = /^(new|var|let|const|yield|void|in|of|typeof|delete|case|return|await|export|default|instanceof|throw|extends|import|from)$/
|
|
325
422
|
straps = `if,in,do,as,of
|
|
@@ -360,19 +457,24 @@ class Javascript {
|
|
|
360
457
|
var origin = queue;
|
|
361
458
|
var queue_push = function (scope) {
|
|
362
459
|
var last = queue.lastUncomment;
|
|
363
|
-
if (
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
if (
|
|
368
|
-
scope.isprop =
|
|
460
|
+
if (queue.isObject || queue.isClass) {
|
|
461
|
+
if (~[VALUE, QUOTED].indexOf(scope.type)) {
|
|
462
|
+
scope.isprop = isProperty();
|
|
463
|
+
}
|
|
464
|
+
else if (scope.type === SCOPED && scope.entry === '[') {
|
|
465
|
+
if (queue.isObject) scope.isprop = isProperty();
|
|
466
|
+
if (queue.isClass) scope.isprop = !last || last.isprop || last.type === STAMP && last.text === ';';
|
|
369
467
|
}
|
|
370
|
-
else if (
|
|
371
|
-
scope.isprop =
|
|
468
|
+
else if (scope.type === STAMP) {
|
|
469
|
+
scope.isprop = scope.text === "*" && isProperty();
|
|
470
|
+
}
|
|
471
|
+
else if (scope.type === PROPERTY) {
|
|
472
|
+
scope.isprop = true;
|
|
372
473
|
}
|
|
373
474
|
}
|
|
374
475
|
if (scope.type !== COMMENT && scope.type !== SPACE) {
|
|
375
|
-
|
|
476
|
+
Object.defineProperty(scope, 'queue', { value: queue });
|
|
477
|
+
if (scope.type === PROPERTY || scope.isprop);
|
|
376
478
|
else if (scope.type === STRAP && /^(get|set|static)$/.test(scope.text)) {
|
|
377
479
|
scope.type = EXPRESS;
|
|
378
480
|
}
|
|
@@ -395,8 +497,11 @@ class Javascript {
|
|
|
395
497
|
else {
|
|
396
498
|
scope.prev = last;
|
|
397
499
|
}
|
|
500
|
+
scope.row = row;
|
|
501
|
+
scope.col = scope.start - colstart;
|
|
398
502
|
queue.push(scope);
|
|
399
503
|
};
|
|
504
|
+
var row = 1, colstart = -1;
|
|
400
505
|
var save = (type) => {
|
|
401
506
|
if (lasttype === STAMP && type === STAMP && !/[,;\:\?]/.test(m)) {
|
|
402
507
|
var scope = queue[queue.length - 1];
|
|
@@ -437,19 +542,26 @@ class Javascript {
|
|
|
437
542
|
}
|
|
438
543
|
else if (isProperty()) type = PROPERTY;
|
|
439
544
|
else if (m === 'from') {
|
|
440
|
-
if (!last || last.type === STRAP && last.text
|
|
545
|
+
if (!last || last.type === STRAP && !/^(im|ex)port$/.test(last.text)) {
|
|
441
546
|
type = EXPRESS;
|
|
442
547
|
break;
|
|
443
548
|
}
|
|
444
549
|
var temp = last;
|
|
445
|
-
while (temp.type === EXPRESS || temp.type === VALUE || temp.type === SCOPED) {
|
|
446
|
-
var prev =
|
|
550
|
+
while (temp.type === STAMP && temp.text === "*" || temp.type === EXPRESS || temp.type === VALUE || temp.type === SCOPED) {
|
|
551
|
+
var prev = temp.prev;
|
|
447
552
|
if (!prev) break;
|
|
448
|
-
if (prev.type
|
|
553
|
+
if (prev.type === STRAP && prev.text === "as") {
|
|
554
|
+
temp = prev.prev;
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
if (prev.type !== STAMP || prev.text !== ',' && (prev.text !== "*" || !prev.prev || !~[STRAP, STAMP].indexOf(prev.prev.type))) {
|
|
558
|
+
temp = prev;
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
449
561
|
temp = prev.prev;
|
|
450
562
|
if (!temp) break;
|
|
451
563
|
}
|
|
452
|
-
if (temp.type !== STRAP || temp.text
|
|
564
|
+
if (!temp || temp.type !== STRAP || !/^(im|ex)port$/.test(temp.text)) {
|
|
453
565
|
type = EXPRESS;
|
|
454
566
|
}
|
|
455
567
|
}
|
|
@@ -458,9 +570,9 @@ class Javascript {
|
|
|
458
570
|
type = EXPRESS;
|
|
459
571
|
break;
|
|
460
572
|
}
|
|
461
|
-
if (~[EXPRESS, VALUE].indexOf(last.type)
|
|
462
|
-
last.type
|
|
463
|
-
last
|
|
573
|
+
if (~[PROPERTY, EXPRESS, VALUE].indexOf(last.type)
|
|
574
|
+
|| last.type === STAMP && last.text === "*" && last.prev && ~[STRAP, STAMP].indexOf(last.prev.type)) {
|
|
575
|
+
Object.defineProperty(last, 'queue', { value: queue });
|
|
464
576
|
} else {
|
|
465
577
|
type = EXPRESS;
|
|
466
578
|
}
|
|
@@ -559,10 +671,14 @@ class Javascript {
|
|
|
559
671
|
var prev = queue.lastUncomment;
|
|
560
672
|
if (queue.isObject) {
|
|
561
673
|
if (!prev || prev.type === STAMP && prev.text === ",") return true;
|
|
674
|
+
if (prev.type === STAMP && prev.isprop) return true;
|
|
562
675
|
}
|
|
563
676
|
if (queue.isClass) {
|
|
564
677
|
if (!prev) return true;
|
|
565
|
-
if (prev.type === STAMP)
|
|
678
|
+
if (prev.type === STAMP) {
|
|
679
|
+
if (prev.isprop) return true;
|
|
680
|
+
return /^(\+\+|\-\-|;)$/.test(prev.text);
|
|
681
|
+
}
|
|
566
682
|
if (prev.type === EXPRESS && !/\.$/.test(prev.text)) return true;
|
|
567
683
|
if (~[SCOPED, VALUE, QUOTED, PROPERTY].indexOf(prev.type)) return true;
|
|
568
684
|
}
|
|
@@ -570,6 +686,9 @@ class Javascript {
|
|
|
570
686
|
if (prev.type === PROPERTY && /^(get|set|async|static)$/.test(prev.text)) {
|
|
571
687
|
return true;
|
|
572
688
|
}
|
|
689
|
+
if (queue.prev && queue.prev.type === STRAP && queue.prev.text === 'export') {
|
|
690
|
+
if (prev.type === STRAP && prev.text === "as") return true;
|
|
691
|
+
}
|
|
573
692
|
return false;
|
|
574
693
|
};
|
|
575
694
|
|
|
@@ -671,7 +790,9 @@ class Javascript {
|
|
|
671
790
|
}
|
|
672
791
|
if (this.space_reg.test(m)) {
|
|
673
792
|
if (/[\r\n\u2028\u2029]/.test(m)) {
|
|
674
|
-
|
|
793
|
+
colstart = match.index + 1;
|
|
794
|
+
m = m.replace(/^[^\r\n\u2028\u2029]+/, '').replace(/\r\n|\r|\n|\u2028|\u2029/g, "\r\n");
|
|
795
|
+
row += m.replace(/[^\r\n]+/, '').length >> 1;
|
|
675
796
|
save(SPACE);
|
|
676
797
|
}
|
|
677
798
|
lasttype = SPACE;
|
|
@@ -689,7 +810,43 @@ class Javascript {
|
|
|
689
810
|
queue.inExpress = false;
|
|
690
811
|
}
|
|
691
812
|
}
|
|
692
|
-
|
|
813
|
+
if (m === 'yield') {
|
|
814
|
+
var temp = queue;
|
|
815
|
+
var type = STRAP;
|
|
816
|
+
var last = queue.lastUncomment;
|
|
817
|
+
if (queue.entry === '[' || queue.isClass || queue.isObject || last && (last.type === STAMP && (
|
|
818
|
+
queue[queue.length - 1].type !== SPACE && /^(\+\+|\-\-)$/.test(last.text)
|
|
819
|
+
|| !/^(>>>?=|<<=|[^><!=]=|[,;])/.test(last.text)
|
|
820
|
+
) || last.type === STRAP)) {
|
|
821
|
+
type = EXPRESS;
|
|
822
|
+
}
|
|
823
|
+
if (type === STRAP) while (temp) {
|
|
824
|
+
if (temp.entry != "{" || !temp.prev || temp.prev.type !== SCOPED || temp.prev.entry !== '(') {
|
|
825
|
+
temp = temp.queue;
|
|
826
|
+
continue;
|
|
827
|
+
}
|
|
828
|
+
var pp = temp.prev.prev;
|
|
829
|
+
var isprop = pp.isprop;
|
|
830
|
+
if (pp && pp.type === EXPRESS || pp.isprop) pp = pp.prev;
|
|
831
|
+
if (!pp || pp.type === STRAP && !/^function$/.test(pp.text)) {
|
|
832
|
+
temp = temp.queue;
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
if (pp.type === STAMP && pp.text === "*" && (pp.isprop || pp.prev && pp.prev.type === STRAP && pp.prev.text === "function")) {
|
|
836
|
+
type = STRAP;
|
|
837
|
+
break;
|
|
838
|
+
}
|
|
839
|
+
if (isprop || pp.type === STRAP && pp.text === "function") {
|
|
840
|
+
type = EXPRESS;
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
843
|
+
temp = temp.queue;
|
|
844
|
+
}
|
|
845
|
+
save(type);
|
|
846
|
+
}
|
|
847
|
+
else {
|
|
848
|
+
save(STRAP);
|
|
849
|
+
}
|
|
693
850
|
continue;
|
|
694
851
|
}
|
|
695
852
|
if (this.value_reg.test(m) || this.number_reg.test(m)) {
|
|
@@ -727,7 +884,8 @@ class Javascript {
|
|
|
727
884
|
else scope.isObject = !/^(;|\+\+|\-\-|=>)$/.test(last.text);
|
|
728
885
|
}
|
|
729
886
|
else if (last.type === STRAP) {
|
|
730
|
-
if (queue[queue.length - 1].type === SPACE && last.text
|
|
887
|
+
if (queue[queue.length - 1].type === SPACE && /^(return|yield)$/.test(last.text));
|
|
888
|
+
else if (/^export$/.test(last.text));
|
|
731
889
|
else scope.isObject = queue.inExpress;
|
|
732
890
|
}
|
|
733
891
|
}
|
|
@@ -58,7 +58,7 @@ var prototype = {
|
|
|
58
58
|
|
|
59
59
|
function createElement(name) {
|
|
60
60
|
var node = isNode(name) ? name.cloneNode() : isFunction(name) ? name() : document.createElement(name);
|
|
61
|
-
if (name.className) node
|
|
61
|
+
if (name.className) addClass(node, name.className);
|
|
62
62
|
appendChild(node, slice.call(arguments, 1));
|
|
63
63
|
extend(node, prototype);
|
|
64
64
|
return node;
|