efront 4.10.2 → 4.11.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/getName.js +4 -4
- package/coms/basic/i18n.md +1 -1
- package/coms/compile/Html.js +2 -1
- package/coms/compile/Html_test.js +6 -3
- package/coms/compile/Javascript.js +50 -25
- package/coms/compile/Javascript_test.js +11 -1
- package/coms/compile/Program.js +15 -6
- package/coms/compile/common.js +6 -2
- package/coms/compile/downLevel.js +2 -4
- package/coms/compile/downLevel_test.js +5 -4
- package/coms/compile/rescan.js +4 -2
- package/coms/compile/unstruct_test.js +1 -1
- package/coms/compile//347/264/240/351/246/250.js +14 -10
- package/coms/compile//347/264/240/351/246/250_test.js +7 -3
- package/coms/docs/codecolor.js +9 -8
- package/coms/docs/codetext.xht +99 -14
- package/coms/zimoli/getGenerator.js +32 -12
- package/coms/zimoli/render.js +2 -1
- package/package.json +1 -1
- package/public/efront.js +1 -1
package/coms/basic/getName.js
CHANGED
|
@@ -9,11 +9,11 @@ function getName(o) {
|
|
|
9
9
|
if (!isEmpty(name)) return String(name);
|
|
10
10
|
}
|
|
11
11
|
for (var k of keys) {
|
|
12
|
-
|
|
13
|
-
if (!isEmpty(o
|
|
14
|
-
if (isString(
|
|
12
|
+
var v = o[k];
|
|
13
|
+
if (!isEmpty(v) && hasOwnProperty.call(o, k)) return String(v);
|
|
14
|
+
if (isString(v)) name = v;
|
|
15
15
|
}
|
|
16
|
-
if (hasOwnProperty.call(o, 'valueOf')) name = o.valueOf();
|
|
16
|
+
if (!name && hasOwnProperty.call(o, 'valueOf')) name = o.valueOf();
|
|
17
17
|
if (isString(name)) return name;
|
|
18
18
|
return String(o);
|
|
19
19
|
}
|
package/coms/basic/i18n.md
CHANGED
package/coms/compile/Html.js
CHANGED
|
@@ -88,7 +88,7 @@ var replaceISO8859 = function (data) {
|
|
|
88
88
|
return String(data).replace(/<\!--([\s\S]*)--\>$/g, '$1').replace(/&\w+;/g, a => iso8859[a] || a).replace(/&#(\d+);/g, (_, a) => String.fromCodePoint(a))
|
|
89
89
|
};
|
|
90
90
|
var parseExpress = function (data, mayberepeat) {
|
|
91
|
-
data = replaceISO8859(data);
|
|
91
|
+
data = "=" + replaceISO8859(data);
|
|
92
92
|
if (mayberepeat && /\s+(in|of)\s+/.test(data)) {
|
|
93
93
|
data = data.split(/\s+(in|of)\s+/).pop();
|
|
94
94
|
}
|
|
@@ -132,6 +132,7 @@ Html.prototype.createScoped = function (code) {
|
|
|
132
132
|
else if (c.tagName === 'STYLE') {
|
|
133
133
|
styleNodes.push(c);
|
|
134
134
|
tempNodes.push(c);
|
|
135
|
+
c.isStyle = true;
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
|
|
@@ -7,6 +7,7 @@ var test = function (source, pick, value) {
|
|
|
7
7
|
if (arguments.length === 2) source = pick;
|
|
8
8
|
assert(h.createString(b), source);
|
|
9
9
|
if (arguments.length === 3) {
|
|
10
|
+
b.scoped = h.createScoped(b);
|
|
10
11
|
assert(seek(b, pick), value);
|
|
11
12
|
}
|
|
12
13
|
};
|
|
@@ -31,7 +32,9 @@ test('<div>$\\{${`<div></div>`}</div>');
|
|
|
31
32
|
test('<div>$\\{${typeof `<div></div>`}</div>');
|
|
32
33
|
test('<div>$\\{${\\a+typeof`<div></div>`}</div>', '<div>$\\{${\\a + typeof `<div></div>`}</div>');
|
|
33
34
|
test('${i18n`加载中..`}<div class="loader"></div>');
|
|
34
|
-
test('${a +typeof i18n`加载中..`}<div class="loader"></div>','${a + typeof i18n`加载中..`}<div class="loader"></div>');
|
|
35
|
+
test('${a +typeof i18n`加载中..`}<div class="loader"></div>', '${a + typeof i18n`加载中..`}<div class="loader"></div>');
|
|
35
36
|
test('${a > 1}');
|
|
36
|
-
test('a>1','a > 1');
|
|
37
|
-
test('a><a></a>','a > <a></a>');
|
|
37
|
+
test('a>1', 'a > 1');
|
|
38
|
+
test('a><a></a>', 'a > <a></a>');
|
|
39
|
+
test('X', 'X');
|
|
40
|
+
test('<input -class="{actived:actived===f}"/>', 'scoped.envs.actived', true);
|
|
@@ -383,6 +383,14 @@ Javascript.prototype.setType = function (o) {
|
|
|
383
383
|
var queue = o.queue;
|
|
384
384
|
|
|
385
385
|
if (last) {
|
|
386
|
+
if (last.type === STAMP && last.text === "?") {
|
|
387
|
+
if (o.type === EXPRESS && /^\.[^\.]|^\.$/.test(o.text)) {
|
|
388
|
+
last.type = EXPRESS;
|
|
389
|
+
var q = o.queue;
|
|
390
|
+
q.question--;
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
386
394
|
if (o.type === STRAP && o.text === "function") {
|
|
387
395
|
if (last.text === 'async' && !last.isend) last.type = STRAP;
|
|
388
396
|
}
|
|
@@ -528,6 +536,28 @@ Javascript.prototype.detour = function (body, ie) {
|
|
|
528
536
|
return envs;
|
|
529
537
|
}
|
|
530
538
|
var context = null, rootenvs = null;
|
|
539
|
+
var detourNullishSeek = function (o, ie) {
|
|
540
|
+
var h = snapExpressHead(o);
|
|
541
|
+
var f = snapExpressFoot(o);
|
|
542
|
+
o = h;
|
|
543
|
+
var rest = [o];
|
|
544
|
+
while (o !== f) {
|
|
545
|
+
o = o.next;
|
|
546
|
+
rest.push(o);
|
|
547
|
+
}
|
|
548
|
+
var text = createString(rest);
|
|
549
|
+
var text1 = text.replace(/^\.\.\./, '');
|
|
550
|
+
var hasdot = text1.length !== text.length;
|
|
551
|
+
remove(h, f.prev);
|
|
552
|
+
text = renderExpress(text1, false);
|
|
553
|
+
if (hasdot) text = "..." + text;
|
|
554
|
+
var o1 = scan(text);
|
|
555
|
+
detour(o1.first, ie);
|
|
556
|
+
patchArrawScope(o1, o);
|
|
557
|
+
replace(o, ...o1);
|
|
558
|
+
o = o1.last;
|
|
559
|
+
return o;
|
|
560
|
+
}
|
|
531
561
|
function detour(o, ie) {
|
|
532
562
|
while (o) {
|
|
533
563
|
switch (o.type) {
|
|
@@ -536,23 +566,7 @@ function detour(o, ie) {
|
|
|
536
566
|
break;
|
|
537
567
|
case STAMP:
|
|
538
568
|
if (o.text === "?.") {
|
|
539
|
-
|
|
540
|
-
var f = snapExpressFoot(o);
|
|
541
|
-
o = h;
|
|
542
|
-
var rest = [o];
|
|
543
|
-
while (o !== f) {
|
|
544
|
-
o = o.next;
|
|
545
|
-
rest.push(o);
|
|
546
|
-
}
|
|
547
|
-
text = createString(rest);
|
|
548
|
-
remove(h, f.prev);
|
|
549
|
-
text = renderExpress(text, false);
|
|
550
|
-
if (hasdot) text = "..." + text;
|
|
551
|
-
var o1 = scan(text);
|
|
552
|
-
detour(o1.first, ie);
|
|
553
|
-
patchArrawScope(o1, o);
|
|
554
|
-
replace(o, ...o1);
|
|
555
|
-
o = o1.last;
|
|
569
|
+
o = detourNullishSeek(o, ie);
|
|
556
570
|
continue;
|
|
557
571
|
}
|
|
558
572
|
else if (o.text === '.') {
|
|
@@ -566,6 +580,10 @@ function detour(o, ie) {
|
|
|
566
580
|
}
|
|
567
581
|
break;
|
|
568
582
|
case EXPRESS:
|
|
583
|
+
if (/^\?\./.test(o.text)) {
|
|
584
|
+
o = detourNullishSeek(o, ie);
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
569
587
|
var text = o.text.replace(/^\.\.\./, '');
|
|
570
588
|
var hasdot = o.text.length !== text.length;
|
|
571
589
|
if (context.avoidMap) {
|
|
@@ -721,14 +739,21 @@ var removeImport = function (c, i, code) {
|
|
|
721
739
|
var t = null;
|
|
722
740
|
if (n && n.type === EXPRESS) {
|
|
723
741
|
t = Object.create(null);
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
742
|
+
removeFromList(used[n.tack], n);
|
|
743
|
+
while (n?.type === EXPRESS) {
|
|
744
|
+
var ts = n.text.split(".")
|
|
745
|
+
for (var e of ts) {
|
|
746
|
+
t[e] = true;
|
|
747
|
+
}
|
|
748
|
+
var ni = code.indexOf(n, i);
|
|
749
|
+
n = n.next;
|
|
750
|
+
if (n?.needle) {
|
|
751
|
+
n = n.next;
|
|
752
|
+
var ne = code.indexOf(n, ni);
|
|
753
|
+
splice(code, ni, ne - ni);
|
|
754
|
+
}
|
|
755
|
+
else splice(code, ni, 1);
|
|
756
|
+
}
|
|
732
757
|
}
|
|
733
758
|
if (!n || n.type !== QUOTED) throw new Error(i18n`缺少导入路径!`);
|
|
734
759
|
var ns = skipAssignment(n);
|
|
@@ -111,4 +111,14 @@ while (++i < 2) {}
|
|
|
111
111
|
a ? function () {} : function () {}
|
|
112
112
|
declare module 'buffer' {}
|
|
113
113
|
a <= 1;
|
|
114
|
-
`)
|
|
114
|
+
`)
|
|
115
|
+
|
|
116
|
+
var testPress = function (text, expect) {
|
|
117
|
+
var code = scanner2(text);
|
|
118
|
+
code.press(false);
|
|
119
|
+
assert(code.toString(), expect);
|
|
120
|
+
};
|
|
121
|
+
testPress(`if(){}\r\nelse {}`, `if(){}else{}`)
|
|
122
|
+
testPress(`if(a)a={}\r\nelse{}`, `if(a)a={};else{}`)
|
|
123
|
+
testPress(`if()a=function(){}\r\nelse {}`,`if()a=function(){};else{}`)
|
|
124
|
+
testPress(`if()function a(){}\r\nelse {}`,`if()function a(){}else{}`)
|
package/coms/compile/Program.js
CHANGED
|
@@ -13,6 +13,7 @@ const {
|
|
|
13
13
|
/*2048 */ELEMENT,
|
|
14
14
|
createString,
|
|
15
15
|
number_reg,
|
|
16
|
+
digit_reg,
|
|
16
17
|
} = require("./common");
|
|
17
18
|
var combine = require("../basic/combine");
|
|
18
19
|
var sortRegster = require("../basic/sortRegister");
|
|
@@ -102,9 +103,10 @@ class Program {
|
|
|
102
103
|
["[", "]"],
|
|
103
104
|
["{", "}"],
|
|
104
105
|
]
|
|
105
|
-
stamps = "
|
|
106
|
+
stamps = "/=+;|:?<>-!~%^&*,".split("")
|
|
106
107
|
value_reg = /^(false|true|null)$/
|
|
107
108
|
number_reg = number_reg;
|
|
109
|
+
digit_reg = digit_reg;
|
|
108
110
|
Code = Array;
|
|
109
111
|
powermap = powermap;
|
|
110
112
|
transive_reg = /^(new|var|let|const|yield|void|in|of|typeof|delete|case|return|await|default|instanceof|throw|extends|import|from)$/;
|
|
@@ -183,6 +185,7 @@ class Program {
|
|
|
183
185
|
var funcstrap_reg = this.funcstrap_reg;
|
|
184
186
|
var entry_reg = this.entry_reg;
|
|
185
187
|
var type_reg = this.type_reg;
|
|
188
|
+
var digit_reg = this.digit_reg;
|
|
186
189
|
var comment_entry = this.comment_entry;
|
|
187
190
|
var rowsOf = m => m.replace(/[^\r\n\u2028\u2029]+/g, ';').replace(/\r\n|\r|\n|\u2028|\u2029/g, ' ').replace(/;/g, '').length;
|
|
188
191
|
var setRows = m => {
|
|
@@ -479,7 +482,7 @@ class Program {
|
|
|
479
482
|
save(space_reg.test(m) ? SPACE : PIECE);
|
|
480
483
|
}
|
|
481
484
|
}
|
|
482
|
-
m = match[0];
|
|
485
|
+
m = match?.[0];
|
|
483
486
|
}
|
|
484
487
|
loop: while (index < text.length) {
|
|
485
488
|
|
|
@@ -492,6 +495,7 @@ class Program {
|
|
|
492
495
|
var match = reg.exec(text);
|
|
493
496
|
if (!match) {
|
|
494
497
|
index = text.length;
|
|
498
|
+
if (queue === origin) push_piece(index);
|
|
495
499
|
break loop;
|
|
496
500
|
}
|
|
497
501
|
var m = match[0];
|
|
@@ -726,7 +730,7 @@ class Program {
|
|
|
726
730
|
save(SPACE);
|
|
727
731
|
}
|
|
728
732
|
else {
|
|
729
|
-
if (this.keepspace) save(SPACE);
|
|
733
|
+
if (this.keepspace || start === 0) save(SPACE);
|
|
730
734
|
}
|
|
731
735
|
lasttype = SPACE;
|
|
732
736
|
continue;
|
|
@@ -763,7 +767,7 @@ class Program {
|
|
|
763
767
|
}
|
|
764
768
|
continue;
|
|
765
769
|
}
|
|
766
|
-
var isdigit =
|
|
770
|
+
var isdigit = digit_reg.exec(m);
|
|
767
771
|
if (isdigit) {
|
|
768
772
|
var m1 = isdigit[0];
|
|
769
773
|
if (m1.length < m.length) {
|
|
@@ -999,9 +1003,14 @@ class Program {
|
|
|
999
1003
|
this.space_reg = new RegExp(`^[${spaces}]+$`, flagUnicode);
|
|
1000
1004
|
this.space_exp = new RegExp(`[${spaces}]+`, flagUnicode);
|
|
1001
1005
|
var quotes_entries = this.createRegExp(this.comments.concat(this.quotes).map(q => q[0]), true).source;
|
|
1002
|
-
var powers = Object.keys(this.powermap).filter(k => this.stamp_reg.test(k));
|
|
1006
|
+
var powers = Object.keys(this.powermap).filter(k => k.length > 1 && this.stamp_reg.test(k));
|
|
1003
1007
|
var powers_entries = this.createRegExp(this.tags.map(t => t[0]).concat(powers), true).source;
|
|
1004
|
-
|
|
1008
|
+
var entries_reg = new RegExp(`^(${powers_entries}|${quotes_entries}|${scopes})$`, this.nocase ? 'iu' : '');
|
|
1009
|
+
stamps = this.compile(this.stamps.filter(s => !entries_reg.test(s)).join(''));
|
|
1010
|
+
var number_reg = this.number_reg;
|
|
1011
|
+
var numbers = number_reg.source.replace(/^\^|\$$/g, "");
|
|
1012
|
+
this.digit_reg = new RegExp(/^[+\-]?/.source + numbers, number_reg.flags);
|
|
1013
|
+
this.entry_reg = new RegExp([`[${spaces}]+|${quotes_entries}|[${scopes}]|${numbers}[^${tokens}]*|${express}|${powers_entries}|[${stamps}]`], "gi" + flagUnicode);
|
|
1005
1014
|
}
|
|
1006
1015
|
}
|
|
1007
1016
|
module.exports = Program;
|
package/coms/compile/common.js
CHANGED
|
@@ -17,7 +17,7 @@ const [
|
|
|
17
17
|
var number_reg = /^(?:(?:0x[0-9a-f]+|0b[01]+|0o?[0-7]+)(?:_[0-9a-f]+)*|(?:(?:(?:\d+_)*\d+|\d*)\.\d+(?:_\d+)*|(?:\d+_)*\d+\.?))(?:e[\+\-]?\d+(?:_\d+)*|[hijklmnu]+)?/i;
|
|
18
18
|
var equal_reg = /^(?:[\+\-\*\/~\^&\|%]|\*\*|>>>?|<<)?\=$|^(?:\+\+|\-\-)$/;
|
|
19
19
|
var needhead_reg = /^\?|^\.(?:[^\.]|$)|^\[/;
|
|
20
|
-
var needfoot_reg = /(
|
|
20
|
+
var needfoot_reg = /(\:\:|\.)$/;
|
|
21
21
|
var skipAssignment = function (o, cx) {
|
|
22
22
|
if (!o) return;
|
|
23
23
|
var next = arguments.length === 1 ? function () {
|
|
@@ -115,6 +115,10 @@ var skipAssignment = function (o, cx) {
|
|
|
115
115
|
next();
|
|
116
116
|
break;
|
|
117
117
|
}
|
|
118
|
+
if (needfoot_reg.test(o.text)) {
|
|
119
|
+
next();
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
118
122
|
var prev = o.prev;
|
|
119
123
|
if (prev?.type === EXPRESS && needfoot_reg.test(prev.text)) {
|
|
120
124
|
next();
|
|
@@ -1356,7 +1360,7 @@ var createString = function (parsed) {
|
|
|
1356
1360
|
}
|
|
1357
1361
|
case SCOPED:
|
|
1358
1362
|
var prev = o.prev;
|
|
1359
|
-
if (patchspace && prev && o.type !== QUOTED && (lasttype === STAMP && !prev.unary && !prev.needle
|
|
1363
|
+
if (patchspace && !intag && prev && o.type !== QUOTED && (lasttype === STAMP && !prev.unary && !prev.needle
|
|
1360
1364
|
|| lasttype & ~(SPACE | STAMP | COMMENT) && o.brace
|
|
1361
1365
|
|| lasttype === STRAP && !/^(this|arguments|import)$/.test(prev.text)
|
|
1362
1366
|
)) result.push(" ");
|
|
@@ -30,7 +30,7 @@ var unslice = function (arr) {
|
|
|
30
30
|
continue;
|
|
31
31
|
}
|
|
32
32
|
var p = o.prev;
|
|
33
|
-
if (p &&
|
|
33
|
+
if (p?.type && (STAMP | EXPRESS) && p.text === '...') {
|
|
34
34
|
var px = arr.lastIndexOf(p, cx);
|
|
35
35
|
splice(arr, px, cx - px + 1, ...o);
|
|
36
36
|
cx += o.length - 1;
|
|
@@ -857,7 +857,7 @@ var killspr = function (body, i, _getobjname, killobj) {
|
|
|
857
857
|
splice(body, i++, 0, ...scanner2('["apply"]'));
|
|
858
858
|
var m1 = skipAssignment(m);
|
|
859
859
|
if (index > 0 || m1 && m1.next) {
|
|
860
|
-
var h = splice(o, 2, o.length);
|
|
860
|
+
var h = splice(o, 2, o.length - 2);
|
|
861
861
|
var c = scanner2(`[]`);
|
|
862
862
|
splice(c[0], 0, 0, ...h);
|
|
863
863
|
killobj(c);
|
|
@@ -940,9 +940,7 @@ var killobj = function (body, getobjname, getletname, getname_, letname_, deep =
|
|
|
940
940
|
var name = getname_("_");
|
|
941
941
|
var y = scanner2(`for await(var ${name} of)yield ${name}`, innerJs);
|
|
942
942
|
splice(y[2], y[2].length, 0, ...splice(body, i, n - i));
|
|
943
|
-
splice.debug = true;
|
|
944
943
|
splice(body, i - 1, 1, ...y);
|
|
945
|
-
splice.debug = false;
|
|
946
944
|
innerJs.setType(y[1]);
|
|
947
945
|
if (y[1].type === EXPRESS) splice(body, i, 1);
|
|
948
946
|
unforof(y[0], getname_.bind(null, '_'), y.used, deepkill);
|
|
@@ -160,7 +160,7 @@ textSpan: highlightSpan.textSpan,
|
|
|
160
160
|
isWriteAccess: highlightSpan.kind === "writtenReference" /* writtenReference */ }, highlightSpan.isInString && { isInString: true }, highlightSpan.contextSpan && { contextSpan: highlightSpan.contextSpan })) }`);
|
|
161
161
|
assert(downLevel(`async()=>({ [argitem.sort ? argitem.sort : 'date']: "desc" })`), `function () { return async_(
|
|
162
162
|
function () {
|
|
163
|
-
_ = {};
|
|
163
|
+
_ = {}; if (!argitem.sort) return [1, 0]; _1 = argitem.sort; return [2, 0]
|
|
164
164
|
},
|
|
165
165
|
function () {
|
|
166
166
|
_1 = 'date'; return [1, 0]
|
|
@@ -430,15 +430,16 @@ function () {
|
|
|
430
430
|
_0 = a; return [_0, 1]
|
|
431
431
|
})
|
|
432
432
|
var a, _0 }`)
|
|
433
|
-
|
|
434
433
|
assert(downLevel(`function(a=b=>b,c){c}`), 'function (a, c) { if (a === undefined) a = function (b) { return b }; c }')
|
|
435
434
|
assert(downLevel(`Object.defineProperty(dis, f.key, {get() {}, set(v) {}})`), `Object.defineProperty(dis, f.key, (_ = {},
|
|
436
435
|
_.get = function () {},
|
|
437
436
|
_.set = function (v) {}, _))
|
|
438
437
|
var _`);
|
|
439
|
-
|
|
438
|
+
downLevel.debug = true; i++;
|
|
439
|
+
assert(downLevel(`var restq = splice(queue, i, i2 - i, ...a[1], { type: STAMP, text: "=" });`), `var slice_ = Array["prototype"]["slice"];
|
|
440
|
+
var restq = splice["apply"](null, [queue, i, i2 - i]["concat"](slice_["call"](a[1]), [{ type: STAMP, text: "=" }]));`)
|
|
440
441
|
var c = scanner2(`\r\n if (search.length) return null;\r\n return path.join(...pathlist);\r\n`);
|
|
441
442
|
c.fix();
|
|
442
443
|
c.break();
|
|
443
444
|
assert(c.toString(), `\r\n if (search["length"]) return null;\r\n return path["join"](...pathlist);\r\n`)
|
|
444
|
-
assert(downLevel.code(c).toString(), `\r\n if (search["length"]) return null;\r\n return
|
|
445
|
+
assert(downLevel.code(c).toString(), `\r\n if (search["length"]) return null;\r\n return path["join"]["apply"](path, pathlist);\r\n`);
|
package/coms/compile/rescan.js
CHANGED
|
@@ -24,10 +24,12 @@ function rescan(strs, ...args) {
|
|
|
24
24
|
var dist = [];
|
|
25
25
|
var i = 0;
|
|
26
26
|
for (var s of strs) {
|
|
27
|
-
dist.push(s, '
|
|
27
|
+
if (s) dist.push(s, ' ');
|
|
28
|
+
dist.push('#\\' + i++, " ");
|
|
28
29
|
}
|
|
30
|
+
dist.pop();
|
|
29
31
|
if (i > args.length) dist.pop();
|
|
30
|
-
dist = scanner2(dist.join('
|
|
32
|
+
dist = scanner2(dist.join(''));
|
|
31
33
|
patchObject(dist, args);
|
|
32
34
|
return dist;
|
|
33
35
|
}
|
|
@@ -126,7 +126,7 @@ test(`switch(a){default: a;case 1:b;}`, 'if (a === 1) return [2, 0]; return [1,
|
|
|
126
126
|
test("loop:{a=b;if(a) continue loop}", "a = b; if (a) return [0, 0]", true);
|
|
127
127
|
test("if(a)try{}finally{}else a;", 'if (!a) return [4, 0]; return [1, 8];\r\n return [0, 9];\r\n return [1, 9];\r\n return [2, 0];\r\n a; return [1, 0]')
|
|
128
128
|
test("b:while(t){switch(a){case c:break b;}}", 'if (!t) return [1, 0]; if (a === c) return [1, 0]; return [0, 0]');
|
|
129
|
-
test("predef[key[1]](r.slice(key[0].length).trim())", '_ = key[1]; _0 = key[0]
|
|
129
|
+
test("predef[key[1]](r.slice(key[0].length).trim())", '_ = key[1]; _0 = key[0].length; _0 = r.slice(_0); _0 = _0.trim(); predef[_](_0)');
|
|
130
130
|
test("predef[key[1]](r.slice())(r.slice())", '_ = key[1]; _0 = r.slice(); _ = predef[_](_0); _0 = r.slice(); _(_0)');
|
|
131
131
|
test("predef[key[1]][key[2]][key[3]]", '_ = key[1]; _ = predef[_]; _0 = key[2]; _ = _[_0]; _0 = key[3]; _[_0]');
|
|
132
132
|
test("[key[1]][key[2]][key[3]]", '_ = key[1]; _ = [_]; _0 = key[2]; _ = _[_0]; _0 = key[3]; _[_0]');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var { STAMP, PROPERTY, SCOPED, VALUE, EXPRESS, QUOTED, SPACE, COMMENT, createString: _createString, splice } = require("./common");
|
|
1
|
+
var { STAMP, PROPERTY, SCOPED, VALUE, STRAP, EXPRESS, QUOTED, SPACE, COMMENT, createString: _createString, splice } = require("./common");
|
|
2
2
|
var createString = function (a) {
|
|
3
3
|
a.autospace = false;
|
|
4
4
|
return _createString(a);
|
|
@@ -274,25 +274,28 @@ macros.each = function (list, body) {
|
|
|
274
274
|
};
|
|
275
275
|
|
|
276
276
|
|
|
277
|
+
var presets = /^@(media|keyframes|layer|import|namespace|page|property|suppports|font-face|document|counter-style|charset|color-profile|container|font-feature-values|font-palette-values|scope|starting-style)(\s|\(|$)/i;
|
|
277
278
|
class 素心 extends Program {
|
|
278
|
-
straps = ["and"];
|
|
279
|
+
straps = ["and", ...presets.source.replace(/^[\s\S]*?\(([\s\S]*?)\)[\s\S]*$/, '$1').split('|').map(a => "@" + a)];
|
|
279
280
|
stamps = `;:,>+~&!/`.split("");
|
|
280
281
|
quotes = rarg.quotes;
|
|
281
282
|
keepspace = true;
|
|
283
|
+
control_reg = presets;
|
|
282
284
|
scopes = [["{", "}"], ["(", ")"]]
|
|
283
285
|
}
|
|
284
286
|
|
|
285
|
-
var presets = /^@(media|keyframes|layer|import|namespace|page|property|suppports|font-face|document|counter-style|charset|color-profile|container|font-feature-values|font-palette-values)(\s|\(|$)/i;
|
|
286
287
|
|
|
287
288
|
素心.prototype.setType = function (o) {
|
|
288
289
|
var p = o.prev;
|
|
289
290
|
if (o.type !== SCOPED) {
|
|
290
291
|
if (!p || p.type === STAMP && p.text === ";" || p.type === SCOPED && p.entry === '{') {
|
|
291
|
-
o.type = PROPERTY;
|
|
292
|
+
if (o.type === EXPRESS) o.type = PROPERTY;
|
|
293
|
+
o.isprop = true;
|
|
292
294
|
return;
|
|
293
295
|
}
|
|
294
|
-
if (p.
|
|
295
|
-
o.type = PROPERTY;
|
|
296
|
+
if (p.isprop && o.type & ~(STAMP | SCOPED)) {
|
|
297
|
+
if (o.type === EXPRESS) o.type = PROPERTY;
|
|
298
|
+
o.isprop = true;
|
|
296
299
|
return;
|
|
297
300
|
}
|
|
298
301
|
}
|
|
@@ -303,7 +306,7 @@ var presets = /^@(media|keyframes|layer|import|namespace|page|property|suppports
|
|
|
303
306
|
}
|
|
304
307
|
while (p && (p.type !== SCOPED || p.entry !== "{") && (p.type !== STAMP || p.text !== ';')) {
|
|
305
308
|
p.isprop = true;
|
|
306
|
-
if (p.type
|
|
309
|
+
if (p.type === EXPRESS) p.type = PROPERTY;
|
|
307
310
|
p = p.prev;
|
|
308
311
|
}
|
|
309
312
|
}
|
|
@@ -334,13 +337,13 @@ var presets = /^@(media|keyframes|layer|import|namespace|page|property|suppports
|
|
|
334
337
|
for (var cx = 0, dx = code.length; cx < dx; cx++) {
|
|
335
338
|
var o = code[cx];
|
|
336
339
|
if (o && (o.type & (SPACE | COMMENT) || o.type === STAMP && o.text === ';')) continue;
|
|
337
|
-
if (o.
|
|
340
|
+
if (!o.isprop) {
|
|
338
341
|
console.log(createString([o]), o.type, createString(code))
|
|
339
342
|
throw new Error(i18n`结构异常`);
|
|
340
343
|
}
|
|
341
344
|
var p = [], v = [];
|
|
342
345
|
while (o && (o.type !== SCOPED || o.entry !== "{")) {
|
|
343
|
-
if (o.type === STAMP) break;
|
|
346
|
+
if (o.type === STAMP && !o.isprop) break;
|
|
344
347
|
p.push(o);
|
|
345
348
|
o = code[++cx];
|
|
346
349
|
}
|
|
@@ -609,4 +612,5 @@ function 素馨(text, scopeName, compress) {
|
|
|
609
612
|
}
|
|
610
613
|
return a;
|
|
611
614
|
}).filter(a => !!a).join(compress ? "" : "\r\n") + getquried();
|
|
612
|
-
}
|
|
615
|
+
}
|
|
616
|
+
素馨.素心 = 素心;
|
|
@@ -70,7 +70,11 @@ assert(素馨(`a>:root{&:not(a):not(b){c:d}}`, '.abc-'), `a>.abc-:not(a):not(b){
|
|
|
70
70
|
assert(素馨(`.a (){ &:after{abc:1}} .b{.a();}`, '.abc-'), `.abc- .b:after{abc:1;}`);
|
|
71
71
|
assert(素馨(`@a:1px;@margin-x:@a+10px; a{m:-@margin-x}`), `a{m:-11px;}`);
|
|
72
72
|
assert(素馨(`a{@a:1px;@margin-x:@a+10px;m:-@margin-x}`), `a{m:-11px;}`);
|
|
73
|
-
assert(素馨(`@media screen{&.a{b:1}}`,'a'), `@media screen{a.a{b:1;}}`);
|
|
74
|
-
assert(素馨(`@media screen and(max-width:100px){&.a{b:1}}`,'a'), `@media screen and (max-width:100px){a.a{b:1;}}`);
|
|
73
|
+
assert(素馨(`@media screen{&.a{b:1}}`, 'a'), `@media screen{a.a{b:1;}}`);
|
|
74
|
+
assert(素馨(`@media screen and(max-width:100px){&.a{b:1}}`, 'a'), `@media screen and (max-width:100px){a.a{b:1;}}`);
|
|
75
75
|
assert(素馨(`b{:not([resizing], [dragging]) {transition: padding .2s, margin .2s;}}`), `b :not([resizing], [dragging]){transition:padding .2s, margin .2s;}`);
|
|
76
|
-
assert(素馨(`@a(@b){a@b{@w:@b/2;c:@w;}} @a(1); @a(2); @a(3)`)
|
|
76
|
+
assert(素馨(`@a(@b){a@b{@w:@b/2;c:@w;}} @a(1); @a(2); @a(3)`), `a1{c:0.5;}\r\na2{c:1;}\r\na3{c:1.5;}`);
|
|
77
|
+
assert(scanner2(`-0.2em .3em -0.2em 0`, new 素馨.素心)[0].text, '-0.2em');
|
|
78
|
+
assert(scanner2(`-0.2em .3em -0.2em 0`, new 素馨.素心)[0].isdigit, true);
|
|
79
|
+
assert(scanner2(`-0.2em .3em -0.2em 0`, new 素馨.素心)[2].text, ".3em");
|
|
80
|
+
assert(scanner2(`-0.2em .3em -0.2em 0`, new 素馨.素心)[2].isdigit, true);
|
package/coms/docs/codecolor.js
CHANGED
|
@@ -13,6 +13,7 @@ var codecolor = function (c, encode) {
|
|
|
13
13
|
var scoped = c.scoped;
|
|
14
14
|
var setdefs = function (scoped) {
|
|
15
15
|
var { used } = scoped;
|
|
16
|
+
if (!isObject(used) || isArray(used)) return;
|
|
16
17
|
for (var k in used) {
|
|
17
18
|
var isdef = false;
|
|
18
19
|
for (var o of used[k]) {
|
|
@@ -29,12 +30,12 @@ var codecolor = function (c, encode) {
|
|
|
29
30
|
}
|
|
30
31
|
scoped.forEach(setdefs);
|
|
31
32
|
};
|
|
32
|
-
setdefs(scoped);
|
|
33
|
+
if (scoped) setdefs(scoped);
|
|
33
34
|
var isConstValue = () => false;
|
|
34
35
|
if (c.program) {
|
|
35
36
|
var { strap_reg, value_reg } = c.program;
|
|
36
37
|
isConstValue = a => strap_reg.test(a) || value_reg.test(a);
|
|
37
|
-
}
|
|
38
|
+
}
|
|
38
39
|
var isInvoke = function (o) {
|
|
39
40
|
var o = o.next;
|
|
40
41
|
if (o?.type === EXPRESS && needhead_reg.test(o.text)) o = o.next;
|
|
@@ -42,9 +43,9 @@ var codecolor = function (c, encode) {
|
|
|
42
43
|
if (o?.type === STAMP && o.needle) o = o.next;
|
|
43
44
|
if (o?.type === SCOPED && o.entry === "(") return true;
|
|
44
45
|
return false;
|
|
45
|
-
}
|
|
46
|
+
};
|
|
46
47
|
var setExpress = function (o, label) {
|
|
47
|
-
if (!o.text) return;
|
|
48
|
+
if (!o.text || /^</.test(o.text)) return;
|
|
48
49
|
var keys = o.text.split(".");
|
|
49
50
|
if (isInvoke(o)) {
|
|
50
51
|
if (!/^[\<\?]/.test(keys[keys.length - 1])) keys[keys.length - 1] = `<invoke>${keys[keys.length - 1]}</invoke>`;
|
|
@@ -55,21 +56,21 @@ var codecolor = function (c, encode) {
|
|
|
55
56
|
else name = `<${label}>${name}</${label}>`;
|
|
56
57
|
keys[0] = name;
|
|
57
58
|
o.text = keys.map(k => /^[\<\?]/.test(k) || !k ? k : `<express>${k}</express>`).join(".");
|
|
58
|
-
}
|
|
59
|
+
};
|
|
59
60
|
var setPredef = o => setExpress(o, 'predef');
|
|
60
61
|
var setOutside = o => setExpress(o, 'outside');
|
|
61
62
|
if (used) for (var k in envs) {
|
|
62
63
|
used[k].forEach(k in predefs ? setPredef : setOutside);
|
|
63
64
|
}
|
|
64
65
|
if (c.program) var { space_exp: spaceReg, control_reg } = c.program;
|
|
65
|
-
var unspaceReg = new RegExp(spaceReg.source.replace(/^\[/, "[^"), spaceReg.flags + 'g');
|
|
66
|
+
if (spaceReg) var unspaceReg = new RegExp(spaceReg.source.replace(/^\[/, "[^"), spaceReg.flags + 'g');
|
|
66
67
|
var wraptext = function (t, l) {
|
|
67
68
|
if (unspaceReg) t = t.replace(unspaceReg, a => {
|
|
68
69
|
a = encode(a);
|
|
69
70
|
return `<${l}>${a}</${l}>`
|
|
70
71
|
});
|
|
71
72
|
return t;
|
|
72
|
-
}
|
|
73
|
+
};
|
|
73
74
|
c.colored = true;
|
|
74
75
|
var setcolor = function (o) {
|
|
75
76
|
if (o.colored) return;
|
|
@@ -151,5 +152,5 @@ var codecolor = function (c, encode) {
|
|
|
151
152
|
}
|
|
152
153
|
};
|
|
153
154
|
c.forEach(setcolor);
|
|
154
|
-
|
|
155
|
+
return c;
|
|
155
156
|
}
|