efront 4.3.14 → 4.4.0

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.
@@ -0,0 +1,13 @@
1
+ module.exports = function (p) {
2
+ var s = [];
3
+ while (p) {
4
+ var reg = /[\$\/\\]/g;
5
+ reg.lastIndex = 1;
6
+ var m = reg.exec(p);
7
+ var i = m ? m.index : p.length;
8
+ s.push(p.slice(0, i));
9
+ p = p.slice(i + 1);
10
+ }
11
+ if (m) s.push('');
12
+ return s;
13
+ }
@@ -153,7 +153,7 @@ class BigNumber {
153
153
  v = +v;
154
154
  }
155
155
  else v = vmap[v];
156
- if (Number.isNaN(v) || v >= system_scale || v !== +v) throw new Error("数据错误!");
156
+ if (v !== v || v >= system_scale || v !== +v) throw new Error("数据错误!");
157
157
 
158
158
  if (dotOccurs) {
159
159
  num = BigNumber.add(num, BigNumber.div(v, scale, BigNumber.DECIMAL_DIGIT))
@@ -1,5 +1,5 @@
1
1
  function isEmpty(value) {
2
- if (value === '' || value === null || value === undefined || Number.isNaN(value)) return true;
2
+ if (value === '' || value === null || value === undefined || value !== value) return true;
3
3
  if (value instanceof Array && value.length === 0 || value.constructor === Object || !value.constructor) {
4
4
  for (var k in value) return false;
5
5
  return true;
@@ -1,5 +1,5 @@
1
1
  function isHandled(value) {
2
- if (value === '' || value === null || value === undefined || Number.isNaN(value)) return false;
2
+ if (value === '' || value === null || value === undefined || value !== value) return false;
3
3
  return true;
4
4
  }
5
5
  module.exports = isHandled;
@@ -1,4 +1,3 @@
1
- var isNaN = Number.isNaN;
2
1
  function isSame(o1, o2) {
3
- return o1 === o2 || isNaN(o1) && isNaN(o2);
2
+ return o1 === o2 || o1 !== o1 && o2 !== o2;
4
3
  }
@@ -1,7 +1,8 @@
1
1
  var iso8859 = require("./iso8859");
2
2
  var Program = require("./Program");
3
+ var Javascript = require("./Javascript");
3
4
  var strings = require("../basic/strings");
4
-
5
+ var common = require("./common");
5
6
  const {
6
7
  /* 1 */COMMENT,
7
8
  /* 2 */SPACE,
@@ -14,22 +15,58 @@ const {
14
15
  /* 256 */SCOPED,
15
16
  /* 512 */LABEL,
16
17
  /*1024 */PROPERTY,
18
+ /*2048 */ELEMENT,
17
19
  createScoped,
18
20
  } = require("./common");
19
21
  var ignore = { test() { return false } };
22
+ var property = new Program;
23
+ property.stamps = "=".split('');
24
+ var parseProperty = function (a) {
25
+ property.lastIndex = 0;
26
+ var s = property.exec(a);
27
+ return s;
28
+ }
29
+
30
+ var fixElement = function (o) {
31
+ if (!o.attributes) return;
32
+ var attributes = [];
33
+ var needValue = false;
34
+ var push = function (p) {
35
+ attributes.push(p);
36
+ if (p.type === STAMP) {
37
+ needValue = true;
38
+ return;
39
+ }
40
+ if (!needValue && p.type === EXPRESS) {
41
+ p.type = PROPERTY;
42
+ }
43
+ needValue = false;
44
+ }
45
+ o.attributes.forEach(a => {
46
+ if (a.type === PIECE) {
47
+ for (var p of parseProperty(a.text)) {
48
+ push(p);
49
+ }
50
+ }
51
+ else {
52
+ push(a);
53
+ }
54
+ });
55
+ o.attributes = attributes;
56
+ }
20
57
 
21
- class Html extends Program {
22
- straps = [];
23
- value_reg = ignore;
24
- strapexp_reg = ignore;
25
- forceend_reg = ignore;
26
- classstrap_reg = ignore;
27
- scopes = [];
28
- intag = false;
29
- stamps = "/<>=".split("");
30
- tags = [];
31
- quotes = [["'", "'", /\\[\s\S]/], ["\"", "\"", /\\[\s\S]/]]
58
+ class Html extends Javascript {
59
+ // value_reg = ignore;
60
+ // strapexp_reg = ignore;
61
+ // forceend_reg = ignore;
62
+ // classstrap_reg = ignore;
63
+ // // scopes = [];
64
+ // inTag = false;
65
+ scriptTags = [];
66
+ ignoreTags = ["SCRIPT", "STYLE"];
32
67
  }
68
+ var property = new Program;
69
+ property.stamps = "=".split('');
33
70
  var p = new Program;
34
71
  var replaceISO8859 = function (data) {
35
72
  return String(data).replace(/<\!--([\s\S]*)--\>$/g, '$1').replace(/&\w+;/g, a => iso8859[a] || a).replace(/&#(\d+);/g, (_, a) => String.fromCodePoint(a))
@@ -42,39 +79,7 @@ var parseExpress = function (data, mayberepeat) {
42
79
  p.lastIndex = 0;
43
80
  return p.exec(data);
44
81
  };
45
- var keep_reg = /^(SCRIPT|STYLE)$/i;
46
- Html.prototype.setType = function (o) {
47
- var q = o.queue;
48
- var p = o.prev;
49
- if (!q.intag) {
50
- if (p && p.type === STAMP) {
51
- if (/^</.test(p.text)) {
52
- if (o.type === EXPRESS) {
53
- if (q.keep && o.text !== q.keep) {
54
- return;
55
- }
56
- q.intag = true;
57
- o.type = LABEL;
58
- if (/^<\//.test(p.text)) o.isclose = true, q.keep = null;
59
- else if (!q.keep) o.isopen = true, q.keep = keep_reg.test(o.text) ? o.text : null;
60
- }
61
- return;
62
- }
63
- }
64
- if (o.type !== STAMP && o.type !== COMMENT) o.type = PIECE;
65
- }
66
- else {
67
- if (o.type === STAMP && /^\/?>/.test(o.text)) {
68
- q.intag = false;
69
- return;
70
- }
71
- if (p.type == STAMP && p.text === '=');
72
- else if (o.type === EXPRESS) {
73
- o.type = PROPERTY;
74
- o.isprop = true;
75
- }
76
- }
77
- };
82
+
78
83
  var toCamelCase = function (a) {
79
84
  return a.replace(/\-([\s\S])/g, (_, a) => a.toUpperCase());
80
85
  }
@@ -84,109 +89,79 @@ class Node { }
84
89
  Html.prototype.createScoped = function (code) {
85
90
  var used = Object.create(null);
86
91
  var vars = Object.create(null);
87
- var dom = new Node;
88
- var nodePath = [dom];
89
- var childNodes = [], children = [];
90
- dom.childNodes = childNodes;
91
- dom.children = children;
92
92
  var scriptNodes = [], styleNodes = [], tempNodes = [];
93
93
  var inScript = false;
94
- for (var cx = 0, dx = code.length, c = code[0]; cx < dx; c = code[++cx])switch (c.type) {
95
- case LABEL:
96
- if (!/^(script|style|template)$/i.test(c.text)) {
97
- var v = toCamelCase(c.text)
98
- if (!used[v]) used[v] = [];
99
- used[v].push(c);
100
- }
101
- if (!c.isclose) {
102
- var node = new Node;
103
- node.tagName = c.text.toUpperCase();
104
- if (node.tagName === 'SCRIPT' || node.tagName === 'STYLE') inScript = true;
105
- nodePath.push(node);
106
- node.childNodes = [];
107
- node.children = [];
108
- var outerStart = cx;
109
- while (code[outerStart] !== c.prev) outerStart--;
110
- node.outerStart = outerStart;
111
- childNodes.push(node);
112
- children.push(node);
113
- children = node.children;
114
- childNodes = node.childNodes;
115
- }
116
- else {
117
- var tagName = c.text.toUpperCase();
118
- for (var cy = nodePath.length - 1; cy >= 0; cy--) {
119
- if (nodePath[cy].tagName === tagName) break;
94
+ var run = function (c) {
95
+ switch (c.type) {
96
+ case ELEMENT:
97
+ var v = toCamelCase(c.tag);
98
+ c.tagName = c.tag.toUpperCase();
99
+ if (!/^(script|style|template)$/i.test(c.tagName)) {
100
+ fixElement(c);
101
+ if (c.attributes) c.attributes.forEach(run);
102
+ if (!used[v]) used[v] = [];
103
+ used[v].push(c);
104
+ c.forEach(run);
120
105
  }
121
- var node = nodePath[cy];
122
- var outerEnd = cx;
123
- while (code[outerEnd++] !== c.next);
124
- node.outerEnd = outerEnd;
125
- var innerEnd = cx;
126
- while (code[innerEnd] !== c.prev) innerEnd--;
127
- node.innerEnd = innerEnd;
128
- var children1 = node.children;
129
- var childNodes1 = node.childNodes;
130
- for (var n of nodePath.splice(cy + 1, nodePath.length)) {
131
- n.noclose = true;
132
- for (var c of n.childNodes) childNodes1.push(c);
133
- for (var c of n.children) children1.push(c);
106
+ else {
107
+ if (c.tagName === 'SCRIPT') {
108
+ scriptNodes.push(c);
109
+ tempNodes.push(c);
110
+ c.isScript = true;
111
+ }
112
+ else if (c.tagName === 'STYLE') {
113
+ styleNodes.push(c);
114
+ tempNodes.push(c);
115
+ }
134
116
  }
135
- if (childNodes1.length) node.innerStart = childNodes1[0].outerStart;
136
- else node.innerStart = innerEnd;
137
- if (node.tagName === "SCRIPT") scriptNodes.push(node), tempNodes.push(node), node.isScript = true, inScript = false;
138
- else if (node.tagName === "STYLE") styleNodes.push(node), tempNodes.push(node), node.isStyle = true, inScript = false;
139
- nodePath.pop();
140
- node = nodePath[nodePath.length - 1];
141
- childNodes = node.childNodes;
142
- children = node.children;
143
- }
144
- continue;
145
- case PROPERTY:
146
- if (c.next && c.next.type === STAMP && c.next.text === '=') {
147
- if (/^(element|render|)id$/i.test(c.text)) {
148
- var nn = c.next.next;
149
- if (!nn || nn.length > 0) continue;
150
- if (nn.type === EXPRESS || nn.type === QUOTED) {
151
- vars[strings.decode(nn.text)] = true;
117
+
118
+
119
+ break;
120
+ case PROPERTY:
121
+ if (c.next && c.next.type === STAMP && c.next.text === '=') {
122
+ if (/^(element|render|)id$/i.test(c.text)) {
123
+ var nn = c.next.next;
124
+ if (!nn || nn.length > 0) return;
125
+ if (nn.type === EXPRESS || nn.type === QUOTED) {
126
+ vars[strings.decode(nn.text)] = true;
127
+ }
152
128
  }
153
129
  }
154
- }
155
- else {
156
- if (/^\#/.test(c.text)) {
157
- var id = c.text.slice(1);
158
- vars[toCamelCase(id)] = true;
130
+ else {
131
+ if (/^\#/.test(c.text)) {
132
+ var id = c.text.slice(1);
133
+ vars[toCamelCase(id)] = true;
134
+ }
159
135
  }
160
- }
161
- break;
162
- case QUOTED:
163
- var t = strings.decode(c.text);
164
- var p = t.prev;
165
- var pp = p && p.prev;
166
- var mayberepeat = p && pp && p.type === STAMP && p.text === "=" && /\-(src|repeat|for|each|foreach)$/i.test(pp.text)
167
- t = parseExpress(t, mayberepeat);
168
- var envs = createScoped(t).envs;
169
- for (var k in envs) {
170
- if (!used[k]) used[k] = [];
171
- }
172
- break;
173
- case EXPRESS:
174
- if (inScript) continue;
175
- var t = c.text;
176
- t = parseExpress(t);
177
- var envs = createScoped(t).envs;
178
- for (var k in envs) {
179
- if (!used[k]) used[k] = [];
180
- }
181
- break;
182
- case PIECE:
183
- case COMMENT:
184
- var n = new Node;
185
- n.text = c.text;
186
- n.outerStart = cx;
187
- childNodes.push(n);
188
- break;
189
- }
136
+ break;
137
+ case QUOTED:
138
+ if (c.length) {
139
+ c.forEach(run);
140
+ break;
141
+ }
142
+ if (!c.text) break;
143
+ var t = strings.decode(c.text);
144
+ var p = t.prev;
145
+ var pp = p && p.prev;
146
+ var mayberepeat = p && pp && p.type === STAMP && p.text === "=" && /\-(src|repeat|for|each|foreach)$/i.test(pp.text)
147
+ t = parseExpress(t, mayberepeat);
148
+ var envs = createScoped(t).envs;
149
+ for (var k in envs) {
150
+ if (!used[k]) used[k] = [];
151
+ }
152
+ break;
153
+ case EXPRESS:
154
+ if (inScript) return;
155
+ var t = c.text;
156
+ t = parseExpress(t);
157
+ var envs = createScoped(t).envs;
158
+ for (var k in envs) {
159
+ if (!used[k]) used[k] = [];
160
+ }
161
+ break;
162
+ }
163
+ };
164
+ code.forEach(run);
190
165
  var envs = Object.create(null);
191
166
  for (var k in used) {
192
167
  if (!vars[k]) {
@@ -196,71 +171,38 @@ Html.prototype.createScoped = function (code) {
196
171
  var scripts = [];
197
172
  var styles = [];
198
173
  var scoped = [];
199
- scoped.richNodes = tempNodes.slice();
174
+ for (var c of scriptNodes) scripts.push(c.innerText = replaceISO8859(this.createString(c)));
175
+ for (var c of styleNodes) styles.push(c.innerText = replaceISO8859(this.createString(c)));
176
+ scoped.richNodes = tempNodes;
200
177
  code = code.slice();
201
- for (var c of scriptNodes) scripts.push(c.innerText = replaceISO8859(this.createString(code.slice(c.innerStart, c.innerEnd))));
202
- for (var c of styleNodes) styles.push(c.innerText = replaceISO8859(this.createString(code.slice(c.innerStart, c.innerEnd))));
203
- while (tempNodes.length) {
204
- var c = tempNodes.pop();
205
- code.splice(c.outerStart, c.outerEnd - c.outerStart);
206
- }
207
178
  scoped.scripts = scripts;
208
179
  scoped.styles = styles;
209
- var rootNodes = dom.childNodes.filter(a => !/^(script|style)$/i.test(a.tagName));
180
+ var rootNodes = code.filter(a => !/^(script|style)$/i.test(a.tagName) && !(a.type & (SPACE | COMMENT)));
210
181
  if (rootNodes.length === 1) {
211
- scoped.outerHTML = this.createString(code);
182
+ scoped.outerHTML = this.createString(rootNodes);
212
183
  var root = rootNodes[0];
213
184
  scoped.tagName = root.tagName;
214
- while (code[code.length - 1].type === COMMENT || code[code.length - 1].type === SPACE) code.pop();
215
- while (code[0].type === COMMENT || code[0].type === SPACE) code.shift();
216
- var attrarea = code.splice(0, root.innerStart - root.outerStart);
217
- var attrs = [];
218
- for (var a of attrarea) {
185
+ var attrs = rootNodes[0].attributes;
186
+ if (attrs) for (var a of attrs) {
219
187
  if (a.type === PROPERTY) {
220
- var at = { name: a.text };
221
- attrs.push(at);
188
+ a.name = a.text;
222
189
  var n = a.next;
223
190
  if (!n) continue;
224
191
  if (n.type !== STAMP || n.text !== '=') continue;
225
192
  var nn = n.next;
226
- if (!nn) return;
227
- at.value = nn.text;
193
+ if (!nn) continue;
194
+ a.value = nn.text;
228
195
  }
229
196
  }
230
- code.splice(root.innerEnd - root.outerEnd, code.length);
231
- scoped.innerHTML = this.createString(code);
232
- scoped.attributes = attrs;
197
+ scoped.innerHTML = this.createString(rootNodes[0]);
233
198
  }
234
199
  else {
235
- scoped.innerHTML = this.createString(code);
200
+ scoped.innerHTML = this.createString(rootNodes);
236
201
  }
237
202
  scoped.envs = envs;
238
203
  scoped.vars = vars;
239
204
  scoped.used = used;
240
205
  return scoped;
241
206
  };
242
- Html.prototype.createString = function (code) {
243
- var dist = [];
244
- var keepspace = code.keepspace;
245
- var p = null;
246
- for (var c of code) {
247
- switch (c.type) {
248
- case PIECE:
249
- if (p && p.type & (PIECE | EXPRESS)) dist.push(" ");
250
- dist.push(c.text);
251
- break;
252
- case SPACE:
253
- if (keepspace) dist.push(c.text);
254
- break;
255
- case PROPERTY:
256
- dist.push(" ");
257
- dist.push(c.text);
258
- break;
259
- default:
260
- dist.push(c.text);
261
- }
262
- p = c;
263
- }
264
- return dist.join('');
265
- }
207
+ Html.prototype.createString = common.createString;
266
208
  module.exports = Html;
@@ -1,5 +1,14 @@
1
1
  var Html = require("./Html");
2
- var h = new Html;
3
- var b = h.exec("<h><a #c>b</a><c b=x>d</c><d /><e>2px</h>");
4
- console.log(h.createScoped(b));
5
- console.log(h.createString(b));
2
+ var test = function (source, pick, value) {
3
+ var h = new Html;
4
+ var b = h.exec(source);
5
+ assert(h.createString(b), source);
6
+ if (pick) {
7
+ assert(seek(b, pick), value);
8
+ }
9
+ };
10
+ test("<h><a #c>b</a><c b=x>d</c><d/><e>2px</e></h>");
11
+ test("<a>Let's Encrypt</a>");
12
+ test("<style>{a-b:2}</style>");
13
+ assert(scanner2("<a>Let's Encrypt</a>", Html).length, 1);
14
+ test('<a href="${i18n``}">Let\'s Encrypt</a>');
@@ -15,6 +15,7 @@ const {
15
15
  /* 256 */SCOPED,
16
16
  /* 512 */LABEL,
17
17
  /*1024 */PROPERTY,
18
+ /*2048 */ELEMENT,
18
19
  createString,
19
20
  getDeclared,
20
21
  createScoped,
@@ -333,7 +334,7 @@ Javascript.prototype.detectLabel = function (o) {
333
334
  Javascript.prototype.setType = function (o) {
334
335
  if (this.detectLabel(o)) return false;
335
336
  var last = o.prev;
336
- if (o.type === EXPRESS && /^\.[^\.]/.test(o.text) && last && last.type === STAMP && last.text === "?") {
337
+ if (o.type === EXPRESS && /^\.[^\.]|^\.$/.test(o.text) && last && last.type === STAMP && last.text === "?") {
337
338
  last = o.prev = snapExpressHead(last.prev);
338
339
  last.type = EXPRESS;
339
340
  return false;