subscript 9.2.0 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -169
- package/feature/access.js +67 -7
- package/feature/accessor.js +49 -0
- package/feature/asi.js +15 -0
- package/feature/async.js +45 -0
- package/feature/block.js +41 -0
- package/feature/class.js +69 -0
- package/feature/collection.js +40 -0
- package/feature/comment.js +25 -5
- package/feature/destruct.js +33 -0
- package/feature/function.js +44 -0
- package/feature/group.js +39 -9
- package/feature/if.js +23 -38
- package/feature/literal.js +13 -0
- package/feature/loop.js +107 -106
- package/feature/module.js +42 -0
- package/feature/number.js +41 -38
- package/feature/op/arithmetic.js +29 -0
- package/feature/op/arrow.js +33 -0
- package/feature/op/assign-logical.js +33 -0
- package/feature/op/assignment.js +47 -0
- package/feature/op/bitwise-unsigned.js +17 -0
- package/feature/op/bitwise.js +29 -0
- package/feature/op/comparison.js +19 -0
- package/feature/op/defer.js +15 -0
- package/feature/op/equality.js +16 -0
- package/feature/op/identity.js +15 -0
- package/feature/op/increment.js +23 -0
- package/feature/op/logical.js +21 -0
- package/feature/op/membership.js +17 -0
- package/feature/op/nullish.js +13 -0
- package/feature/op/optional.js +61 -0
- package/feature/op/pow.js +19 -0
- package/feature/op/range.js +26 -0
- package/feature/op/spread.js +15 -0
- package/feature/op/ternary.js +15 -0
- package/feature/op/type.js +18 -0
- package/feature/op/unary.js +41 -0
- package/feature/prop.js +34 -0
- package/feature/regex.js +31 -0
- package/feature/seq.js +21 -0
- package/feature/string.js +24 -17
- package/feature/switch.js +48 -0
- package/feature/template.js +39 -0
- package/feature/try.js +57 -0
- package/feature/unit.js +35 -0
- package/feature/var.js +51 -41
- package/jessie.js +31 -0
- package/jessie.min.js +8 -0
- package/justin.js +39 -48
- package/justin.min.js +8 -4
- package/package.json +15 -16
- package/parse.js +153 -0
- package/subscript.d.ts +45 -5
- package/subscript.js +62 -22
- package/subscript.min.js +5 -4
- package/util/bundle.js +507 -0
- package/util/stringify.js +172 -0
- package/feature/add.js +0 -22
- package/feature/array.js +0 -11
- package/feature/arrow.js +0 -23
- package/feature/assign.js +0 -11
- package/feature/bitwise.js +0 -11
- package/feature/bool.js +0 -5
- package/feature/call.js +0 -15
- package/feature/compare.js +0 -11
- package/feature/control.js +0 -142
- package/feature/increment.js +0 -11
- package/feature/logic.js +0 -11
- package/feature/mult.js +0 -25
- package/feature/object.js +0 -17
- package/feature/optional.js +0 -23
- package/feature/pow.js +0 -5
- package/feature/shift.js +0 -12
- package/feature/spread.js +0 -6
- package/feature/ternary.js +0 -10
- package/src/compile.d.ts +0 -17
- package/src/compile.js +0 -28
- package/src/const.js +0 -45
- package/src/parse.d.ts +0 -22
- package/src/parse.js +0 -113
- package/src/stringify.js +0 -27
- /package/{LICENSE → license} +0 -0
package/feature/string.js
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Strings with escape sequences
|
|
3
|
+
*
|
|
4
|
+
* Configurable via parse.string: { '"': true } or { '"': true, "'": true }
|
|
5
|
+
*/
|
|
6
|
+
import { parse, lookup, next, err, skip, idx, cur } from '../parse.js';
|
|
3
7
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
qc && err('Unexpected string') // must not follow another token
|
|
7
|
-
skip()
|
|
8
|
-
// while (c = cur.charCodeAt(idx), c - q) {
|
|
9
|
-
// if (c === BSLASH) skip(), c = cur[idx], skip(), str += escape[c] || c
|
|
10
|
-
// else str += cur[idx], skip()
|
|
11
|
-
// }
|
|
12
|
-
next(c => c - q && (c === BSLASH ? (str += escape[cur[idx+1]] || cur[idx+1], 2 ) : (str += cur[idx], 1)))
|
|
13
|
-
skip() || err('Bad string')
|
|
14
|
-
return [, str]
|
|
15
|
-
}
|
|
8
|
+
const BSLASH = 92, DQUOTE = 34, SQUOTE = 39;
|
|
9
|
+
const esc = { n: '\n', r: '\r', t: '\t', b: '\b', f: '\f', v: '\v' };
|
|
16
10
|
|
|
11
|
+
// Parse string with given quote char code
|
|
12
|
+
const parseString = q => (a, _, s = '') => {
|
|
13
|
+
if (a || !parse.string?.[String.fromCharCode(q)]) return;
|
|
14
|
+
skip();
|
|
15
|
+
next(c => c - q && (c === BSLASH ? (s += esc[cur[idx + 1]] || cur[idx + 1], 2) : (s += cur[idx], 1)));
|
|
16
|
+
cur[idx] === String.fromCharCode(q) ? skip() : err('Bad string');
|
|
17
|
+
return [, s];
|
|
18
|
+
};
|
|
17
19
|
|
|
18
|
-
//
|
|
19
|
-
lookup[DQUOTE] =
|
|
20
|
-
lookup[
|
|
20
|
+
// Register both quote chars (enabled via parse.string config)
|
|
21
|
+
lookup[DQUOTE] = parseString(DQUOTE);
|
|
22
|
+
lookup[SQUOTE] = parseString(SQUOTE);
|
|
23
|
+
|
|
24
|
+
// Default: double quotes only
|
|
25
|
+
parse.string = { '"': true };
|
|
26
|
+
|
|
27
|
+
export { esc };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Switch/case/default
|
|
2
|
+
// AST: ['switch', val, [';', ['case', test], stmts..., ['default'], stmts...]]
|
|
3
|
+
import { expr, skip, space, parens, operator, compile } from '../parse.js';
|
|
4
|
+
import { keyword, block } from './block.js';
|
|
5
|
+
import { BREAK } from './loop.js';
|
|
6
|
+
|
|
7
|
+
const STATEMENT = 5, ASSIGN = 20, COLON = 58;
|
|
8
|
+
|
|
9
|
+
keyword('switch', STATEMENT + 1, () => (space(), ['switch', parens(), block()]));
|
|
10
|
+
keyword('case', STATEMENT + 1, () => (space(), (c => (space() === COLON && skip(), ['case', c]))(expr(ASSIGN))));
|
|
11
|
+
keyword('default', STATEMENT + 1, () => (space() === COLON && skip(), ['default']));
|
|
12
|
+
|
|
13
|
+
// Compile
|
|
14
|
+
operator('switch', (val, cases) => {
|
|
15
|
+
val = compile(val);
|
|
16
|
+
// Parse cases body: [';', ['case', test], stmts..., ['default'], stmts...]
|
|
17
|
+
if (!cases) return ctx => val(ctx);
|
|
18
|
+
const parsed = [];
|
|
19
|
+
const items = cases[0] === ';' ? cases.slice(1) : [cases];
|
|
20
|
+
let current = null;
|
|
21
|
+
for (const item of items) {
|
|
22
|
+
if (Array.isArray(item) && (item[0] === 'case' || item[0] === 'default')) {
|
|
23
|
+
if (current) parsed.push(current);
|
|
24
|
+
current = [item[0] === 'case' ? compile(item[1]) : null, []];
|
|
25
|
+
} else if (current) {
|
|
26
|
+
current[1].push(compile(item));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (current) parsed.push(current);
|
|
30
|
+
|
|
31
|
+
return ctx => {
|
|
32
|
+
const v = val(ctx);
|
|
33
|
+
let matched = false, result;
|
|
34
|
+
for (const [test, stmts] of parsed) {
|
|
35
|
+
if (matched || test === null || test(ctx) === v) {
|
|
36
|
+
matched = true;
|
|
37
|
+
for (const stmt of stmts) {
|
|
38
|
+
try { result = stmt(ctx); }
|
|
39
|
+
catch (e) {
|
|
40
|
+
if (e?.type === BREAK) return e.value !== undefined ? e.value : result;
|
|
41
|
+
throw e;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template literals: `a ${x} b` → ['`', [,'a '], 'x', [,' b']]
|
|
3
|
+
* Tagged templates: tag`...` → ['``', 'tag', ...]
|
|
4
|
+
*/
|
|
5
|
+
import { parse, skip, err, expr, lookup, cur, idx, operator, compile } from '../parse.js';
|
|
6
|
+
|
|
7
|
+
const ACCESS = 170, BACKTICK = 96, DOLLAR = 36, OBRACE = 123, BSLASH = 92;
|
|
8
|
+
const esc = { n: '\n', r: '\r', t: '\t', b: '\b', f: '\f', v: '\v' };
|
|
9
|
+
|
|
10
|
+
// Parse template body after opening `
|
|
11
|
+
const parseBody = () => {
|
|
12
|
+
const parts = [];
|
|
13
|
+
for (let s = '', c; (c = cur.charCodeAt(idx)) !== BACKTICK; )
|
|
14
|
+
!c ? err('Unterminated template') :
|
|
15
|
+
c === BSLASH ? (skip(), s += esc[cur[idx]] || cur[idx], skip()) :
|
|
16
|
+
c === DOLLAR && cur.charCodeAt(idx + 1) === OBRACE ? (s && parts.push([, s]), s = '', skip(2), parts.push(expr(0, 125))) :
|
|
17
|
+
(s += cur[idx], skip(), c = cur.charCodeAt(idx), c === BACKTICK && s && parts.push([, s]));
|
|
18
|
+
return skip(), parts;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const prev = lookup[BACKTICK];
|
|
22
|
+
// Tagged templates: decline when ASI with newline (return undefined to let ASI handle)
|
|
23
|
+
lookup[BACKTICK] = (a, prec) =>
|
|
24
|
+
a && prec < ACCESS ? (parse.asi && parse.newline ? void 0 : (skip(), ['``', a, ...parseBody()])) : // tagged
|
|
25
|
+
!a ? (skip(), (p => p.length < 2 && p[0]?.[0] === undefined ? p[0] || [,''] : ['`', ...p])(parseBody())) : // plain
|
|
26
|
+
prev?.(a, prec);
|
|
27
|
+
|
|
28
|
+
// Compile
|
|
29
|
+
operator('`', (...parts) => (parts = parts.map(compile), ctx => parts.map(p => p(ctx)).join('')));
|
|
30
|
+
operator('``', (tag, ...parts) => {
|
|
31
|
+
tag = compile(tag);
|
|
32
|
+
const strings = [], exprs = [];
|
|
33
|
+
for (const p of parts) {
|
|
34
|
+
if (Array.isArray(p) && p[0] === undefined) strings.push(p[1]);
|
|
35
|
+
else exprs.push(compile(p));
|
|
36
|
+
}
|
|
37
|
+
const strs = Object.assign([...strings], { raw: strings });
|
|
38
|
+
return ctx => tag(ctx)(strs, ...exprs.map(e => e(ctx)));
|
|
39
|
+
});
|
package/feature/try.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// try/catch/finally/throw statements
|
|
2
|
+
// AST: ['catch', ['try', body], param, catchBody] or ['finally', inner, body]
|
|
3
|
+
import { space, parse, parens, expr, operator, compile } from '../parse.js';
|
|
4
|
+
import { keyword, infix, block } from './block.js';
|
|
5
|
+
import { BREAK, CONTINUE, RETURN } from './loop.js';
|
|
6
|
+
|
|
7
|
+
const STATEMENT = 5;
|
|
8
|
+
|
|
9
|
+
keyword('try', STATEMENT + 1, () => ['try', block()]);
|
|
10
|
+
infix('catch', STATEMENT + 1, a => (space(), ['catch', a, parens(), block()]));
|
|
11
|
+
infix('finally', STATEMENT + 1, a => ['finally', a, block()]);
|
|
12
|
+
|
|
13
|
+
keyword('throw', STATEMENT + 1, () => {
|
|
14
|
+
parse.asi && (parse.newline = false);
|
|
15
|
+
space();
|
|
16
|
+
if (parse.newline) throw SyntaxError('Unexpected newline after throw');
|
|
17
|
+
return ['throw', expr(STATEMENT)];
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Compile
|
|
21
|
+
operator('try', tryBody => {
|
|
22
|
+
tryBody = tryBody ? compile(tryBody) : null;
|
|
23
|
+
return ctx => tryBody?.(ctx);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
operator('catch', (tryNode, catchName, catchBody) => {
|
|
27
|
+
const tryBody = tryNode?.[1] ? compile(tryNode[1]) : null;
|
|
28
|
+
catchBody = catchBody ? compile(catchBody) : null;
|
|
29
|
+
return ctx => {
|
|
30
|
+
let result;
|
|
31
|
+
try {
|
|
32
|
+
result = tryBody?.(ctx);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
if (e?.type === BREAK || e?.type === CONTINUE || e?.type === RETURN) throw e;
|
|
35
|
+
if (catchName !== null && catchBody) {
|
|
36
|
+
const had = catchName in ctx, orig = ctx[catchName];
|
|
37
|
+
ctx[catchName] = e;
|
|
38
|
+
try { result = catchBody(ctx); }
|
|
39
|
+
finally { had ? ctx[catchName] = orig : delete ctx[catchName]; }
|
|
40
|
+
} else if (catchName === null) throw e;
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
operator('finally', (inner, finallyBody) => {
|
|
47
|
+
inner = inner ? compile(inner) : null;
|
|
48
|
+
finallyBody = finallyBody ? compile(finallyBody) : null;
|
|
49
|
+
return ctx => {
|
|
50
|
+
let result;
|
|
51
|
+
try { result = inner?.(ctx); }
|
|
52
|
+
finally { finallyBody?.(ctx); }
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
operator('throw', val => (val = compile(val), ctx => { throw val(ctx); }));
|
package/feature/unit.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit suffixes: 5px, 10rem, 2s, 500ms
|
|
3
|
+
*
|
|
4
|
+
* AST:
|
|
5
|
+
* 5px → ['px', [,5]]
|
|
6
|
+
* 2.5s → ['s', [,2.5]]
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { unit } from 'subscript/feature/unit.js'
|
|
10
|
+
* unit('px', 'em', 'rem', 's', 'ms')
|
|
11
|
+
*/
|
|
12
|
+
import { lookup, next, parse, idx, seek, operator, compile } from '../parse.js';
|
|
13
|
+
|
|
14
|
+
const units = {};
|
|
15
|
+
|
|
16
|
+
export const unit = (...names) => names.forEach(name => {
|
|
17
|
+
units[name] = 1;
|
|
18
|
+
operator(name, val => (val = compile(val), ctx => ({ value: val(ctx), unit: name })));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Wrap number handler to check for unit suffix
|
|
22
|
+
const wrapNum = cc => {
|
|
23
|
+
const orig = lookup[cc];
|
|
24
|
+
if (!orig) return;
|
|
25
|
+
lookup[cc] = (a, prec) => {
|
|
26
|
+
const r = orig(a, prec);
|
|
27
|
+
if (!r || r[0] !== undefined) return r;
|
|
28
|
+
const start = idx, u = next(c => parse.id(c) && !(c >= 48 && c <= 57));
|
|
29
|
+
return u && units[u] ? [u, r] : (u && seek(start), r);
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Wrap digit and period handlers
|
|
34
|
+
for (let i = 48; i <= 57; i++) wrapNum(i);
|
|
35
|
+
wrapNum(46);
|
package/feature/var.js
CHANGED
|
@@ -1,49 +1,59 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Variable declarations: let, const
|
|
3
|
-
*
|
|
2
|
+
* Variable declarations: let, const, var
|
|
3
|
+
*
|
|
4
4
|
* AST:
|
|
5
|
-
* let x
|
|
6
|
-
* let x = 1
|
|
7
|
-
* const
|
|
5
|
+
* let x = 1 → ['let', ['=', 'x', 1]]
|
|
6
|
+
* let x = 1, y = 2 → ['let', ['=', 'x', 1], ['=', 'y', 2]]
|
|
7
|
+
* const {a} = x → ['const', ['=', ['{}', 'a'], 'x']]
|
|
8
|
+
* for (let x in o) → ['for', ['in', ['let', 'x'], 'o'], body]
|
|
9
|
+
* var x → ['var', 'x'] (acts as assignment target)
|
|
8
10
|
*/
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
11
|
+
import { token, expr, space, operator, compile } from '../parse.js';
|
|
12
|
+
import { keyword } from './block.js';
|
|
13
|
+
import { destructure } from './destruct.js';
|
|
12
14
|
|
|
13
|
-
const
|
|
15
|
+
const STATEMENT = 5, SEQ = 10, ASSIGN = 20;
|
|
14
16
|
|
|
15
|
-
// let
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return [
|
|
27
|
-
}
|
|
17
|
+
// let/const: expr(SEQ-1) consumes assignment, stops before comma
|
|
18
|
+
// For for-in/of, return ['in/of', ['let', x], iterable] not ['let', ['in', x, it]]
|
|
19
|
+
// For comma, return ['let', decl1, decl2, ...] not ['let', [',', ...]]
|
|
20
|
+
const decl = keyword => {
|
|
21
|
+
let node = expr(SEQ - 1);
|
|
22
|
+
// for (let x in obj) - restructure so for-loop sees in/of at top
|
|
23
|
+
if (node?.[0] === 'in' || node?.[0] === 'of')
|
|
24
|
+
return [node[0], [keyword, node[1]], node[2]];
|
|
25
|
+
// let x = 1, y = 2 - flatten comma into nary let
|
|
26
|
+
if (node?.[0] === ',')
|
|
27
|
+
return [keyword, ...node.slice(1)];
|
|
28
|
+
return [keyword, node];
|
|
29
|
+
};
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return ctx => { ctx[name] = val ? val(ctx) : undefined }
|
|
32
|
-
})
|
|
31
|
+
token('let', STATEMENT + 1, a => !a && decl('let'));
|
|
32
|
+
token('const', STATEMENT + 1, a => !a && decl('const'));
|
|
33
33
|
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
space()
|
|
38
|
-
const name = next(parse.id)
|
|
39
|
-
if (!name) err('Expected identifier')
|
|
40
|
-
space()
|
|
41
|
-
P.cur.charCodeAt(P.idx) === 61 && P.cur.charCodeAt(P.idx + 1) !== 61 || err('Expected =')
|
|
42
|
-
skip()
|
|
43
|
-
return ['const', name, expr(PREC_STATEMENT)]
|
|
44
|
-
})
|
|
34
|
+
// var: just declares identifier, assignment happens separately
|
|
35
|
+
// var x = 5 → ['=', ['var', 'x'], 5]
|
|
36
|
+
keyword('var', STATEMENT, () => (space(), ['var', expr(ASSIGN)]));
|
|
45
37
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
// Compile
|
|
39
|
+
const varOp = (...decls) => {
|
|
40
|
+
decls = decls.map(d => {
|
|
41
|
+
// Just identifier: let x
|
|
42
|
+
if (typeof d === 'string') return ctx => { ctx[d] = undefined; };
|
|
43
|
+
// Assignment: let x = 1
|
|
44
|
+
if (d[0] === '=') {
|
|
45
|
+
const [, pattern, val] = d;
|
|
46
|
+
const v = compile(val);
|
|
47
|
+
if (typeof pattern === 'string') return ctx => { ctx[pattern] = v(ctx); };
|
|
48
|
+
return ctx => destructure(pattern, v(ctx), ctx);
|
|
49
|
+
}
|
|
50
|
+
return compile(d);
|
|
51
|
+
});
|
|
52
|
+
return ctx => { for (const d of decls) d(ctx); };
|
|
53
|
+
};
|
|
54
|
+
operator('let', varOp);
|
|
55
|
+
operator('const', varOp);
|
|
56
|
+
// var just declares the variable (assignment handled by = operator)
|
|
57
|
+
operator('var', name => (typeof name === 'string'
|
|
58
|
+
? ctx => { ctx[name] = undefined; }
|
|
59
|
+
: () => {}));
|
package/jessie.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* jessie: Practical JS subset
|
|
3
|
+
*
|
|
4
|
+
* Builds on justin with statements: blocks, variables, if/else,
|
|
5
|
+
* loops, functions, try/catch, switch, throw.
|
|
6
|
+
*/
|
|
7
|
+
import './justin.js';
|
|
8
|
+
|
|
9
|
+
// Statement features (var.js must come before destruct.js)
|
|
10
|
+
import './feature/var.js';
|
|
11
|
+
import './feature/function.js';
|
|
12
|
+
import './feature/async.js';
|
|
13
|
+
import './feature/class.js';
|
|
14
|
+
import './feature/regex.js';
|
|
15
|
+
import './feature/destruct.js';
|
|
16
|
+
|
|
17
|
+
// Control flow
|
|
18
|
+
import './feature/if.js';
|
|
19
|
+
import './feature/loop.js';
|
|
20
|
+
import './feature/try.js';
|
|
21
|
+
import './feature/switch.js';
|
|
22
|
+
|
|
23
|
+
// Module system
|
|
24
|
+
import './feature/module.js';
|
|
25
|
+
import './feature/accessor.js';
|
|
26
|
+
|
|
27
|
+
// Automatic Semicolon Insertion
|
|
28
|
+
import './feature/asi.js';
|
|
29
|
+
|
|
30
|
+
export * from './parse.js';
|
|
31
|
+
export { default } from './subscript.js';
|
package/jessie.min.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var l,d,c=r=>(l=0,d=r,c.newline=!1,r=A(),d[l]?I():r||""),I=(r="Unexpected token",e=l,t=d.slice(0,e).split(`
|
|
2
|
+
`),o=t.pop(),n=d.slice(Math.max(0,e-40),e),s="\u032D",u=(d[e]||"\u2205")+s,f=d.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
|
|
3
|
+
${(d[e-41]!==`
|
|
4
|
+
`?"...":"")+n}${u}${f}`)},Z=(r,e=l)=>(Array.isArray(r)&&(r.loc=e),r),k=(r,e=l,t)=>{for(;t=r(d.charCodeAt(l));)l+=t;return d.slice(e,l)},E=(r=1)=>d[l+=r],K=r=>l=r,A=(r=0,e)=>{let t,o,n,s,u=c.reserved,f;for(e&&c.asi&&(c.newline=!1),c.reserved=0;(t=c.space())&&(f=c.newline,1)&&t!==e&&(n=((s=C[t])&&s(o,r))??(c.asi&&o&&f&&(n=c.asi(o,r,A)))??(!o&&!c.reserved&&k(c.id)));)o=n,c.reserved=0;return c.reserved=u,e&&(t==e?l++:I("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},h=c.space=(r,e=l)=>{for(;(r=d.charCodeAt(l))<=32;)c.asi&&r===10&&(c.newline=!0),l++;return r},dt=c.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,D=(r,e=r.length)=>d.substr(l,e)===r&&!c.id(d.charCodeAt(l+e)),N=()=>(E(),A(0,41)),C=[],S=(r,e=32,t,o=r.charCodeAt(0),n=r.length,s=C[o],u=r.toUpperCase()!==r,f,y)=>C[o]=(g,T,X,w=l)=>(f=X,(X?r==X:(n<2||r.charCodeAt(1)===d.charCodeAt(l+1)&&(n<3||d.substr(l,n)==r))&&(!u||!c.id(d.charCodeAt(l+n)))&&(f=X=r))&&T<e&&(l+=n,(y=t(g))?Z(y,w):(l=w,f=0,u&&y!==!1&&(c.reserved=1),!u&&!s&&I()),y)||s?.(g,T,f)),m=(r,e,t=!1)=>S(r,e,(o,n)=>o&&(n=A(e-(t?.5:0)))&&[r,o,n]),v=(r,e,t)=>S(r,e,o=>t?o&&[r,o]:!o&&(o=A(e-.5))&&[r,o]),L=(r,e)=>S(r,200,t=>!t&&[,e]),pr=(r,e,t)=>{S(r,e,(o,n)=>(n=A(e-(t?.5:0)),o?.[0]!==r&&(o=[r,o||null]),n?.[0]===r?o.push(...n.slice(1)):o.push(n||null),o))},z=(r,e)=>S(r[0],e,t=>!t&&[r,A(0,r.charCodeAt(1))||null]),ur=(r,e)=>S(r[0],e,t=>t&&[r,t,A(0,r.charCodeAt(1))||null]),Tr,re=(r="Compile error",e=Tr)=>I(r,e?.loc),sr={},p=(r,e,t=sr[r])=>sr[r]=(...o)=>e(...o)||t?.(...o),i=r=>(Tr=r,Array.isArray(r)?r[0]===void 0?(e=>()=>e)(r[1]):sr[r[0]]?.(...r.slice(1))??re(`Unknown operator: ${r[0]}`):r===void 0?()=>{}:e=>e?.[r]);var q=46,J=48,x=57,ee=69,te=101,oe=43,ne=45,ie=97,se=102,pe=65,ue=70,fr=r=>[,(r=+k(e=>e===q&&d.charCodeAt(l+1)!==q||e>=J&&e<=x||((e===ee||e===te)&&((e=d.charCodeAt(l+1))>=J&&e<=x||e===oe||e===ne)?2:0)))!=r?I():r],fe={2:r=>r===48||r===49,8:r=>r>=48&&r<=55,16:r=>r>=J&&r<=x||r>=ie&&r<=se||r>=pe&&r<=ue};c.number=null;C[q]=r=>!r&&d.charCodeAt(l+1)!==q&&fr();for(let r=J;r<=x;r++)C[r]=e=>e?void 0:fr();C[J]=r=>{if(r)return;let e=c.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&d[l+1]?.toLowerCase()===t[1])return E(2),[,parseInt(k(fe[o]),o)]}return fr()};var le=92,Ir=34,Nr=39,me={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Rr=r=>(e,t,o="")=>{if(!(e||!c.string?.[String.fromCharCode(r)]))return E(),k(n=>n-r&&(n===le?(o+=me[d[l+1]]||d[l+1],2):(o+=d[l],1))),d[l]===String.fromCharCode(r)?E():I("Bad string"),[,o]};C[Ir]=Rr(Ir);C[Nr]=Rr(Nr);c.string={'"':!0};var P=20;m("=",P,!0);m("+=",P,!0);m("-=",P,!0);m("*=",P,!0);m("/=",P,!0);m("%=",P,!0);m("|=",P,!0);m("&=",P,!0);m("^=",P,!0);m(">>=",P,!0);m("<<=",P,!0);var _=(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?_(r[1],e):(()=>{throw Error("Invalid assignment target")})();p("=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]=e(n))));p("+=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]+=e(n))));p("-=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]-=e(n))));p("*=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]*=e(n))));p("/=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]/=e(n))));p("%=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]%=e(n))));p("|=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]|=e(n))));p("&=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]&=e(n))));p("^=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]^=e(n))));p(">>=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]>>=e(n))));p("<<=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]<<=e(n))));var ce=30,de=40,_r=140;m("!",_r);v("!",_r);m("||",ce);m("&&",de);p("!",r=>(r=i(r),e=>!r(e)));p("||",(r,e)=>(r=i(r),e=i(e),t=>r(t)||e(t)));p("&&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&&e(t)));var Ae=50,he=60,ye=70,Or=100,Ee=140;m("|",Ae);m("&",ye);m("^",he);m(">>",Or);m("<<",Or);v("~",Ee);p("~",r=>(r=i(r),e=>~r(e)));p("|",(r,e)=>(r=i(r),e=i(e),t=>r(t)|e(t)));p("&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&e(t)));p("^",(r,e)=>(r=i(r),e=i(e),t=>r(t)^e(t)));p(">>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>e(t)));p("<<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<<e(t)));var b=90;m("<",b);m(">",b);m("<=",b);m(">=",b);p(">",(r,e)=>(r=i(r),e=i(e),t=>r(t)>e(t)));p("<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<e(t)));p(">=",(r,e)=>(r=i(r),e=i(e),t=>r(t)>=e(t)));p("<=",(r,e)=>(r=i(r),e=i(e),t=>r(t)<=e(t)));var Pr=80;m("==",Pr);m("!=",Pr);p("==",(r,e)=>(r=i(r),e=i(e),t=>r(t)==e(t)));p("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(t)));var Mr=110,lr=120,Ur=140;m("+",Mr);m("-",Mr);m("*",lr);m("/",lr);m("%",lr);v("+",Ur);v("-",Ur);p("+",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)+e(t)):(r=i(r),t=>+r(t)));p("-",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)-e(t)):(r=i(r),t=>-r(t)));p("*",(r,e)=>(r=i(r),e=i(e),t=>r(t)*e(t)));p("/",(r,e)=>(r=i(r),e=i(e),t=>r(t)/e(t)));p("%",(r,e)=>(r=i(r),e=i(e),t=>r(t)%e(t)));var rr=150;S("++",rr,r=>r?["++",r,null]:["++",A(rr-1)]);S("--",rr,r=>r?["--",r,null]:["--",A(rr-1)]);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")})();p("++",(r,e)=>mr(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));p("--",(r,e)=>mr(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var cr=5,Lr=123,Fr=125,a=(r,e,t,o=r.charCodeAt(0),n=r.length,s=C[o],u)=>C[o]=(f,y,g,T=l)=>!f&&(g?r==g:(n<2||d.substr(l,n)==r)&&(g=r))&&y<e&&!c.id(d.charCodeAt(l+n))&&(K(l+n),(u=t())?Z(u,T):(K(T),!s&&I()),u)||s?.(f,y,g),dr=(r,e,t,o=r.charCodeAt(0),n=r.length,s=C[o],u)=>C[o]=(f,y,g,T=l)=>f&&(g?r==g:(n<2||d.substr(l,n)==r)&&(g=r))&&y<e&&!c.id(d.charCodeAt(l+n))&&(K(l+n),Z(u=t(f),T),u)||s?.(f,y,g),M=()=>(h()===Lr||I("Expected {"),E(),A(cr-.5,Fr)||null),B=()=>h()!==Lr?A(cr+.5):(E(),["block",A(cr-.5,Fr)||null]);p("block",r=>r===void 0?()=>{}:(r=i(r),e=>r(e)));var F=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...n]=r;if(o==="{}")for(let s of n){let u,f,y;s[0]==="="?[,[,u,f],y]=s:[,u,f]=s;let g=e[u];g===void 0&&y&&(g=i(y)(t)),F(f,g,t)}else if(o==="[]"){let s=0;for(let u of n){if(u===null){s++;continue}if(Array.isArray(u)&&u[0]==="..."){t[u[1]]=e.slice(s);break}let f=u,y;Array.isArray(u)&&u[0]==="="&&([,f,y]=u);let g=e[s++];g===void 0&&y&&(g=i(y)(t)),F(f,g,t)}}};var Q=Symbol("break"),j=Symbol("continue"),W=Symbol("return"),V=(r,e)=>{try{return{v:r(e)}}catch(t){if(t?.type===Q)return{b:1};if(t?.type===j)return{c:1};if(t?.type===W)return{r:1,v:t.value};throw t}},$=5,ge=125,ae=59;a("while",$+1,()=>(h(),["while",N(),B()]));a("do",$+1,()=>(r=>(h(),E(5),h(),["do",r,N()]))(B()));a("for",$+1,()=>(h(),D("await")?(E(5),h(),["for await",N(),B()]):["for",N(),B()]));a("break",$+1,()=>["break"]);a("continue",$+1,()=>["continue"]);a("return",$+1,()=>{c.asi&&(c.newline=!1),h();let r=d.charCodeAt(l);return!r||r===ge||r===ae||c.newline?["return"]:["return",A($)]});p("while",(r,e)=>(r=i(r),e=i(e),t=>{let o,n;for(;r(t)&&!(o=V(e,t)).b;){if(o.r)return o.v;o.c||(n=o.v)}return n}));p("do",(r,e)=>(r=i(r),e=i(e),t=>{let o,n;do{if((o=V(r,t)).b)break;if(o.r)return o.v;o.c||(n=o.v)}while(e(t));return n}));p("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),s=>{let u,f;for(t?.(s);o(s)&&!(u=V(e,s)).b;n?.(s)){if(u.r)return u.v;u.c||(f=u.v)}return f}}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 we(o,n,e);if(t==="of")return Se(o,n,e)}});var Se=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let s,u,f=o?null:n[r];for(let y of e(n)){if(o?F(r,y,n):n[r]=y,(s=V(t,n)).b)break;if(s.r)return s.v;s.c||(u=s.v)}return o||(n[r]=f),u}},we=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let s,u,f=o?null:n[r];for(let y in e(n)){if(o?F(r,y,n):n[r]=y,(s=V(t,n)).b)break;if(s.r)return s.v;s.c||(u=s.v)}return o||(n[r]=f),u}};p("break",()=>()=>{throw{type:Q}});p("continue",()=>()=>{throw{type:j}});p("return",r=>(r=r!==void 0?i(r):null,e=>{throw{type:W,value:r?.(e)}}));var G=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",hr=170;ur("[]",hr);m(".",hr);ur("()",hr);var Ar=r=>{throw Error(r)};p("[]",(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&&Ar("Missing index"),r=i(r),e=i(e),t=>{let o=e(t);return G(o)?void 0:r(t)[o]}));p(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],G(e)?()=>{}:t=>r(t)[e]));p("()",(r,e)=>{if(e===void 0)return r==null?Ar("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(s=>s==null||t(s));t(e)&&Ar("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];return R(r,(n,s,u)=>n[s](...o(u)),!0)});var U=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&U(r[1])||r[0]==="{}"),Ce=r=>{throw Error(r)},R=(r,e,t,o,n)=>r==null?Ce("Empty ()"):r[0]==="()"&&r.length==2?R(r[1],e,t):typeof r=="string"?s=>e(s,r,s):r[0]==="."?(o=i(r[1]),n=r[2],s=>e(o(s),n,s)):r[0]==="?."?(o=i(r[1]),n=r[2],s=>{let u=o(s);return u==null?void 0:e(u,n,s)}):r[0]==="[]"&&r.length===3?(o=i(r[1]),n=i(r[2]),s=>e(o(s),n(s),s)):r[0]==="?.[]"?(o=i(r[1]),n=i(r[2]),s=>{let u=o(s);return u==null?void 0:e(u,n(s),s)}):(r=i(r),s=>e([r(s)],0,s));var ke=5,ve=10,Te=170;z("()",Te);pr(",",ve);pr(";",ke,!0);var Gr=r=>{throw Error(r)};p("()",(r,e)=>{if(e===void 0)return r==null?Gr("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(s=>s==null||t(s));t(e)&&Gr("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];return R(r,(n,s,u)=>n[s](...o(u)),!0)});var Xr=(...r)=>(r=r.map(i),e=>{let t;for(let o of r)try{t=o(e)}catch(n){throw(n?.type===Q||n?.type===j)&&(n.value=t),n}return t});p(",",Xr);p(";",Xr);var Kr=new WeakMap,Ie=(r,...e)=>typeof r=="string"?i(c(r)):Kr.get(r)||Kr.set(r,Ne(r,e)).get(r),Dr=57344,Ne=(r,e)=>{let t=r.reduce((s,u,f)=>s+(f?String.fromCharCode(Dr+f-1):"")+u,""),o=c(t),n=s=>{if(typeof s=="string"&&s.length===1){let u=s.charCodeAt(0)-Dr,f;if(u>=0&&u<e.length)return f=e[u],Re(f)?f:[,f]}return Array.isArray(s)?s.map(n):s};return i(n(o))},Re=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Br=Ie;var _e=32,Oe=c.space;c.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};var yr;c.space=()=>{yr||(yr=Object.entries(c.comment).map(([n,s])=>[n,s,n.charCodeAt(0)]));for(var r;r=Oe();){for(var e=0,t;t=yr[e++];)if(r===t[2]&&d.substr(l,t[0].length)===t[0]){var o=l+t[0].length;if(t[1]===`
|
|
7
|
+
`)for(;d.charCodeAt(o)>=_e;)o++;else{for(;d[o]&&d.substr(o,t[1].length)!==t[1];)o++;d[o]&&(o+=t[1].length)}K(o),r=0;break}if(r)return r}return r};var Qr=80;m("===",Qr);m("!==",Qr);p("===",(r,e)=>(r=i(r),e=i(e),t=>r(t)===e(t)));p("!==",(r,e)=>(r=i(r),e=i(e),t=>r(t)!==e(t)));var Pe=30;m("??",Pe);p("??",(r,e)=>(r=i(r),e=i(e),t=>r(t)??e(t)));var Me=130,Ue=20;m("**",Me,!0);m("**=",Ue,!0);p("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));var Le=r=>{throw Error(r)};p("**=",(r,e)=>(U(r)||Le("Invalid assignment target"),e=i(e),R(r,(t,o,n)=>t[o]**=e(n))));var $r=90;m("in",$r);m("of",$r);p("in",(r,e)=>(r=i(r),e=i(e),t=>r(t)in e(t)));var Fe=20,Ge=100,Xe=r=>{throw Error(r)};m(">>>",Ge);m(">>>=",Fe,!0);p(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));p(">>>=",(r,e)=>(U(r)||Xe("Invalid assignment target"),e=i(e),R(r,(t,o,n)=>t[o]>>>=e(n))));var Er=20,er=r=>{throw Error(r)};m("||=",Er,!0);m("&&=",Er,!0);m("??=",Er,!0);p("=",(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 U(r)||er("Invalid assignment target"),e=i(e),R(r,(t,o,n)=>t[o]=e(n))});p("||=",(r,e)=>(U(r)||er("Invalid assignment target"),e=i(e),R(r,(t,o,n)=>t[o]||=e(n))));p("&&=",(r,e)=>(U(r)||er("Invalid assignment target"),e=i(e),R(r,(t,o,n)=>t[o]&&=e(n))));p("??=",(r,e)=>(U(r)||er("Invalid assignment target"),e=i(e),R(r,(t,o,n)=>t[o]??=e(n))));L("true",!0);L("false",!1);L("null",null);L("undefined",void 0);L("NaN",NaN);L("Infinity",1/0);var gr=20;S("?",gr,(r,e,t)=>r&&(e=A(gr-1))&&k(o=>o===58)&&(t=A(gr-1),["?",r,e,t]));p("?",(r,e,t)=>(r=i(r),e=i(e),t=i(t),o=>r(o)?e(o):t(o)));var Ke=20;m("=>",Ke,!0);p("=>",(r,e)=>{r=r[0]==="()"?r[1]:r,r=r?r[0]===","?r.slice(1):[r]:[];let t=-1,o=null;return r.length&&Array.isArray(r[r.length-1])&&r[r.length-1][0]==="..."&&(t=r.length-1,o=r[t][1],r=r.slice(0,-1)),e=i(e[0]==="{}"?e[1]:e),(n=null)=>(n=Object.create(n),(...s)=>(r.forEach((u,f)=>n[u]=s[f]),o&&(n[o]=s.slice(t)),e(n)))});var De=140;v("...",De);p("...",r=>(r=i(r),e=>Object.entries(r(e))));var Hr=170;S("?.",Hr,(r,e)=>{if(!r)return;let t=h();return t===40?(E(),["?.()",r,A(0,41)||null]):t===91?(E(),["?.[]",r,A(0,93)]):(e=A(Hr),e?["?.",r,e]:void 0)});p("?.",(r,e)=>(r=i(r),G(e)?()=>{}:t=>r(t)?.[e]));p("?.[]",(r,e)=>(r=i(r),e=i(e),t=>{let o=e(t);return G(o)?void 0:r(t)?.[o]}));p("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];if(r[0]==="?."){let n=i(r[1]),s=r[2];return G(s)?()=>{}:u=>n(u)?.[s]?.(...t(u))}if(r[0]==="?.[]"){let n=i(r[1]),s=i(r[2]);return u=>{let f=n(u),y=s(u);return G(y)?void 0:f?.[y]?.(...t(u))}}if(r[0]==="."){let n=i(r[1]),s=r[2];return G(s)?()=>{}:u=>n(u)?.[s]?.(...t(u))}if(r[0]==="[]"&&r.length===3){let n=i(r[1]),s=i(r[2]);return u=>{let f=n(u),y=s(u);return G(y)?void 0:f?.[y]?.(...t(u))}}let o=i(r);return n=>o(n)?.(...t(n))});var tr=140;v("typeof",tr);v("void",tr);v("delete",tr);v("new",tr);p("typeof",r=>(r=i(r),e=>typeof r(e)));p("void",r=>(r=i(r),e=>(r(e),void 0)));p("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});p("new",r=>{let e=i(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,o=t?t[0]===","?(n=>s=>n.map(u=>u(s)))(t.slice(1).map(i)):(n=>s=>[n(s)])(i(t)):()=>[];return n=>new(e(n))(...o(n))});var or=Symbol("accessor"),jr=20,Be=40,Qe=41,$e=123,He=125,Wr=r=>e=>{if(e)return;h();let t=k(c.id);if(!t||(h(),d.charCodeAt(l)!==Be))return!1;E();let o=A(0,Qe);return h(),d.charCodeAt(l)!==$e?!1:(E(),[r,t,o,A(0,He)])};S("get",jr-1,Wr("get"));S("set",jr-1,Wr("set"));p("get",(r,e)=>(e=e?i(e):()=>{},t=>[[or,r,{get:function(){let o=Object.create(t||{});return o.this=this,e(o)}}]]));p("set",(r,e,t)=>(t=t?i(t):()=>{},o=>[[or,r,{set:function(n){let s=Object.create(o||{});s.this=this,s[e]=n,t(s)}}]]));var je=20,zr=200;z("[]",zr);z("{}",zr);m(":",je-1,!0);p("{}",(r,e)=>{if(e!==void 0)return;r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(o=>i(typeof o=="string"?[":",o,o]:o));return o=>{let n={},s={};for(let u of t.flatMap(f=>f(o)))if(u[0]===or){let[,f,y]=u;s[f]={...s[f],...y,configurable:!0,enumerable:!0}}else n[u[0]]=u[1];for(let u in s)Object.defineProperty(n,u,s[u]);return n}});p(":",(r,e)=>(e=i(e),Array.isArray(r)?(r=i(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));var We=170,nr=96,ze=36,Je=123,Ve=92,Ye={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Jr=()=>{let r=[];for(let e="",t;(t=d.charCodeAt(l))!==nr;)t?t===Ve?(E(),e+=Ye[d[l]]||d[l],E()):t===ze&&d.charCodeAt(l+1)===Je?(e&&r.push([,e]),e="",E(2),r.push(A(0,125))):(e+=d[l],E(),t=d.charCodeAt(l),t===nr&&e&&r.push([,e])):I("Unterminated template");return E(),r},Ze=C[nr];C[nr]=(r,e)=>r&&e<We?c.asi&&c.newline?void 0:(E(),["``",r,...Jr()]):r?Ze?.(r,e):(E(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(Jr()));p("`",(...r)=>(r=r.map(i),e=>r.map(t=>t(e)).join("")));p("``",(r,...e)=>{r=i(r);let t=[],o=[];for(let s of e)Array.isArray(s)&&s[0]===void 0?t.push(s[1]):o.push(i(s));let n=Object.assign([...t],{raw:t});return s=>r(s)(n,...o.map(u=>u(s)))});c.string["'"]=!0;c.number={"0x":16,"0b":2,"0o":8};var ar=5,qe=10,xe=20,Vr=r=>{let e=A(qe-1);return e?.[0]==="in"||e?.[0]==="of"?[e[0],[r,e[1]],e[2]]:e?.[0]===","?[r,...e.slice(1)]:[r,e]};S("let",ar+1,r=>!r&&Vr("let"));S("const",ar+1,r=>!r&&Vr("const"));a("var",ar,()=>(h(),["var",A(xe)]));var Yr=(...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"?s=>{s[t]=n(s)}:s=>F(t,n(s),s)}return i(e)}),e=>{for(let t of r)t(e)});p("let",Yr);p("const",Yr);p("var",r=>typeof r=="string"?e=>{e[r]=void 0}:()=>{});var be=200;a("function",be,()=>{h();let r=k(c.id);return r&&h(),["function",r,N()||null,M()]});p("function",(r,e,t)=>{t=t?i(t):()=>{};let o=e?e[0]===","?e.slice(1):[e]:[],n=null,s=-1,u=o[o.length-1];return Array.isArray(u)&&u[0]==="..."&&(s=o.length-1,n=u[1],o.length--),f=>{let y=(...g)=>{let T={};o.forEach((w,O)=>T[w]=g[O]),n&&(T[n]=g.slice(s));let X=new Proxy(T,{get:(w,O)=>O in w?w[O]:f[O],set:(w,O,br)=>((O in w?w:f)[O]=br,!0),has:(w,O)=>O in w||O in f});try{return t(X)}catch(w){if(w?.type===W)return w.value;throw w}};return r&&(f[r]=y),y}});var ir=140,Sr=20;v("await",ir);a("yield",ir,()=>(h(),d[l]==="*"?(E(),h(),["yield*",A(Sr)]):["yield",A(Sr)]));a("async",ir,()=>{if(h(),D("function"))return["async",A(ir)];let r=A(Sr-.5);return r&&["async",r]});p("async",r=>{let e=i(r);return t=>{let o=e(t);return async function(...n){return o(...n)}}});p("await",r=>(r=i(r),async e=>await r(e)));p("yield",r=>(r=r?i(r):null,e=>{throw{__yield__:r?r(e):void 0}}));p("yield*",r=>(r=i(r),e=>{throw{__yield_all__:r(e)}}));var wr=200,rt=140,et=90,tt=Symbol("static");L("super",Symbol.for("super"));v("static",rt);m("instanceof",et);S("#",wr,r=>{if(r)return;let e=k(c.id);return e?"#"+e:void 0});a("class",wr,()=>{h();let r=k(c.id)||null;if(r==="extends")r=null;else if(h(),!D("extends"))return["class",r,null,M()];return h(),["class",r,A(wr),M()]});var ot=r=>{throw Error(r)};p("instanceof",(r,e)=>(r=i(r),e=i(e),t=>r(t)instanceof e(t)));p("class",(r,e,t)=>(e=e?i(e):null,t=t?i(t):null,o=>{let n=e?e(o):Object,s=function(...u){if(!(this instanceof s))return ot("Class constructor must be called with new");let f=e?Reflect.construct(n,u,s):this;return s.prototype.__constructor__&&s.prototype.__constructor__.apply(f,u),f};if(Object.setPrototypeOf(s.prototype,n.prototype),Object.setPrototypeOf(s,n),t){let u=Object.create(o);u.super=n;let f=t(u),y=Array.isArray(f)&&typeof f[0]?.[0]=="string"?f:[];for(let[g,T]of y)g==="constructor"?s.prototype.__constructor__=T:s.prototype[g]=T}return r&&(o[r]=s),s}));p("static",r=>(r=i(r),e=>[[tt,r(e)]]));var nt=140,Cr=47,it=92,st=r=>r===it?2:r&&r!==Cr,pt=r=>r===103||r===105||r===109||r===115||r===117||r===121;S("/",nt,r=>{if(r)return;let e=d.charCodeAt(l);if(e===Cr||e===42||e===43||e===63||e===61)return;let t=k(st);d.charCodeAt(l)===Cr||I("Unterminated regex"),E();try{return[,new RegExp(t,k(pt))]}catch(o){I("Invalid regex: "+o.message)}});var ut=5,ft=59,lt=()=>{let r=l;return h()===ft&&E(),h(),D("else")?(E(4),!0):(K(r),!1)};a("if",ut+1,()=>{h();let r=["if",N(),B()];return lt()&&r.push(B()),r});p("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 Y=5;a("try",Y+1,()=>["try",M()]);dr("catch",Y+1,r=>(h(),["catch",r,N(),M()]));dr("finally",Y+1,r=>["finally",r,M()]);a("throw",Y+1,()=>{if(c.asi&&(c.newline=!1),h(),c.newline)throw SyntaxError("Unexpected newline after throw");return["throw",A(Y)]});p("try",r=>(r=r?i(r):null,e=>r?.(e)));p("catch",(r,e,t)=>{let o=r?.[1]?i(r[1]):null;return t=t?i(t):null,n=>{let s;try{s=o?.(n)}catch(u){if(u?.type===Q||u?.type===j||u?.type===W)throw u;if(e!==null&&t){let f=e in n,y=n[e];n[e]=u;try{s=t(n)}finally{f?n[e]=y:delete n[e]}}else if(e===null)throw u}return s}});p("finally",(r,e)=>(r=r?i(r):null,e=e?i(e):null,t=>{let o;try{o=r?.(t)}finally{e?.(t)}return o}));p("throw",r=>(r=i(r),e=>{throw r(e)}));var kr=5,mt=20,Zr=58;a("switch",kr+1,()=>(h(),["switch",N(),M()]));a("case",kr+1,()=>(h(),(r=>(h()===Zr&&E(),["case",r]))(A(mt))));a("default",kr+1,()=>(h()===Zr&&E(),["default"]));p("switch",(r,e)=>{if(r=i(r),!e)return s=>r(s);let t=[],o=e[0]===";"?e.slice(1):[e],n=null;for(let s of o)Array.isArray(s)&&(s[0]==="case"||s[0]==="default")?(n&&t.push(n),n=[s[0]==="case"?i(s[1]):null,[]]):n&&n[1].push(i(s));return n&&t.push(n),s=>{let u=r(s),f=!1,y;for(let[g,T]of t)if(f||g===null||g(s)===u){f=!0;for(let X of T)try{y=X(s)}catch(w){if(w?.type===Q)return w.value!==void 0?w.value:y;throw w}}return y}});var vr=5,H=10,qr=42,ct=C[qr];C[qr]=(r,e)=>r?ct?.(r,e):(E(),"*");S("from",H+1,r=>r?r[0]!=="="&&r[0]!==","&&(h(),["from",r,A(H+1)]):!1);S("as",H+2,r=>r?(h(),["as",r,A(H+2)]):!1);a("import",vr,()=>(h(),["import",A(H)]));a("export",vr,()=>(h(),["export",A(vr)]));a("default",H+1,()=>(h(),["default",A(H)]));p("import",()=>()=>{});p("export",()=>()=>{});p("from",(r,e)=>()=>{});p("as",(r,e)=>()=>{});p("default",r=>i(r));var xr=5;c.asi=(r,e,t)=>{if(e>=xr)return;let o=t(xr-.5);if(o)return r?.[0]!==";"?[";",r,o]:(r.push(o),r)};export{ur as access,m as binary,i as compile,d as cur,Br as default,I as err,A as expr,z as group,dt as id,l as idx,L as literal,Z as loc,C as lookup,pr as nary,k as next,p as operator,sr as operators,N as parens,c as parse,K as seek,E as skip,h as space,S as token,v as unary,D as word};
|
package/justin.js
CHANGED
|
@@ -1,48 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import './
|
|
8
|
-
import './
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
operator('>>>=', (a, b) => (b = compile(b), prop(a, (obj, path, ctx) => (obj[path] >>>= b(ctx)))))
|
|
41
|
-
|
|
42
|
-
// add JS literals
|
|
43
|
-
token('undefined', 20, a => a ? err() : [, undefined])
|
|
44
|
-
token('NaN', 20, a => a ? err() : [, NaN])
|
|
45
|
-
token('null', 20, a => a ? err() : [, null])
|
|
46
|
-
|
|
47
|
-
export default subscript
|
|
48
|
-
export * from './subscript.js'
|
|
1
|
+
/**
|
|
2
|
+
* justin: JSON superset expression language
|
|
3
|
+
*
|
|
4
|
+
* Builds on subscript with JS-specific features:
|
|
5
|
+
* optional chaining, arrow functions, spread, templates.
|
|
6
|
+
*/
|
|
7
|
+
import './subscript.js';
|
|
8
|
+
import { parse } from './parse.js';
|
|
9
|
+
|
|
10
|
+
// Add single quotes
|
|
11
|
+
parse.string["'"] = true;
|
|
12
|
+
|
|
13
|
+
// Add hex, binary, octal prefixes
|
|
14
|
+
parse.number = { '0x': 16, '0b': 2, '0o': 8 };
|
|
15
|
+
|
|
16
|
+
import './feature/comment.js';
|
|
17
|
+
|
|
18
|
+
// Extended operators
|
|
19
|
+
// Note: assignment (=) is in subscript, must come BEFORE identity (===)
|
|
20
|
+
import './feature/op/identity.js'; // === !==
|
|
21
|
+
import './feature/op/nullish.js'; // ??
|
|
22
|
+
import './feature/op/pow.js'; // ** **=
|
|
23
|
+
import './feature/op/membership.js'; // in (instanceof is in jessie/class.js)
|
|
24
|
+
import './feature/op/bitwise-unsigned.js'; // >>> >>>=
|
|
25
|
+
import './feature/op/assign-logical.js'; // ||= &&= ??= + destructuring
|
|
26
|
+
|
|
27
|
+
// JS-specific operators (ternary, arrow, spread, optional chaining, typeof/void/delete/new)
|
|
28
|
+
import './feature/literal.js';
|
|
29
|
+
import './feature/op/ternary.js';
|
|
30
|
+
import './feature/op/arrow.js';
|
|
31
|
+
import './feature/op/spread.js';
|
|
32
|
+
import './feature/op/optional.js';
|
|
33
|
+
import './feature/op/unary.js';
|
|
34
|
+
|
|
35
|
+
import './feature/collection.js';
|
|
36
|
+
import './feature/template.js';
|
|
37
|
+
|
|
38
|
+
export * from './parse.js';
|
|
39
|
+
export { default } from './subscript.js';
|
package/justin.min.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var f,d,m=r=>(f=0,d=r,m.newline=!1,r=h(),d[f]?k():r||""),k=(r="Unexpected token",e=f,t=d.slice(0,e).split(`
|
|
2
|
+
`),o=t.pop(),n=d.slice(Math.max(0,e-40),e),s="\u032D",u=(d[e]||"\u2205")+s,c=d.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
|
|
3
|
+
${(d[e-41]!==`
|
|
4
|
+
`?"...":"")+n}${u}${c}`)},x=(r,e=f)=>(Array.isArray(r)&&(r.loc=e),r),R=(r,e=f,t)=>{for(;t=r(d.charCodeAt(f));)f+=t;return d.slice(e,f)},g=(r=1)=>d[f+=r],M=r=>f=r,h=(r=0,e)=>{let t,o,n,s,u=m.reserved,c;for(e&&m.asi&&(m.newline=!1),m.reserved=0;(t=m.space())&&(c=m.newline,1)&&t!==e&&(n=((s=y[t])&&s(o,r))??(m.asi&&o&&c&&(n=m.asi(o,r,h)))??(!o&&!m.reserved&&R(m.id)));)o=n,m.reserved=0;return m.reserved=u,e&&(t==e?f++:k("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},S=m.space=(r,e=f)=>{for(;(r=d.charCodeAt(f))<=32;)m.asi&&r===10&&(m.newline=!0),f++;return r},Be=m.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,e=r.length)=>d.substr(f,e)===r&&!m.id(d.charCodeAt(f+e)),_=()=>(g(),h(0,41)),y=[],C=(r,e=32,t,o=r.charCodeAt(0),n=r.length,s=y[o],u=r.toUpperCase()!==r,c,A)=>y[o]=(E,B,$,lr=f)=>(c=$,($?r==$:(n<2||r.charCodeAt(1)===d.charCodeAt(f+1)&&(n<3||d.substr(f,n)==r))&&(!u||!m.id(d.charCodeAt(f+n)))&&(c=$=r))&&B<e&&(f+=n,(A=t(E))?x(A,lr):(f=lr,c=0,u&&A!==!1&&(m.reserved=1),!u&&!s&&k()),A)||s?.(E,B,c)),l=(r,e,t=!1)=>C(r,e,(o,n)=>o&&(n=h(e-(t?.5:0)))&&[r,o,n]),v=(r,e,t)=>C(r,e,o=>t?o&&[r,o]:!o&&(o=h(e-.5))&&[r,o]),O=(r,e)=>C(r,200,t=>!t&&[,e]),b=(r,e,t)=>{C(r,e,(o,n)=>(n=h(e-(t?.5:0)),o?.[0]!==r&&(o=[r,o||null]),n?.[0]===r?o.push(...n.slice(1)):o.push(n||null),o))},F=(r,e)=>C(r[0],e,t=>!t&&[r,h(0,r.charCodeAt(1))||null]),rr=(r,e)=>C(r[0],e,t=>t&&[r,t,h(0,r.charCodeAt(1))||null]),mr,Br=(r="Compile error",e=mr)=>k(r,e?.loc),q={},p=(r,e,t=q[r])=>q[r]=(...o)=>e(...o)||t?.(...o),i=r=>(mr=r,Array.isArray(r)?r[0]===void 0?(e=>()=>e)(r[1]):q[r[0]]?.(...r.slice(1))??Br(`Unknown operator: ${r[0]}`):r===void 0?()=>{}:e=>e?.[r]);var K=46,D=48,Q=57,Mr=69,_r=101,Fr=43,Dr=45,Gr=97,Xr=102,$r=65,Kr=70,er=r=>[,(r=+R(e=>e===K&&d.charCodeAt(f+1)!==K||e>=D&&e<=Q||((e===Mr||e===_r)&&((e=d.charCodeAt(f+1))>=D&&e<=Q||e===Fr||e===Dr)?2:0)))!=r?k():r],Qr={2:r=>r===48||r===49,8:r=>r>=48&&r<=55,16:r=>r>=D&&r<=Q||r>=Gr&&r<=Xr||r>=$r&&r<=Kr};m.number=null;y[K]=r=>!r&&d.charCodeAt(f+1)!==K&&er();for(let r=D;r<=Q;r++)y[r]=e=>e?void 0:er();y[D]=r=>{if(r)return;let e=m.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&d[f+1]?.toLowerCase()===t[1])return g(2),[,parseInt(R(Qr[o]),o)]}return er()};var Hr=92,cr=34,dr=39,Wr={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Ar=r=>(e,t,o="")=>{if(!(e||!m.string?.[String.fromCharCode(r)]))return g(),R(n=>n-r&&(n===Hr?(o+=Wr[d[f+1]]||d[f+1],2):(o+=d[f],1))),d[f]===String.fromCharCode(r)?g():k("Bad string"),[,o]};y[cr]=Ar(cr);y[dr]=Ar(dr);m.string={'"':!0};var N=20;l("=",N,!0);l("+=",N,!0);l("-=",N,!0);l("*=",N,!0);l("/=",N,!0);l("%=",N,!0);l("|=",N,!0);l("&=",N,!0);l("^=",N,!0);l(">>=",N,!0);l("<<=",N,!0);var I=(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?I(r[1],e):(()=>{throw Error("Invalid assignment target")})();p("=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]=e(n))));p("+=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]+=e(n))));p("-=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]-=e(n))));p("*=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]*=e(n))));p("/=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]/=e(n))));p("%=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]%=e(n))));p("|=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]|=e(n))));p("&=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]&=e(n))));p("^=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]^=e(n))));p(">>=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]>>=e(n))));p("<<=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]<<=e(n))));var jr=30,zr=40,hr=140;l("!",hr);v("!",hr);l("||",jr);l("&&",zr);p("!",r=>(r=i(r),e=>!r(e)));p("||",(r,e)=>(r=i(r),e=i(e),t=>r(t)||e(t)));p("&&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&&e(t)));var Jr=50,Vr=60,Yr=70,gr=100,Zr=140;l("|",Jr);l("&",Yr);l("^",Vr);l(">>",gr);l("<<",gr);v("~",Zr);p("~",r=>(r=i(r),e=>~r(e)));p("|",(r,e)=>(r=i(r),e=i(e),t=>r(t)|e(t)));p("&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&e(t)));p("^",(r,e)=>(r=i(r),e=i(e),t=>r(t)^e(t)));p(">>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>e(t)));p("<<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<<e(t)));var H=90;l("<",H);l(">",H);l("<=",H);l(">=",H);p(">",(r,e)=>(r=i(r),e=i(e),t=>r(t)>e(t)));p("<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<e(t)));p(">=",(r,e)=>(r=i(r),e=i(e),t=>r(t)>=e(t)));p("<=",(r,e)=>(r=i(r),e=i(e),t=>r(t)<=e(t)));var yr=80;l("==",yr);l("!=",yr);p("==",(r,e)=>(r=i(r),e=i(e),t=>r(t)==e(t)));p("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(t)));var Cr=110,tr=120,Er=140;l("+",Cr);l("-",Cr);l("*",tr);l("/",tr);l("%",tr);v("+",Er);v("-",Er);p("+",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)+e(t)):(r=i(r),t=>+r(t)));p("-",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)-e(t)):(r=i(r),t=>-r(t)));p("*",(r,e)=>(r=i(r),e=i(e),t=>r(t)*e(t)));p("/",(r,e)=>(r=i(r),e=i(e),t=>r(t)/e(t)));p("%",(r,e)=>(r=i(r),e=i(e),t=>r(t)%e(t)));var W=150;C("++",W,r=>r?["++",r,null]:["++",h(W-1)]);C("--",W,r=>r?["--",r,null]:["--",h(W-1)]);var or=(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?or(r[1],e):(()=>{throw Error("Invalid increment target")})();p("++",(r,e)=>or(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));p("--",(r,e)=>or(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var Sr=5,qr=123,xr=125,P=(r,e,t,o=r.charCodeAt(0),n=r.length,s=y[o],u)=>y[o]=(c,A,E,B=f)=>!c&&(E?r==E:(n<2||d.substr(f,n)==r)&&(E=r))&&A<e&&!m.id(d.charCodeAt(f+n))&&(M(f+n),(u=t())?x(u,B):(M(B),!s&&k()),u)||s?.(c,A,E);var G=()=>S()!==qr?h(Sr+.5):(g(),["block",h(Sr-.5,xr)||null]);p("block",r=>r===void 0?()=>{}:(r=i(r),e=>r(e)));var L=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...n]=r;if(o==="{}")for(let s of n){let u,c,A;s[0]==="="?[,[,u,c],A]=s:[,u,c]=s;let E=e[u];E===void 0&&A&&(E=i(A)(t)),L(c,E,t)}else if(o==="[]"){let s=0;for(let u of n){if(u===null){s++;continue}if(Array.isArray(u)&&u[0]==="..."){t[u[1]]=e.slice(s);break}let c=u,A;Array.isArray(u)&&u[0]==="="&&([,c,A]=u);let E=e[s++];E===void 0&&A&&(E=i(A)(t)),L(c,E,t)}}};var j=Symbol("break"),z=Symbol("continue"),vr=Symbol("return"),X=(r,e)=>{try{return{v:r(e)}}catch(t){if(t?.type===j)return{b:1};if(t?.type===z)return{c:1};if(t?.type===vr)return{r:1,v:t.value};throw t}},U=5,br=125,re=59;P("while",U+1,()=>(S(),["while",_(),G()]));P("do",U+1,()=>(r=>(S(),g(5),S(),["do",r,_()]))(G()));P("for",U+1,()=>(S(),fr("await")?(g(5),S(),["for await",_(),G()]):["for",_(),G()]));P("break",U+1,()=>["break"]);P("continue",U+1,()=>["continue"]);P("return",U+1,()=>{m.asi&&(m.newline=!1),S();let r=d.charCodeAt(f);return!r||r===br||r===re||m.newline?["return"]:["return",h(U)]});p("while",(r,e)=>(r=i(r),e=i(e),t=>{let o,n;for(;r(t)&&!(o=X(e,t)).b;){if(o.r)return o.v;o.c||(n=o.v)}return n}));p("do",(r,e)=>(r=i(r),e=i(e),t=>{let o,n;do{if((o=X(r,t)).b)break;if(o.r)return o.v;o.c||(n=o.v)}while(e(t));return n}));p("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),s=>{let u,c;for(t?.(s);o(s)&&!(u=X(e,s)).b;n?.(s)){if(u.r)return u.v;u.c||(c=u.v)}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 te(o,n,e);if(t==="of")return ee(o,n,e)}});var ee=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let s,u,c=o?null:n[r];for(let A of e(n)){if(o?L(r,A,n):n[r]=A,(s=X(t,n)).b)break;if(s.r)return s.v;s.c||(u=s.v)}return o||(n[r]=c),u}},te=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let s,u,c=o?null:n[r];for(let A in e(n)){if(o?L(r,A,n):n[r]=A,(s=X(t,n)).b)break;if(s.r)return s.v;s.c||(u=s.v)}return o||(n[r]=c),u}};p("break",()=>()=>{throw{type:j}});p("continue",()=>()=>{throw{type:z}});p("return",r=>(r=r!==void 0?i(r):null,e=>{throw{type:vr,value:r?.(e)}}));var a=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",ir=170;rr("[]",ir);l(".",ir);rr("()",ir);var nr=r=>{throw Error(r)};p("[]",(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&&nr("Missing index"),r=i(r),e=i(e),t=>{let o=e(t);return a(o)?void 0:r(t)[o]}));p(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],a(e)?()=>{}:t=>r(t)[e]));p("()",(r,e)=>{if(e===void 0)return r==null?nr("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(s=>s==null||t(s));t(e)&&nr("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];return w(r,(n,s,u)=>n[s](...o(u)),!0)});var T=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&T(r[1])||r[0]==="{}"),oe=r=>{throw Error(r)},w=(r,e,t,o,n)=>r==null?oe("Empty ()"):r[0]==="()"&&r.length==2?w(r[1],e,t):typeof r=="string"?s=>e(s,r,s):r[0]==="."?(o=i(r[1]),n=r[2],s=>e(o(s),n,s)):r[0]==="?."?(o=i(r[1]),n=r[2],s=>{let u=o(s);return u==null?void 0:e(u,n,s)}):r[0]==="[]"&&r.length===3?(o=i(r[1]),n=i(r[2]),s=>e(o(s),n(s),s)):r[0]==="?.[]"?(o=i(r[1]),n=i(r[2]),s=>{let u=o(s);return u==null?void 0:e(u,n(s),s)}):(r=i(r),s=>e([r(s)],0,s));var ne=5,ie=10,se=170;F("()",se);b(",",ie);b(";",ne,!0);var wr=r=>{throw Error(r)};p("()",(r,e)=>{if(e===void 0)return r==null?wr("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(s=>s==null||t(s));t(e)&&wr("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];return w(r,(n,s,u)=>n[s](...o(u)),!0)});var kr=(...r)=>(r=r.map(i),e=>{let t;for(let o of r)try{t=o(e)}catch(n){throw(n?.type===j||n?.type===z)&&(n.value=t),n}return t});p(",",kr);p(";",kr);var Ir=new WeakMap,pe=(r,...e)=>typeof r=="string"?i(m(r)):Ir.get(r)||Ir.set(r,ue(r,e)).get(r),Nr=57344,ue=(r,e)=>{let t=r.reduce((s,u,c)=>s+(c?String.fromCharCode(Nr+c-1):"")+u,""),o=m(t),n=s=>{if(typeof s=="string"&&s.length===1){let u=s.charCodeAt(0)-Nr,c;if(u>=0&&u<e.length)return c=e[u],le(c)?c:[,c]}return Array.isArray(s)?s.map(n):s};return i(n(o))},le=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),fe=pe;var me=32,ce=m.space;m.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};var sr;m.space=()=>{sr||(sr=Object.entries(m.comment).map(([n,s])=>[n,s,n.charCodeAt(0)]));for(var r;r=ce();){for(var e=0,t;t=sr[e++];)if(r===t[2]&&d.substr(f,t[0].length)===t[0]){var o=f+t[0].length;if(t[1]===`
|
|
7
|
+
`)for(;d.charCodeAt(o)>=me;)o++;else{for(;d[o]&&d.substr(o,t[1].length)!==t[1];)o++;d[o]&&(o+=t[1].length)}M(o),r=0;break}if(r)return r}return r};var Rr=80;l("===",Rr);l("!==",Rr);p("===",(r,e)=>(r=i(r),e=i(e),t=>r(t)===e(t)));p("!==",(r,e)=>(r=i(r),e=i(e),t=>r(t)!==e(t)));var de=30;l("??",de);p("??",(r,e)=>(r=i(r),e=i(e),t=>r(t)??e(t)));var Ae=130,he=20;l("**",Ae,!0);l("**=",he,!0);p("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));var ge=r=>{throw Error(r)};p("**=",(r,e)=>(T(r)||ge("Invalid assignment target"),e=i(e),w(r,(t,o,n)=>t[o]**=e(n))));var Tr=90;l("in",Tr);l("of",Tr);p("in",(r,e)=>(r=i(r),e=i(e),t=>r(t)in e(t)));var ye=20,Ce=100,Ee=r=>{throw Error(r)};l(">>>",Ce);l(">>>=",ye,!0);p(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));p(">>>=",(r,e)=>(T(r)||Ee("Invalid assignment target"),e=i(e),w(r,(t,o,n)=>t[o]>>>=e(n))));var pr=20,J=r=>{throw Error(r)};l("||=",pr,!0);l("&&=",pr,!0);l("??=",pr,!0);p("=",(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=>L(t,e(o),o)}return T(r)||J("Invalid assignment target"),e=i(e),w(r,(t,o,n)=>t[o]=e(n))});p("||=",(r,e)=>(T(r)||J("Invalid assignment target"),e=i(e),w(r,(t,o,n)=>t[o]||=e(n))));p("&&=",(r,e)=>(T(r)||J("Invalid assignment target"),e=i(e),w(r,(t,o,n)=>t[o]&&=e(n))));p("??=",(r,e)=>(T(r)||J("Invalid assignment target"),e=i(e),w(r,(t,o,n)=>t[o]??=e(n))));O("true",!0);O("false",!1);O("null",null);O("undefined",void 0);O("NaN",NaN);O("Infinity",1/0);var ur=20;C("?",ur,(r,e,t)=>r&&(e=h(ur-1))&&R(o=>o===58)&&(t=h(ur-1),["?",r,e,t]));p("?",(r,e,t)=>(r=i(r),e=i(e),t=i(t),o=>r(o)?e(o):t(o)));var Se=20;l("=>",Se,!0);p("=>",(r,e)=>{r=r[0]==="()"?r[1]:r,r=r?r[0]===","?r.slice(1):[r]:[];let t=-1,o=null;return r.length&&Array.isArray(r[r.length-1])&&r[r.length-1][0]==="..."&&(t=r.length-1,o=r[t][1],r=r.slice(0,-1)),e=i(e[0]==="{}"?e[1]:e),(n=null)=>(n=Object.create(n),(...s)=>(r.forEach((u,c)=>n[u]=s[c]),o&&(n[o]=s.slice(t)),e(n)))});var ve=140;v("...",ve);p("...",r=>(r=i(r),e=>Object.entries(r(e))));var ar=170;C("?.",ar,(r,e)=>{if(!r)return;let t=S();return t===40?(g(),["?.()",r,h(0,41)||null]):t===91?(g(),["?.[]",r,h(0,93)]):(e=h(ar),e?["?.",r,e]:void 0)});p("?.",(r,e)=>(r=i(r),a(e)?()=>{}:t=>r(t)?.[e]));p("?.[]",(r,e)=>(r=i(r),e=i(e),t=>{let o=e(t);return a(o)?void 0:r(t)?.[o]}));p("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];if(r[0]==="?."){let n=i(r[1]),s=r[2];return a(s)?()=>{}:u=>n(u)?.[s]?.(...t(u))}if(r[0]==="?.[]"){let n=i(r[1]),s=i(r[2]);return u=>{let c=n(u),A=s(u);return a(A)?void 0:c?.[A]?.(...t(u))}}if(r[0]==="."){let n=i(r[1]),s=r[2];return a(s)?()=>{}:u=>n(u)?.[s]?.(...t(u))}if(r[0]==="[]"&&r.length===3){let n=i(r[1]),s=i(r[2]);return u=>{let c=n(u),A=s(u);return a(A)?void 0:c?.[A]?.(...t(u))}}let o=i(r);return n=>o(n)?.(...t(n))});var V=140;v("typeof",V);v("void",V);v("delete",V);v("new",V);p("typeof",r=>(r=i(r),e=>typeof r(e)));p("void",r=>(r=i(r),e=>(r(e),void 0)));p("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});p("new",r=>{let e=i(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,o=t?t[0]===","?(n=>s=>n.map(u=>u(s)))(t.slice(1).map(i)):(n=>s=>[n(s)])(i(t)):()=>[];return n=>new(e(n))(...o(n))});var Y=Symbol("accessor"),Or=20,we=40,ke=41,Ie=123,Ne=125,Pr=r=>e=>{if(e)return;S();let t=R(m.id);if(!t||(S(),d.charCodeAt(f)!==we))return!1;g();let o=h(0,ke);return S(),d.charCodeAt(f)!==Ie?!1:(g(),[r,t,o,h(0,Ne)])};C("get",Or-1,Pr("get"));C("set",Or-1,Pr("set"));p("get",(r,e)=>(e=e?i(e):()=>{},t=>[[Y,r,{get:function(){let o=Object.create(t||{});return o.this=this,e(o)}}]]));p("set",(r,e,t)=>(t=t?i(t):()=>{},o=>[[Y,r,{set:function(n){let s=Object.create(o||{});s.this=this,s[e]=n,t(s)}}]]));var Re=20,Lr=200;F("[]",Lr);F("{}",Lr);l(":",Re-1,!0);p("{}",(r,e)=>{if(e!==void 0)return;r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(o=>i(typeof o=="string"?[":",o,o]:o));return o=>{let n={},s={};for(let u of t.flatMap(c=>c(o)))if(u[0]===Y){let[,c,A]=u;s[c]={...s[c],...A,configurable:!0,enumerable:!0}}else n[u[0]]=u[1];for(let u in s)Object.defineProperty(n,u,s[u]);return n}});p(":",(r,e)=>(e=i(e),Array.isArray(r)?(r=i(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));var Te=170,Z=96,ae=36,Oe=123,Pe=92,Le={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Ur=()=>{let r=[];for(let e="",t;(t=d.charCodeAt(f))!==Z;)t?t===Pe?(g(),e+=Le[d[f]]||d[f],g()):t===ae&&d.charCodeAt(f+1)===Oe?(e&&r.push([,e]),e="",g(2),r.push(h(0,125))):(e+=d[f],g(),t=d.charCodeAt(f),t===Z&&e&&r.push([,e])):k("Unterminated template");return g(),r},Ue=y[Z];y[Z]=(r,e)=>r&&e<Te?m.asi&&m.newline?void 0:(g(),["``",r,...Ur()]):r?Ue?.(r,e):(g(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(Ur()));p("`",(...r)=>(r=r.map(i),e=>r.map(t=>t(e)).join("")));p("``",(r,...e)=>{r=i(r);let t=[],o=[];for(let s of e)Array.isArray(s)&&s[0]===void 0?t.push(s[1]):o.push(i(s));let n=Object.assign([...t],{raw:t});return s=>r(s)(n,...o.map(u=>u(s)))});m.string["'"]=!0;m.number={"0x":16,"0b":2,"0o":8};export{rr as access,l as binary,i as compile,d as cur,fe as default,k as err,h as expr,F as group,Be as id,f as idx,O as literal,x as loc,y as lookup,b as nary,R as next,p as operator,q as operators,_ as parens,m as parse,M as seek,g as skip,S as space,C as token,v as unary,fr as word};
|