subscript 10.7.0 → 10.7.2
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/README.md +6 -4
- package/eval/access.js +25 -7
- package/eval/bigint.js +7 -0
- package/eval/class.js +6 -4
- package/eval/op/optional.js +20 -9
- package/eval/op/spread.js +6 -1
- package/eval/prop.js +2 -16
- package/eval/var.js +4 -3
- package/feature/bigint.js +33 -0
- package/feature/number.js +2 -5
- package/feature/string.js +31 -27
- package/feature/template.js +6 -3
- package/jessie.min.js +7 -8
- package/justin.min.js +6 -7
- package/package.json +1 -1
- package/parse.js +4 -1
- package/subscript.d.ts +3 -0
- package/subscript.min.js +4 -4
package/README.md
CHANGED
|
@@ -111,15 +111,17 @@ See [docs.md](./docs.md) for full API.
|
|
|
111
111
|
## Safety
|
|
112
112
|
|
|
113
113
|
Blocked by default:
|
|
114
|
-
- `__proto__
|
|
114
|
+
- `__proto__` and any other `__*` property
|
|
115
115
|
- `constructor`, `prototype`
|
|
116
|
-
-
|
|
116
|
+
- Globals outside the supplied context
|
|
117
117
|
|
|
118
118
|
```js
|
|
119
|
-
subscript('constructor
|
|
120
|
-
// undefined
|
|
119
|
+
subscript('constructor')({}) // undefined
|
|
120
|
+
subscript('constructor.constructor("alert(1)")')({}) // undefined
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
+
Context values are capabilities. Do not pass reflection helpers such as `Reflect.get` or `Object.getOwnPropertyDescriptor` to untrusted expressions.
|
|
124
|
+
|
|
123
125
|
## Performance
|
|
124
126
|
|
|
125
127
|
Parsing `a + b * c - d / e + f.g[0](h) + i.j`, 30k iterations — each iteration parses an unseen source, so source-keyed compile caches (`new Function`, angular-expressions) don't help:
|
package/eval/access.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// Property access - eval half
|
|
2
2
|
import { operator, compile } from '../parse.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const isObject = value => value != null && (typeof value === 'object' || typeof value === 'function');
|
|
5
|
+
// Coerce object keys once and preserve Symbol results.
|
|
6
|
+
export const toKey = key => isObject(key) ? Reflect.ownKeys({ [key]: 0 })[0] : key;
|
|
7
|
+
export const unsafeName = key => typeof key === 'string' && (key[0] === '_' && key[1] === '_' || key === 'constructor' || key === 'prototype');
|
|
8
|
+
export const unsafe = key => unsafeName(toKey(key));
|
|
9
|
+
compile.id = node => node === undefined || unsafe(node) ? () => undefined : ctx => ctx?.[node];
|
|
6
10
|
|
|
7
11
|
const err = msg => { throw Error(msg) };
|
|
8
12
|
operator('[]', (a, b) => {
|
|
@@ -15,9 +19,9 @@ operator('[]', (a, b) => {
|
|
|
15
19
|
// Member access: a[b]
|
|
16
20
|
if (b == null) err('Missing index');
|
|
17
21
|
a = compile(a); b = compile(b);
|
|
18
|
-
return ctx => { const k = b(ctx); return
|
|
22
|
+
return ctx => { const k = toKey(b(ctx)); return unsafeName(k) ? undefined : a(ctx)[k]; };
|
|
19
23
|
});
|
|
20
|
-
operator('.', (a, b) => (a = compile(a), b = !b[0] ? b[1] : b,
|
|
24
|
+
operator('.', (a, b) => (a = compile(a), b = toKey(!b[0] ? b[1] : b), unsafeName(b) ? () => undefined : ctx => a(ctx)[b]));
|
|
21
25
|
operator('()', (a, b) => {
|
|
22
26
|
// Group: (expr) - no second argument means grouping, not call
|
|
23
27
|
if (b === undefined) return a == null ? err('Empty ()') : compile(a);
|
|
@@ -28,7 +32,10 @@ operator('()', (a, b) => {
|
|
|
28
32
|
b[0] === ',' ? (b = b.slice(1).map(compile), ctx => b.map(arg => arg(ctx))) :
|
|
29
33
|
(b = compile(b), ctx => [b(ctx)]);
|
|
30
34
|
// Inline call handling for x(), a.b(), a[b](), (x)()
|
|
31
|
-
|
|
35
|
+
const guard = callGuard(a);
|
|
36
|
+
return guard < 0 ? () => undefined : call(a, guard ?
|
|
37
|
+
(obj, path, ctx) => (path = toKey(path), unsafeName(path) ? undefined : obj[path](...args(ctx))) :
|
|
38
|
+
(obj, path, ctx) => obj[path](...args(ctx)));
|
|
32
39
|
});
|
|
33
40
|
|
|
34
41
|
// Left-value check (valid assignment target)
|
|
@@ -53,5 +60,16 @@ const call = (a, fn, obj, path) => (
|
|
|
53
60
|
(a = compile(a), ctx => fn([a(ctx)], 0, ctx))
|
|
54
61
|
);
|
|
55
62
|
|
|
56
|
-
//
|
|
57
|
-
|
|
63
|
+
// Calls bypass member-read compilation to preserve `this`. Classify the key
|
|
64
|
+
// once: -1 blocked, 0 statically safe, 1 dynamic (guard at evaluation time).
|
|
65
|
+
const keyGuard = key => isObject(key) ? 1 : unsafeName(key) ? -1 : 0;
|
|
66
|
+
const callGuard = (a, op = a?.[0], key = a?.[2]) =>
|
|
67
|
+
typeof a === 'string' ? keyGuard(a) :
|
|
68
|
+
op === '()' && a.length == 2 ? callGuard(a[1]) :
|
|
69
|
+
op === '.' || op === '?.' ? keyGuard(key) :
|
|
70
|
+
(op === '[]' || op === '?.[]') && a.length === 3 ?
|
|
71
|
+
Array.isArray(key) && key[0] == null ? keyGuard(key[1]) : 1 : 0;
|
|
72
|
+
|
|
73
|
+
// Guard property references used by assignment-style operators too.
|
|
74
|
+
export const prop = (a, fn, guard = callGuard(a)) => guard < 0 ? () => undefined : call(a, guard ?
|
|
75
|
+
(obj, key, ctx) => (key = toKey(key), unsafeName(key) ? undefined : fn(obj, key, ctx)) : fn);
|
package/eval/bigint.js
ADDED
package/eval/class.js
CHANGED
|
@@ -9,18 +9,20 @@ operator('class', (name, base, body) => {
|
|
|
9
9
|
base = base ? compile(base) : null;
|
|
10
10
|
body = body ? compile(body) : null;
|
|
11
11
|
return ctx => {
|
|
12
|
-
const Parent = base
|
|
12
|
+
const Parent = base?.(ctx);
|
|
13
13
|
const cls = function(...args) {
|
|
14
14
|
if (!(this instanceof cls)) return err('Class constructor must be called with new');
|
|
15
15
|
const instance = base ? Reflect.construct(Parent, args, cls) : this;
|
|
16
16
|
if (cls.prototype.__constructor__) cls.prototype.__constructor__.apply(instance, args);
|
|
17
17
|
return instance;
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
if (base) {
|
|
20
|
+
Object.setPrototypeOf(cls.prototype, Parent.prototype);
|
|
21
|
+
Object.setPrototypeOf(cls, Parent);
|
|
22
|
+
}
|
|
21
23
|
if (body) {
|
|
22
24
|
const methods = Object.create(ctx);
|
|
23
|
-
methods['super'] = Parent;
|
|
25
|
+
if (base) methods['super'] = Parent;
|
|
24
26
|
const entries = body(methods);
|
|
25
27
|
const items = Array.isArray(entries) && typeof entries[0]?.[0] === 'string' ? entries : [];
|
|
26
28
|
for (const [k, v] of items) {
|
package/eval/op/optional.js
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
1
|
// Optional chaining operators - eval half
|
|
2
2
|
import { operator, compile } from '../../parse.js';
|
|
3
|
-
import {
|
|
3
|
+
import { toKey, unsafeName } from '../access.js';
|
|
4
4
|
|
|
5
|
-
operator('?.', (a, b) => (a = compile(a),
|
|
6
|
-
operator('?.[]', (a, b) => (a = compile(a), b = compile(b), ctx => {
|
|
5
|
+
operator('?.', (a, b) => (a = compile(a), b = toKey(b), unsafeName(b) ? () => undefined : ctx => a(ctx)?.[b]));
|
|
6
|
+
operator('?.[]', (a, b) => (a = compile(a), b = compile(b), ctx => {
|
|
7
|
+
const obj = a(ctx);
|
|
8
|
+
if (obj == null) return undefined;
|
|
9
|
+
const key = toKey(b(ctx));
|
|
10
|
+
return unsafeName(key) ? undefined : obj[key];
|
|
11
|
+
}));
|
|
7
12
|
operator('?.()', (a, b) => {
|
|
8
13
|
const args = !b ? () => [] :
|
|
9
14
|
b[0] === ',' ? (b = b.slice(1).map(compile), ctx => b.map(arg => arg(ctx))) :
|
|
10
15
|
(b = compile(b), ctx => [b(ctx)]);
|
|
11
16
|
|
|
12
|
-
//
|
|
13
|
-
// The only real distinction is static key vs dynamic key.
|
|
17
|
+
// Preserve whether the member access itself is optional.
|
|
14
18
|
if (a[0] === '.' || a[0] === '?.') {
|
|
15
|
-
const obj = compile(a[1]), key = a[2];
|
|
16
|
-
return
|
|
19
|
+
const optional = a[0] === '?.', obj = compile(a[1]), key = toKey(a[2]);
|
|
20
|
+
return unsafeName(key) ? () => undefined : optional ?
|
|
21
|
+
ctx => obj(ctx)?.[key]?.(...args(ctx)) :
|
|
22
|
+
ctx => obj(ctx)[key]?.(...args(ctx));
|
|
17
23
|
}
|
|
18
24
|
if ((a[0] === '[]' || a[0] === '?.[]') && a.length === 3) {
|
|
19
|
-
const obj = compile(a[1]), key = compile(a[2]);
|
|
20
|
-
return ctx => {
|
|
25
|
+
const optional = a[0] === '?.[]', obj = compile(a[1]), key = compile(a[2]);
|
|
26
|
+
return ctx => {
|
|
27
|
+
const value = obj(ctx);
|
|
28
|
+
if (optional && value == null) return undefined;
|
|
29
|
+
const k = toKey(key(ctx));
|
|
30
|
+
return unsafeName(k) ? undefined : value[k]?.(...args(ctx));
|
|
31
|
+
};
|
|
21
32
|
}
|
|
22
33
|
const fn = compile(a);
|
|
23
34
|
return ctx => fn(ctx)?.(...args(ctx));
|
package/eval/op/spread.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
// Spread/rest operator - eval half (for arrays/objects spread)
|
|
2
2
|
import { operator, compile } from '../../parse.js';
|
|
3
|
+
import { unsafeName } from '../access.js';
|
|
3
4
|
|
|
4
|
-
operator('...', a => (a = compile(a), ctx =>
|
|
5
|
+
operator('...', a => (a = compile(a), ctx => {
|
|
6
|
+
const obj = a(ctx), entries = [];
|
|
7
|
+
for (const key of Object.keys(obj)) if (!unsafeName(key)) entries.push([key, obj[key]]);
|
|
8
|
+
return entries;
|
|
9
|
+
}));
|
package/eval/prop.js
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
// Minimal property
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const err = msg => { throw Error(msg) };
|
|
5
|
-
operator('[]', (a, b) => (b == null && err('Missing index'), a = compile(a), b = compile(b), ctx => a(ctx)[b(ctx)]));
|
|
6
|
-
operator('.', (a, b) => (a = compile(a), b = !b[0] ? b[1] : b, ctx => a(ctx)[b]));
|
|
7
|
-
operator('()', (a, b) => {
|
|
8
|
-
// Group: (expr) - no second argument means grouping, not call
|
|
9
|
-
if (b === undefined) return a == null ? err('Empty ()') : compile(a);
|
|
10
|
-
// Function call: a(b,c)
|
|
11
|
-
const args = !b ? () => [] :
|
|
12
|
-
b[0] === ',' ? (b = b.slice(1).map(compile), ctx => b.map(arg => arg(ctx))) :
|
|
13
|
-
(b = compile(b), ctx => [b(ctx)]);
|
|
14
|
-
a = compile(a);
|
|
15
|
-
return ctx => a(ctx)(...args(ctx));
|
|
16
|
-
});
|
|
1
|
+
// Minimal property syntax uses the canonical guarded runtime.
|
|
2
|
+
export * from './access.js';
|
package/eval/var.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Variable declarations: let, const, var - eval half
|
|
2
2
|
import { operator, compile } from '../parse.js';
|
|
3
|
+
import { toKey, unsafeName } from './access.js';
|
|
3
4
|
|
|
4
5
|
// Flatten comma into array: [',', a, b, c] → [a, b, c]
|
|
5
6
|
const flatten = items => items[0]?.[0] === ',' ? items[0].slice(1) : items;
|
|
@@ -15,7 +16,7 @@ export const destructure = (pattern, value, ctx) => {
|
|
|
15
16
|
// Rest: {...rest}
|
|
16
17
|
if (Array.isArray(item) && item[0] === '...') {
|
|
17
18
|
const rest = {};
|
|
18
|
-
for (const k in value) if (!used.includes(k)) rest[k] = value[k];
|
|
19
|
+
for (const k in value) if (!used.includes(k) && !unsafeName(k)) rest[k] = value[k];
|
|
19
20
|
ctx[item[1]] = rest;
|
|
20
21
|
break;
|
|
21
22
|
}
|
|
@@ -26,8 +27,8 @@ export const destructure = (pattern, value, ctx) => {
|
|
|
26
27
|
if (typeof item === 'string') { key = binding = item }
|
|
27
28
|
else if (item[0] === '=') { typeof item[1] === 'string' ? (key = binding = item[1]) : ([, key, binding] = item[1]); def = item[2] }
|
|
28
29
|
else { [, key, binding] = item }
|
|
29
|
-
used.push(key);
|
|
30
|
-
let val = value[key];
|
|
30
|
+
used.push(key = toKey(key));
|
|
31
|
+
let val = unsafeName(key) ? undefined : value[key];
|
|
31
32
|
if (val === undefined && def) val = compile(def)(ctx);
|
|
32
33
|
destructure(binding, val, ctx);
|
|
33
34
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BigInt literals - parse half: 123n, 0xFFn, 0b101n, 1_000n
|
|
3
|
+
*
|
|
4
|
+
* AST (token form, JSON-serializable):
|
|
5
|
+
* 123n → ['n', '123']
|
|
6
|
+
* 0xFFn → ['n', '0xFF']
|
|
7
|
+
*
|
|
8
|
+
* Not part of any dialect: import 'subscript/feature/bigint.js' to enable.
|
|
9
|
+
* Pair with 'subscript/eval/bigint.js' for runtime.
|
|
10
|
+
*/
|
|
11
|
+
import { lookup, idx, cur, skip, err } from '../parse.js';
|
|
12
|
+
|
|
13
|
+
const _n = 110, PERIOD = 46, _0 = 48, _9 = 57, _x = 120;
|
|
14
|
+
|
|
15
|
+
// Wrap number handler to check for `n` suffix (mirrors feature/unit.js)
|
|
16
|
+
const wrapNum = cc => {
|
|
17
|
+
const orig = lookup[cc];
|
|
18
|
+
if (!orig) return;
|
|
19
|
+
lookup[cc] = (a, prec) => {
|
|
20
|
+
const start = idx;
|
|
21
|
+
const r = orig(a, prec);
|
|
22
|
+
if (!r || r[0] !== undefined || cur.charCodeAt(idx) !== _n) return r;
|
|
23
|
+
const digits = cur.slice(start, idx).replace(/_/g, '');
|
|
24
|
+
// integer literals only: 1.5n, 1e3n are invalid (hex digits may contain e/E)
|
|
25
|
+
if ((cur.charCodeAt(start + 1) | 32) !== _x && /[.eE]/.test(digits)) err('Invalid BigInt');
|
|
26
|
+
skip();
|
|
27
|
+
return ['n', digits];
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// Wrap digit and period handlers
|
|
32
|
+
for (let i = _0; i <= _9; i++) wrapNum(i);
|
|
33
|
+
wrapNum(PERIOD);
|
package/feature/number.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { parse, lookup, next, err, skip, idx, cur } from '../parse.js';
|
|
7
7
|
|
|
8
|
-
const PERIOD = 46, _0 = 48, _9 = 57, _E = 69, _e = 101, PLUS = 43, MINUS = 45, UNDERSCORE = 95
|
|
8
|
+
const PERIOD = 46, _0 = 48, _9 = 57, _E = 69, _e = 101, PLUS = 43, MINUS = 45, UNDERSCORE = 95;
|
|
9
9
|
const _a = 97, _f = 102, _A = 65, _F = 70;
|
|
10
10
|
|
|
11
11
|
// Strip underscores only if present (avoid allocation for common case)
|
|
@@ -20,11 +20,9 @@ const dec = c =>
|
|
|
20
20
|
c === UNDERSCORE ||
|
|
21
21
|
((c === _E || c === _e) && ((c = cur.charCodeAt(idx + 1)) >= _0 && c <= _9 || c === PLUS || c === MINUS) ? 2 : 0);
|
|
22
22
|
|
|
23
|
-
// Decimal number
|
|
23
|
+
// Decimal number: 123, 1.5, 1e-3, 1_000
|
|
24
24
|
const num = a => {
|
|
25
25
|
let str = strip(next(dec));
|
|
26
|
-
// BigInt suffix
|
|
27
|
-
if (cur.charCodeAt(idx) === _n) { skip(); return [, BigInt(str)]; }
|
|
28
26
|
return (a = +str) != a ? err() : [, a];
|
|
29
27
|
};
|
|
30
28
|
|
|
@@ -48,7 +46,6 @@ lookup[_0] = (a, base) => {
|
|
|
48
46
|
if (pre[0] === '0' && (cur.charCodeAt(idx + 1) | 32) === pre.charCodeAt(1)) {
|
|
49
47
|
skip(2);
|
|
50
48
|
const str = strip(next(charTest(base = parse.number[pre])));
|
|
51
|
-
if (cur.charCodeAt(idx) === _n) { skip(); return [, BigInt('0' + pre[1] + str)]; }
|
|
52
49
|
return [, parseInt(str, base)];
|
|
53
50
|
}
|
|
54
51
|
}
|
package/feature/string.js
CHANGED
|
@@ -13,37 +13,41 @@ const hex = c =>
|
|
|
13
13
|
c >= 65 && c <= 70 ? c - 55 :
|
|
14
14
|
c >= 97 && c <= 102 ? c - 87 : -1;
|
|
15
15
|
|
|
16
|
+
// Decode the escape at idx (a BSLASH) → [decodedText, sourceCharsConsumed].
|
|
17
|
+
// Malformed escapes fall back to the literal next char; line continuations
|
|
18
|
+
// (\<LF>, \<CR><LF>) decode to ''. Shared by string literals and template
|
|
19
|
+
// literal text chunks (feature/template.js) — cooked semantics are identical.
|
|
20
|
+
const decodeEscape = () => {
|
|
21
|
+
const n = cur.charCodeAt(idx + 1);
|
|
22
|
+
if (n === LF) return ['', 2];
|
|
23
|
+
if (n === CR) return ['', cur.charCodeAt(idx + 2) === LF ? 3 : 2];
|
|
24
|
+
// \xHH or \uHHHH
|
|
25
|
+
if (n === X || (n === U && cur.charCodeAt(idx + 2) !== LBRACE)) {
|
|
26
|
+
const w = n === X ? 2 : 4;
|
|
27
|
+
let cp = 0, h;
|
|
28
|
+
for (let k = 0; k < w; k++) {
|
|
29
|
+
if ((h = hex(cur.charCodeAt(idx + 2 + k))) < 0) return [cur[idx + 1], 2];
|
|
30
|
+
cp = cp * 16 + h;
|
|
31
|
+
}
|
|
32
|
+
return [String.fromCharCode(cp), 2 + w];
|
|
33
|
+
}
|
|
34
|
+
// \u{H...H}
|
|
35
|
+
if (n === U) {
|
|
36
|
+
let cp = 0, k = idx + 3, h;
|
|
37
|
+
while ((h = hex(cur.charCodeAt(k))) >= 0) cp = cp * 16 + h, k++;
|
|
38
|
+
if (k > idx + 3 && cp <= 0x10ffff && cur.charCodeAt(k) === RBRACE)
|
|
39
|
+
return [String.fromCodePoint(cp), k - idx + 1];
|
|
40
|
+
return [cur[idx + 1], 2];
|
|
41
|
+
}
|
|
42
|
+
return [esc[cur[idx + 1]] || cur[idx + 1], 2];
|
|
43
|
+
};
|
|
44
|
+
|
|
16
45
|
// `s` is the closed-over accumulator shared with the escape handler.
|
|
17
46
|
const parseString = q => (a, _, s = '', qc = String.fromCharCode(q)) => {
|
|
18
47
|
if (a || !parse.string?.[qc]) return;
|
|
19
48
|
skip();
|
|
20
49
|
|
|
21
|
-
|
|
22
|
-
// Malformed escapes fall back to literal next char.
|
|
23
|
-
const escape = () => {
|
|
24
|
-
const n = cur.charCodeAt(idx + 1);
|
|
25
|
-
if (n === LF) return 2;
|
|
26
|
-
if (n === CR) return cur.charCodeAt(idx + 2) === LF ? 3 : 2;
|
|
27
|
-
// \xHH or \uHHHH
|
|
28
|
-
if (n === X || (n === U && cur.charCodeAt(idx + 2) !== LBRACE)) {
|
|
29
|
-
const w = n === X ? 2 : 4;
|
|
30
|
-
let cp = 0, h;
|
|
31
|
-
for (let k = 0; k < w; k++) {
|
|
32
|
-
if ((h = hex(cur.charCodeAt(idx + 2 + k))) < 0) return s += cur[idx + 1], 2;
|
|
33
|
-
cp = cp * 16 + h;
|
|
34
|
-
}
|
|
35
|
-
return s += String.fromCharCode(cp), 2 + w;
|
|
36
|
-
}
|
|
37
|
-
// \u{H...H}
|
|
38
|
-
if (n === U) {
|
|
39
|
-
let cp = 0, k = idx + 3, h;
|
|
40
|
-
while ((h = hex(cur.charCodeAt(k))) >= 0) cp = cp * 16 + h, k++;
|
|
41
|
-
if (k > idx + 3 && cp <= 0x10ffff && cur.charCodeAt(k) === RBRACE)
|
|
42
|
-
return s += String.fromCodePoint(cp), k - idx + 1;
|
|
43
|
-
return s += cur[idx + 1], 2;
|
|
44
|
-
}
|
|
45
|
-
return s += esc[cur[idx + 1]] || cur[idx + 1], 2;
|
|
46
|
-
};
|
|
50
|
+
const escape = () => { const [t, w] = decodeEscape(); s += t; return w; };
|
|
47
51
|
|
|
48
52
|
// c - q is 0 at close, NaN at EOF — both falsy, terminating the loop.
|
|
49
53
|
next(c => c - q && (c !== BSLASH ? (s += cur[idx], 1) : escape()));
|
|
@@ -55,4 +59,4 @@ lookup[DQUOTE] = parseString(DQUOTE);
|
|
|
55
59
|
lookup[SQUOTE] = parseString(SQUOTE);
|
|
56
60
|
parse.string = { '"': true };
|
|
57
61
|
|
|
58
|
-
export { esc };
|
|
62
|
+
export { esc, decodeEscape };
|
package/feature/template.js
CHANGED
|
@@ -4,19 +4,22 @@
|
|
|
4
4
|
* Tagged: tag`...` → ['``', 'tag', ...]
|
|
5
5
|
*/
|
|
6
6
|
import { parse, skip, err, expr, lookup, cur, idx } from '../parse.js';
|
|
7
|
+
import { decodeEscape } from './string.js';
|
|
7
8
|
|
|
8
9
|
const ACCESS = 170, BACKTICK = 96, DOLLAR = 36, OBRACE = 123, BSLASH = 92;
|
|
9
|
-
const esc = { n: '\n', r: '\r', t: '\t', b: '\b', f: '\f', v: '\v' };
|
|
10
10
|
|
|
11
11
|
// Parse template body after opening ` — string and expression segments
|
|
12
12
|
// strictly alternate (string, expr, string, …), so every interpolation is
|
|
13
13
|
// flanked by a string part even when empty: `${x}${y}` → [,''] x [,''] y [,''].
|
|
14
|
+
// Escapes cook exactly like string literals (decodeEscape: \n \xHH \uHHHH
|
|
15
|
+
// \u{H…H}, line continuations) — a template chunk `` must yield the
|
|
16
|
+
// same code point as the '' literal.
|
|
14
17
|
const parseBody = () => {
|
|
15
18
|
const parts = [];
|
|
16
|
-
let s = '', c;
|
|
19
|
+
let s = '', c, e;
|
|
17
20
|
for (; (c = cur.charCodeAt(idx)) !== BACKTICK; )
|
|
18
21
|
!c ? err('Unterminated template') :
|
|
19
|
-
c === BSLASH ? (
|
|
22
|
+
c === BSLASH ? (e = decodeEscape(), s += e[0], skip(e[1])) :
|
|
20
23
|
c === DOLLAR && cur.charCodeAt(idx + 1) === OBRACE ? (parts.push([, s]), s = '', skip(2), parts.push(expr(0, 125))) :
|
|
21
24
|
(s += cur[idx], skip());
|
|
22
25
|
return parts.push([, s]), skip(), parts;
|
package/jessie.min.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
var l,
|
|
2
|
-
`),o=t.pop(),n=
|
|
3
|
-
${n}${
|
|
4
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},
|
|
5
|
-
`,"/*":"*/"};s.space=()=>{for(var r,e,t,o,n;r=
|
|
6
|
-
`?n:n+o.length),r=0;break}if(r)return r}return r};var
|
|
7
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},fe=()=>{let r=[],e="",t;for(;(t=c.charCodeAt(l))!==dr;)t?t===wt?(h(),e+=gt[c[l]]||c[l],h()):t===yt&&c.charCodeAt(l+1)===Ct?(r.push([,e]),e="",h(2),r.push(d(0,125))):(e+=c[l],h()):R("Unterminated template");return r.push([,e]),h(),r},Et=r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r],St=I[dr];I[dr]=(r,e)=>r&&e<At?s.asi&&s.newline?void 0:(h(),["``",r,...fe()]):r?St?.(r,e):(h(),Et(fe()));s.string["'"]=!0;s.number={"0x":16,"0b":2,"0o":8};var kt=92,Tt=117,Nt=123,It=125,Rt=183,Ot=s.id,le=r=>r>=48&&r<=57||r>=65&&r<=70||r>=97&&r<=102,_t=(r=l+2,e,t=0,o=0)=>{if(c.charCodeAt(l)!==kt||c.charCodeAt(l+1)!==Tt)return 0;if(c.charCodeAt(r)===Nt){for(;le(e=c.charCodeAt(++r));)t=t*16+(e<=57?e-48:(e&31)+9);return r>l+3&&t<=1114111&&c.charCodeAt(r)===It?r-l+1:0}for(;o<4&&le(c.charCodeAt(r+o));)o++;return o===4?6:0};s.id=r=>Ot(r)||r===Rt||_t();var hr=5,ce=10,Ar=r=>{let e=l,t=d(ce-1);return t==null?r:r==="let"&&(t==="in"||t==="of")?(T(e),r):t[0]===","?[r,...t.slice(1)]:[r,t]};C("let",hr+1,()=>Ar("let"));C("const",hr+1,()=>Ar("const"));C("var",hr+1,()=>Ar("var"));var ue=r=>Array.isArray(r)&&r[0]==="="&&typeof r[1]=="string";C("using",200,()=>{let r=l;s.space();let e=c.charCodeAt(l);if(s.id(e)&&(e<48||e>57)){let t=l;if(E(s.id),s.space(),c.charCodeAt(l)===61&&c.charCodeAt(l+1)!==61&&c.charCodeAt(l+1)!==62){T(t);let o=d(ce-1);if(o[0]===","?o.slice(1).every(ue):ue(o))return o[0]===","?["using",...o.slice(1)]:["using",o]}}return T(r),"using"});var q=5,vt=59,B=()=>(s.space()===123||R("Expected {"),h(),d(q-.5,125)||null),K=()=>s.space()!==123?d(q+.5):(h(),d(q-.5,125)||null),Lt=()=>{let r=l;return s.space()===vt&&h(),s.space(),S("else")?(h(4),s.semi=!1,!0):(T(r),!1)};C("if",q+1,()=>{s.space();let r=["if",v(),K()];return Lt()&&r.push(K()),r});var Pt=200;C("function",Pt,()=>{s.space();let r=!1;c[l]==="*"&&(r=!0,h(),s.space());let e=E(s.id);return e&&s.space(),r?["function*",e,v()||null,B()]:["function",e,v()||null,B()]});var b=140,yr=20,Bt=40;_("await",b);var Mt=10,Ut=13,Kt=r=>{let e;for(;(e=c.charCodeAt(r))<=32;){if(e===Mt||e===Ut)return!0;r++}return!1};C("yield",b,()=>Kt(l)?["yield"]:(s.space(),c[l]==="*"?(h(),s.space(),["yield*",d(yr)]):["yield",d(yr)]));C("async",b,()=>{if(s.space(),S("function"))return["async",d(b)];let r=l,e=E(s.id);if(e){if(s.space(),c.charCodeAt(l)===Bt)return["async",e];T(r)}let t=d(yr-.5);return t&&["async",t]});var me=200;var Dt=90,Ft=175,Gt=160,Ht=Gt-.5;_("static",Ft);A("instanceof",Dt);g("#",me,r=>{if(r)return;let e=E(s.id);return e?"#"+e:void 0});C("class",me,()=>{s.space();let r=E(s.id)||null;if(r==="extends")r=null,s.space();else{if(s.space(),!S("extends"))return["class",r,null,B()];h(7),s.space()}return["class",r,d(Ht),B()]});var Cr=47,Xt=92,Qt=91,$t=93;g("/",140,r=>{let e=c.charCodeAt(l);if(r||e===Cr||e===42||e===43||e===63)return;let t=!1,o=E(p=>p===Xt?2:p===Qt?(t=!0,1):p===$t?(t=!1,1):p&&(t||p!==Cr));c.charCodeAt(l)===Cr||R("Unterminated regex"),h();let n=E(p=>p===103||p===105||p===109||p===115||p===117||p===121);return n?["//",o,n]:["//",o]});var X=5,J=125,V=59;C("while",X+1,()=>(s.space(),["while",v(),K()]));C("do",X+1,r=>(r=K(),s.space(),h(5),s.space(),["do",r,v()]));var ae={let:1,const:1,var:1},wr=(r,e=r,t)=>{if(ae[r?.[0]]&&Array.isArray(r[1]))return(e=wr(r[1]))?.[0]==="in"||e?.[0]==="of"?[e[0],[r[0],e[1]],r.length>2?[",",e[2],...r.slice(2)]:e[2]]:r;for(;Array.isArray(e)&&L[e[0]]<L.in&&!ae[e[0]];)t=e,e=e[1];return t&&Array.isArray(e)&&(e[0]==="in"||e[0]==="of")?(t[1]=e[2],[e[0],e[1],r]):r};C("for",X+1,()=>(s.space(),S("await")?(h(5),s.space(),["for await",wr(v()),K()]):["for",wr(v()),K()]));C("break",X+1,()=>{s.asi&&(s.newline=!1);let r=l,e=s.space();if(!e||e===J||e===V||s.newline)return["break"];let t=E(s.id);if(!t)return["break"];let o=s.space();return!o||o===J||o===V||s.newline?["break",t]:(T(r),["break"])});C("continue",X+1,()=>{s.asi&&(s.newline=!1);let r=l,e=s.space();if(!e||e===J||e===V||s.newline)return["continue"];let t=E(s.id);if(!t)return["continue"];let o=s.space();return!o||o===J||o===V||s.newline?["continue",t]:(T(r),["continue"])});C("return",X+1,()=>{s.asi&&(s.newline=!1);let r=s.space();return!r||r===J||r===V||s.newline?["return"]:["return",d(X)]});var gr=5;C("try",gr+1,()=>{let r=["try",B()];return s.space(),S("catch")&&(h(5),s.space(),r.push(["catch",W()===40?v():null,B()])),s.space(),S("finally")&&(h(7),r.push(["finally",B()])),r});C("throw",gr+1,()=>{if(s.asi&&(s.newline=!1),s.space(),s.newline)throw SyntaxError("Unexpected newline after throw");return["throw",d(gr)]});var Ae=5,xt=20,de=58,jt=59,Er=125,Sr=0,ye=(r,e=r.length,t=r.charCodeAt(0),o=I[t])=>I[t]=(n,p,m)=>S(r)&&!n&&Sr&&(!s.prop||s.prop(l+e))||o?.(n,p,m);ye("case");ye("default");var he=r=>{let e=[];for(;(r=s.space())!==Er&&!S("case")&&!S("default");){if(r===jt){h();continue}s.semi=!1,e.push(d(Ae+.5))||R()}return e.length>1?[";",...e]:e[0]||null},Wt=()=>{s.space()===123||R("Expected {"),h(),Sr++;let r=[];try{for(;s.space()!==Er;)if(S("case")){T(l+4),s.space(),s.semi=!1;let e=d(xt-.5);s.space()===de&&h(),r.push(["case",e,he()])}else S("default")?(T(l+7),s.space()===de&&h(),r.push(["default",he()])):R("Expected case or default")}finally{Sr--}return h(),s.exit?.(0,Er),r};C("switch",Ae+1,()=>s.space()===40&&["switch",v(),...Wt()]);var kr=5,zt=20;C("debugger",kr+1,()=>["debugger"]);C("with",kr+1,()=>(s.space(),["with",v(),K()]));var Jt=["if","for","while","do","switch","try"];g(":",zt-1,r=>typeof r=="string"&&(s.space(),Jt.some(e=>S(e)))&&[":",r,d(kr)]);var Tr=5,j=10,Ce=42,Vt=I[Ce];I[Ce]=(r,e)=>r?Vt?.(r,e):(h(),"*");g("from",j+1,r=>r?r[0]!=="="&&r[0]!==","&&(s.space(),["from",r,d(j+1)]):!1);g("as",j+2,r=>r?(s.space(),["as",r,d(j+2)]):!1);C("import",Tr,()=>S(".meta")?(h(5),["import.meta"]):["import",d(j)]);C("export",Tr,()=>(s.space(),S("default")?(h(7),["export",["default",d(j)]]):["export",d(Tr)]));var Ir=20,we=200,Yt=10,Zt=13,qt=34,bt=35,ro=39,ge=40,Rr=41,eo=91,Or=123,_r=125,to=(r,e)=>{for(;r<e;){let t=c.charCodeAt(r++);if(t===Yt||t===Zt)return!0}return!1},oo=r=>r===qt||r===ro||r===eo||r===bt,Ee=()=>E(s.id)||(oo(c.charCodeAt(l))?d(we-.5):null),no=r=>typeof r=="string"||Array.isArray(r)&&(r[0]===void 0||r[0]==="[]"),Se=r=>e=>{if(e)return;let t=l;if(s.space(),s.semi||to(t,l))return!1;let o=Ee();if(!o||(s.space(),c.charCodeAt(l)!==ge))return!1;h();let n=d(0,Rr);return s.space(),c.charCodeAt(l)!==Or?!1:(h(),[r,o,n,d(0,_r)])};g("get",Ir-1,Se("get"));g("set",Ir-1,Se("set"));var Nr=r=>r==null||typeof r=="string"||Array.isArray(r)&&(r[0]===","?r.slice(1).every(Nr):r[0]==="="?typeof r[1]=="string"||Nr(r[1]):r[0]==="..."||r[0]==="{}"||r[0]==="[]"),io=L["*"];g("*",we,r=>{let e=r&&s.newline;if(r&&!e)return;let t=l,o=Ee();if(!o)return r?(T(t),void 0):!1;if(s.space(),c.charCodeAt(l)!==ge)return r?(T(t),void 0):!1;h();let n=d(0,Rr)||null;if(r&&!Nr(n))return T(t),void 0;if(s.space(),c.charCodeAt(l)!==Or)return r?(T(t),void 0):!1;h();let p=[":",o,["function*",null,n,d(0,_r)||null]];return r?r[0]===";"?(r.push(p),r):[";",r,p]:p});L["*"]=io;g("(",Ir-1,r=>{if(!r)return;let e,t;if(Array.isArray(r)&&r[0]==="static"&&(e="static",r=r[1]),Array.isArray(r)&&r[0]==="async"&&(t=!0,r=r[1]),!no(r))return;let o=d(0,Rr)||null;if(s.space(),c.charCodeAt(l)!==Or)return;h();let n=["=>",["()",o],d(0,_r)||null];t&&(n=["async",n]);let p=[":",r,n];return e?[e,p]:p});s.comment["#!"]=`
|
|
8
|
-
`;var Ie=32,Br=10,so=59,po=125,ke=91,Te=40,rr=L.asi??L[";"],fo=s._baseSpace??=s.space,lo=s._baseStep??=s.step,vr=r=>Array.isArray(r)||typeof r=="string",uo=(L[";"]??5)+1,Pr=r=>Array.isArray(r)&&(L[r[0]]<=uo||r[0]==="{}"&&Pr(r[1])),co=(r,e)=>{for(;(e=c.charCodeAt(r))<=Ie;){if(e===Br)return!0;r++}return!1},mo=(r=l,e)=>{for(;r-- >0&&(e=c.charCodeAt(r))<=Ie;)if(e===Br)return!0;return!1};s.space=(r,e)=>{for(;;){for(e=l,r=fo();e<l;)if(c.charCodeAt(e++)===Br){s.newline=!0;break}if(r===so&&co(l+1)){T(l+1),s.newline=s.semi=!0;continue}return r}};s.enter=()=>s.newline=s.semi=!1;s.exit=(r,e)=>{e===po&&(s.newline=!0,s.semi=!1)};s.step=(r,e,t,o)=>{if(s.semi&&e>=rr)return!1;if(r&&!vr(r))return null;if(vr(r)){let p=(t===ke||t===Te)&&mo();if(s.semi||t===ke&&(p||Pr(r))||t===Te&&(Pr(r)||p&&e>=rr))return Ne(r,e,o)??null}let n=s.newline;return lo(r,e,t,o)??(vr(r)&&n?Ne(r,e,o)??null:null)};var Lr=0,ao=2e3,Ne=s.asi=(r,e,t,o,n)=>{if(e>=rr||Lr>=ao)return;s.semi=!1;let p=l;Lr++;try{o=t(rr-.5)}finally{Lr--}if(!(!o||l===p))return n=o?.[0]===";"?o.slice(1):[o],r?.[0]===";"?(r.push(...n),r):[";",r,...n]};var Oe=(r,e,t,o)=>typeof r=="string"?n=>e(n,r,n):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o,n)):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n),n)):r[0]==="()"&&r.length===2?Oe(r[1],e):(()=>{throw Error("Invalid assignment target")})(),Re={"=":(r,e,t)=>r[e]=t,"+=":(r,e,t)=>r[e]+=t,"-=":(r,e,t)=>r[e]-=t,"*=":(r,e,t)=>r[e]*=t,"/=":(r,e,t)=>r[e]/=t,"%=":(r,e,t)=>r[e]%=t,"|=":(r,e,t)=>r[e]|=t,"&=":(r,e,t)=>r[e]&=t,"^=":(r,e,t)=>r[e]^=t,">>=":(r,e,t)=>r[e]>>=t,"<<=":(r,e,t)=>r[e]<<=t};for(let r in Re)f(r,(e,t)=>(t=i(t),Oe(e,(o,n,p)=>Re[r](o,n,t(p)))));f("!",r=>(r=i(r),e=>!r(e)));f("||",(r,e)=>(r=i(r),e=i(e),t=>r(t)||e(t)));f("&&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&&e(t)));f("~",r=>(r=i(r),e=>~r(e)));f("|",(r,e)=>(r=i(r),e=i(e),t=>r(t)|e(t)));f("&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&e(t)));f("^",(r,e)=>(r=i(r),e=i(e),t=>r(t)^e(t)));f(">>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>e(t)));f("<<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<<e(t)));f(">",(r,e)=>(r=i(r),e=i(e),t=>r(t)>e(t)));f("<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<e(t)));f(">=",(r,e)=>(r=i(r),e=i(e),t=>r(t)>=e(t)));f("<=",(r,e)=>(r=i(r),e=i(e),t=>r(t)<=e(t)));f("==",(r,e)=>(r=i(r),e=i(e),t=>r(t)==e(t)));f("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(t)));f("+",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)+e(t)):(r=i(r),t=>+r(t)));f("-",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)-e(t)):(r=i(r),t=>-r(t)));f("*",(r,e)=>(r=i(r),e=i(e),t=>r(t)*e(t)));f("/",(r,e)=>(r=i(r),e=i(e),t=>r(t)/e(t)));f("%",(r,e)=>(r=i(r),e=i(e),t=>r(t)%e(t)));var Mr=(r,e,t,o)=>typeof r=="string"?n=>e(n,r):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o)):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n))):r[0]==="()"&&r.length===2?Mr(r[1],e):(()=>{throw Error("Invalid increment target")})();f("++",(r,e)=>Mr(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));f("--",(r,e)=>Mr(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var _e=(...r)=>(r=r.map(i),e=>{let t;for(let o of r)t=o(e);return t});f(",",_e);f(";",_e);var Q=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",er=r=>{throw Error(r)};f("[]",(r,e)=>e===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(t=>t==null?(()=>{}):t[0]==="..."?(t=i(t[1]),o=>t(o)):(t=i(t),o=>[t(o)])),t=>r.flatMap(o=>o(t))):(e==null&&er("Missing index"),r=i(r),e=i(e),t=>{let o=e(t);return Q(o)?void 0:r(t)[o]}));f(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],Q(e)?()=>{}:t=>r(t)[e]));f("()",(r,e)=>{if(e===void 0)return r==null?er("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(p=>p==null||t(p));t(e)&&er("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(p=>p(n))):(e=i(e),n=>[e(n)]):()=>[];return Ur(r,(n,p,m)=>n[p](...o(m)))});var M=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&M(r[1])||r[0]==="{}"),Ur=(r,e,t,o)=>r==null?er("Empty ()"):r[0]==="()"&&r.length==2?Ur(r[1],e):typeof r=="string"?n=>e(n,r,n):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o,n)):r[0]==="?."?(t=i(r[1]),o=r[2],n=>{let p=t(n);return p==null?void 0:e(p,o,n)}):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n),n)):r[0]==="?.[]"?(t=i(r[1]),o=i(r[2]),n=>{let p=t(n);return p==null?void 0:e(p,o(n),n)}):(r=i(r),n=>e([r(n)],0,n)),D=Ur;f("===",(r,e)=>(r=i(r),e=i(e),t=>r(t)===e(t)));f("!==",(r,e)=>(r=i(r),e=i(e),t=>r(t)!==e(t)));f("??",(r,e)=>(r=i(r),e=i(e),t=>r(t)??e(t)));var ho=r=>{throw Error(r)};f("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));f("**=",(r,e)=>(M(r)||ho("Invalid assignment target"),e=i(e),D(r,(t,o,n)=>t[o]**=e(n))));f("in",(r,e)=>(r=i(r),e=i(e),t=>r(t)in e(t)));var Ao=r=>{throw Error(r)};f(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));f(">>>=",(r,e)=>(M(r)||Ao("Invalid assignment target"),e=i(e),D(r,(t,o,n)=>t[o]>>>=e(n))));var yo=r=>r[0]?.[0]===","?r[0].slice(1):r,F=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...n]=r,p=yo(n);if(o==="{}"){let m=[];for(let u of p){if(Array.isArray(u)&&u[0]==="..."){let w={};for(let O in e)m.includes(O)||(w[O]=e[O]);t[u[1]]=w;break}let a,y,N;typeof u=="string"?a=y=u:u[0]==="="?(typeof u[1]=="string"?a=y=u[1]:[,a,y]=u[1],N=u[2]):[,a,y]=u,m.push(a);let k=e[a];k===void 0&&N&&(k=i(N)(t)),F(y,k,t)}}else if(o==="[]"){let m=0;for(let u of p){if(u===null){m++;continue}if(Array.isArray(u)&&u[0]==="..."){t[u[1]]=e.slice(m);break}let a=u,y;Array.isArray(u)&&u[0]==="="&&([,a,y]=u);let N=e[m++];N===void 0&&y&&(N=i(y)(t)),F(a,N,t)}}},Kr=(...r)=>(r=r.map(e=>{if(typeof e=="string")return t=>{t[e]=void 0};if(e[0]==="="){let[,t,o]=e,n=i(o);return typeof t=="string"?p=>{p[t]=n(p)}:p=>F(t,n(p),p)}return i(e)}),e=>{for(let t of r)t(e)});f("let",Kr);f("const",Kr);f("var",Kr);var tr=r=>{throw Error(r)};f("=",(r,e)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let t=r[1];return e=i(e),typeof t=="string"?o=>{o[t]=e(o)}:o=>F(t,e(o),o)}return M(r)||tr("Invalid assignment target"),e=i(e),D(r,(t,o,n)=>t[o]=e(n))});f("||=",(r,e)=>(M(r)||tr("Invalid assignment target"),e=i(e),D(r,(t,o,n)=>t[o]||=e(n))));f("&&=",(r,e)=>(M(r)||tr("Invalid assignment target"),e=i(e),D(r,(t,o,n)=>t[o]&&=e(n))));f("??=",(r,e)=>(M(r)||tr("Invalid assignment target"),e=i(e),D(r,(t,o,n)=>t[o]??=e(n))));f("?",(r,e,t)=>(r=i(r),e=i(e),t=i(t),o=>r(o)?e(o):t(o)));var P=[];f("=>",(r,e)=>{r=r?.[0]==="()"?r[1]:r;let t=r?r[0]===","?r.slice(1):[r]:[],o=-1,n=null,p=t[t.length-1];Array.isArray(p)&&p[0]==="..."&&(o=t.length-1,n=p[1],t.length--);let m=e?.[0]==="{}";return e=i(m?["{",e[1]]:e),u=>(...a)=>{let y={};t.forEach((k,w)=>y[k]=a[w]),n&&(y[n]=a.slice(o));let N=new Proxy(y,{get:(k,w)=>w in k?k[w]:u?.[w],set:(k,w,O)=>((w in k?k:u)[w]=O,!0),has:(k,w)=>w in k||(u?w in u:!1)});try{let k=e(N);return m?void 0:k}catch(k){if(k===P)return k[0];throw k}}});f("...",r=>(r=i(r),e=>Object.entries(r(e))));f("?.",(r,e)=>(r=i(r),Q(e)?()=>{}:t=>r(t)?.[e]));f("?.[]",(r,e)=>(r=i(r),e=i(e),t=>{let o=e(t);return Q(o)?void 0:r(t)?.[o]}));f("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(p=>p(n))):(e=i(e),n=>[e(n)]):()=>[];if(r[0]==="."||r[0]==="?."){let n=i(r[1]),p=r[2];return Q(p)?()=>{}:m=>n(m)?.[p]?.(...t(m))}if((r[0]==="[]"||r[0]==="?.[]")&&r.length===3){let n=i(r[1]),p=i(r[2]);return m=>{let u=p(m);return Q(u)?void 0:n(m)?.[u]?.(...t(m))}}let o=i(r);return n=>o(n)?.(...t(n))});f("typeof",r=>(r=i(r),e=>typeof r(e)));f("void",r=>(r=i(r),e=>(r(e),void 0)));f("delete",r=>{if(r[0]==="."){let e=i(r[1]),t=r[2];return o=>delete e(o)[t]}if(r[0]==="[]"){let e=i(r[1]),t=i(r[2]);return o=>delete e(o)[t(o)]}return()=>!0});f("new",r=>{let e=i(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,o=t?t[0]===","?(n=>p=>n.map(m=>m(p)))(t.slice(1).map(i)):(n=>p=>[n(p)])(i(t)):()=>[];return n=>new(e(n))(...o(n))});var or=Symbol("accessor");f("get",(r,e)=>(e=e?i(e):()=>{},t=>[[or,r,{get:function(){let o=Object.create(t||{});return o.this=this,e(o)}}]]));f("set",(r,e,t)=>(t=t?i(t):()=>{},o=>[[or,r,{set:function(n){let p=Object.create(o||{});p.this=this,p[e]=n,t(p)}}]]));var Co=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);f("{}",(r,e)=>{if(e!==void 0)return;if(!Co(r))return i(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(o=>i(typeof o=="string"?[":",o,o]:o));return o=>{let n={},p={};for(let m of t.flatMap(u=>u(o)))if(m[0]===or){let[,u,a]=m;p[u]={...p[u],...a,configurable:!0,enumerable:!0}}else n[m[0]]=m[1];for(let m in p)Object.defineProperty(n,m,p[m]);return n}});f("{",r=>(r=r?i(r):()=>{},e=>r(Object.create(e))));f(":",(r,e)=>(e=i(e),Array.isArray(r)?(r=i(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));f("`",(...r)=>(r=r.map(i),e=>r.map(t=>t(e)).join("")));f("``",(r,...e)=>{r=i(r);let t=[],o=[];for(let p of e)Array.isArray(p)&&p[0]===void 0?t.push(p[1]):o.push(i(p));let n=Object.assign([...t],{raw:t});return p=>r(p)(n,...o.map(m=>m(p)))});f("function",(r,e,t)=>{t=t?i(t):()=>{};let o=e?e[0]===","?e.slice(1):[e]:[],n=null,p=-1,m=o[o.length-1];return Array.isArray(m)&&m[0]==="..."&&(p=o.length-1,n=m[1],o.length--),u=>{let a=(...y)=>{let N={};o.forEach((w,O)=>N[w]=y[O]),n&&(N[n]=y.slice(p));let k=new Proxy(N,{get:(w,O)=>O in w?w[O]:u[O],set:(w,O,Pe)=>((O in w?w:u)[O]=Pe,!0),has:(w,O)=>O in w||O in u});try{return t(k)}catch(w){if(w===P)return w[0];throw w}};return r&&(u[r]=a),a}});f("function*",(r,e,t)=>{throw Error("Generator functions are not supported in evaluation")});f("async",r=>{let e=i(r);return t=>{let o=e(t);return async function(...n){return o(...n)}}});f("await",r=>(r=i(r),async e=>await r(e)));f("yield",r=>(r=r?i(r):null,e=>{throw{__yield__:r?r(e):void 0}}));f("yield*",r=>(r=i(r),e=>{throw{__yield_all__:r(e)}}));var wo=Symbol("static"),go=r=>{throw Error(r)};f("instanceof",(r,e)=>(r=i(r),e=i(e),t=>r(t)instanceof e(t)));f("class",(r,e,t)=>(e=e?i(e):null,t=t?i(t):null,o=>{let n=e?e(o):Object,p=function(...m){if(!(this instanceof p))return go("Class constructor must be called with new");let u=e?Reflect.construct(n,m,p):this;return p.prototype.__constructor__&&p.prototype.__constructor__.apply(u,m),u};if(Object.setPrototypeOf(p.prototype,n.prototype),Object.setPrototypeOf(p,n),t){let m=Object.create(o);m.super=n;let u=t(m),a=Array.isArray(u)&&typeof u[0]?.[0]=="string"?u:[];for(let[y,N]of a)y==="constructor"?p.prototype.__constructor__=N:p.prototype[y]=N}return r&&(o[r]=p),p}));f("static",r=>(r=i(r),e=>[[wo,r(e)]]));f("//",(r,e)=>{let t=new RegExp(r,e||"");return()=>t});f("if",(r,e,t)=>(r=i(r),e=i(e),t=t!==void 0?i(t):null,o=>r(o)?e(o):t?.(o)));var U=Symbol("break"),G=Symbol("continue");f("while",(r,e)=>(r=i(r),e=i(e),t=>{let o;for(;r(t);)try{o=e(t)}catch(n){if(n===U)break;if(n===G)continue;if(n===P)return n[0];throw n}return o}));f("do",(r,e)=>(r=i(r),e=i(e),t=>{let o;do try{o=r(t)}catch(n){if(n===U)break;if(n===G)continue;if(n===P)return n[0];throw n}while(e(t));return o}));f("for",(r,e)=>{if(Array.isArray(r)&&r[0]===";"){let[,t,o,n]=r;return t=t?i(t):null,o=o?i(o):()=>!0,n=n?i(n):null,e=i(e),p=>{let m;for(t?.(p);o(p);n?.(p))try{m=e(p)}catch(u){if(u===U)break;if(u===G)continue;if(u===P)return u[0];throw u}return m}}if(Array.isArray(r)&&(r[0]==="in"||r[0]==="of")){let[t,o,n]=r;if(Array.isArray(o)&&(o[0]==="let"||o[0]==="const"||o[0]==="var")&&(o=o[1]),t==="in")return So(o,n,e);if(t==="of")return Eo(o,n,e)}});var Eo=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let p,m=o?null:n[r];for(let u of e(n)){o?F(r,u,n):n[r]=u;try{p=t(n)}catch(a){if(a===U)break;if(a===G)continue;if(a===P)return a[0];throw a}}return o||(n[r]=m),p}},So=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let p,m=o?null:n[r];for(let u in e(n)){o?F(r,u,n):n[r]=u;try{p=t(n)}catch(a){if(a===U)break;if(a===G)continue;if(a===P)return a[0];throw a}}return o||(n[r]=m),p}};f("break",()=>()=>{throw U});f("continue",()=>()=>{throw G});f("return",r=>(r=r!==void 0?i(r):null,e=>{throw P[0]=r?.(e),P}));f("try",(r,...e)=>{r=r?i(r):null;let t=e.find(u=>u?.[0]==="catch"),o=e.find(u=>u?.[0]==="finally"),n=t?.[1],p=t?.[2]?i(t[2]):null,m=o?.[1]?i(o[1]):null;return u=>{let a;try{a=r?.(u)}catch(y){if(y===U||y===G||y===P)throw y;if(n!=null&&p){let N=n in u,k=u[n];u[n]=y;try{a=p(u)}finally{N?u[n]=k:delete u[n]}}else if(!p)throw y}finally{m?.(u)}return a}});f("throw",r=>(r=i(r),e=>{throw r(e)}));f("switch",(r,...e)=>(r=i(r),e.length?(e=e.map(t=>[t[0]==="case"?i(t[1]):null,(t[0]==="case"?t[2]:t[1])?.[0]===";"?(t[0]==="case"?t[2]:t[1]).slice(1).map(i):(t[0]==="case"?t[2]:t[1])?[i(t[0]==="case"?t[2]:t[1])]:[]]),t=>{let o=r(t),n=!1,p;for(let[u,a]of e)if(n||u===null||u(t)===o)for(n=!0,m=0;m<a.length;m++)try{p=a[m](t)}catch(y){if(y===U)return p;throw y}var m;return p}):t=>r(t)));f("import",()=>()=>{});f("export",()=>()=>{});f("from",(r,e)=>()=>{});f("as",(r,e)=>()=>{});f("default",r=>i(r));var ve=new WeakMap,ko=(r,...e)=>typeof r=="string"?i(s(r)):ve.get(r)||ve.set(r,To(r,e)).get(r),Le=57344,To=(r,e)=>{let t=r.reduce((p,m,u)=>p+(u?String.fromCharCode(Le+u-1):"")+m,""),o=s(t),n=p=>{if(typeof p=="string"&&p.length===1){let m=p.charCodeAt(0)-Le,u;if(m>=0&&m<e.length)return u=e[m],No(u)?u:[,u]}return Array.isArray(p)?p.map(n):p};return i(n(o))},No=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Io=ko;export{sr as access,A as binary,i as compile,c as cur,Io as default,R as err,d as expr,z as group,Ro as id,l as idx,C as keyword,$ as literal,Be as loc,I as lookup,Fr as member,ir as nary,E as next,f as operator,nr as operators,v as parens,s as parse,W as peek,L as prec,pr as propName,T as seek,h as skip,g as token,_ as unary,S as word};
|
|
1
|
+
var l,m,s=r=>(l=0,m=r,s.enter?.(),r=d(),m[l]?O():r||""),O=(r="Unexpected token",e=l,t=m.slice(0,e).split(`
|
|
2
|
+
`),o=t.pop(),n=m.slice(Math.max(0,e-40),e),p="\u032D",c=(m[e]||" ")+p,u=m.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
|
|
3
|
+
${n}${c}${u}`)},De=(r,e=l)=>(Array.isArray(r)&&(r.loc=e),r),E=(r,e=l,t)=>{for(;t=r(m.charCodeAt(l));)l+=t;return m.slice(e,l)},h=(r=1)=>m[l+=r],T=r=>l=r,d=(r=0,e)=>{let t,o,n;for(e&&s.enter?.(r,e);(t=s.space())&&t!==e&&(n=s.step(o,r,t,d));)o=n;return e&&(t==e?(l++,s.exit?.(r,e)):O("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},z=(r=l)=>{for(;m.charCodeAt(r)<=32;)r++;return m.charCodeAt(r)},Po=s.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,S=(r,e=r.length)=>m.substr(l,e)===r&&!s.id(m.charCodeAt(l+e)),L=()=>(h(),d(0,41)),N=[],v={},g=(r,e=32,t,o=r.charCodeAt(0))=>$r({op:r,l:r.length,p:v[r]=!N[o]&&v[r]||e,map:t,word:r.toUpperCase()!==r,kw:!1}),A=(r,e,t=!1)=>g(r,e,(o,n)=>o&&(n=d(e-(t?.5:0)))&&[r,o,n]),_=(r,e,t)=>g(r,e,o=>t?o&&[r,o]:!o&&(o=d(e-.5))&&[r,o]),j=(r,e)=>g(r,200,t=>!t&&[,e]),sr=(r,e,t,o)=>g(r,e,(n,p,c=n)=>(p=d(e-(t?.5:0)),n?.[0]!==r&&(n=[r,n||null]),p?.[0]===r?n.push(...p.slice(1)):p?n.push(p):o||z()===r.charCodeAt(0)?n.push(null):c&&n.length===2&&(n=n[1]),n)),J=(r,e)=>g(r[0],e,t=>!t&&[r,d(0,r.charCodeAt(1))||null]),pr=(r,e)=>g(r[0],e,t=>t&&[r,t,d(0,r.charCodeAt(1))||null]),fr=(r,e)=>(s.space(),e=m.charCodeAt(l),s.id(e)&&(e<48||e>57)?E(s.id):d(r)),Qr=(r,e)=>g(r,e,(t,o)=>t&&(o=fr(e))&&[r,t,o]),w=(r,e,t)=>(v[r]??=e,$r({op:r,l:r.length,p:e,map:t,word:!0,kw:!0})),Xr=(r,e,t=(o,n,p,c=l,u,a,y)=>{for(y=0;a=r[y++];)if(!(a.kw&&o)&&!(p?a.op!==p:!((a.l<2||a.op.charCodeAt(1)===m.charCodeAt(l+1)&&(a.l<3||m.substr(l,a.l)===a.op))&&(!a.word||!s.id(m.charCodeAt(l+a.l)))&&(p=a.op)))&&!(n>=a.p)&&!(a.kw&&s.prop&&!s.prop(l+a.l))){if(l+=a.l,u=a.map(o))return De(u,c);l=c,p=0,a.word||o||e||r[y]||O()}return e?.(o,n,p)})=>(t.ops=r,t.tail=e,t),$r=(r,e=r.op.charCodeAt(0),t=N[e])=>N[e]=t?.ops?Xr([r,...t.ops],t.tail):Xr([r],t);s.space=r=>{for(;(r=m.charCodeAt(l))<=32;)l++;return r};s.step=(r,e,t,o,n)=>(n=N[t])&&n(r,e)||(r?null:E(s.id)||null);var ir={},f=(r,e,t=ir[r])=>ir[r]=(...o)=>e(...o)||t?.(...o),i=r=>Array.isArray(r)?r[0]==null?(e=>()=>e)(r[1]):ir[r[0]]?.(...r.slice(1))??O(`Unknown operator: ${r[0]}`,r?.loc):i.id(r);i.id=r=>r===void 0?()=>{}:e=>e?.[r];var lr=46,Q=48,x=57,jr=69,xr=101,Ge=43,Fe=45,Wr=95,He=97,Xe=102,Qe=65,$e=70,zr=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),je=r=>r===lr&&(r=m.charCodeAt(l+1))!==lr&&!(s.id(r)&&r>x&&r!==xr&&r!==jr)||r>=Q&&r<=x||r===Wr||((r===jr||r===xr)&&((r=m.charCodeAt(l+1))>=Q&&r<=x||r===Ge||r===Fe)?2:0),ur=r=>(r=+zr(E(je)))!=r?O():[,r],xe=r=>e=>e===Wr||e>=Q&&e<=x&&e-Q<r||r===16&&(e>=He&&e<=Xe||e>=Qe&&e<=$e);s.number=null;N[lr]=r=>!r&&m.charCodeAt(l+1)>=Q&&m.charCodeAt(l+1)<=x&&ur();for(let r=Q;r<=x;r++)N[r]=e=>e?void 0:ur();N[Q]=(r,e)=>{if(!r){for(let t in s.number)if(t[0]==="0"&&(m.charCodeAt(l+1)|32)===t.charCodeAt(1)){h(2);let o=zr(E(xe(e=s.number[t])));return[,parseInt(o,e)]}return ur()}};var We=92,Jr=34,Vr=39,Yr=117,Zr=120,ze=123,Je=125,qr=10,Ve=13,Ye={n:`
|
|
4
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},br=r=>r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:-1,cr=()=>{let r=m.charCodeAt(l+1);if(r===qr)return["",2];if(r===Ve)return["",m.charCodeAt(l+2)===qr?3:2];if(r===Zr||r===Yr&&m.charCodeAt(l+2)!==ze){let e=r===Zr?2:4,t=0,o;for(let n=0;n<e;n++){if((o=br(m.charCodeAt(l+2+n)))<0)return[m[l+1],2];t=t*16+o}return[String.fromCharCode(t),2+e]}if(r===Yr){let e=0,t=l+3,o;for(;(o=br(m.charCodeAt(t)))>=0;)e=e*16+o,t++;return t>l+3&&e<=1114111&&m.charCodeAt(t)===Je?[String.fromCodePoint(e),t-l+1]:[m[l+1],2]}return[Ye[m[l+1]]||m[l+1],2]},re=r=>(e,t,o="",n=String.fromCharCode(r))=>{if(e||!s.string?.[n])return;h();let p=()=>{let[c,u]=cr();return o+=c,u};return E(c=>c-r&&(c!==We?(o+=m[l],1):p())),m[l]===n?h():O("Bad string"),[,o]};N[Jr]=re(Jr);N[Vr]=re(Vr);s.string={'"':!0};var Ze=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>A(r,Ze,!0));var qe=30,be=40,rt=140;_("!",rt);A("||",qe);A("&&",be);var et=50,tt=60,ot=70,ee=100,nt=140;A("|",et);A("&",ot);A("^",tt);A(">>",ee);A("<<",ee);_("~",nt);var Z=90;A("<",Z);A(">",Z);A("<=",Z);A(">=",Z);var te=80;A("==",te);A("!=",te);var oe=110,mr=120,ne=140;A("+",oe);A("-",oe);A("*",mr);A("/",mr);A("%",mr);_("+",ne);_("-",ne);var q=150;g("++",q,r=>r?["++",r,null]:["++",d(q-1)]);g("--",q,r=>r?["--",r,null]:["--",d(q-1)]);var it=5,st=10;sr(",",st);sr(";",it,!0,!0);var pt=170;J("()",pt);var ie=170,ft=160;pr("[]",ie);Qr(".",ie);pr("()",ft);var lt=s.space;s.comment??={"//":`
|
|
5
|
+
`,"/*":"*/"};s.space=()=>{for(var r,e,t,o,n;r=lt();){for(t in e=s.comment)if(r===t.charCodeAt(0)&&(t.length<2||m.charCodeAt(l+1)===t.charCodeAt(1))&&(t.length<3||m.substr(l,t.length)===t)){o=e[t],n=m.indexOf(o,l+t.length),T(n<0?m.length:o===`
|
|
6
|
+
`?n:n+o.length),r=0;break}if(r)return r}return r};var se=80;A("===",se);A("!==",se);var ut=30;A("??",ut);var ct=130,mt=20;A("**",ct,!0);A("**=",mt,!0);var pe=90;A("in",pe);A("of",pe);var at=20,dt=100;A(">>>",dt);A(">>>=",at,!0);var ar=20;A("||=",ar,!0);A("&&=",ar,!0);A("??=",ar,!0);j("true",!0);j("false",!1);j("null",null);w("undefined",200,()=>[]);j("NaN",NaN);j("Infinity",1/0);var dr=20;g("?",dr,(r,e,t)=>r&&(e=d(dr-1))&&E(o=>o===58)&&(t=d(dr-1),["?",r,e,t]));var ht=20;A("=>",ht,!0);var At=20;_("...",At);var fe=170;g("?.",fe,(r,e)=>{if(!r)return;let t=s.space();return t===40?(h(),["?.()",r,d(0,41)||null]):t===91?(h(),["?.[]",r,d(0,93)]):(e=fr(fe),e?["?.",r,e]:void 0)});var hr=140,le=160,yt=le+1;_("typeof",hr);_("void",hr);_("delete",hr);var wt=r=>s.space()===40?(h(),["()",r,d(0,41)||null]):r;w("new",yt,()=>S(".target")?(h(7),["new.target"]):["new",wt(d(le))]);var Ct=20,ue=200;s.prop=r=>z(r)!==58;J("[]",ue);J("{}",ue);A(":",Ct-1,!0);var gt=170,Ar=96,Et=36,St=123,kt=92,ce=()=>{let r=[],e="",t,o;for(;(t=m.charCodeAt(l))!==Ar;)t?t===kt?(o=cr(),e+=o[0],h(o[1])):t===Et&&m.charCodeAt(l+1)===St?(r.push([,e]),e="",h(2),r.push(d(0,125))):(e+=m[l],h()):O("Unterminated template");return r.push([,e]),h(),r},Tt=r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r],Nt=N[Ar];N[Ar]=(r,e)=>r&&e<gt?s.asi&&s.newline?void 0:(h(),["``",r,...ce()]):r?Nt?.(r,e):(h(),Tt(ce()));s.string["'"]=!0;s.number={"0x":16,"0b":2,"0o":8};var Rt=92,It=117,Ot=123,_t=125,Lt=183,Pt=s.id,me=r=>r>=48&&r<=57||r>=65&&r<=70||r>=97&&r<=102,vt=(r=l+2,e,t=0,o=0)=>{if(m.charCodeAt(l)!==Rt||m.charCodeAt(l+1)!==It)return 0;if(m.charCodeAt(r)===Ot){for(;me(e=m.charCodeAt(++r));)t=t*16+(e<=57?e-48:(e&31)+9);return r>l+3&&t<=1114111&&m.charCodeAt(r)===_t?r-l+1:0}for(;o<4&&me(m.charCodeAt(r+o));)o++;return o===4?6:0};s.id=r=>Pt(r)||r===Lt||vt();var yr=5,de=10,wr=r=>{let e=l,t=d(de-1);return t==null?r:r==="let"&&(t==="in"||t==="of")?(T(e),r):t[0]===","?[r,...t.slice(1)]:[r,t]};w("let",yr+1,()=>wr("let"));w("const",yr+1,()=>wr("const"));w("var",yr+1,()=>wr("var"));var ae=r=>Array.isArray(r)&&r[0]==="="&&typeof r[1]=="string";w("using",200,()=>{let r=l;s.space();let e=m.charCodeAt(l);if(s.id(e)&&(e<48||e>57)){let t=l;if(E(s.id),s.space(),m.charCodeAt(l)===61&&m.charCodeAt(l+1)!==61&&m.charCodeAt(l+1)!==62){T(t);let o=d(de-1);if(o[0]===","?o.slice(1).every(ae):ae(o))return o[0]===","?["using",...o.slice(1)]:["using",o]}}return T(r),"using"});var b=5,Bt=59,U=()=>(s.space()===123||O("Expected {"),h(),d(b-.5,125)||null),G=()=>s.space()!==123?d(b+.5):(h(),d(b-.5,125)||null),Mt=()=>{let r=l;return s.space()===Bt&&h(),s.space(),S("else")?(h(4),s.semi=!1,!0):(T(r),!1)};w("if",b+1,()=>{s.space();let r=["if",L(),G()];return Mt()&&r.push(G()),r});var Ut=200;w("function",Ut,()=>{s.space();let r=!1;m[l]==="*"&&(r=!0,h(),s.space());let e=E(s.id);return e&&s.space(),r?["function*",e,L()||null,U()]:["function",e,L()||null,U()]});var rr=140,Cr=20,Kt=40;_("await",rr);var Dt=10,Gt=13,Ft=r=>{let e;for(;(e=m.charCodeAt(r))<=32;){if(e===Dt||e===Gt)return!0;r++}return!1};w("yield",rr,()=>Ft(l)?["yield"]:(s.space(),m[l]==="*"?(h(),s.space(),["yield*",d(Cr)]):["yield",d(Cr)]));w("async",rr,()=>{if(s.space(),S("function"))return["async",d(rr)];let r=l,e=E(s.id);if(e){if(s.space(),m.charCodeAt(l)===Kt)return["async",e];T(r)}let t=d(Cr-.5);return t&&["async",t]});var he=200;var Ht=90,Xt=175,Qt=160,$t=Qt-.5;_("static",Xt);A("instanceof",Ht);g("#",he,r=>{if(r)return;let e=E(s.id);return e?"#"+e:void 0});w("class",he,()=>{s.space();let r=E(s.id)||null;if(r==="extends")r=null,s.space();else{if(s.space(),!S("extends"))return["class",r,null,U()];h(7),s.space()}return["class",r,d($t),U()]});var gr=47,jt=92,xt=91,Wt=93;g("/",140,r=>{let e=m.charCodeAt(l);if(r||e===gr||e===42||e===43||e===63)return;let t=!1,o=E(p=>p===jt?2:p===xt?(t=!0,1):p===Wt?(t=!1,1):p&&(t||p!==gr));m.charCodeAt(l)===gr||O("Unterminated regex"),h();let n=E(p=>p===103||p===105||p===109||p===115||p===117||p===121);return n?["//",o,n]:["//",o]});var $=5,V=125,Y=59;w("while",$+1,()=>(s.space(),["while",L(),G()]));w("do",$+1,r=>(r=G(),s.space(),h(5),s.space(),["do",r,L()]));var Ae={let:1,const:1,var:1},Er=(r,e=r,t)=>{if(Ae[r?.[0]]&&Array.isArray(r[1]))return(e=Er(r[1]))?.[0]==="in"||e?.[0]==="of"?[e[0],[r[0],e[1]],r.length>2?[",",e[2],...r.slice(2)]:e[2]]:r;for(;Array.isArray(e)&&v[e[0]]<v.in&&!Ae[e[0]];)t=e,e=e[1];return t&&Array.isArray(e)&&(e[0]==="in"||e[0]==="of")?(t[1]=e[2],[e[0],e[1],r]):r};w("for",$+1,()=>(s.space(),S("await")?(h(5),s.space(),["for await",Er(L()),G()]):["for",Er(L()),G()]));w("break",$+1,()=>{s.asi&&(s.newline=!1);let r=l,e=s.space();if(!e||e===V||e===Y||s.newline)return["break"];let t=E(s.id);if(!t)return["break"];let o=s.space();return!o||o===V||o===Y||s.newline?["break",t]:(T(r),["break"])});w("continue",$+1,()=>{s.asi&&(s.newline=!1);let r=l,e=s.space();if(!e||e===V||e===Y||s.newline)return["continue"];let t=E(s.id);if(!t)return["continue"];let o=s.space();return!o||o===V||o===Y||s.newline?["continue",t]:(T(r),["continue"])});w("return",$+1,()=>{s.asi&&(s.newline=!1);let r=s.space();return!r||r===V||r===Y||s.newline?["return"]:["return",d($)]});var Sr=5;w("try",Sr+1,()=>{let r=["try",U()];return s.space(),S("catch")&&(h(5),s.space(),r.push(["catch",z()===40?L():null,U()])),s.space(),S("finally")&&(h(7),r.push(["finally",U()])),r});w("throw",Sr+1,()=>{if(s.asi&&(s.newline=!1),s.space(),s.newline)throw SyntaxError("Unexpected newline after throw");return["throw",d(Sr)]});var Ce=5,zt=20,ye=58,Jt=59,kr=125,Tr=0,ge=(r,e=r.length,t=r.charCodeAt(0),o=N[t])=>N[t]=(n,p,c)=>S(r)&&!n&&Tr&&(!s.prop||s.prop(l+e))||o?.(n,p,c);ge("case");ge("default");var we=r=>{let e=[];for(;(r=s.space())!==kr&&!S("case")&&!S("default");){if(r===Jt){h();continue}s.semi=!1,e.push(d(Ce+.5))||O()}return e.length>1?[";",...e]:e[0]||null},Vt=()=>{s.space()===123||O("Expected {"),h(),Tr++;let r=[];try{for(;s.space()!==kr;)if(S("case")){T(l+4),s.space(),s.semi=!1;let e=d(zt-.5);s.space()===ye&&h(),r.push(["case",e,we()])}else S("default")?(T(l+7),s.space()===ye&&h(),r.push(["default",we()])):O("Expected case or default")}finally{Tr--}return h(),s.exit?.(0,kr),r};w("switch",Ce+1,()=>s.space()===40&&["switch",L(),...Vt()]);var Nr=5,Yt=20;w("debugger",Nr+1,()=>["debugger"]);w("with",Nr+1,()=>(s.space(),["with",L(),G()]));var Zt=["if","for","while","do","switch","try"];g(":",Yt-1,r=>typeof r=="string"&&(s.space(),Zt.some(e=>S(e)))&&[":",r,d(Nr)]);var Rr=5,W=10,Ee=42,qt=N[Ee];N[Ee]=(r,e)=>r?qt?.(r,e):(h(),"*");g("from",W+1,r=>r?r[0]!=="="&&r[0]!==","&&(s.space(),["from",r,d(W+1)]):!1);g("as",W+2,r=>r?(s.space(),["as",r,d(W+2)]):!1);w("import",Rr,()=>S(".meta")?(h(5),["import.meta"]):["import",d(W)]);w("export",Rr,()=>(s.space(),S("default")?(h(7),["export",["default",d(W)]]):["export",d(Rr)]));var Or=20,Se=200,bt=10,ro=13,eo=34,to=35,oo=39,ke=40,_r=41,no=91,Lr=123,Pr=125,io=(r,e)=>{for(;r<e;){let t=m.charCodeAt(r++);if(t===bt||t===ro)return!0}return!1},so=r=>r===eo||r===oo||r===no||r===to,Te=()=>E(s.id)||(so(m.charCodeAt(l))?d(Se-.5):null),po=r=>typeof r=="string"||Array.isArray(r)&&(r[0]===void 0||r[0]==="[]"),Ne=r=>e=>{if(e)return;let t=l;if(s.space(),s.semi||io(t,l))return!1;let o=Te();if(!o||(s.space(),m.charCodeAt(l)!==ke))return!1;h();let n=d(0,_r);return s.space(),m.charCodeAt(l)!==Lr?!1:(h(),[r,o,n,d(0,Pr)])};g("get",Or-1,Ne("get"));g("set",Or-1,Ne("set"));var Ir=r=>r==null||typeof r=="string"||Array.isArray(r)&&(r[0]===","?r.slice(1).every(Ir):r[0]==="="?typeof r[1]=="string"||Ir(r[1]):r[0]==="..."||r[0]==="{}"||r[0]==="[]"),fo=v["*"];g("*",Se,r=>{let e=r&&s.newline;if(r&&!e)return;let t=l,o=Te();if(!o)return r?(T(t),void 0):!1;if(s.space(),m.charCodeAt(l)!==ke)return r?(T(t),void 0):!1;h();let n=d(0,_r)||null;if(r&&!Ir(n))return T(t),void 0;if(s.space(),m.charCodeAt(l)!==Lr)return r?(T(t),void 0):!1;h();let p=[":",o,["function*",null,n,d(0,Pr)||null]];return r?r[0]===";"?(r.push(p),r):[";",r,p]:p});v["*"]=fo;g("(",Or-1,r=>{if(!r)return;let e,t;if(Array.isArray(r)&&r[0]==="static"&&(e="static",r=r[1]),Array.isArray(r)&&r[0]==="async"&&(t=!0,r=r[1]),!po(r))return;let o=d(0,_r)||null;if(s.space(),m.charCodeAt(l)!==Lr)return;h();let n=["=>",["()",o],d(0,Pr)||null];t&&(n=["async",n]);let p=[":",r,n];return e?[e,p]:p});s.comment["#!"]=`
|
|
7
|
+
`;var _e=32,Ur=10,lo=59,uo=125,Re=91,Ie=40,er=v.asi??v[";"],co=s._baseSpace??=s.space,mo=s._baseStep??=s.step,vr=r=>Array.isArray(r)||typeof r=="string",ao=(v[";"]??5)+1,Mr=r=>Array.isArray(r)&&(v[r[0]]<=ao||r[0]==="{}"&&Mr(r[1])),ho=(r,e)=>{for(;(e=m.charCodeAt(r))<=_e;){if(e===Ur)return!0;r++}return!1},Ao=(r=l,e)=>{for(;r-- >0&&(e=m.charCodeAt(r))<=_e;)if(e===Ur)return!0;return!1};s.space=(r,e)=>{for(;;){for(e=l,r=co();e<l;)if(m.charCodeAt(e++)===Ur){s.newline=!0;break}if(r===lo&&ho(l+1)){T(l+1),s.newline=s.semi=!0;continue}return r}};s.enter=()=>s.newline=s.semi=!1;s.exit=(r,e)=>{e===uo&&(s.newline=!0,s.semi=!1)};s.step=(r,e,t,o)=>{if(s.semi&&e>=er)return!1;if(r&&!vr(r))return null;if(vr(r)){let p=(t===Re||t===Ie)&&Ao();if(s.semi||t===Re&&(p||Mr(r))||t===Ie&&(Mr(r)||p&&e>=er))return Oe(r,e,o)??null}let n=s.newline;return mo(r,e,t,o)??(vr(r)&&n?Oe(r,e,o)??null:null)};var Br=0,yo=2e3,Oe=s.asi=(r,e,t,o,n)=>{if(e>=er||Br>=yo)return;s.semi=!1;let p=l;Br++;try{o=t(er-.5)}finally{Br--}if(!(!o||l===p))return n=o?.[0]===";"?o.slice(1):[o],r?.[0]===";"?(r.push(...n),r):[";",r,...n]};var Pe=(r,e,t,o)=>typeof r=="string"?n=>e(n,r,n):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o,n)):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n),n)):r[0]==="()"&&r.length===2?Pe(r[1],e):(()=>{throw Error("Invalid assignment target")})(),Le={"=":(r,e,t)=>r[e]=t,"+=":(r,e,t)=>r[e]+=t,"-=":(r,e,t)=>r[e]-=t,"*=":(r,e,t)=>r[e]*=t,"/=":(r,e,t)=>r[e]/=t,"%=":(r,e,t)=>r[e]%=t,"|=":(r,e,t)=>r[e]|=t,"&=":(r,e,t)=>r[e]&=t,"^=":(r,e,t)=>r[e]^=t,">>=":(r,e,t)=>r[e]>>=t,"<<=":(r,e,t)=>r[e]<<=t};for(let r in Le)f(r,(e,t)=>(t=i(t),Pe(e,(o,n,p)=>Le[r](o,n,t(p)))));f("!",r=>(r=i(r),e=>!r(e)));f("||",(r,e)=>(r=i(r),e=i(e),t=>r(t)||e(t)));f("&&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&&e(t)));f("~",r=>(r=i(r),e=>~r(e)));f("|",(r,e)=>(r=i(r),e=i(e),t=>r(t)|e(t)));f("&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&e(t)));f("^",(r,e)=>(r=i(r),e=i(e),t=>r(t)^e(t)));f(">>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>e(t)));f("<<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<<e(t)));f(">",(r,e)=>(r=i(r),e=i(e),t=>r(t)>e(t)));f("<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<e(t)));f(">=",(r,e)=>(r=i(r),e=i(e),t=>r(t)>=e(t)));f("<=",(r,e)=>(r=i(r),e=i(e),t=>r(t)<=e(t)));f("==",(r,e)=>(r=i(r),e=i(e),t=>r(t)==e(t)));f("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(t)));f("+",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)+e(t)):(r=i(r),t=>+r(t)));f("-",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)-e(t)):(r=i(r),t=>-r(t)));f("*",(r,e)=>(r=i(r),e=i(e),t=>r(t)*e(t)));f("/",(r,e)=>(r=i(r),e=i(e),t=>r(t)/e(t)));f("%",(r,e)=>(r=i(r),e=i(e),t=>r(t)%e(t)));var Kr=(r,e,t,o)=>typeof r=="string"?n=>e(n,r):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o)):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n))):r[0]==="()"&&r.length===2?Kr(r[1],e):(()=>{throw Error("Invalid increment target")})();f("++",(r,e)=>Kr(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));f("--",(r,e)=>Kr(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var ve=(...r)=>(r=r.map(i),e=>{let t;for(let o of r)t=o(e);return t});f(",",ve);f(";",ve);var Be=r=>r!=null&&(typeof r=="object"||typeof r=="function"),M=r=>Be(r)?Reflect.ownKeys({[r]:0})[0]:r,P=r=>typeof r=="string"&&(r[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype"),wo=r=>P(M(r));i.id=r=>r===void 0||wo(r)?()=>{}:e=>e?.[r];var tr=r=>{throw Error(r)};f("[]",(r,e)=>e===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(t=>t==null?(()=>{}):t[0]==="..."?(t=i(t[1]),o=>t(o)):(t=i(t),o=>[t(o)])),t=>r.flatMap(o=>o(t))):(e==null&&tr("Missing index"),r=i(r),e=i(e),t=>{let o=M(e(t));return P(o)?void 0:r(t)[o]}));f(".",(r,e)=>(r=i(r),e=M(e[0]?e:e[1]),P(e)?()=>{}:t=>r(t)[e]));f("()",(r,e)=>{if(e===void 0)return r==null?tr("Empty ()"):i(r);let t=p=>p?.[0]===","&&p.slice(1).some(c=>c==null||t(c));t(e)&&tr("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(i),p=>e.map(c=>c(p))):(e=i(e),p=>[e(p)]):()=>[],n=Fr(r);return n<0?()=>{}:Gr(r,n?(p,c,u)=>(c=M(c),P(c)?void 0:p[c](...o(u))):(p,c,u)=>p[c](...o(u)))});var K=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&K(r[1])||r[0]==="{}"),Gr=(r,e,t,o)=>r==null?tr("Empty ()"):r[0]==="()"&&r.length==2?Gr(r[1],e):typeof r=="string"?n=>e(n,r,n):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o,n)):r[0]==="?."?(t=i(r[1]),o=r[2],n=>{let p=t(n);return p==null?void 0:e(p,o,n)}):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n),n)):r[0]==="?.[]"?(t=i(r[1]),o=i(r[2]),n=>{let p=t(n);return p==null?void 0:e(p,o(n),n)}):(r=i(r),n=>e([r(n)],0,n)),Dr=r=>Be(r)?1:P(r)?-1:0,Fr=(r,e=r?.[0],t=r?.[2])=>typeof r=="string"?Dr(r):e==="()"&&r.length==2?Fr(r[1]):e==="."||e==="?."?Dr(t):(e==="[]"||e==="?.[]")&&r.length===3?Array.isArray(t)&&t[0]==null?Dr(t[1]):1:0,F=(r,e,t=Fr(r))=>t<0?()=>{}:Gr(r,t?(o,n,p)=>(n=M(n),P(n)?void 0:e(o,n,p)):e);f("===",(r,e)=>(r=i(r),e=i(e),t=>r(t)===e(t)));f("!==",(r,e)=>(r=i(r),e=i(e),t=>r(t)!==e(t)));f("??",(r,e)=>(r=i(r),e=i(e),t=>r(t)??e(t)));var Co=r=>{throw Error(r)};f("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));f("**=",(r,e)=>(K(r)||Co("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]**=e(n))));f("in",(r,e)=>(r=i(r),e=i(e),t=>r(t)in e(t)));var go=r=>{throw Error(r)};f(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));f(">>>=",(r,e)=>(K(r)||go("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]>>>=e(n))));var Eo=r=>r[0]?.[0]===","?r[0].slice(1):r,H=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...n]=r,p=Eo(n);if(o==="{}"){let c=[];for(let u of p){if(Array.isArray(u)&&u[0]==="..."){let C={};for(let I in e)!c.includes(I)&&!P(I)&&(C[I]=e[I]);t[u[1]]=C;break}let a,y,R;typeof u=="string"?a=y=u:u[0]==="="?(typeof u[1]=="string"?a=y=u[1]:[,a,y]=u[1],R=u[2]):[,a,y]=u,c.push(a=M(a));let k=P(a)?void 0:e[a];k===void 0&&R&&(k=i(R)(t)),H(y,k,t)}}else if(o==="[]"){let c=0;for(let u of p){if(u===null){c++;continue}if(Array.isArray(u)&&u[0]==="..."){t[u[1]]=e.slice(c);break}let a=u,y;Array.isArray(u)&&u[0]==="="&&([,a,y]=u);let R=e[c++];R===void 0&&y&&(R=i(y)(t)),H(a,R,t)}}},Hr=(...r)=>(r=r.map(e=>{if(typeof e=="string")return t=>{t[e]=void 0};if(e[0]==="="){let[,t,o]=e,n=i(o);return typeof t=="string"?p=>{p[t]=n(p)}:p=>H(t,n(p),p)}return i(e)}),e=>{for(let t of r)t(e)});f("let",Hr);f("const",Hr);f("var",Hr);var or=r=>{throw Error(r)};f("=",(r,e)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let t=r[1];return e=i(e),typeof t=="string"?o=>{o[t]=e(o)}:o=>H(t,e(o),o)}return K(r)||or("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]=e(n))});f("||=",(r,e)=>(K(r)||or("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]||=e(n))));f("&&=",(r,e)=>(K(r)||or("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]&&=e(n))));f("??=",(r,e)=>(K(r)||or("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]??=e(n))));f("?",(r,e,t)=>(r=i(r),e=i(e),t=i(t),o=>r(o)?e(o):t(o)));var B=[];f("=>",(r,e)=>{r=r?.[0]==="()"?r[1]:r;let t=r?r[0]===","?r.slice(1):[r]:[],o=-1,n=null,p=t[t.length-1];Array.isArray(p)&&p[0]==="..."&&(o=t.length-1,n=p[1],t.length--);let c=e?.[0]==="{}";return e=i(c?["{",e[1]]:e),u=>(...a)=>{let y={};t.forEach((k,C)=>y[k]=a[C]),n&&(y[n]=a.slice(o));let R=new Proxy(y,{get:(k,C)=>C in k?k[C]:u?.[C],set:(k,C,I)=>((C in k?k:u)[C]=I,!0),has:(k,C)=>C in k||(u?C in u:!1)});try{let k=e(R);return c?void 0:k}catch(k){if(k===B)return k[0];throw k}}});f("...",r=>(r=i(r),e=>{let t=r(e),o=[];for(let n of Object.keys(t))P(n)||o.push([n,t[n]]);return o}));f("?.",(r,e)=>(r=i(r),e=M(e),P(e)?()=>{}:t=>r(t)?.[e]));f("?.[]",(r,e)=>(r=i(r),e=i(e),t=>{let o=r(t);if(o==null)return;let n=M(e(t));return P(n)?void 0:o[n]}));f("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(p=>p(n))):(e=i(e),n=>[e(n)]):()=>[];if(r[0]==="."||r[0]==="?."){let n=r[0]==="?.",p=i(r[1]),c=M(r[2]);return P(c)?()=>{}:n?u=>p(u)?.[c]?.(...t(u)):u=>p(u)[c]?.(...t(u))}if((r[0]==="[]"||r[0]==="?.[]")&&r.length===3){let n=r[0]==="?.[]",p=i(r[1]),c=i(r[2]);return u=>{let a=p(u);if(n&&a==null)return;let y=M(c(u));return P(y)?void 0:a[y]?.(...t(u))}}let o=i(r);return n=>o(n)?.(...t(n))});f("typeof",r=>(r=i(r),e=>typeof r(e)));f("void",r=>(r=i(r),e=>(r(e),void 0)));f("delete",r=>{if(r[0]==="."){let e=i(r[1]),t=r[2];return o=>delete e(o)[t]}if(r[0]==="[]"){let e=i(r[1]),t=i(r[2]);return o=>delete e(o)[t(o)]}return()=>!0});f("new",r=>{let e=i(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,o=t?t[0]===","?(n=>p=>n.map(c=>c(p)))(t.slice(1).map(i)):(n=>p=>[n(p)])(i(t)):()=>[];return n=>new(e(n))(...o(n))});var nr=Symbol("accessor");f("get",(r,e)=>(e=e?i(e):()=>{},t=>[[nr,r,{get:function(){let o=Object.create(t||{});return o.this=this,e(o)}}]]));f("set",(r,e,t)=>(t=t?i(t):()=>{},o=>[[nr,r,{set:function(n){let p=Object.create(o||{});p.this=this,p[e]=n,t(p)}}]]));var So=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);f("{}",(r,e)=>{if(e!==void 0)return;if(!So(r))return i(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(o=>i(typeof o=="string"?[":",o,o]:o));return o=>{let n={},p={};for(let c of t.flatMap(u=>u(o)))if(c[0]===nr){let[,u,a]=c;p[u]={...p[u],...a,configurable:!0,enumerable:!0}}else n[c[0]]=c[1];for(let c in p)Object.defineProperty(n,c,p[c]);return n}});f("{",r=>(r=r?i(r):()=>{},e=>r(Object.create(e))));f(":",(r,e)=>(e=i(e),Array.isArray(r)?(r=i(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));f("`",(...r)=>(r=r.map(i),e=>r.map(t=>t(e)).join("")));f("``",(r,...e)=>{r=i(r);let t=[],o=[];for(let p of e)Array.isArray(p)&&p[0]===void 0?t.push(p[1]):o.push(i(p));let n=Object.assign([...t],{raw:t});return p=>r(p)(n,...o.map(c=>c(p)))});f("function",(r,e,t)=>{t=t?i(t):()=>{};let o=e?e[0]===","?e.slice(1):[e]:[],n=null,p=-1,c=o[o.length-1];return Array.isArray(c)&&c[0]==="..."&&(p=o.length-1,n=c[1],o.length--),u=>{let a=(...y)=>{let R={};o.forEach((C,I)=>R[C]=y[I]),n&&(R[n]=y.slice(p));let k=new Proxy(R,{get:(C,I)=>I in C?C[I]:u[I],set:(C,I,Ke)=>((I in C?C:u)[I]=Ke,!0),has:(C,I)=>I in C||I in u});try{return t(k)}catch(C){if(C===B)return C[0];throw C}};return r&&(u[r]=a),a}});f("function*",(r,e,t)=>{throw Error("Generator functions are not supported in evaluation")});f("async",r=>{let e=i(r);return t=>{let o=e(t);return async function(...n){return o(...n)}}});f("await",r=>(r=i(r),async e=>await r(e)));f("yield",r=>(r=r?i(r):null,e=>{throw{__yield__:r?r(e):void 0}}));f("yield*",r=>(r=i(r),e=>{throw{__yield_all__:r(e)}}));var ko=Symbol("static"),To=r=>{throw Error(r)};f("instanceof",(r,e)=>(r=i(r),e=i(e),t=>r(t)instanceof e(t)));f("class",(r,e,t)=>(e=e?i(e):null,t=t?i(t):null,o=>{let n=e?.(o),p=function(...c){if(!(this instanceof p))return To("Class constructor must be called with new");let u=e?Reflect.construct(n,c,p):this;return p.prototype.__constructor__&&p.prototype.__constructor__.apply(u,c),u};if(e&&(Object.setPrototypeOf(p.prototype,n.prototype),Object.setPrototypeOf(p,n)),t){let c=Object.create(o);e&&(c.super=n);let u=t(c),a=Array.isArray(u)&&typeof u[0]?.[0]=="string"?u:[];for(let[y,R]of a)y==="constructor"?p.prototype.__constructor__=R:p.prototype[y]=R}return r&&(o[r]=p),p}));f("static",r=>(r=i(r),e=>[[ko,r(e)]]));f("//",(r,e)=>{let t=new RegExp(r,e||"");return()=>t});f("if",(r,e,t)=>(r=i(r),e=i(e),t=t!==void 0?i(t):null,o=>r(o)?e(o):t?.(o)));var D=Symbol("break"),X=Symbol("continue");f("while",(r,e)=>(r=i(r),e=i(e),t=>{let o;for(;r(t);)try{o=e(t)}catch(n){if(n===D)break;if(n===X)continue;if(n===B)return n[0];throw n}return o}));f("do",(r,e)=>(r=i(r),e=i(e),t=>{let o;do try{o=r(t)}catch(n){if(n===D)break;if(n===X)continue;if(n===B)return n[0];throw n}while(e(t));return o}));f("for",(r,e)=>{if(Array.isArray(r)&&r[0]===";"){let[,t,o,n]=r;return t=t?i(t):null,o=o?i(o):()=>!0,n=n?i(n):null,e=i(e),p=>{let c;for(t?.(p);o(p);n?.(p))try{c=e(p)}catch(u){if(u===D)break;if(u===X)continue;if(u===B)return u[0];throw u}return c}}if(Array.isArray(r)&&(r[0]==="in"||r[0]==="of")){let[t,o,n]=r;if(Array.isArray(o)&&(o[0]==="let"||o[0]==="const"||o[0]==="var")&&(o=o[1]),t==="in")return Ro(o,n,e);if(t==="of")return No(o,n,e)}});var No=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let p,c=o?null:n[r];for(let u of e(n)){o?H(r,u,n):n[r]=u;try{p=t(n)}catch(a){if(a===D)break;if(a===X)continue;if(a===B)return a[0];throw a}}return o||(n[r]=c),p}},Ro=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let p,c=o?null:n[r];for(let u in e(n)){o?H(r,u,n):n[r]=u;try{p=t(n)}catch(a){if(a===D)break;if(a===X)continue;if(a===B)return a[0];throw a}}return o||(n[r]=c),p}};f("break",()=>()=>{throw D});f("continue",()=>()=>{throw X});f("return",r=>(r=r!==void 0?i(r):null,e=>{throw B[0]=r?.(e),B}));f("try",(r,...e)=>{r=r?i(r):null;let t=e.find(u=>u?.[0]==="catch"),o=e.find(u=>u?.[0]==="finally"),n=t?.[1],p=t?.[2]?i(t[2]):null,c=o?.[1]?i(o[1]):null;return u=>{let a;try{a=r?.(u)}catch(y){if(y===D||y===X||y===B)throw y;if(n!=null&&p){let R=n in u,k=u[n];u[n]=y;try{a=p(u)}finally{R?u[n]=k:delete u[n]}}else if(!p)throw y}finally{c?.(u)}return a}});f("throw",r=>(r=i(r),e=>{throw r(e)}));f("switch",(r,...e)=>(r=i(r),e.length?(e=e.map(t=>[t[0]==="case"?i(t[1]):null,(t[0]==="case"?t[2]:t[1])?.[0]===";"?(t[0]==="case"?t[2]:t[1]).slice(1).map(i):(t[0]==="case"?t[2]:t[1])?[i(t[0]==="case"?t[2]:t[1])]:[]]),t=>{let o=r(t),n=!1,p;for(let[u,a]of e)if(n||u===null||u(t)===o)for(n=!0,c=0;c<a.length;c++)try{p=a[c](t)}catch(y){if(y===D)return p;throw y}var c;return p}):t=>r(t)));f("import",()=>()=>{});f("export",()=>()=>{});f("from",(r,e)=>()=>{});f("as",(r,e)=>()=>{});f("default",r=>i(r));var Me=new WeakMap,Io=(r,...e)=>typeof r=="string"?i(s(r)):Me.get(r)||Me.set(r,Oo(r,e)).get(r),Ue=57344,Oo=(r,e)=>{let t=r.reduce((p,c,u)=>p+(u?String.fromCharCode(Ue+u-1):"")+c,""),o=s(t),n=p=>{if(typeof p=="string"&&p.length===1){let c=p.charCodeAt(0)-Ue,u;if(c>=0&&c<e.length)return u=e[c],_o(u)?u:[,u]}return Array.isArray(p)?p.map(n):p};return i(n(o))},_o=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Lo=Io;export{pr as access,A as binary,i as compile,m as cur,Lo as default,O as err,d as expr,J as group,Po as id,l as idx,w as keyword,j as literal,De as loc,N as lookup,Qr as member,sr as nary,E as next,f as operator,ir as operators,L as parens,s as parse,z as peek,v as prec,fr as propName,T as seek,h as skip,g as token,_ as unary,S as word};
|
package/justin.min.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),o=e.pop(),i=
|
|
3
|
-
${i}${
|
|
4
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},
|
|
5
|
-
`,"/*":"*/"};d.space=()=>{for(var r,t,e,o,i;r=
|
|
6
|
-
`?i:i+o.length),r=0;break}if(r)return r}return r};var vr=80;c("===",vr);c("!==",vr);var ft=30;c("??",ft);var lt=130,ut=20;c("**",lt,!0);c("**=",ut,!0);var Lr=90;c("in",Lr);c("of",Lr);var ct=20,dt=100;c(">>>",dt);c(">>>=",ct,!0);var Z=20;c("||=",Z,!0);c("&&=",Z,!0);c("??=",Z,!0);a("true",!0);a("false",!1);a("null",null);M("undefined",200,()=>[]);a("NaN",NaN);a("Infinity",1/0);var q=20;w("?",q,(r,t,e)=>r&&(t=g(q-1))&&L(o=>o===58)&&(e=g(q-1),["?",r,t,e]));var ht=20;c("=>",ht,!0);var At=20;k("...",At);var Or=170;w("?.",Or,(r,t)=>{if(!r)return;let e=d.space();return e===40?(y(),["?.()",r,g(0,41)||null]):e===91?(y(),["?.[]",r,g(0,93)]):(t=z(Or),t?["?.",r,t]:void 0)});var x=140,Rr=160,gt=Rr+1;k("typeof",x);k("void",x);k("delete",x);var yt=r=>d.space()===40?(y(),["()",r,g(0,41)||null]):r;M("new",gt,()=>ir(".target")?(y(7),["new.target"]):["new",yt(g(Rr))]);var Ct=20,Pr=200;d.prop=r=>K(r)!==58;_("[]",Pr);_("{}",Pr);c(":",Ct-1,!0);var St=170,b=96,Et=36,wt=123,It=92,kt={n:`
|
|
7
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},ar=()=>{let r=[],t="",e;for(;(e=u.charCodeAt(m))!==b;)e?e===It?(y(),t+=kt[u[m]]||u[m],y()):e===Et&&u.charCodeAt(m+1)===wt?(r.push([,t]),t="",y(2),r.push(g(0,125))):(t+=u[m],y()):N("Unterminated template");return r.push([,t]),y(),r},Nt=r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r],vt=E[b];E[b]=(r,t)=>r&&t<St?d.asi&&d.newline?void 0:(y(),["``",r,...ar()]):r?vt?.(r,t):(y(),Nt(ar()));d.string["'"]=!0;d.number={"0x":16,"0b":2,"0o":8};var Ur=(r,t,e,o)=>typeof r=="string"?i=>t(i,r,i):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o,i)):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i),i)):r[0]==="()"&&r.length===2?Ur(r[1],t):(()=>{throw Error("Invalid assignment target")})(),Tr={"=":(r,t,e)=>r[t]=e,"+=":(r,t,e)=>r[t]+=e,"-=":(r,t,e)=>r[t]-=e,"*=":(r,t,e)=>r[t]*=e,"/=":(r,t,e)=>r[t]/=e,"%=":(r,t,e)=>r[t]%=e,"|=":(r,t,e)=>r[t]|=e,"&=":(r,t,e)=>r[t]&=e,"^=":(r,t,e)=>r[t]^=e,">>=":(r,t,e)=>r[t]>>=e,"<<=":(r,t,e)=>r[t]<<=e};for(let r in Tr)p(r,(t,e)=>(e=n(e),Ur(t,(o,i,s)=>Tr[r](o,i,e(s)))));p("!",r=>(r=n(r),t=>!r(t)));p("||",(r,t)=>(r=n(r),t=n(t),e=>r(e)||t(e)));p("&&",(r,t)=>(r=n(r),t=n(t),e=>r(e)&&t(e)));p("~",r=>(r=n(r),t=>~r(t)));p("|",(r,t)=>(r=n(r),t=n(t),e=>r(e)|t(e)));p("&",(r,t)=>(r=n(r),t=n(t),e=>r(e)&t(e)));p("^",(r,t)=>(r=n(r),t=n(t),e=>r(e)^t(e)));p(">>",(r,t)=>(r=n(r),t=n(t),e=>r(e)>>t(e)));p("<<",(r,t)=>(r=n(r),t=n(t),e=>r(e)<<t(e)));p(">",(r,t)=>(r=n(r),t=n(t),e=>r(e)>t(e)));p("<",(r,t)=>(r=n(r),t=n(t),e=>r(e)<t(e)));p(">=",(r,t)=>(r=n(r),t=n(t),e=>r(e)>=t(e)));p("<=",(r,t)=>(r=n(r),t=n(t),e=>r(e)<=t(e)));p("==",(r,t)=>(r=n(r),t=n(t),e=>r(e)==t(e)));p("!=",(r,t)=>(r=n(r),t=n(t),e=>r(e)!=t(e)));p("+",(r,t)=>t!==void 0?(r=n(r),t=n(t),e=>r(e)+t(e)):(r=n(r),e=>+r(e)));p("-",(r,t)=>t!==void 0?(r=n(r),t=n(t),e=>r(e)-t(e)):(r=n(r),e=>-r(e)));p("*",(r,t)=>(r=n(r),t=n(t),e=>r(e)*t(e)));p("/",(r,t)=>(r=n(r),t=n(t),e=>r(e)/t(e)));p("%",(r,t)=>(r=n(r),t=n(t),e=>r(e)%t(e)));var rr=(r,t,e,o)=>typeof r=="string"?i=>t(i,r):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o)):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i))):r[0]==="()"&&r.length===2?rr(r[1],t):(()=>{throw Error("Invalid increment target")})();p("++",(r,t)=>rr(r,t===null?(e,o)=>e[o]++:(e,o)=>++e[o]));p("--",(r,t)=>rr(r,t===null?(e,o)=>e[o]--:(e,o)=>--e[o]));var _r=(...r)=>(r=r.map(n),t=>{let e;for(let o of r)e=o(t);return e});p(",",_r);p(";",_r);var P=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",G=r=>{throw Error(r)};p("[]",(r,t)=>t===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(e=>e==null?(()=>{}):e[0]==="..."?(e=n(e[1]),o=>e(o)):(e=n(e),o=>[e(o)])),e=>r.flatMap(o=>o(e))):(t==null&&G("Missing index"),r=n(r),t=n(t),e=>{let o=t(e);return P(o)?void 0:r(e)[o]}));p(".",(r,t)=>(r=n(r),t=t[0]?t:t[1],P(t)?()=>{}:e=>r(e)[t]));p("()",(r,t)=>{if(t===void 0)return r==null?G("Empty ()"):n(r);let e=i=>i?.[0]===","&&i.slice(1).some(s=>s==null||e(s));e(t)&&G("Empty argument");let o=t?t[0]===","?(t=t.slice(1).map(n),i=>t.map(s=>s(i))):(t=n(t),i=>[t(i)]):()=>[];return tr(r,(i,s,l)=>i[s](...o(l)))});var v=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&v(r[1])||r[0]==="{}"),tr=(r,t,e,o)=>r==null?G("Empty ()"):r[0]==="()"&&r.length==2?tr(r[1],t):typeof r=="string"?i=>t(i,r,i):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o,i)):r[0]==="?."?(e=n(r[1]),o=r[2],i=>{let s=e(i);return s==null?void 0:t(s,o,i)}):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i),i)):r[0]==="?.[]"?(e=n(r[1]),o=n(r[2]),i=>{let s=e(i);return s==null?void 0:t(s,o(i),i)}):(r=n(r),i=>t([r(i)],0,i)),O=tr;p("===",(r,t)=>(r=n(r),t=n(t),e=>r(e)===t(e)));p("!==",(r,t)=>(r=n(r),t=n(t),e=>r(e)!==t(e)));p("??",(r,t)=>(r=n(r),t=n(t),e=>r(e)??t(e)));var Lt=r=>{throw Error(r)};p("**",(r,t)=>(r=n(r),t=n(t),e=>r(e)**t(e)));p("**=",(r,t)=>(v(r)||Lt("Invalid assignment target"),t=n(t),O(r,(e,o,i)=>e[o]**=t(i))));p("in",(r,t)=>(r=n(r),t=n(t),e=>r(e)in t(e)));var Ot=r=>{throw Error(r)};p(">>>",(r,t)=>(r=n(r),t=n(t),e=>r(e)>>>t(e)));p(">>>=",(r,t)=>(v(r)||Ot("Invalid assignment target"),t=n(t),O(r,(e,o,i)=>e[o]>>>=t(i))));var Rt=r=>r[0]?.[0]===","?r[0].slice(1):r,B=(r,t,e)=>{if(typeof r=="string"){e[r]=t;return}let[o,...i]=r,s=Rt(i);if(o==="{}"){let l=[];for(let f of s){if(Array.isArray(f)&&f[0]==="..."){let S={};for(let U in t)l.includes(U)||(S[U]=t[U]);e[f[1]]=S;break}let h,A,I;typeof f=="string"?h=A=f:f[0]==="="?(typeof f[1]=="string"?h=A=f[1]:[,h,A]=f[1],I=f[2]):[,h,A]=f,l.push(h);let C=t[h];C===void 0&&I&&(C=n(I)(e)),B(A,C,e)}}else if(o==="[]"){let l=0;for(let f of s){if(f===null){l++;continue}if(Array.isArray(f)&&f[0]==="..."){e[f[1]]=t.slice(l);break}let h=f,A;Array.isArray(f)&&f[0]==="="&&([,h,A]=f);let I=t[l++];I===void 0&&A&&(I=n(A)(e)),B(h,I,e)}}},er=(...r)=>(r=r.map(t=>{if(typeof t=="string")return e=>{e[t]=void 0};if(t[0]==="="){let[,e,o]=t,i=n(o);return typeof e=="string"?s=>{s[e]=i(s)}:s=>B(e,i(s),s)}return n(t)}),t=>{for(let e of r)e(t)});p("let",er);p("const",er);p("var",er);var X=r=>{throw Error(r)};p("=",(r,t)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let e=r[1];return t=n(t),typeof e=="string"?o=>{o[e]=t(o)}:o=>B(e,t(o),o)}return v(r)||X("Invalid assignment target"),t=n(t),O(r,(e,o,i)=>e[o]=t(i))});p("||=",(r,t)=>(v(r)||X("Invalid assignment target"),t=n(t),O(r,(e,o,i)=>e[o]||=t(i))));p("&&=",(r,t)=>(v(r)||X("Invalid assignment target"),t=n(t),O(r,(e,o,i)=>e[o]&&=t(i))));p("??=",(r,t)=>(v(r)||X("Invalid assignment target"),t=n(t),O(r,(e,o,i)=>e[o]??=t(i))));p("?",(r,t,e)=>(r=n(r),t=n(t),e=n(e),o=>r(o)?t(o):e(o)));var Pt=[];p("=>",(r,t)=>{r=r?.[0]==="()"?r[1]:r;let e=r?r[0]===","?r.slice(1):[r]:[],o=-1,i=null,s=e[e.length-1];Array.isArray(s)&&s[0]==="..."&&(o=e.length-1,i=s[1],e.length--);let l=t?.[0]==="{}";return t=n(l?["{",t[1]]:t),f=>(...h)=>{let A={};e.forEach((C,S)=>A[C]=h[S]),i&&(A[i]=h.slice(o));let I=new Proxy(A,{get:(C,S)=>S in C?C[S]:f?.[S],set:(C,S,U)=>((S in C?C:f)[S]=U,!0),has:(C,S)=>S in C||(f?S in f:!1)});try{let C=t(I);return l?void 0:C}catch(C){if(C===Pt)return C[0];throw C}}});p("...",r=>(r=n(r),t=>Object.entries(r(t))));p("?.",(r,t)=>(r=n(r),P(t)?()=>{}:e=>r(e)?.[t]));p("?.[]",(r,t)=>(r=n(r),t=n(t),e=>{let o=t(e);return P(o)?void 0:r(e)?.[o]}));p("?.()",(r,t)=>{let e=t?t[0]===","?(t=t.slice(1).map(n),i=>t.map(s=>s(i))):(t=n(t),i=>[t(i)]):()=>[];if(r[0]==="."||r[0]==="?."){let i=n(r[1]),s=r[2];return P(s)?()=>{}:l=>i(l)?.[s]?.(...e(l))}if((r[0]==="[]"||r[0]==="?.[]")&&r.length===3){let i=n(r[1]),s=n(r[2]);return l=>{let f=s(l);return P(f)?void 0:i(l)?.[f]?.(...e(l))}}let o=n(r);return i=>o(i)?.(...e(i))});p("typeof",r=>(r=n(r),t=>typeof r(t)));p("void",r=>(r=n(r),t=>(r(t),void 0)));p("delete",r=>{if(r[0]==="."){let t=n(r[1]),e=r[2];return o=>delete t(o)[e]}if(r[0]==="[]"){let t=n(r[1]),e=n(r[2]);return o=>delete t(o)[e(o)]}return()=>!0});p("new",r=>{let t=n(r?.[0]==="()"?r[1]:r),e=r?.[0]==="()"?r[2]:null,o=e?e[0]===","?(i=>s=>i.map(l=>l(s)))(e.slice(1).map(n)):(i=>s=>[i(s)])(n(e)):()=>[];return i=>new(t(i))(...o(i))});var $=Symbol("accessor");p("get",(r,t)=>(t=t?n(t):()=>{},e=>[[$,r,{get:function(){let o=Object.create(e||{});return o.this=this,t(o)}}]]));p("set",(r,t,e)=>(e=e?n(e):()=>{},o=>[[$,r,{set:function(i){let s=Object.create(o||{});s.this=this,s[t]=i,e(s)}}]]));var at=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);p("{}",(r,t)=>{if(t!==void 0)return;if(!at(r))return n(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let e=r.map(o=>n(typeof o=="string"?[":",o,o]:o));return o=>{let i={},s={};for(let l of e.flatMap(f=>f(o)))if(l[0]===$){let[,f,h]=l;s[f]={...s[f],...h,configurable:!0,enumerable:!0}}else i[l[0]]=l[1];for(let l in s)Object.defineProperty(i,l,s[l]);return i}});p("{",r=>(r=r?n(r):()=>{},t=>r(Object.create(t))));p(":",(r,t)=>(t=n(t),Array.isArray(r)?(r=n(r),e=>[[r(e),t(e)]]):e=>[[r,t(e)]]));p("`",(...r)=>(r=r.map(n),t=>r.map(e=>e(t)).join("")));p("``",(r,...t)=>{r=n(r);let e=[],o=[];for(let s of t)Array.isArray(s)&&s[0]===void 0?e.push(s[1]):o.push(n(s));let i=Object.assign([...e],{raw:e});return s=>r(s)(i,...o.map(l=>l(s)))});var Br=new WeakMap,Tt=(r,...t)=>typeof r=="string"?n(d(r)):Br.get(r)||Br.set(r,Ut(r,t)).get(r),Mr=57344,Ut=(r,t)=>{let e=r.reduce((s,l,f)=>s+(f?String.fromCharCode(Mr+f-1):"")+l,""),o=d(e),i=s=>{if(typeof s=="string"&&s.length===1){let l=s.charCodeAt(0)-Mr,f;if(l>=0&&l<t.length)return f=t[l],_t(f)?f:[,f]}return Array.isArray(s)?s.map(i):s};return n(i(o))},_t=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Bt=Tt;export{j as access,c as binary,n as compile,u as cur,Bt as default,N as err,g as expr,_ as group,Mt as id,m as idx,M as keyword,a as literal,Dr as loc,E as lookup,pr as member,W as nary,L as next,p as operator,H as operators,Dt as parens,d as parse,K as peek,Q as prec,z as propName,nr as seek,y as skip,w as token,k as unary,ir as word};
|
|
1
|
+
var u,c,d=r=>(u=0,c=r,d.enter?.(),r=A(),c[u]?O():r||""),O=(r="Unexpected token",t=u,e=c.slice(0,t).split(`
|
|
2
|
+
`),o=e.pop(),i=c.slice(Math.max(0,t-40),t),s="\u032D",f=(c[t]||" ")+s,m=c.slice(t+1,t+20))=>{throw SyntaxError(`${r} at ${e.length+1}:${o.length+1}
|
|
3
|
+
${i}${f}${m}`)},Kr=(r,t=u)=>(Array.isArray(r)&&(r.loc=t),r),v=(r,t=u,e)=>{for(;e=r(c.charCodeAt(u));)u+=e;return c.slice(t,u)},C=(r=1)=>c[u+=r],mr=r=>u=r,A=(r=0,t)=>{let e,o,i;for(t&&d.enter?.(r,t);(e=d.space())&&e!==t&&(i=d.step(o,r,e,A));)o=i;return t&&(e==t?(u++,d.exit?.(r,t)):O("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),o},H=(r=u)=>{for(;c.charCodeAt(r)<=32;)r++;return c.charCodeAt(r)},Xt=d.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,fr=(r,t=r.length)=>c.substr(u,t)===r&&!d.id(c.charCodeAt(u+t)),Kt=()=>(C(),A(0,41)),w=[],j={},I=(r,t=32,e,o=r.charCodeAt(0))=>lr({op:r,l:r.length,p:j[r]=!w[o]&&j[r]||t,map:e,word:r.toUpperCase()!==r,kw:!1}),l=(r,t,e=!1)=>I(r,t,(o,i)=>o&&(i=A(t-(e?.5:0)))&&[r,o,i]),N=(r,t,e)=>I(r,t,o=>e?o&&[r,o]:!o&&(o=A(t-.5))&&[r,o]),U=(r,t)=>I(r,200,e=>!e&&[,t]),W=(r,t,e,o)=>I(r,t,(i,s,f=i)=>(s=A(t-(e?.5:0)),i?.[0]!==r&&(i=[r,i||null]),s?.[0]===r?i.push(...s.slice(1)):s?i.push(s):o||H()===r.charCodeAt(0)?i.push(null):f&&i.length===2&&(i=i[1]),i)),B=(r,t)=>I(r[0],t,e=>!e&&[r,A(0,r.charCodeAt(1))||null]),z=(r,t)=>I(r[0],t,e=>e&&[r,e,A(0,r.charCodeAt(1))||null]),J=(r,t)=>(d.space(),t=c.charCodeAt(u),d.id(t)&&(t<48||t>57)?v(d.id):A(r)),ur=(r,t)=>I(r,t,(e,o)=>e&&(o=J(t))&&[r,e,o]),M=(r,t,e)=>(j[r]??=t,lr({op:r,l:r.length,p:t,map:e,word:!0,kw:!0})),pr=(r,t,e=(o,i,s,f=u,m,h,g)=>{for(g=0;h=r[g++];)if(!(h.kw&&o)&&!(s?h.op!==s:!((h.l<2||h.op.charCodeAt(1)===c.charCodeAt(u+1)&&(h.l<3||c.substr(u,h.l)===h.op))&&(!h.word||!d.id(c.charCodeAt(u+h.l)))&&(s=h.op)))&&!(i>=h.p)&&!(h.kw&&d.prop&&!d.prop(u+h.l))){if(u+=h.l,m=h.map(o))return Kr(m,f);u=f,s=0,h.word||o||t||r[g]||O()}return t?.(o,i,s)})=>(e.ops=r,e.tail=t,e),lr=(r,t=r.op.charCodeAt(0),e=w[t])=>w[t]=e?.ops?pr([r,...e.ops],e.tail):pr([r],e);d.space=r=>{for(;(r=c.charCodeAt(u))<=32;)u++;return r};d.step=(r,t,e,o,i)=>(i=w[e])&&i(r,t)||(r?null:v(d.id)||null);var Q={},p=(r,t,e=Q[r])=>Q[r]=(...o)=>t(...o)||e?.(...o),n=r=>Array.isArray(r)?r[0]==null?(t=>()=>t)(r[1]):Q[r[0]]?.(...r.slice(1))??O(`Unknown operator: ${r[0]}`,r?.loc):n.id(r);n.id=r=>r===void 0?()=>{}:t=>t?.[r];var V=46,a=48,_=57,cr=69,dr=101,$r=43,jr=45,hr=95,Qr=97,Hr=102,Wr=65,zr=70,Ar=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),Jr=r=>r===V&&(r=c.charCodeAt(u+1))!==V&&!(d.id(r)&&r>_&&r!==dr&&r!==cr)||r>=a&&r<=_||r===hr||((r===cr||r===dr)&&((r=c.charCodeAt(u+1))>=a&&r<=_||r===$r||r===jr)?2:0),Y=r=>(r=+Ar(v(Jr)))!=r?O():[,r],Vr=r=>t=>t===hr||t>=a&&t<=_&&t-a<r||r===16&&(t>=Qr&&t<=Hr||t>=Wr&&t<=zr);d.number=null;w[V]=r=>!r&&c.charCodeAt(u+1)>=a&&c.charCodeAt(u+1)<=_&&Y();for(let r=a;r<=_;r++)w[r]=t=>t?void 0:Y();w[a]=(r,t)=>{if(!r){for(let e in d.number)if(e[0]==="0"&&(c.charCodeAt(u+1)|32)===e.charCodeAt(1)){C(2);let o=Ar(v(Vr(t=d.number[e])));return[,parseInt(o,t)]}return Y()}};var Yr=92,gr=34,yr=39,Cr=117,Sr=120,Zr=123,qr=125,Er=10,xr=13,br={n:`
|
|
4
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},wr=r=>r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:-1,Z=()=>{let r=c.charCodeAt(u+1);if(r===Er)return["",2];if(r===xr)return["",c.charCodeAt(u+2)===Er?3:2];if(r===Sr||r===Cr&&c.charCodeAt(u+2)!==Zr){let t=r===Sr?2:4,e=0,o;for(let i=0;i<t;i++){if((o=wr(c.charCodeAt(u+2+i)))<0)return[c[u+1],2];e=e*16+o}return[String.fromCharCode(e),2+t]}if(r===Cr){let t=0,e=u+3,o;for(;(o=wr(c.charCodeAt(e)))>=0;)t=t*16+o,e++;return e>u+3&&t<=1114111&&c.charCodeAt(e)===qr?[String.fromCodePoint(t),e-u+1]:[c[u+1],2]}return[br[c[u+1]]||c[u+1],2]},Ir=r=>(t,e,o="",i=String.fromCharCode(r))=>{if(t||!d.string?.[i])return;C();let s=()=>{let[f,m]=Z();return o+=f,m};return v(f=>f-r&&(f!==Yr?(o+=c[u],1):s())),c[u]===i?C():O("Bad string"),[,o]};w[gr]=Ir(gr);w[yr]=Ir(yr);d.string={'"':!0};var rt=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>l(r,rt,!0));var tt=30,et=40,ot=140;N("!",ot);l("||",tt);l("&&",et);var nt=50,it=60,st=70,Nr=100,pt=140;l("|",nt);l("&",st);l("^",it);l(">>",Nr);l("<<",Nr);N("~",pt);var D=90;l("<",D);l(">",D);l("<=",D);l(">=",D);var kr=80;l("==",kr);l("!=",kr);var Or=110,q=120,Lr=140;l("+",Or);l("-",Or);l("*",q);l("/",q);l("%",q);N("+",Lr);N("-",Lr);var F=150;I("++",F,r=>r?["++",r,null]:["++",A(F-1)]);I("--",F,r=>r?["--",r,null]:["--",A(F-1)]);var mt=5,ft=10;W(",",ft);W(";",mt,!0,!0);var ut=170;B("()",ut);var Rr=170,lt=160;z("[]",Rr);ur(".",Rr);z("()",lt);var ct=d.space;d.comment??={"//":`
|
|
5
|
+
`,"/*":"*/"};d.space=()=>{for(var r,t,e,o,i;r=ct();){for(e in t=d.comment)if(r===e.charCodeAt(0)&&(e.length<2||c.charCodeAt(u+1)===e.charCodeAt(1))&&(e.length<3||c.substr(u,e.length)===e)){o=t[e],i=c.indexOf(o,u+e.length),mr(i<0?c.length:o===`
|
|
6
|
+
`?i:i+o.length),r=0;break}if(r)return r}return r};var vr=80;l("===",vr);l("!==",vr);var dt=30;l("??",dt);var ht=130,At=20;l("**",ht,!0);l("**=",At,!0);var Pr=90;l("in",Pr);l("of",Pr);var gt=20,yt=100;l(">>>",yt);l(">>>=",gt,!0);var x=20;l("||=",x,!0);l("&&=",x,!0);l("??=",x,!0);U("true",!0);U("false",!1);U("null",null);M("undefined",200,()=>[]);U("NaN",NaN);U("Infinity",1/0);var b=20;I("?",b,(r,t,e)=>r&&(t=A(b-1))&&v(o=>o===58)&&(e=A(b-1),["?",r,t,e]));var Ct=20;l("=>",Ct,!0);var St=20;N("...",St);var ar=170;I("?.",ar,(r,t)=>{if(!r)return;let e=d.space();return e===40?(C(),["?.()",r,A(0,41)||null]):e===91?(C(),["?.[]",r,A(0,93)]):(t=J(ar),t?["?.",r,t]:void 0)});var rr=140,Tr=160,Et=Tr+1;N("typeof",rr);N("void",rr);N("delete",rr);var wt=r=>d.space()===40?(C(),["()",r,A(0,41)||null]):r;M("new",Et,()=>fr(".target")?(C(7),["new.target"]):["new",wt(A(Tr))]);var It=20,Ur=200;d.prop=r=>H(r)!==58;B("[]",Ur);B("{}",Ur);l(":",It-1,!0);var Nt=170,tr=96,kt=36,Ot=123,Lt=92,_r=()=>{let r=[],t="",e,o;for(;(e=c.charCodeAt(u))!==tr;)e?e===Lt?(o=Z(),t+=o[0],C(o[1])):e===kt&&c.charCodeAt(u+1)===Ot?(r.push([,t]),t="",C(2),r.push(A(0,125))):(t+=c[u],C()):O("Unterminated template");return r.push([,t]),C(),r},Rt=r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r],vt=w[tr];w[tr]=(r,t)=>r&&t<Nt?d.asi&&d.newline?void 0:(C(),["``",r,..._r()]):r?vt?.(r,t):(C(),Rt(_r()));d.string["'"]=!0;d.number={"0x":16,"0b":2,"0o":8};var Gr=(r,t,e,o)=>typeof r=="string"?i=>t(i,r,i):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o,i)):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i),i)):r[0]==="()"&&r.length===2?Gr(r[1],t):(()=>{throw Error("Invalid assignment target")})(),Br={"=":(r,t,e)=>r[t]=e,"+=":(r,t,e)=>r[t]+=e,"-=":(r,t,e)=>r[t]-=e,"*=":(r,t,e)=>r[t]*=e,"/=":(r,t,e)=>r[t]/=e,"%=":(r,t,e)=>r[t]%=e,"|=":(r,t,e)=>r[t]|=e,"&=":(r,t,e)=>r[t]&=e,"^=":(r,t,e)=>r[t]^=e,">>=":(r,t,e)=>r[t]>>=e,"<<=":(r,t,e)=>r[t]<<=e};for(let r in Br)p(r,(t,e)=>(e=n(e),Gr(t,(o,i,s)=>Br[r](o,i,e(s)))));p("!",r=>(r=n(r),t=>!r(t)));p("||",(r,t)=>(r=n(r),t=n(t),e=>r(e)||t(e)));p("&&",(r,t)=>(r=n(r),t=n(t),e=>r(e)&&t(e)));p("~",r=>(r=n(r),t=>~r(t)));p("|",(r,t)=>(r=n(r),t=n(t),e=>r(e)|t(e)));p("&",(r,t)=>(r=n(r),t=n(t),e=>r(e)&t(e)));p("^",(r,t)=>(r=n(r),t=n(t),e=>r(e)^t(e)));p(">>",(r,t)=>(r=n(r),t=n(t),e=>r(e)>>t(e)));p("<<",(r,t)=>(r=n(r),t=n(t),e=>r(e)<<t(e)));p(">",(r,t)=>(r=n(r),t=n(t),e=>r(e)>t(e)));p("<",(r,t)=>(r=n(r),t=n(t),e=>r(e)<t(e)));p(">=",(r,t)=>(r=n(r),t=n(t),e=>r(e)>=t(e)));p("<=",(r,t)=>(r=n(r),t=n(t),e=>r(e)<=t(e)));p("==",(r,t)=>(r=n(r),t=n(t),e=>r(e)==t(e)));p("!=",(r,t)=>(r=n(r),t=n(t),e=>r(e)!=t(e)));p("+",(r,t)=>t!==void 0?(r=n(r),t=n(t),e=>r(e)+t(e)):(r=n(r),e=>+r(e)));p("-",(r,t)=>t!==void 0?(r=n(r),t=n(t),e=>r(e)-t(e)):(r=n(r),e=>-r(e)));p("*",(r,t)=>(r=n(r),t=n(t),e=>r(e)*t(e)));p("/",(r,t)=>(r=n(r),t=n(t),e=>r(e)/t(e)));p("%",(r,t)=>(r=n(r),t=n(t),e=>r(e)%t(e)));var er=(r,t,e,o)=>typeof r=="string"?i=>t(i,r):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o)):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i))):r[0]==="()"&&r.length===2?er(r[1],t):(()=>{throw Error("Invalid increment target")})();p("++",(r,t)=>er(r,t===null?(e,o)=>e[o]++:(e,o)=>++e[o]));p("--",(r,t)=>er(r,t===null?(e,o)=>e[o]--:(e,o)=>--e[o]));var Mr=(...r)=>(r=r.map(n),t=>{let e;for(let o of r)e=o(t);return e});p(",",Mr);p(";",Mr);var Dr=r=>r!=null&&(typeof r=="object"||typeof r=="function"),k=r=>Dr(r)?Reflect.ownKeys({[r]:0})[0]:r,S=r=>typeof r=="string"&&(r[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype"),Pt=r=>S(k(r));n.id=r=>r===void 0||Pt(r)?()=>{}:t=>t?.[r];var X=r=>{throw Error(r)};p("[]",(r,t)=>t===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(e=>e==null?(()=>{}):e[0]==="..."?(e=n(e[1]),o=>e(o)):(e=n(e),o=>[e(o)])),e=>r.flatMap(o=>o(e))):(t==null&&X("Missing index"),r=n(r),t=n(t),e=>{let o=k(t(e));return S(o)?void 0:r(e)[o]}));p(".",(r,t)=>(r=n(r),t=k(t[0]?t:t[1]),S(t)?()=>{}:e=>r(e)[t]));p("()",(r,t)=>{if(t===void 0)return r==null?X("Empty ()"):n(r);let e=s=>s?.[0]===","&&s.slice(1).some(f=>f==null||e(f));e(t)&&X("Empty argument");let o=t?t[0]===","?(t=t.slice(1).map(n),s=>t.map(f=>f(s))):(t=n(t),s=>[t(s)]):()=>[],i=ir(r);return i<0?()=>{}:nr(r,i?(s,f,m)=>(f=k(f),S(f)?void 0:s[f](...o(m))):(s,f,m)=>s[f](...o(m)))});var L=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&L(r[1])||r[0]==="{}"),nr=(r,t,e,o)=>r==null?X("Empty ()"):r[0]==="()"&&r.length==2?nr(r[1],t):typeof r=="string"?i=>t(i,r,i):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o,i)):r[0]==="?."?(e=n(r[1]),o=r[2],i=>{let s=e(i);return s==null?void 0:t(s,o,i)}):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i),i)):r[0]==="?.[]"?(e=n(r[1]),o=n(r[2]),i=>{let s=e(i);return s==null?void 0:t(s,o(i),i)}):(r=n(r),i=>t([r(i)],0,i)),or=r=>Dr(r)?1:S(r)?-1:0,ir=(r,t=r?.[0],e=r?.[2])=>typeof r=="string"?or(r):t==="()"&&r.length==2?ir(r[1]):t==="."||t==="?."?or(e):(t==="[]"||t==="?.[]")&&r.length===3?Array.isArray(e)&&e[0]==null?or(e[1]):1:0,P=(r,t,e=ir(r))=>e<0?()=>{}:nr(r,e?(o,i,s)=>(i=k(i),S(i)?void 0:t(o,i,s)):t);p("===",(r,t)=>(r=n(r),t=n(t),e=>r(e)===t(e)));p("!==",(r,t)=>(r=n(r),t=n(t),e=>r(e)!==t(e)));p("??",(r,t)=>(r=n(r),t=n(t),e=>r(e)??t(e)));var at=r=>{throw Error(r)};p("**",(r,t)=>(r=n(r),t=n(t),e=>r(e)**t(e)));p("**=",(r,t)=>(L(r)||at("Invalid assignment target"),t=n(t),P(r,(e,o,i)=>e[o]**=t(i))));p("in",(r,t)=>(r=n(r),t=n(t),e=>r(e)in t(e)));var Tt=r=>{throw Error(r)};p(">>>",(r,t)=>(r=n(r),t=n(t),e=>r(e)>>>t(e)));p(">>>=",(r,t)=>(L(r)||Tt("Invalid assignment target"),t=n(t),P(r,(e,o,i)=>e[o]>>>=t(i))));var Ut=r=>r[0]?.[0]===","?r[0].slice(1):r,G=(r,t,e)=>{if(typeof r=="string"){e[r]=t;return}let[o,...i]=r,s=Ut(i);if(o==="{}"){let f=[];for(let m of s){if(Array.isArray(m)&&m[0]==="..."){let E={};for(let T in t)!f.includes(T)&&!S(T)&&(E[T]=t[T]);e[m[1]]=E;break}let h,g,R;typeof m=="string"?h=g=m:m[0]==="="?(typeof m[1]=="string"?h=g=m[1]:[,h,g]=m[1],R=m[2]):[,h,g]=m,f.push(h=k(h));let y=S(h)?void 0:t[h];y===void 0&&R&&(y=n(R)(e)),G(g,y,e)}}else if(o==="[]"){let f=0;for(let m of s){if(m===null){f++;continue}if(Array.isArray(m)&&m[0]==="..."){e[m[1]]=t.slice(f);break}let h=m,g;Array.isArray(m)&&m[0]==="="&&([,h,g]=m);let R=t[f++];R===void 0&&g&&(R=n(g)(e)),G(h,R,e)}}},sr=(...r)=>(r=r.map(t=>{if(typeof t=="string")return e=>{e[t]=void 0};if(t[0]==="="){let[,e,o]=t,i=n(o);return typeof e=="string"?s=>{s[e]=i(s)}:s=>G(e,i(s),s)}return n(t)}),t=>{for(let e of r)e(t)});p("let",sr);p("const",sr);p("var",sr);var K=r=>{throw Error(r)};p("=",(r,t)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let e=r[1];return t=n(t),typeof e=="string"?o=>{o[e]=t(o)}:o=>G(e,t(o),o)}return L(r)||K("Invalid assignment target"),t=n(t),P(r,(e,o,i)=>e[o]=t(i))});p("||=",(r,t)=>(L(r)||K("Invalid assignment target"),t=n(t),P(r,(e,o,i)=>e[o]||=t(i))));p("&&=",(r,t)=>(L(r)||K("Invalid assignment target"),t=n(t),P(r,(e,o,i)=>e[o]&&=t(i))));p("??=",(r,t)=>(L(r)||K("Invalid assignment target"),t=n(t),P(r,(e,o,i)=>e[o]??=t(i))));p("?",(r,t,e)=>(r=n(r),t=n(t),e=n(e),o=>r(o)?t(o):e(o)));var _t=[];p("=>",(r,t)=>{r=r?.[0]==="()"?r[1]:r;let e=r?r[0]===","?r.slice(1):[r]:[],o=-1,i=null,s=e[e.length-1];Array.isArray(s)&&s[0]==="..."&&(o=e.length-1,i=s[1],e.length--);let f=t?.[0]==="{}";return t=n(f?["{",t[1]]:t),m=>(...h)=>{let g={};e.forEach((y,E)=>g[y]=h[E]),i&&(g[i]=h.slice(o));let R=new Proxy(g,{get:(y,E)=>E in y?y[E]:m?.[E],set:(y,E,T)=>((E in y?y:m)[E]=T,!0),has:(y,E)=>E in y||(m?E in m:!1)});try{let y=t(R);return f?void 0:y}catch(y){if(y===_t)return y[0];throw y}}});p("...",r=>(r=n(r),t=>{let e=r(t),o=[];for(let i of Object.keys(e))S(i)||o.push([i,e[i]]);return o}));p("?.",(r,t)=>(r=n(r),t=k(t),S(t)?()=>{}:e=>r(e)?.[t]));p("?.[]",(r,t)=>(r=n(r),t=n(t),e=>{let o=r(e);if(o==null)return;let i=k(t(e));return S(i)?void 0:o[i]}));p("?.()",(r,t)=>{let e=t?t[0]===","?(t=t.slice(1).map(n),i=>t.map(s=>s(i))):(t=n(t),i=>[t(i)]):()=>[];if(r[0]==="."||r[0]==="?."){let i=r[0]==="?.",s=n(r[1]),f=k(r[2]);return S(f)?()=>{}:i?m=>s(m)?.[f]?.(...e(m)):m=>s(m)[f]?.(...e(m))}if((r[0]==="[]"||r[0]==="?.[]")&&r.length===3){let i=r[0]==="?.[]",s=n(r[1]),f=n(r[2]);return m=>{let h=s(m);if(i&&h==null)return;let g=k(f(m));return S(g)?void 0:h[g]?.(...e(m))}}let o=n(r);return i=>o(i)?.(...e(i))});p("typeof",r=>(r=n(r),t=>typeof r(t)));p("void",r=>(r=n(r),t=>(r(t),void 0)));p("delete",r=>{if(r[0]==="."){let t=n(r[1]),e=r[2];return o=>delete t(o)[e]}if(r[0]==="[]"){let t=n(r[1]),e=n(r[2]);return o=>delete t(o)[e(o)]}return()=>!0});p("new",r=>{let t=n(r?.[0]==="()"?r[1]:r),e=r?.[0]==="()"?r[2]:null,o=e?e[0]===","?(i=>s=>i.map(f=>f(s)))(e.slice(1).map(n)):(i=>s=>[i(s)])(n(e)):()=>[];return i=>new(t(i))(...o(i))});var $=Symbol("accessor");p("get",(r,t)=>(t=t?n(t):()=>{},e=>[[$,r,{get:function(){let o=Object.create(e||{});return o.this=this,t(o)}}]]));p("set",(r,t,e)=>(e=e?n(e):()=>{},o=>[[$,r,{set:function(i){let s=Object.create(o||{});s.this=this,s[t]=i,e(s)}}]]));var Bt=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);p("{}",(r,t)=>{if(t!==void 0)return;if(!Bt(r))return n(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let e=r.map(o=>n(typeof o=="string"?[":",o,o]:o));return o=>{let i={},s={};for(let f of e.flatMap(m=>m(o)))if(f[0]===$){let[,m,h]=f;s[m]={...s[m],...h,configurable:!0,enumerable:!0}}else i[f[0]]=f[1];for(let f in s)Object.defineProperty(i,f,s[f]);return i}});p("{",r=>(r=r?n(r):()=>{},t=>r(Object.create(t))));p(":",(r,t)=>(t=n(t),Array.isArray(r)?(r=n(r),e=>[[r(e),t(e)]]):e=>[[r,t(e)]]));p("`",(...r)=>(r=r.map(n),t=>r.map(e=>e(t)).join("")));p("``",(r,...t)=>{r=n(r);let e=[],o=[];for(let s of t)Array.isArray(s)&&s[0]===void 0?e.push(s[1]):o.push(n(s));let i=Object.assign([...e],{raw:e});return s=>r(s)(i,...o.map(f=>f(s)))});var Fr=new WeakMap,Gt=(r,...t)=>typeof r=="string"?n(d(r)):Fr.get(r)||Fr.set(r,Mt(r,t)).get(r),Xr=57344,Mt=(r,t)=>{let e=r.reduce((s,f,m)=>s+(m?String.fromCharCode(Xr+m-1):"")+f,""),o=d(e),i=s=>{if(typeof s=="string"&&s.length===1){let f=s.charCodeAt(0)-Xr,m;if(f>=0&&f<t.length)return m=t[f],Dt(m)?m:[,m]}return Array.isArray(s)?s.map(i):s};return n(i(o))},Dt=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Ft=Gt;export{z as access,l as binary,n as compile,c as cur,Ft as default,O as err,A as expr,B as group,Xt as id,u as idx,M as keyword,U as literal,Kr as loc,w as lookup,ur as member,W as nary,v as next,p as operator,Q as operators,Kt as parens,d as parse,H as peek,j as prec,J as propName,mr as seek,C as skip,I as token,N as unary,fr as word};
|
package/package.json
CHANGED
package/parse.js
CHANGED
|
@@ -189,9 +189,12 @@ export const operator = (op, fn, prev = operators[op]) =>
|
|
|
189
189
|
// Compile AST to evaluator function
|
|
190
190
|
// Note: [, value] serializes to [null, value] in JSON, both forms accepted
|
|
191
191
|
export const compile = node => (
|
|
192
|
-
!Array.isArray(node) ? (node
|
|
192
|
+
!Array.isArray(node) ? compile.id(node) :
|
|
193
193
|
node[0] == null ? (v => () => v)(node[1]) : // == catches both undefined and null
|
|
194
194
|
operators[node[0]]?.(...node.slice(1)) ?? err(`Unknown operator: ${node[0]}`, node?.loc)
|
|
195
195
|
);
|
|
196
196
|
|
|
197
|
+
// Identifier compiler hook. Eval layers can replace context lookup policy.
|
|
198
|
+
compile.id = node => node === undefined ? () => undefined : ctx => ctx?.[node];
|
|
199
|
+
|
|
197
200
|
export default parse;
|
package/subscript.d.ts
CHANGED
|
@@ -35,6 +35,9 @@ export function propName(prec: number): AST;
|
|
|
35
35
|
export const operators: Record<string, Operator>;
|
|
36
36
|
export function operator(op: string, fn: Operator): void;
|
|
37
37
|
export function compile(node: AST): Evaluator;
|
|
38
|
+
export namespace compile {
|
|
39
|
+
let id: (node: Identifier | undefined) => Evaluator;
|
|
40
|
+
}
|
|
38
41
|
|
|
39
42
|
// Default export
|
|
40
43
|
export default parse;
|
package/subscript.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),o=e.pop(),
|
|
3
|
-
${
|
|
4
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},
|
|
1
|
+
var s,l,f=r=>(s=0,l=r,f.enter?.(),r=A(),l[s]?E():r||""),E=(r="Unexpected token",t=s,e=l.slice(0,t).split(`
|
|
2
|
+
`),o=e.pop(),i=l.slice(Math.max(0,t-40),t),p="\u032D",u=(l[t]||" ")+p,d=l.slice(t+1,t+20))=>{throw SyntaxError(`${r} at ${e.length+1}:${o.length+1}
|
|
3
|
+
${i}${u}${d}`)},dr=(r,t=s)=>(Array.isArray(r)&&(r.loc=t),r),S=(r,t=s,e)=>{for(;e=r(l.charCodeAt(s));)s+=e;return l.slice(t,s)},R=(r=1)=>l[s+=r],Jr=r=>s=r,A=(r=0,t)=>{let e,o,i;for(t&&f.enter?.(r,t);(e=f.space())&&e!==t&&(i=f.step(o,r,e,A));)o=i;return t&&(e==t?(s++,f.exit?.(r,t)):E("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),o},hr=(r=s)=>{for(;l.charCodeAt(r)<=32;)r++;return l.charCodeAt(r)},Vr=f.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,Yr=(r,t=r.length)=>l.substr(s,t)===r&&!f.id(l.charCodeAt(s+t)),Zr=()=>(R(),A(0,41)),C=[],D={},g=(r,t=32,e,o=r.charCodeAt(0))=>v({op:r,l:r.length,p:D[r]=!C[o]&&D[r]||t,map:e,word:r.toUpperCase()!==r,kw:!1}),c=(r,t,e=!1)=>g(r,t,(o,i)=>o&&(i=A(t-(e?.5:0)))&&[r,o,i]),y=(r,t,e)=>g(r,t,o=>e?o&&[r,o]:!o&&(o=A(t-.5))&&[r,o]),qr=(r,t)=>g(r,200,e=>!e&&[,t]),F=(r,t,e,o)=>g(r,t,(i,p,u=i)=>(p=A(t-(e?.5:0)),i?.[0]!==r&&(i=[r,i||null]),p?.[0]===r?i.push(...p.slice(1)):p?i.push(p):o||hr()===r.charCodeAt(0)?i.push(null):u&&i.length===2&&(i=i[1]),i)),H=(r,t)=>g(r[0],t,e=>!e&&[r,A(0,r.charCodeAt(1))||null]),O=(r,t)=>g(r[0],t,e=>e&&[r,e,A(0,r.charCodeAt(1))||null]),Ar=(r,t)=>(f.space(),t=l.charCodeAt(s),f.id(t)&&(t<48||t>57)?S(f.id):A(r)),K=(r,t)=>g(r,t,(e,o)=>e&&(o=Ar(t))&&[r,e,o]),jr=(r,t,e)=>(D[r]??=t,v({op:r,l:r.length,p:t,map:e,word:!0,kw:!0})),G=(r,t,e=(o,i,p,u=s,d,h,N)=>{for(N=0;h=r[N++];)if(!(h.kw&&o)&&!(p?h.op!==p:!((h.l<2||h.op.charCodeAt(1)===l.charCodeAt(s+1)&&(h.l<3||l.substr(s,h.l)===h.op))&&(!h.word||!f.id(l.charCodeAt(s+h.l)))&&(p=h.op)))&&!(i>=h.p)&&!(h.kw&&f.prop&&!f.prop(s+h.l))){if(s+=h.l,d=h.map(o))return dr(d,u);s=u,p=0,h.word||o||t||r[N]||E()}return t?.(o,i,p)})=>(e.ops=r,e.tail=t,e),v=(r,t=r.op.charCodeAt(0),e=C[t])=>C[t]=e?.ops?G([r,...e.ops],e.tail):G([r],e);f.space=r=>{for(;(r=l.charCodeAt(s))<=32;)s++;return r};f.step=(r,t,e,o,i)=>(i=C[e])&&i(r,t)||(r?null:S(f.id)||null);var M={},m=(r,t,e=M[r])=>M[r]=(...o)=>t(...o)||e?.(...o),n=r=>Array.isArray(r)?r[0]==null?(t=>()=>t)(r[1]):M[r[0]]?.(...r.slice(1))??E(`Unknown operator: ${r[0]}`,r?.loc):n.id(r);n.id=r=>r===void 0?()=>{}:t=>t?.[r];var $=46,w=48,_=57,W=69,x=101,Cr=43,gr=45,z=95,Er=97,Sr=102,yr=65,wr=70,J=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),Rr=r=>r===$&&(r=l.charCodeAt(s+1))!==$&&!(f.id(r)&&r>_&&r!==x&&r!==W)||r>=w&&r<=_||r===z||((r===W||r===x)&&((r=l.charCodeAt(s+1))>=w&&r<=_||r===Cr||r===gr)?2:0),X=r=>(r=+J(S(Rr)))!=r?E():[,r],_r=r=>t=>t===z||t>=w&&t<=_&&t-w<r||r===16&&(t>=Er&&t<=Sr||t>=yr&&t<=wr);f.number=null;C[$]=r=>!r&&l.charCodeAt(s+1)>=w&&l.charCodeAt(s+1)<=_&&X();for(let r=w;r<=_;r++)C[r]=t=>t?void 0:X();C[w]=(r,t)=>{if(!r){for(let e in f.number)if(e[0]==="0"&&(l.charCodeAt(s+1)|32)===e.charCodeAt(1)){R(2);let o=J(S(_r(t=f.number[e])));return[,parseInt(o,t)]}return X()}};var Pr=92,V=34,Y=39,Z=117,q=120,Ur=123,Ir=125,j=10,Tr=13,Lr={n:`
|
|
4
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},a=r=>r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:-1,Nr=()=>{let r=l.charCodeAt(s+1);if(r===j)return["",2];if(r===Tr)return["",l.charCodeAt(s+2)===j?3:2];if(r===q||r===Z&&l.charCodeAt(s+2)!==Ur){let t=r===q?2:4,e=0,o;for(let i=0;i<t;i++){if((o=a(l.charCodeAt(s+2+i)))<0)return[l[s+1],2];e=e*16+o}return[String.fromCharCode(e),2+t]}if(r===Z){let t=0,e=s+3,o;for(;(o=a(l.charCodeAt(e)))>=0;)t=t*16+o,e++;return e>s+3&&t<=1114111&&l.charCodeAt(e)===Ir?[String.fromCodePoint(t),e-s+1]:[l[s+1],2]}return[Lr[l[s+1]]||l[s+1],2]},b=r=>(t,e,o="",i=String.fromCharCode(r))=>{if(t||!f.string?.[i])return;R();let p=()=>{let[u,d]=Nr();return o+=u,d};return S(u=>u-r&&(u!==Pr?(o+=l[s],1):p())),l[s]===i?R():E("Bad string"),[,o]};C[V]=b(V);C[Y]=b(Y);f.string={'"':!0};var Dr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>c(r,Dr,!0));var Mr=30,Fr=40,Or=140;y("!",Or);c("||",Mr);c("&&",Fr);var $r=50,Xr=60,kr=70,rr=100,Br=140;c("|",$r);c("&",kr);c("^",Xr);c(">>",rr);c("<<",rr);y("~",Br);var U=90;c("<",U);c(">",U);c("<=",U);c(">=",U);var tr=80;c("==",tr);c("!=",tr);var er=110,k=120,or=140;c("+",er);c("-",er);c("*",k);c("/",k);c("%",k);y("+",or);y("-",or);var I=150;g("++",I,r=>r?["++",r,null]:["++",A(I-1)]);g("--",I,r=>r?["--",r,null]:["--",A(I-1)]);var Qr=5,Gr=10;F(",",Gr);F(";",Qr,!0,!0);var Hr=170;H("()",Hr);var nr=170,Kr=160;O("[]",nr);K(".",nr);O("()",Kr);var sr=(r,t,e,o)=>typeof r=="string"?i=>t(i,r,i):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o,i)):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i),i)):r[0]==="()"&&r.length===2?sr(r[1],t):(()=>{throw Error("Invalid assignment target")})(),ir={"=":(r,t,e)=>r[t]=e,"+=":(r,t,e)=>r[t]+=e,"-=":(r,t,e)=>r[t]-=e,"*=":(r,t,e)=>r[t]*=e,"/=":(r,t,e)=>r[t]/=e,"%=":(r,t,e)=>r[t]%=e,"|=":(r,t,e)=>r[t]|=e,"&=":(r,t,e)=>r[t]&=e,"^=":(r,t,e)=>r[t]^=e,">>=":(r,t,e)=>r[t]>>=e,"<<=":(r,t,e)=>r[t]<<=e};for(let r in ir)m(r,(t,e)=>(e=n(e),sr(t,(o,i,p)=>ir[r](o,i,e(p)))));m("!",r=>(r=n(r),t=>!r(t)));m("||",(r,t)=>(r=n(r),t=n(t),e=>r(e)||t(e)));m("&&",(r,t)=>(r=n(r),t=n(t),e=>r(e)&&t(e)));m("~",r=>(r=n(r),t=>~r(t)));m("|",(r,t)=>(r=n(r),t=n(t),e=>r(e)|t(e)));m("&",(r,t)=>(r=n(r),t=n(t),e=>r(e)&t(e)));m("^",(r,t)=>(r=n(r),t=n(t),e=>r(e)^t(e)));m(">>",(r,t)=>(r=n(r),t=n(t),e=>r(e)>>t(e)));m("<<",(r,t)=>(r=n(r),t=n(t),e=>r(e)<<t(e)));m(">",(r,t)=>(r=n(r),t=n(t),e=>r(e)>t(e)));m("<",(r,t)=>(r=n(r),t=n(t),e=>r(e)<t(e)));m(">=",(r,t)=>(r=n(r),t=n(t),e=>r(e)>=t(e)));m("<=",(r,t)=>(r=n(r),t=n(t),e=>r(e)<=t(e)));m("==",(r,t)=>(r=n(r),t=n(t),e=>r(e)==t(e)));m("!=",(r,t)=>(r=n(r),t=n(t),e=>r(e)!=t(e)));m("+",(r,t)=>t!==void 0?(r=n(r),t=n(t),e=>r(e)+t(e)):(r=n(r),e=>+r(e)));m("-",(r,t)=>t!==void 0?(r=n(r),t=n(t),e=>r(e)-t(e)):(r=n(r),e=>-r(e)));m("*",(r,t)=>(r=n(r),t=n(t),e=>r(e)*t(e)));m("/",(r,t)=>(r=n(r),t=n(t),e=>r(e)/t(e)));m("%",(r,t)=>(r=n(r),t=n(t),e=>r(e)%t(e)));var B=(r,t,e,o)=>typeof r=="string"?i=>t(i,r):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o)):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i))):r[0]==="()"&&r.length===2?B(r[1],t):(()=>{throw Error("Invalid increment target")})();m("++",(r,t)=>B(r,t===null?(e,o)=>e[o]++:(e,o)=>++e[o]));m("--",(r,t)=>B(r,t===null?(e,o)=>e[o]--:(e,o)=>--e[o]));var pr=(...r)=>(r=r.map(n),t=>{let e;for(let o of r)e=o(t);return e});m(",",pr);m(";",pr);var lr=r=>r!=null&&(typeof r=="object"||typeof r=="function"),L=r=>lr(r)?Reflect.ownKeys({[r]:0})[0]:r,P=r=>typeof r=="string"&&(r[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype"),vr=r=>P(L(r));n.id=r=>r===void 0||vr(r)?()=>{}:t=>t?.[r];var T=r=>{throw Error(r)};m("[]",(r,t)=>t===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(e=>e==null?(()=>{}):e[0]==="..."?(e=n(e[1]),o=>e(o)):(e=n(e),o=>[e(o)])),e=>r.flatMap(o=>o(e))):(t==null&&T("Missing index"),r=n(r),t=n(t),e=>{let o=L(t(e));return P(o)?void 0:r(e)[o]}));m(".",(r,t)=>(r=n(r),t=L(t[0]?t:t[1]),P(t)?()=>{}:e=>r(e)[t]));m("()",(r,t)=>{if(t===void 0)return r==null?T("Empty ()"):n(r);let e=p=>p?.[0]===","&&p.slice(1).some(u=>u==null||e(u));e(t)&&T("Empty argument");let o=t?t[0]===","?(t=t.slice(1).map(n),p=>t.map(u=>u(p))):(t=n(t),p=>[t(p)]):()=>[],i=ur(r);return i<0?()=>{}:mr(r,i?(p,u,d)=>(u=L(u),P(u)?void 0:p[u](...o(d))):(p,u,d)=>p[u](...o(d)))});var mr=(r,t,e,o)=>r==null?T("Empty ()"):r[0]==="()"&&r.length==2?mr(r[1],t):typeof r=="string"?i=>t(i,r,i):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o,i)):r[0]==="?."?(e=n(r[1]),o=r[2],i=>{let p=e(i);return p==null?void 0:t(p,o,i)}):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i),i)):r[0]==="?.[]"?(e=n(r[1]),o=n(r[2]),i=>{let p=e(i);return p==null?void 0:t(p,o(i),i)}):(r=n(r),i=>t([r(i)],0,i)),Q=r=>lr(r)?1:P(r)?-1:0,ur=(r,t=r?.[0],e=r?.[2])=>typeof r=="string"?Q(r):t==="()"&&r.length==2?ur(r[1]):t==="."||t==="?."?Q(e):(t==="[]"||t==="?.[]")&&r.length===3?Array.isArray(e)&&e[0]==null?Q(e[1]):1:0;var fr=new WeakMap,Wr=(r,...t)=>typeof r=="string"?n(f(r)):fr.get(r)||fr.set(r,xr(r,t)).get(r),cr=57344,xr=(r,t)=>{let e=r.reduce((p,u,d)=>p+(d?String.fromCharCode(cr+d-1):"")+u,""),o=f(e),i=p=>{if(typeof p=="string"&&p.length===1){let u=p.charCodeAt(0)-cr,d;if(u>=0&&u<t.length)return d=t[u],zr(d)?d:[,d]}return Array.isArray(p)?p.map(i):p};return n(i(o))},zr=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Yt=Wr;export{O as access,c as binary,n as compile,l as cur,Yt as default,E as err,A as expr,H as group,Vr as id,s as idx,jr as keyword,qr as literal,dr as loc,C as lookup,K as member,F as nary,S as next,m as operator,M as operators,Zr as parens,f as parse,hr as peek,D as prec,Ar as propName,Jr as seek,R as skip,g as token,y as unary,Yr as word};
|