efront 4.4.13 → 4.4.14

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.
@@ -1448,7 +1448,7 @@
1448
1448
  en: "Other environmental variables are as follows:"
1449
1449
 
1450
1450
  - zh-CN: 不支持该命令<red2> $1 </red2>
1451
- en: The command is not supported<red2>$1</red2>
1451
+ en: The command <red2>$1</red2> is not supported
1452
1452
 
1453
1453
  - zh-CN: 如下命令与您输入的命令相似:
1454
1454
  en: "The following command is similar to the one you entered:"
@@ -1,10 +1,12 @@
1
1
  国际化工具的时的语法如下:
2
2
  ```javascript
3
- i18n`中文内容${参数}`//参数中不能有执行体,否则可能被执行多次造成异常
3
+ i18n`中文内容${参数}`
4
4
  ```
5
5
  在项目目录存在指定的国际化文件时,efront会自动转换为类似如下版本,具体语言语种及内容以国际化文件为主:
6
6
 
7
7
  ```javascript
8
- i18n(`中文内容${参数}`,`English Content${参数}`)
8
+ i18n(`中文内容${参数}`,`English Content${参数}`);
9
+ // 如果参数中有破坏型的执行体,将转换为如下形式来保证参数中的代码只执行一次
10
+ i18n(()=>`中文内容${参数}`,()=>`English Content${参数}`)()
9
11
  ```
10
12
  国际化文件可以在文档国际化工具中扫描生成。
