efront 3.8.4 → 3.8.5

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.
@@ -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(/[^\/\$]+$/, "");
@@ -112,7 +112,8 @@ var skipAssignment = function (o) {
112
112
  };
113
113
  var createScoped = function (parsed) {
114
114
  var used = Object.create(null); var vars = Object.create(null), lets = vars;
115
- var scoped = [];
115
+ var scoped = [], funcbody = scoped;
116
+ scoped.isfunc = true;
116
117
  var run = function (o, id) {
117
118
  loop: while (o) {
118
119
  var isCatch = false;
@@ -120,6 +121,7 @@ var createScoped = function (parsed) {
120
121
  var isScope = false;
121
122
  var isArrow = false;
122
123
  var isDeclare = false;
124
+ var isYield = false;
123
125
  switch (o.type) {
124
126
  case QUOTED:
125
127
  if (o.length) {
@@ -145,6 +147,7 @@ var createScoped = function (parsed) {
145
147
  if (/^\.\.\./.test(u)) u = u.slice(3);
146
148
  var u = u.replace(/^([^\.\[]*)[\s\S]*$/, '$1');
147
149
  if (!u) break;
150
+ if (u === 'yield') funcbody.yield = false;
148
151
  if (o.next && o.next.type === STAMP && o.next.text === "=>") {
149
152
  isScope = true;
150
153
  isArrow = true;
@@ -164,6 +167,24 @@ var createScoped = function (parsed) {
164
167
  case STRAP:
165
168
  var s = o.text;
166
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;
167
188
  case "as":
168
189
  case "from":
169
190
  break;
@@ -186,7 +207,10 @@ var createScoped = function (parsed) {
186
207
  continue loop;
187
208
  case "function":
188
209
  isFunction = true;
189
- if (o.next.type === STAMP) o = o.next;
210
+ if (o.next.type === STAMP) {
211
+ isYield = true;
212
+ o = o.next;
213
+ }
190
214
  case "catch":
191
215
  isCatch = true;
192
216
  case "class":
@@ -209,11 +233,18 @@ var createScoped = function (parsed) {
209
233
  break;
210
234
  case SCOPED:
211
235
  if (o.entry === "(") {
212
- if (o.next && o.next.type === STAMP && o.next.text === "=>"
213
- || o.prev && (o.prev.type === PROPERTY || o.prev.isprop)) {
236
+ if (o.next && o.next.type === STAMP && o.next.text === "=>") {
214
237
  isArrow = true;
215
238
  isScope = true;
216
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
+ }
217
248
  else {
218
249
  run(o.first);
219
250
  }
@@ -241,8 +272,13 @@ var createScoped = function (parsed) {
241
272
  scoped.used = used;
242
273
  scoped.vars = vars;
243
274
  lets = vars;
244
- if (isFunction) vars.this = true, vars.arguments = true;
275
+ if (isFunction) {
276
+ vars.this = true, vars.arguments = true;
277
+ scoped.yield = isYield;
278
+ }
279
+ scoped.isfunc = true;
245
280
  isFunction = true;
281
+ funcbody = scoped;
246
282
  } else {
247
283
  vars = _vars;
248
284
  scoped.lets = lets;
@@ -335,6 +371,10 @@ var createScoped = function (parsed) {
335
371
  delete vars.this;
336
372
  delete vars.arguments;
337
373
  }
374
+ if (_scoped.isfunc && !funcbody.yield) {
375
+ if (used.yield) _scoped.yield = false;
376
+ funcbody = _scoped;
377
+ }
338
378
  used = _used;
339
379
  lets = _lets;
340
380
  vars = _vars;
@@ -354,6 +394,12 @@ var createScoped = function (parsed) {
354
394
  if (!/^(true|false|null|this|arguments)$/.test(u)) envs[u] = true;
355
395
  }
356
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
+ }
357
403
  scoped.envs = envs;
358
404
  return scoped;
359
405
  };
@@ -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
+ }
@@ -365,6 +365,15 @@ class Program extends Array {
365
365
  get used() {
366
366
  return this.scoped.used;
367
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
+ }
368
377
  get scoped() {
369
378
  if (this._scoped) return this._scoped;
370
379
  return this._scoped = createScoped(this);
@@ -804,7 +813,14 @@ class Javascript {
804
813
  if (m === 'yield') {
805
814
  var temp = queue;
806
815
  var type = STRAP;
807
- while (temp) {
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) {
808
824
  if (temp.entry != "{" || !temp.prev || temp.prev.type !== SCOPED || temp.prev.entry !== '(') {
809
825
  temp = temp.queue;
810
826
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.8.4",
3
+ "version": "3.8.5",
4
4
  "description": "一个开发工具,开放源代码,自带组件库和编译环境,可以用来开发web组件,web应用或nodejs模块,或做为已有代码的加密工具,也可以做为静态页面服务器或跨域中转服务器使用",
5
5
  "main": "public/efront.js",
6
6
  "directories": {