@@ -1374,6 +1374,28 @@ var canbeTemp = function (body, strip = false) {
1374
1374
  if (!o) return false;
1375
1375
  return o.type === EXPRESS && (strip || !/[\.\[]/.test(o.text)) || o.type === VALUE || o.type === QUOTED && !o.length;
1376
1376
  };
1377
+ var canbeDuplicate = function (body) {
1378
+ for (var b of body) {
1379
+ switch (b.type) {
1380
+ case EXPRESS:
1381
+ if (/[\.\[]/.test(b.text)) return false;
1382
+ break;
1383
+ case SCOPED:
1384
+ if (b.isObject || b.isClass || b.entry === '[') return false;
1385
+ if (!isEval(b)) return false;
1386
+ if (!canbeTemp(b)) return false;
1387
+ break;
1388
+ case QUOTED:
1389
+ if (b.length && !canbeTemp(b)) return false;
1390
+ break;
1391
+ case STAMP:
1392
+ if (/^(\+\+|\-\-)$|^([^\=\>\<]+|>>>?|<<)?\=$/.test(b.text)) return false;
1393
+ break;
1394
+ case ELEMENT: return false;
1395
+ }
1396
+ }
1397
+ return true;
1398
+ };
1377
1399
  var pickArgument = function (o) {
1378
1400
  var res = [];
1379
1401
  var t = o && o.prev, p = o;
@@ -1457,6 +1479,7 @@ module.exports = {
1457
1479
  setqueue,
1458
1480
  replace,
1459
1481
  canbeTemp,
1482
+ canbeDuplicate,
1460
1483
  skipFunction,
1461
1484
  isHalfSentence,
1462
1485
  splice,
@@ -1,10 +1,16 @@
1
1
  var scanner2 = require("./scanner2");
2
- var { SCOPED, QUOTED, SCOPED, PROPERTY, STAMP, PIECE, setqueue, splice, relink, number_reg, replace, createString } = require("./common");
2
+ var { SCOPED, QUOTED, SCOPED, PROPERTY, STAMP, PIECE, setqueue, splice, relink, number_reg, replace, canbeDuplicate, createString } = require("./common");
3
3
  var strings = require("../basic/strings");
4
4
  var program = null;
5
5
  var patchTranslate = function (c) {
6
6
  if (c.length) {
7
- c.translate = c.map((o, i) => o.type === PIECE ? strings.decode(`\`${o.text}\``) : `$${i + 1 >> 1}`).join('').replace(/\r\n|\r|\n/g, '\r\n');
7
+ var canbeDup = true;
8
+ c.translate = c.map((o, i) => {
9
+ if (o.type === PIECE) return strings.decode(`\`${o.text}\``);
10
+ if (canbeDup && !canbeDuplicate(o)) canbeDup = false;
11
+ return `$${i + 1 >> 1}`;
12
+ }).join('').replace(/\r\n|\r|\n/g, '\r\n');
13
+ c.nodup = !canbeDup;
8
14
  }
9
15
  else {
10
16
  if (/^['"`]/.test(c.text) && c.text.length > 2) {
@@ -74,7 +80,7 @@ var ctn = function (tt, t) {
74
80
  if (a in t) return `\${${a}}`;
75
81
  return _;
76
82
  }));
77
- tn[tn.length - 1].forEach(n => {
83
+ (tn[0].type === SCOPED ? tn[0] : tn[1]).forEach(n => {
78
84
  if (n.type !== QUOTED || !n.length) return;
79
85
  n.forEach((a, i) => {
80
86
  if (a.type !== SCOPED) return;
@@ -91,13 +97,25 @@ function translate([imap, supports], code) {
91
97
  if (a.start > b.start && a.end < b.end) return -1;
92
98
  return 0;
93
99
  });
94
- var getm = function (tt, warn) {
95
- tt = tt.trim();
96
- if (!imap[tt]) {
100
+ var getm = function (tt, nodup, warn) {
101
+ var mq = /^(\s*)([\s\S]*?)(\s*)$/.exec(tt);
102
+ var mq = [mq[1] || '', mq[2], mq[3] || ''];
103
+ var tt = mq[1];
104
+ var wrap = m => {
105
+ mq[1] = m || tt;
106
+ return strings.encode(mq.join(''), '`');
107
+ };
108
+
109
+ var imp = imap[tt];
110
+ if (!imp) {
97
111
  if (warn !== false) console.warn(`<yellow>${i18n`国际化翻译缺失:`}</yellow>${tt}`);
98
- imap[tt] = supports.map(_ => tt);
112
+ imp = imap[tt] = supports.map(_ => tt);
99
113
  }
100
- return imap[tt].map(m => strings.encode(m || tt, '`'));
114
+ if (nodup && imp.length <= 1) nodup = false;
115
+ var mp = nodup ? m => "()=>" + wrap(m) : m => wrap(m);
116
+ var m = `(${imp.map(mp)})`;
117
+ if (nodup) m += '()';
118
+ return m;
101
119
  };
102
120
  var used = code.used;
103
121
  for (var t of texts) {
@@ -109,8 +127,8 @@ function translate([imap, supports], code) {
109
127
  p.leave = ")";
110
128
  }
111
129
  var tt = t.translate;
112
- var tn = ctn(`(${getm(tt)})`, t);
113
- replace(t, tn[0]);
130
+ var tn = ctn(getm(tt, t.nodup), t);
131
+ replace(t, ...tn);
114
132
  }
115
133
  else if (t.transtype === 字段名) {
116
134
  var i = t.queue.indexOf(t.prev);
@@ -138,7 +156,7 @@ function translate([imap, supports], code) {
138
156
  if (a in t) v = t[a];
139
157
  else v = scanner2(JSON.stringify(v));
140
158
  }
141
- else if (k === 'name') v = ctn(`i18n(${getm(v, t.warn)})`, t);
159
+ else if (k === 'name') v = ctn('i18n' + getm(v, t.nodup, t.warn), t);
142
160
  else v = scanner2(JSON.stringify(v));
143
161
  o.push({ type: PROPERTY, isprop: true, text: JSON.stringify(k) }, { type: STAMP, text: ':' }, ...v, { type: STAMP, text: ',' });
144
162
  })
@@ -0,0 +1,8 @@
1
+ var test = function (src, text, expact) {
2
+ var code = scanner2(text);
3
+ translate([src, Object.keys(src)], code);
4
+ assert(code.toString(), expact);
5
+ };
6
+ test({ "a$1b": ["a$1b", "c$1d"] }, 'i18n`a${a}b`', 'i18n(`a${a}b`, `c${a}d`)')
7
+ test({ "a$1b": ["a$1b", "c$1d"] }, 'i18n`a${a++}b`', 'i18n(() => `a${a++}b`, () => `c${a++}d`)()')
8
+ test({ "a$1b": ["c$1d"] }, 'i18n`a${a++}b`', 'i18n(`c${a++}d`)')
@@ -74,7 +74,7 @@ function filterTime(time, format) {
74
74
  case 0:
75
75
  return `${month}${format || '月'}${date}${format ? '' : '日'} `;
76
76
  case 1:
77
- if (month1 % 12 - month % 12 === 1) {
77
+ if (month1 < month) {
78
78
  return `${month}${format || '月'}${date}${format ? '' : '日'} `;
79
79
  }
80
80
  return "去年" + month + "月";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "4.4.13",
3
+ "version": "4.4.14",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {