subscript 10.4.8 → 10.4.9
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 +24 -12
- package/feature/accessor.js +5 -5
- package/feature/async.js +4 -4
- package/feature/class.js +5 -5
- package/feature/function.js +4 -4
- package/feature/if.js +6 -6
- package/feature/loop.js +10 -10
- package/feature/module.js +4 -4
- package/feature/op/optional.js +2 -2
- package/feature/regex.js +8 -19
- package/feature/statement.js +2 -2
- package/feature/switch.js +8 -8
- package/feature/try.js +5 -5
- package/jessie.min.js +9 -9
- package/justin.min.js +6 -6
- package/package.json +2 -1
- package/parse.js +12 -26
- package/subscript.min.js +4 -4
package/README.md
CHANGED
|
@@ -122,21 +122,33 @@ subscript('constructor.constructor("alert(1)")()')({})
|
|
|
122
122
|
|
|
123
123
|
## Performance
|
|
124
124
|
|
|
125
|
+
Parsing `a + b * c - d / e + f.g[0](h) + i.j`, 30k iterations:
|
|
126
|
+
|
|
125
127
|
```
|
|
126
|
-
Parse
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
expr
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
128
|
+
Parse:
|
|
129
|
+
new Function 8ms
|
|
130
|
+
subscript 34ms
|
|
131
|
+
cel-js 39ms
|
|
132
|
+
angular-expr 42ms
|
|
133
|
+
justin 51ms
|
|
134
|
+
jsep 54ms
|
|
135
|
+
jessie 76ms ← JS subset (statements + functions)
|
|
136
|
+
expr-eval 81ms
|
|
137
|
+
oxc 84ms ← full JS parser (native Rust)
|
|
138
|
+
mathjs 185ms
|
|
139
|
+
jexl 403ms
|
|
140
|
+
|
|
141
|
+
Eval:
|
|
142
|
+
subscript 3ms
|
|
143
|
+
new Function 4ms
|
|
144
|
+
cel-js 13ms
|
|
145
|
+
expression-eval 14ms
|
|
146
|
+
mathjs 17ms
|
|
147
|
+
angular-expr 62ms
|
|
138
148
|
```
|
|
139
149
|
|
|
150
|
+
Run via `node --import ./test/https-loader.js test/benchmark.js`.
|
|
151
|
+
|
|
140
152
|
## Utils
|
|
141
153
|
|
|
142
154
|
### Codegen
|
package/feature/accessor.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* { get x() { body } } → ['{}', ['get', 'x', body]]
|
|
5
5
|
* { set x(v) { body } } → ['{}', ['set', 'x', 'v', body]]
|
|
6
6
|
*/
|
|
7
|
-
import { token, expr, skip,
|
|
7
|
+
import { token, expr, skip, next, parse, cur, idx } from '../parse.js';
|
|
8
8
|
|
|
9
9
|
const ASSIGN = 20;
|
|
10
10
|
const LF = 10, CR = 13;
|
|
@@ -23,15 +23,15 @@ const hasLineTerminator = (from, to) => {
|
|
|
23
23
|
const accessor = (kind) => a => {
|
|
24
24
|
if (a) return; // not prefix
|
|
25
25
|
const from = idx;
|
|
26
|
-
space();
|
|
26
|
+
parse.space();
|
|
27
27
|
if (parse.semi || hasLineTerminator(from, idx)) return false;
|
|
28
28
|
const name = next(parse.id);
|
|
29
29
|
if (!name) return false; // no property name = not accessor (e.g. `{ get: 1 }`)
|
|
30
|
-
space();
|
|
30
|
+
parse.space();
|
|
31
31
|
if (cur.charCodeAt(idx) !== OPAREN) return false; // not followed by ( = not accessor
|
|
32
32
|
skip();
|
|
33
33
|
const params = expr(0, CPAREN);
|
|
34
|
-
space();
|
|
34
|
+
parse.space();
|
|
35
35
|
if (cur.charCodeAt(idx) !== OBRACE) return false;
|
|
36
36
|
skip();
|
|
37
37
|
return [kind, name, params, expr(0, CBRACE)];
|
|
@@ -51,7 +51,7 @@ token('(', ASSIGN - 1, a => {
|
|
|
51
51
|
// Accept identifier or string-literal node as key
|
|
52
52
|
if (typeof a !== 'string' && !(Array.isArray(a) && a[0] === undefined)) return;
|
|
53
53
|
const params = expr(0, CPAREN) || null;
|
|
54
|
-
space();
|
|
54
|
+
parse.space();
|
|
55
55
|
// Not followed by { - not method shorthand, fall through
|
|
56
56
|
if (cur.charCodeAt(idx) !== OBRACE) return;
|
|
57
57
|
skip();
|
package/feature/async.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Async/await/yield: async function, async arrow, await, yield expressions - parse half
|
|
2
|
-
import { unary, expr, skip,
|
|
2
|
+
import { parse, unary, expr, skip, keyword, cur, idx, word } from '../parse.js';
|
|
3
3
|
|
|
4
4
|
const PREFIX = 140, ASSIGN = 20;
|
|
5
5
|
|
|
@@ -9,10 +9,10 @@ unary('await', PREFIX);
|
|
|
9
9
|
// yield expr → ['yield', expr]
|
|
10
10
|
// yield* expr → ['yield*', expr]
|
|
11
11
|
keyword('yield', PREFIX, () => {
|
|
12
|
-
space();
|
|
12
|
+
parse.space();
|
|
13
13
|
if (cur[idx] === '*') {
|
|
14
14
|
skip();
|
|
15
|
-
space();
|
|
15
|
+
parse.space();
|
|
16
16
|
return ['yield*', expr(ASSIGN)];
|
|
17
17
|
}
|
|
18
18
|
return ['yield', expr(ASSIGN)];
|
|
@@ -22,7 +22,7 @@ keyword('yield', PREFIX, () => {
|
|
|
22
22
|
// async () => {} → ['async', ['=>', params, body]]
|
|
23
23
|
// async x => {} → ['async', ['=>', x, body]]
|
|
24
24
|
keyword('async', PREFIX, () => {
|
|
25
|
-
space();
|
|
25
|
+
parse.space();
|
|
26
26
|
// async function - check for 'function' word
|
|
27
27
|
if (word('function')) return ['async', expr(PREFIX)];
|
|
28
28
|
// async arrow: async () => or async x =>
|
package/feature/class.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Class declarations and expressions - parse half
|
|
2
2
|
// class A extends B { ... }
|
|
3
|
-
import { binary, unary, token, expr,
|
|
3
|
+
import { binary, unary, token, expr, next, parse, keyword, word, skip } from '../parse.js';
|
|
4
4
|
import { block } from './if.js';
|
|
5
5
|
|
|
6
6
|
const TOKEN = 200, PREFIX = 140, COMP = 90, STATIC = 175;
|
|
@@ -22,17 +22,17 @@ token('#', TOKEN, a => {
|
|
|
22
22
|
|
|
23
23
|
// class [Name] [extends Base] { body }
|
|
24
24
|
keyword('class', TOKEN, () => {
|
|
25
|
-
space();
|
|
25
|
+
parse.space();
|
|
26
26
|
let name = next(parse.id) || null;
|
|
27
27
|
// 'extends' parsed as name? → anonymous class
|
|
28
28
|
if (name === 'extends') {
|
|
29
29
|
name = null;
|
|
30
|
-
space();
|
|
30
|
+
parse.space();
|
|
31
31
|
} else {
|
|
32
|
-
space();
|
|
32
|
+
parse.space();
|
|
33
33
|
if (!word('extends')) return ['class', name, null, block()];
|
|
34
34
|
skip(7); // skip 'extends'
|
|
35
|
-
space();
|
|
35
|
+
parse.space();
|
|
36
36
|
}
|
|
37
37
|
return ['class', name, expr(TOKEN), block()];
|
|
38
38
|
});
|
package/feature/function.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
// Function declarations and expressions - parse half
|
|
2
|
-
import {
|
|
2
|
+
import { next, parse, keyword, parens, cur, idx, skip } from '../parse.js';
|
|
3
3
|
import { block } from './if.js';
|
|
4
4
|
|
|
5
5
|
const TOKEN = 200;
|
|
6
6
|
|
|
7
7
|
keyword('function', TOKEN, () => {
|
|
8
|
-
space();
|
|
8
|
+
parse.space();
|
|
9
9
|
// Check for generator: function*
|
|
10
10
|
let generator = false;
|
|
11
11
|
if (cur[idx] === '*') {
|
|
12
12
|
generator = true;
|
|
13
13
|
skip();
|
|
14
|
-
space();
|
|
14
|
+
parse.space();
|
|
15
15
|
}
|
|
16
16
|
const name = next(parse.id);
|
|
17
|
-
name && space();
|
|
17
|
+
name && parse.space();
|
|
18
18
|
const node = generator ? ['function*', name, parens() || null, block()] : ['function', name, parens() || null, block()];
|
|
19
19
|
return node;
|
|
20
20
|
});
|
package/feature/if.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
// If/else statement - parse half. else consumed internally.
|
|
2
|
-
import {
|
|
2
|
+
import { parse, skip, expr, err, keyword, parens, word, idx, seek } from '../parse.js';
|
|
3
3
|
|
|
4
4
|
const STATEMENT = 5, SEMI = 59;
|
|
5
5
|
|
|
6
6
|
// block() - parse required { body }
|
|
7
7
|
export const block = () =>
|
|
8
|
-
(space() === 123 || err('Expected {'), skip(), expr(STATEMENT - .5, 125) || null);
|
|
8
|
+
(parse.space() === 123 || err('Expected {'), skip(), expr(STATEMENT - .5, 125) || null);
|
|
9
9
|
|
|
10
10
|
// body() - parse { body } or single statement
|
|
11
11
|
export const body = () =>
|
|
12
|
-
space() !== 123 ? expr(STATEMENT + .5) : (skip(), expr(STATEMENT - .5, 125) || null);
|
|
12
|
+
parse.space() !== 123 ? expr(STATEMENT + .5) : (skip(), expr(STATEMENT - .5, 125) || null);
|
|
13
13
|
|
|
14
14
|
// Check for `else` after optional semicolon
|
|
15
15
|
const checkElse = () => {
|
|
16
16
|
const from = idx;
|
|
17
|
-
if (space() === SEMI) skip();
|
|
18
|
-
space();
|
|
17
|
+
if (parse.space() === SEMI) skip();
|
|
18
|
+
parse.space();
|
|
19
19
|
if (word('else')) return skip(4), true;
|
|
20
20
|
return seek(from), false;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
// if (cond) body [else body] - self-contained
|
|
24
24
|
keyword('if', STATEMENT + 1, () => {
|
|
25
|
-
space();
|
|
25
|
+
parse.space();
|
|
26
26
|
const node = ['if', parens(), body()];
|
|
27
27
|
if (checkElse()) node.push(body());
|
|
28
28
|
return node;
|
package/feature/loop.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// Loops: while, do-while, for, for await, break, continue, return - parse half
|
|
2
|
-
import { expr, skip,
|
|
2
|
+
import { expr, skip, parse, word, keyword, parens, cur, idx, next, seek } from '../parse.js';
|
|
3
3
|
import { body } from './if.js';
|
|
4
4
|
|
|
5
5
|
const STATEMENT = 5, CBRACE = 125, SEMI = 59;
|
|
6
6
|
|
|
7
|
-
keyword('while', STATEMENT + 1, () => (space(), ['while', parens(), body()]));
|
|
8
|
-
keyword('do', STATEMENT + 1, () => (b => (space(), skip(5), space(), ['do', b, parens()]))(body()));
|
|
7
|
+
keyword('while', STATEMENT + 1, () => (parse.space(), ['while', parens(), body()]));
|
|
8
|
+
keyword('do', STATEMENT + 1, () => (b => (parse.space(), skip(5), parse.space(), ['do', b, parens()]))(body()));
|
|
9
9
|
|
|
10
10
|
// for / for await
|
|
11
11
|
keyword('for', STATEMENT + 1, () => {
|
|
12
|
-
space();
|
|
12
|
+
parse.space();
|
|
13
13
|
// for await (x of y)
|
|
14
14
|
if (word('await')) {
|
|
15
15
|
skip(5);
|
|
16
|
-
return (space(), ['for await', parens(), body()]);
|
|
16
|
+
return (parse.space(), ['for await', parens(), body()]);
|
|
17
17
|
}
|
|
18
18
|
return ['for', parens(), body()];
|
|
19
19
|
});
|
|
@@ -21,13 +21,13 @@ keyword('for', STATEMENT + 1, () => {
|
|
|
21
21
|
keyword('break', STATEMENT + 1, () => {
|
|
22
22
|
parse.asi && (parse.newline = false);
|
|
23
23
|
const from = idx;
|
|
24
|
-
space();
|
|
24
|
+
parse.space();
|
|
25
25
|
const c = cur.charCodeAt(idx);
|
|
26
26
|
if (!c || c === CBRACE || c === SEMI || parse.newline) return ['break'];
|
|
27
27
|
const label = next(parse.id);
|
|
28
28
|
if (!label) return ['break'];
|
|
29
29
|
// Label must be followed by end/semicolon/newline, not another token
|
|
30
|
-
space();
|
|
30
|
+
parse.space();
|
|
31
31
|
const cc = cur.charCodeAt(idx);
|
|
32
32
|
if (!cc || cc === CBRACE || cc === SEMI || parse.newline) return ['break', label];
|
|
33
33
|
// Not a valid label - backtrack
|
|
@@ -37,12 +37,12 @@ keyword('break', STATEMENT + 1, () => {
|
|
|
37
37
|
keyword('continue', STATEMENT + 1, () => {
|
|
38
38
|
parse.asi && (parse.newline = false);
|
|
39
39
|
const from = idx;
|
|
40
|
-
space();
|
|
40
|
+
parse.space();
|
|
41
41
|
const c = cur.charCodeAt(idx);
|
|
42
42
|
if (!c || c === CBRACE || c === SEMI || parse.newline) return ['continue'];
|
|
43
43
|
const label = next(parse.id);
|
|
44
44
|
if (!label) return ['continue'];
|
|
45
|
-
space();
|
|
45
|
+
parse.space();
|
|
46
46
|
const cc = cur.charCodeAt(idx);
|
|
47
47
|
if (!cc || cc === CBRACE || cc === SEMI || parse.newline) return ['continue', label];
|
|
48
48
|
seek(from);
|
|
@@ -50,6 +50,6 @@ keyword('continue', STATEMENT + 1, () => {
|
|
|
50
50
|
});
|
|
51
51
|
keyword('return', STATEMENT + 1, () => {
|
|
52
52
|
parse.asi && (parse.newline = false);
|
|
53
|
-
const c = space();
|
|
53
|
+
const c = parse.space();
|
|
54
54
|
return !c || c === CBRACE || c === SEMI || parse.newline ? ['return'] : ['return', expr(STATEMENT)];
|
|
55
55
|
});
|
package/feature/module.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* export { a } from './x' → ['export', ['from', ['{}', ...], path]]
|
|
9
9
|
* export const x = 1 → ['export', decl]
|
|
10
10
|
*/
|
|
11
|
-
import { token, expr,
|
|
11
|
+
import { parse, token, expr, keyword, lookup, skip, word } from '../parse.js';
|
|
12
12
|
|
|
13
13
|
const STATEMENT = 5, SEQ = 10, STAR = 42;
|
|
14
14
|
|
|
@@ -17,10 +17,10 @@ const prevStar = lookup[STAR];
|
|
|
17
17
|
lookup[STAR] = (a, prec) => !a ? (skip(), '*') : prevStar?.(a, prec);
|
|
18
18
|
|
|
19
19
|
// 'from' as contextual binary - only after import-like LHS (not = or ,), false in prefix for identifier fallback
|
|
20
|
-
token('from', SEQ + 1, a => !a ? false : a[0] !== '=' && a[0] !== ',' && (space(), ['from', a, expr(SEQ + 1)]));
|
|
20
|
+
token('from', SEQ + 1, a => !a ? false : a[0] !== '=' && a[0] !== ',' && (parse.space(), ['from', a, expr(SEQ + 1)]));
|
|
21
21
|
|
|
22
22
|
// 'as' for aliasing: * as X, { a as b }. False in prefix for identifier fallback
|
|
23
|
-
token('as', SEQ + 2, a => !a ? false : (space(), ['as', a, expr(SEQ + 2)]));
|
|
23
|
+
token('as', SEQ + 2, a => !a ? false : (parse.space(), ['as', a, expr(SEQ + 2)]));
|
|
24
24
|
|
|
25
25
|
// import: prefix that parses specifiers + from + path
|
|
26
26
|
// import.meta returns ['import.meta']
|
|
@@ -31,7 +31,7 @@ keyword('import', STATEMENT, () => (
|
|
|
31
31
|
// export: prefix for declarations or re-exports (use STATEMENT to capture const/let/function).
|
|
32
32
|
// `export default X` is recognized inline; outside `export`, `default` stays an identifier.
|
|
33
33
|
keyword('export', STATEMENT, () => (
|
|
34
|
-
space(),
|
|
34
|
+
parse.space(),
|
|
35
35
|
word('default')
|
|
36
36
|
? (skip(7), ['export', ['default', expr(SEQ)]])
|
|
37
37
|
: ['export', expr(STATEMENT)]
|
package/feature/op/optional.js
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* a?.[x] → optional computed access
|
|
6
6
|
* a?.() → optional call
|
|
7
7
|
*/
|
|
8
|
-
import { token, expr, skip
|
|
8
|
+
import { parse, token, expr, skip } from '../../parse.js';
|
|
9
9
|
|
|
10
10
|
const ACCESS = 170;
|
|
11
11
|
|
|
12
12
|
token('?.', ACCESS, (a, b) => {
|
|
13
13
|
if (!a) return;
|
|
14
|
-
const cc = space();
|
|
14
|
+
const cc = parse.space();
|
|
15
15
|
// Optional call: a?.()
|
|
16
16
|
if (cc === 40) { skip(); return ['?.()', a, expr(0, 41) || null]; }
|
|
17
17
|
// Optional computed: a?.[x]
|
package/feature/regex.js
CHANGED
|
@@ -11,26 +11,15 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { token, skip, err, next, idx, cur } from '../parse.js';
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const SLASH = 47, BSLASH = 92;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// Invalid regex start (quantifiers) or /= - fall through
|
|
23
|
-
const first = cur.charCodeAt(idx);
|
|
24
|
-
if (first === SLASH || first === 42 || first === 43 || first === 63 || first === 61) return;
|
|
25
|
-
|
|
26
|
-
const pattern = next(regexChar);
|
|
16
|
+
token('/', 140, a => {
|
|
17
|
+
// left operand = division; `//` `/*` `/?` `/+` `/=` = not a regex start
|
|
18
|
+
const c = cur.charCodeAt(idx);
|
|
19
|
+
if (a || c === SLASH || c === 42 || c === 43 || c === 63 || c === 61) return;
|
|
20
|
+
const pattern = next(c => c === BSLASH ? 2 : c && c !== SLASH); // \x = 2 chars, else 1 until /
|
|
27
21
|
cur.charCodeAt(idx) === SLASH || err('Unterminated regex');
|
|
28
|
-
skip();
|
|
29
|
-
|
|
30
|
-
const flags = next(regexFlag);
|
|
31
|
-
// Validate regex syntax
|
|
32
|
-
try { new RegExp(pattern, flags); }
|
|
33
|
-
catch (e) { err('Invalid regex: ' + e.message); }
|
|
34
|
-
|
|
22
|
+
skip();
|
|
23
|
+
const flags = next(c => c === 103 || c === 105 || c === 109 || c === 115 || c === 117 || c === 121); // gimsuy
|
|
35
24
|
return flags ? ['//', pattern, flags] : ['//', pattern];
|
|
36
25
|
});
|
package/feature/statement.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Additional JS statements: debugger, with (parse-only)
|
|
2
2
|
// debugger → ['debugger']
|
|
3
3
|
// with (obj) body → ['with', obj, body]
|
|
4
|
-
import {
|
|
4
|
+
import { parse, keyword, parens } from '../parse.js';
|
|
5
5
|
import { body } from './if.js';
|
|
6
6
|
|
|
7
7
|
const STATEMENT = 5;
|
|
@@ -10,4 +10,4 @@ const STATEMENT = 5;
|
|
|
10
10
|
keyword('debugger', STATEMENT + 1, () => ['debugger']);
|
|
11
11
|
|
|
12
12
|
// with statement
|
|
13
|
-
keyword('with', STATEMENT + 1, () => (space(), ['with', parens(), body()]));
|
|
13
|
+
keyword('with', STATEMENT + 1, () => (parse.space(), ['with', parens(), body()]));
|
package/feature/switch.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Switch/case/default - parse half
|
|
2
2
|
// AST: ['switch', val, ['case', test, body], ['default', body], ...]
|
|
3
|
-
import { expr, skip,
|
|
3
|
+
import { parse, expr, skip, keyword, parens, idx, err, seek, lookup, word } from '../parse.js';
|
|
4
4
|
|
|
5
5
|
const STATEMENT = 5, ASSIGN = 20, COLON = 58, SEMI = 59, CBRACE = 125;
|
|
6
6
|
|
|
@@ -17,7 +17,7 @@ reserve('default');
|
|
|
17
17
|
// caseBody() - parse statements until next case/default/}
|
|
18
18
|
const caseBody = (c) => {
|
|
19
19
|
const stmts = [];
|
|
20
|
-
while ((c = space()) !== CBRACE && !word('case') && !word('default')) {
|
|
20
|
+
while ((c = parse.space()) !== CBRACE && !word('case') && !word('default')) {
|
|
21
21
|
if (c === SEMI) { skip(); continue; }
|
|
22
22
|
stmts.push(expr(STATEMENT - .5)) || err();
|
|
23
23
|
}
|
|
@@ -26,18 +26,18 @@ const caseBody = (c) => {
|
|
|
26
26
|
|
|
27
27
|
// switchBody() - parse case/default statements
|
|
28
28
|
const switchBody = () => {
|
|
29
|
-
space() === 123 || err('Expected {'); skip();
|
|
29
|
+
parse.space() === 123 || err('Expected {'); skip();
|
|
30
30
|
inSwitch++;
|
|
31
31
|
const cases = [];
|
|
32
32
|
try {
|
|
33
|
-
while (space() !== CBRACE) {
|
|
33
|
+
while (parse.space() !== CBRACE) {
|
|
34
34
|
if (word('case')) {
|
|
35
|
-
seek(idx + 4); space();
|
|
35
|
+
seek(idx + 4); parse.space();
|
|
36
36
|
const test = expr(ASSIGN - .5);
|
|
37
|
-
space() === COLON && skip();
|
|
37
|
+
parse.space() === COLON && skip();
|
|
38
38
|
cases.push(['case', test, caseBody()]);
|
|
39
39
|
} else if (word('default')) {
|
|
40
|
-
seek(idx + 7); space() === COLON && skip();
|
|
40
|
+
seek(idx + 7); parse.space() === COLON && skip();
|
|
41
41
|
cases.push(['default', caseBody()]);
|
|
42
42
|
} else err('Expected case or default');
|
|
43
43
|
}
|
|
@@ -47,4 +47,4 @@ const switchBody = () => {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
// switch (x) { ... }
|
|
50
|
-
keyword('switch', STATEMENT + 1, () => space() === 40 && ['switch', parens(), ...switchBody()]);
|
|
50
|
+
keyword('switch', STATEMENT + 1, () => parse.space() === 40 && ['switch', parens(), ...switchBody()]);
|
package/feature/try.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// try/catch/finally/throw statements - parse half
|
|
2
2
|
// AST (faithful): ['try', body, ['catch', param, handler]?, ['finally', cleanup]?]
|
|
3
|
-
import {
|
|
3
|
+
import { parse, keyword, parens, expr, word, skip, peek } from '../parse.js';
|
|
4
4
|
import { block } from './if.js';
|
|
5
5
|
|
|
6
6
|
const STATEMENT = 5;
|
|
@@ -8,13 +8,13 @@ const STATEMENT = 5;
|
|
|
8
8
|
// try { body } [catch (param) { handler }] [finally { cleanup }]
|
|
9
9
|
keyword('try', STATEMENT + 1, () => {
|
|
10
10
|
const node = ['try', block()];
|
|
11
|
-
space();
|
|
11
|
+
parse.space();
|
|
12
12
|
if (word('catch')) {
|
|
13
|
-
skip(5); space();
|
|
13
|
+
skip(5); parse.space();
|
|
14
14
|
// ES2019 optional catch binding: `catch { ... }` (no parameter)
|
|
15
15
|
node.push(['catch', peek() === 40 ? parens() : null, block()]);
|
|
16
16
|
}
|
|
17
|
-
space();
|
|
17
|
+
parse.space();
|
|
18
18
|
if (word('finally')) {
|
|
19
19
|
skip(7);
|
|
20
20
|
node.push(['finally', block()]);
|
|
@@ -24,7 +24,7 @@ keyword('try', STATEMENT + 1, () => {
|
|
|
24
24
|
|
|
25
25
|
keyword('throw', STATEMENT + 1, () => {
|
|
26
26
|
parse.asi && (parse.newline = false);
|
|
27
|
-
space();
|
|
27
|
+
parse.space();
|
|
28
28
|
if (parse.newline) throw SyntaxError('Unexpected newline after throw');
|
|
29
29
|
return ['throw', expr(STATEMENT)];
|
|
30
30
|
});
|
package/jessie.min.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),o=
|
|
3
|
-
${c[
|
|
4
|
-
`,""+n}${
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},
|
|
6
|
-
`,"/*":"*/"};var
|
|
7
|
-
`)for(;c.charCodeAt(o)
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
9
|
-
`;var ct=32,Pr=10,ve=59,Be=125,Le=91,Me=40,Or=$.asi??$[";"],Ue=m._baseSpace??=m.space,Fe=m._baseStep??=m.step,Rr=r=>Array.isArray(r)||typeof r=="string",De=(r,t)=>{for(;(t=c.charCodeAt(r))<=ct;){if(t===Pr)return!0;r++}return!1},Ge=(r=u,t)=>{for(;r-- >0&&(t=c.charCodeAt(r))<=ct;)if(t===Pr)return!0;return!1};m.space=(r,t)=>{for(;;){for(t=u,r=Ue();t<u;)if(c.charCodeAt(t++)===Pr){m.newline=!0;break}if(r===ve&&De(u+1)){P(u+1),m.newline=m.semi=!0;continue}return r}};m.enter=()=>m.newline=m.semi=!1;m.exit=(r,t)=>{t===Be&&(m.newline=!0,m.semi=!1)};m.step=(r,t,e,o)=>{if(m.semi&&t>=Or)return!1;if(r&&!Rr(r))return null;if(Rr(r)&&(m.semi||(e===Le||e===Me)&&Ge()))return mt(r,t,o)??null;let n=m.newline;return Fe(r,t,e,o)??(Rr(r)&&n?mt(r,t,o)??null:null)};var _r=0,Xe=2e3,mt=m.asi=(r,t,e,o,n)=>{if(t>=Or||_r>=Xe)return;m.semi=!1;let s=u;_r++;try{o=e(Or-.5)}finally{_r--}if(!(!o||u===s))return n=o?.[0]===";"?o.slice(1):[o],r?.[0]===";"?(r.push(...n),r):[";",r,...n]};var at=(r,t,e,o)=>typeof r=="string"?n=>t(n,r,n):r[0]==="."?(e=i(r[1]),o=r[2],n=>t(e(n),o,n)):r[0]==="[]"&&r.length===3?(e=i(r[1]),o=i(r[2]),n=>t(e(n),o(n),n)):r[0]==="()"&&r.length===2?at(r[1],t):(()=>{throw Error("Invalid assignment target")})(),dt={"=":(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 dt)p(r,(t,e)=>(e=i(e),at(t,(o,n,s)=>dt[r](o,n,e(s)))));p("!",r=>(r=i(r),t=>!r(t)));p("||",(r,t)=>(r=i(r),t=i(t),e=>r(e)||t(e)));p("&&",(r,t)=>(r=i(r),t=i(t),e=>r(e)&&t(e)));p("~",r=>(r=i(r),t=>~r(t)));p("|",(r,t)=>(r=i(r),t=i(t),e=>r(e)|t(e)));p("&",(r,t)=>(r=i(r),t=i(t),e=>r(e)&t(e)));p("^",(r,t)=>(r=i(r),t=i(t),e=>r(e)^t(e)));p(">>",(r,t)=>(r=i(r),t=i(t),e=>r(e)>>t(e)));p("<<",(r,t)=>(r=i(r),t=i(t),e=>r(e)<<t(e)));p(">",(r,t)=>(r=i(r),t=i(t),e=>r(e)>t(e)));p("<",(r,t)=>(r=i(r),t=i(t),e=>r(e)<t(e)));p(">=",(r,t)=>(r=i(r),t=i(t),e=>r(e)>=t(e)));p("<=",(r,t)=>(r=i(r),t=i(t),e=>r(e)<=t(e)));p("==",(r,t)=>(r=i(r),t=i(t),e=>r(e)==t(e)));p("!=",(r,t)=>(r=i(r),t=i(t),e=>r(e)!=t(e)));p("+",(r,t)=>t!==void 0?(r=i(r),t=i(t),e=>r(e)+t(e)):(r=i(r),e=>+r(e)));p("-",(r,t)=>t!==void 0?(r=i(r),t=i(t),e=>r(e)-t(e)):(r=i(r),e=>-r(e)));p("*",(r,t)=>(r=i(r),t=i(t),e=>r(e)*t(e)));p("/",(r,t)=>(r=i(r),t=i(t),e=>r(e)/t(e)));p("%",(r,t)=>(r=i(r),t=i(t),e=>r(e)%t(e)));var vr=(r,t,e,o)=>typeof r=="string"?n=>t(n,r):r[0]==="."?(e=i(r[1]),o=r[2],n=>t(e(n),o)):r[0]==="[]"&&r.length===3?(e=i(r[1]),o=i(r[2]),n=>t(e(n),o(n))):r[0]==="()"&&r.length===2?vr(r[1],t):(()=>{throw Error("Invalid increment target")})();p("++",(r,t)=>vr(r,t===null?(e,o)=>e[o]++:(e,o)=>++e[o]));p("--",(r,t)=>vr(r,t===null?(e,o)=>e[o]--:(e,o)=>--e[o]));var ht=(...r)=>(r=r.map(i),t=>{let e;for(let o of r)e=o(t);return e});p(",",ht);p(";",ht);var D=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",ir=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=i(e[1]),o=>e(o)):(e=i(e),o=>[e(o)])),e=>r.flatMap(o=>o(e))):(t==null&&ir("Missing index"),r=i(r),t=i(t),e=>{let o=t(e);return D(o)?void 0:r(e)[o]}));p(".",(r,t)=>(r=i(r),t=t[0]?t:t[1],D(t)?()=>{}:e=>r(e)[t]));p("()",(r,t)=>{if(t===void 0)return r==null?ir("Empty ()"):i(r);let e=n=>n?.[0]===","&&n.slice(1).some(s=>s==null||e(s));e(t)&&ir("Empty argument");let o=t?t[0]===","?(t=t.slice(1).map(i),n=>t.map(s=>s(n))):(t=i(t),n=>[t(n)]):()=>[];return Br(r,(n,s,l)=>n[s](...o(l)))});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]==="{}"),Br=(r,t,e,o)=>r==null?ir("Empty ()"):r[0]==="()"&&r.length==2?Br(r[1],t):typeof r=="string"?n=>t(n,r,n):r[0]==="."?(e=i(r[1]),o=r[2],n=>t(e(n),o,n)):r[0]==="?."?(e=i(r[1]),o=r[2],n=>{let s=e(n);return s==null?void 0:t(s,o,n)}):r[0]==="[]"&&r.length===3?(e=i(r[1]),o=i(r[2]),n=>t(e(n),o(n),n)):r[0]==="?.[]"?(e=i(r[1]),o=i(r[2]),n=>{let s=e(n);return s==null?void 0:t(s,o(n),n)}):(r=i(r),n=>t([r(n)],0,n)),G=Br;p("===",(r,t)=>(r=i(r),t=i(t),e=>r(e)===t(e)));p("!==",(r,t)=>(r=i(r),t=i(t),e=>r(e)!==t(e)));p("??",(r,t)=>(r=i(r),t=i(t),e=>r(e)??t(e)));var Ke=r=>{throw Error(r)};p("**",(r,t)=>(r=i(r),t=i(t),e=>r(e)**t(e)));p("**=",(r,t)=>(M(r)||Ke("Invalid assignment target"),t=i(t),G(r,(e,o,n)=>e[o]**=t(n))));p("in",(r,t)=>(r=i(r),t=i(t),e=>r(e)in t(e)));var He=r=>{throw Error(r)};p(">>>",(r,t)=>(r=i(r),t=i(t),e=>r(e)>>>t(e)));p(">>>=",(r,t)=>(M(r)||He("Invalid assignment target"),t=i(t),G(r,(e,o,n)=>e[o]>>>=t(n))));var je=r=>r[0]?.[0]===","?r[0].slice(1):r,X=(r,t,e)=>{if(typeof r=="string"){e[r]=t;return}let[o,...n]=r,s=je(n);if(o==="{}"){let l=[];for(let f of s){if(Array.isArray(f)&&f[0]==="..."){let w={};for(let _ in t)l.includes(_)||(w[_]=t[_]);e[f[1]]=w;break}let d,C,E;typeof f=="string"?d=C=f:f[0]==="="?(typeof f[1]=="string"?d=C=f[1]:[,d,C]=f[1],E=f[2]):[,d,C]=f,l.push(d);let S=t[d];S===void 0&&E&&(S=i(E)(e)),X(C,S,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 d=f,C;Array.isArray(f)&&f[0]==="="&&([,d,C]=f);let E=t[l++];E===void 0&&C&&(E=i(C)(e)),X(d,E,e)}}},Lr=(...r)=>(r=r.map(t=>{if(typeof t=="string")return e=>{e[t]=void 0};if(t[0]==="="){let[,e,o]=t,n=i(o);return typeof e=="string"?s=>{s[e]=n(s)}:s=>X(e,n(s),s)}return i(t)}),t=>{for(let e of r)e(t)});p("let",Lr);p("const",Lr);p("var",Lr);var sr=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=i(t),typeof e=="string"?o=>{o[e]=t(o)}:o=>X(e,t(o),o)}return M(r)||sr("Invalid assignment target"),t=i(t),G(r,(e,o,n)=>e[o]=t(n))});p("||=",(r,t)=>(M(r)||sr("Invalid assignment target"),t=i(t),G(r,(e,o,n)=>e[o]||=t(n))));p("&&=",(r,t)=>(M(r)||sr("Invalid assignment target"),t=i(t),G(r,(e,o,n)=>e[o]&&=t(n))));p("??=",(r,t)=>(M(r)||sr("Invalid assignment target"),t=i(t),G(r,(e,o,n)=>e[o]??=t(n))));p("?",(r,t,e)=>(r=i(r),t=i(t),e=i(e),o=>r(o)?t(o):e(o)));var B=[];p("=>",(r,t)=>{r=r?.[0]==="()"?r[1]:r;let e=r?r[0]===","?r.slice(1):[r]:[],o=-1,n=null,s=e[e.length-1];Array.isArray(s)&&s[0]==="..."&&(o=e.length-1,n=s[1],e.length--);let l=t?.[0]==="{}";return t=i(l?["{",t[1]]:t),f=>(...d)=>{let C={};e.forEach((S,w)=>C[S]=d[w]),n&&(C[n]=d.slice(o));let E=new Proxy(C,{get:(S,w)=>w in S?S[w]:f?.[w],set:(S,w,_)=>((w in S?S:f)[w]=_,!0),has:(S,w)=>w in S||(f?w in f:!1)});try{let S=t(E);return l?void 0:S}catch(S){if(S===B)return S[0];throw S}}});p("...",r=>(r=i(r),t=>Object.entries(r(t))));p("?.",(r,t)=>(r=i(r),D(t)?()=>{}:e=>r(e)?.[t]));p("?.[]",(r,t)=>(r=i(r),t=i(t),e=>{let o=t(e);return D(o)?void 0:r(e)?.[o]}));p("?.()",(r,t)=>{let e=t?t[0]===","?(t=t.slice(1).map(i),n=>t.map(s=>s(n))):(t=i(t),n=>[t(n)]):()=>[];if(r[0]==="?."){let n=i(r[1]),s=r[2];return D(s)?()=>{}:l=>n(l)?.[s]?.(...e(l))}if(r[0]==="?.[]"){let n=i(r[1]),s=i(r[2]);return l=>{let f=n(l),d=s(l);return D(d)?void 0:f?.[d]?.(...e(l))}}if(r[0]==="."){let n=i(r[1]),s=r[2];return D(s)?()=>{}:l=>n(l)?.[s]?.(...e(l))}if(r[0]==="[]"&&r.length===3){let n=i(r[1]),s=i(r[2]);return l=>{let f=n(l),d=s(l);return D(d)?void 0:f?.[d]?.(...e(l))}}let o=i(r);return n=>o(n)?.(...e(n))});p("typeof",r=>(r=i(r),t=>typeof r(t)));p("void",r=>(r=i(r),t=>(r(t),void 0)));p("delete",r=>{if(r[0]==="."){let t=i(r[1]),e=r[2];return o=>delete t(o)[e]}if(r[0]==="[]"){let t=i(r[1]),e=i(r[2]);return o=>delete t(o)[e(o)]}return()=>!0});p("new",r=>{let t=i(r?.[0]==="()"?r[1]:r),e=r?.[0]==="()"?r[2]:null,o=e?e[0]===","?(n=>s=>n.map(l=>l(s)))(e.slice(1).map(i)):(n=>s=>[n(s)])(i(e)):()=>[];return n=>new(t(n))(...o(n))});var pr=Symbol("accessor");p("get",(r,t)=>(t=t?i(t):()=>{},e=>[[pr,r,{get:function(){let o=Object.create(e||{});return o.this=this,t(o)}}]]));p("set",(r,t,e)=>(e=e?i(e):()=>{},o=>[[pr,r,{set:function(n){let s=Object.create(o||{});s.this=this,s[t]=n,e(s)}}]]));var Qe=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);p("{}",(r,t)=>{if(t!==void 0)return;if(!Qe(r))return i(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let e=r.map(o=>i(typeof o=="string"?[":",o,o]:o));return o=>{let n={},s={};for(let l of e.flatMap(f=>f(o)))if(l[0]===pr){let[,f,d]=l;s[f]={...s[f],...d,configurable:!0,enumerable:!0}}else n[l[0]]=l[1];for(let l in s)Object.defineProperty(n,l,s[l]);return n}});p("{",r=>(r=r?i(r):()=>{},t=>r(Object.create(t))));p(":",(r,t)=>(t=i(t),Array.isArray(r)?(r=i(r),e=>[[r(e),t(e)]]):e=>[[r,t(e)]]));p("`",(...r)=>(r=r.map(i),t=>r.map(e=>e(t)).join("")));p("``",(r,...t)=>{r=i(r);let e=[],o=[];for(let s of t)Array.isArray(s)&&s[0]===void 0?e.push(s[1]):o.push(i(s));let n=Object.assign([...e],{raw:e});return s=>r(s)(n,...o.map(l=>l(s)))});p("function",(r,t,e)=>{e=e?i(e):()=>{};let o=t?t[0]===","?t.slice(1):[t]:[],n=null,s=-1,l=o[o.length-1];return Array.isArray(l)&&l[0]==="..."&&(s=o.length-1,n=l[1],o.length--),f=>{let d=(...C)=>{let E={};o.forEach((w,_)=>E[w]=C[_]),n&&(E[n]=C.slice(s));let S=new Proxy(E,{get:(w,_)=>_ in w?w[_]:f[_],set:(w,_,Ct)=>((_ in w?w:f)[_]=Ct,!0),has:(w,_)=>_ in w||_ in f});try{return e(S)}catch(w){if(w===B)return w[0];throw w}};return r&&(f[r]=d),d}});p("function*",(r,t,e)=>{throw Error("Generator functions are not supported in evaluation")});p("async",r=>{let t=i(r);return e=>{let o=t(e);return async function(...n){return o(...n)}}});p("await",r=>(r=i(r),async t=>await r(t)));p("yield",r=>(r=r?i(r):null,t=>{throw{__yield__:r?r(t):void 0}}));p("yield*",r=>(r=i(r),t=>{throw{__yield_all__:r(t)}}));var $e=Symbol("static"),xe=r=>{throw Error(r)};p("instanceof",(r,t)=>(r=i(r),t=i(t),e=>r(e)instanceof t(e)));p("class",(r,t,e)=>(t=t?i(t):null,e=e?i(e):null,o=>{let n=t?t(o):Object,s=function(...l){if(!(this instanceof s))return xe("Class constructor must be called with new");let f=t?Reflect.construct(n,l,s):this;return s.prototype.__constructor__&&s.prototype.__constructor__.apply(f,l),f};if(Object.setPrototypeOf(s.prototype,n.prototype),Object.setPrototypeOf(s,n),e){let l=Object.create(o);l.super=n;let f=e(l),d=Array.isArray(f)&&typeof f[0]?.[0]=="string"?f:[];for(let[C,E]of d)C==="constructor"?s.prototype.__constructor__=E:s.prototype[C]=E}return r&&(o[r]=s),s}));p("static",r=>(r=i(r),t=>[[$e,r(t)]]));p("//",(r,t)=>{let e=new RegExp(r,t||"");return()=>e});p("if",(r,t,e)=>(r=i(r),t=i(t),e=e!==void 0?i(e):null,o=>r(o)?t(o):e?.(o)));var U=Symbol("break"),K=Symbol("continue");p("while",(r,t)=>(r=i(r),t=i(t),e=>{let o;for(;r(e);)try{o=t(e)}catch(n){if(n===U)break;if(n===K)continue;if(n===B)return n[0];throw n}return o}));p("do",(r,t)=>(r=i(r),t=i(t),e=>{let o;do try{o=r(e)}catch(n){if(n===U)break;if(n===K)continue;if(n===B)return n[0];throw n}while(t(e));return o}));p("for",(r,t)=>{if(Array.isArray(r)&&r[0]===";"){let[,e,o,n]=r;return e=e?i(e):null,o=o?i(o):()=>!0,n=n?i(n):null,t=i(t),s=>{let l;for(e?.(s);o(s);n?.(s))try{l=t(s)}catch(f){if(f===U)break;if(f===K)continue;if(f===B)return f[0];throw f}return l}}if(Array.isArray(r)&&(r[0]==="in"||r[0]==="of")){let[e,o,n]=r;if(Array.isArray(o)&&(o[0]==="let"||o[0]==="const"||o[0]==="var")&&(o=o[1]),e==="in")return ze(o,n,t);if(e==="of")return We(o,n,t)}});var We=(r,t,e)=>{t=i(t),e=i(e);let o=Array.isArray(r);return n=>{let s,l=o?null:n[r];for(let f of t(n)){o?X(r,f,n):n[r]=f;try{s=e(n)}catch(d){if(d===U)break;if(d===K)continue;if(d===B)return d[0];throw d}}return o||(n[r]=l),s}},ze=(r,t,e)=>{t=i(t),e=i(e);let o=Array.isArray(r);return n=>{let s,l=o?null:n[r];for(let f in t(n)){o?X(r,f,n):n[r]=f;try{s=e(n)}catch(d){if(d===U)break;if(d===K)continue;if(d===B)return d[0];throw d}}return o||(n[r]=l),s}};p("break",()=>()=>{throw U});p("continue",()=>()=>{throw K});p("return",r=>(r=r!==void 0?i(r):null,t=>{throw B[0]=r?.(t),B}));p("try",(r,...t)=>{r=r?i(r):null;let e=t.find(f=>f?.[0]==="catch"),o=t.find(f=>f?.[0]==="finally"),n=e?.[1],s=e?.[2]?i(e[2]):null,l=o?.[1]?i(o[1]):null;return f=>{let d;try{d=r?.(f)}catch(C){if(C===U||C===K||C===B)throw C;if(n!=null&&s){let E=n in f,S=f[n];f[n]=C;try{d=s(f)}finally{E?f[n]=S:delete f[n]}}else if(!s)throw C}finally{l?.(f)}return d}});p("throw",r=>(r=i(r),t=>{throw r(t)}));p("switch",(r,...t)=>(r=i(r),t.length?(t=t.map(e=>[e[0]==="case"?i(e[1]):null,(e[0]==="case"?e[2]:e[1])?.[0]===";"?(e[0]==="case"?e[2]:e[1]).slice(1).map(i):(e[0]==="case"?e[2]:e[1])?[i(e[0]==="case"?e[2]:e[1])]:[]]),e=>{let o=r(e),n=!1,s;for(let[f,d]of t)if(n||f===null||f(e)===o)for(n=!0,l=0;l<d.length;l++)try{s=d[l](e)}catch(C){if(C===U)return s;throw C}var l;return s}):e=>r(e)));p("import",()=>()=>{});p("export",()=>()=>{});p("from",(r,t)=>()=>{});p("as",(r,t)=>()=>{});p("default",r=>i(r));var At=new WeakMap,Je=(r,...t)=>typeof r=="string"?i(m(r)):At.get(r)||At.set(r,Ve(r,t)).get(r),yt=57344,Ve=(r,t)=>{let e=r.reduce((s,l,f)=>s+(f?String.fromCharCode(yt+f-1):"")+l,""),o=m(e),n=s=>{if(typeof s=="string"&&s.length===1){let l=s.charCodeAt(0)-yt,f;if(l>=0&&l<t.length)return f=t[l],Ye(f)?f:[,f]}return Array.isArray(s)?s.map(n):s};return i(n(o))},Ye=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Ze=Je;export{mr as access,y as binary,i as compile,c as cur,Ze as default,R as err,A as expr,x as group,qe as id,u as idx,g as keyword,j as literal,Mr as loc,T as lookup,lr as nary,N as next,p as operator,ur as operators,v as parens,m as parse,Y as peek,$ as prec,P as seek,h as skip,a as space,fr as step,k as token,O as unary,I as word};
|
|
1
|
+
var l,c,s=r=>(l=0,c=r,s.enter?.(),r=h(),c[l]?N():r||""),N=(r="Unexpected token",e=l,t=c.slice(0,e).split(`
|
|
2
|
+
`),o=t.pop(),n=c.slice(Math.max(0,e-40),e),p="\u032D",m=(c[e]||" ")+p,u=c.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
|
|
3
|
+
${c[e-41]!==`
|
|
4
|
+
`,""+n}${m}${u}`)},Br=(r,e=l)=>(Array.isArray(r)&&(r.loc=e),r),I=(r,e=l,t)=>{for(;t=r(c.charCodeAt(l));)l+=t;return c.slice(e,l)},d=(r=1)=>c[l+=r],O=r=>l=r,h=(r=0,e)=>{let t,o,n;for(e&&s.enter?.(r,e);(t=s.space())&&t!==e&&(n=s.step(o,r,t,h));)o=n;return e&&(t==e?(l++,s.exit?.(r,e)):N("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},Y=(r=l)=>{for(;c.charCodeAt(r)<=32;)r++;return c.charCodeAt(r)},Jt=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,k=(r,e=r.length)=>c.substr(l,e)===r&&!s.id(c.charCodeAt(l+e)),P=()=>(d(),h(0,41)),T=[],$={},S=(r,e=32,t,o=r.charCodeAt(0),n=r.length,p=T[o],m=r.toUpperCase()!==r,u,a)=>(e=$[r]=!p&&$[r]||e,T[o]=(y,g,E,w=l)=>(u=E,(E?r==E:(n<2||r.charCodeAt(1)===c.charCodeAt(l+1)&&(n<3||c.substr(l,n)==r))&&(!m||!s.id(c.charCodeAt(l+n)))&&(u=E=r))&&g<e&&(l+=n,(a=t(y))?Br(a,w):(l=w,u=0,!m&&!p&&!y&&N()),a)||p?.(y,g,u))),A=(r,e,t=!1)=>S(r,e,o=>o&&(n=>n&&[r,o,n])(h(e-(t?.5:0)))),_=(r,e,t)=>S(r,e,o=>t?o&&[r,o]:!o&&(o=h(e-.5))&&[r,o]),H=(r,e)=>S(r,200,t=>!t&&[,e]),fr=(r,e,t)=>S(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)),j=(r,e)=>S(r[0],e,t=>!t&&[r,h(0,r.charCodeAt(1))||null]),ur=(r,e)=>S(r[0],e,t=>t&&[r,t,h(0,r.charCodeAt(1))||null]),C=(r,e,t,o=r.charCodeAt(0),n=r.length,p=T[o],m)=>T[o]=(u,a,y,g=l)=>!u&&(y?r==y:(n<2||c.substr(l,n)==r)&&(y=r))&&a<e&&!s.id(c.charCodeAt(l+n))&&(!s.prop||s.prop(l+n))&&(O(l+n),(m=t())?Br(m,g):O(g),m)||p?.(u,a,y);s.space=r=>{for(;(r=c.charCodeAt(l))<=32;)l++;return r};s.step=(r,e,t,o,n)=>(n=T[t])&&n(r,e)||(r?null:I(s.id)||null);var pr={},f=(r,e,t=pr[r])=>pr[r]=(...o)=>e(...o)||t?.(...o),i=r=>Array.isArray(r)?r[0]==null?(e=>()=>e)(r[1]):pr[r[0]]?.(...r.slice(1))??N(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var q=46,W=48,x=57,ye=69,Ce=101,we=43,ge=45,Z=95,Lr=110,Ee=97,Se=102,ke=65,Te=70,Mr=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),lr=r=>{let e=Mr(I(t=>t===q&&c.charCodeAt(l+1)!==q||t>=W&&t<=x||t===Z||((t===ye||t===Ce)&&((t=c.charCodeAt(l+1))>=W&&t<=x||t===we||t===ge)?2:0)));return c.charCodeAt(l)===Lr?(d(),[,BigInt(e)]):(r=+e)!=r?N():[,r]},Ie={2:r=>r===48||r===49||r===Z,8:r=>r>=48&&r<=55||r===Z,16:r=>r>=W&&r<=x||r>=Ee&&r<=Se||r>=ke&&r<=Te||r===Z};s.number=null;T[q]=r=>!r&&c.charCodeAt(l+1)!==q&&lr();for(let r=W;r<=x;r++)T[r]=e=>e?void 0:lr();T[W]=r=>{if(r)return;let e=s.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&c[l+1]?.toLowerCase()===t[1]){d(2);let n=Mr(I(Ie[o]));return c.charCodeAt(l)===Lr?(d(),[,BigInt("0"+t[1]+n)]):[,parseInt(n,o)]}}return lr()};var Ne=92,Ur=34,Dr=39,Fr=117,Gr=120,Re=123,_e=125,Xr=10,Oe=13,Pe={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},Kr=r=>r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:-1,Hr=r=>(e,t,o="",n=String.fromCharCode(r))=>{if(e||!s.string?.[n])return;d();let p=()=>{let m=c.charCodeAt(l+1);if(m===Xr)return 2;if(m===Oe)return c.charCodeAt(l+2)===Xr?3:2;if(m===Gr||m===Fr&&c.charCodeAt(l+2)!==Re){let u=m===Gr?2:4,a=0,y;for(let g=0;g<u;g++){if((y=Kr(c.charCodeAt(l+2+g)))<0)return o+=c[l+1],2;a=a*16+y}return o+=String.fromCharCode(a),2+u}if(m===Fr){let u=0,a=l+3,y;for(;(y=Kr(c.charCodeAt(a)))>=0;)u=u*16+y,a++;return a>l+3&&u<=1114111&&c.charCodeAt(a)===_e?(o+=String.fromCodePoint(u),a-l+1):(o+=c[l+1],2)}return o+=Pe[c[l+1]]||c[l+1],2};return I(m=>m-r&&(m!==Ne?(o+=c[l],1):p())),c[l]===n?d():N("Bad string"),[,o]};T[Ur]=Hr(Ur);T[Dr]=Hr(Dr);s.string={'"':!0};var ve=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>A(r,ve,!0));var Be=30,Le=40,Me=140;_("!",Me);A("||",Be);A("&&",Le);var Ue=50,De=60,Fe=70,Qr=100,Ge=140;A("|",Ue);A("&",Fe);A("^",De);A(">>",Qr);A("<<",Qr);_("~",Ge);var b=90;A("<",b);A(">",b);A("<=",b);A(">=",b);var $r=80;A("==",$r);A("!=",$r);var jr=110,mr=120,Wr=140;A("+",jr);A("-",jr);A("*",mr);A("/",mr);A("%",mr);_("+",Wr);_("-",Wr);var rr=150;S("++",rr,r=>r?["++",r,null]:["++",h(rr-1)]);S("--",rr,r=>r?["--",r,null]:["--",h(rr-1)]);var Xe=5,Ke=10;fr(",",Ke);fr(";",Xe,!0);var He=170;j("()",He);var cr=170;ur("[]",cr);A(".",cr);ur("()",cr);var Qe=32,$e=s.space;s.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};var ar;s.space=()=>{ar||(ar=Object.entries(s.comment).map(([n,p])=>[n,p,n.charCodeAt(0)]));for(var r;r=$e();){for(var e=0,t;t=ar[e++];)if(r===t[2]&&c.substr(l,t[0].length)===t[0]){var o=l+t[0].length;if(t[1]===`
|
|
7
|
+
`)for(;c.charCodeAt(o)>=Qe;)o++;else{for(;c[o]&&c.substr(o,t[1].length)!==t[1];)o++;c[o]&&(o+=t[1].length)}O(o),r=0;break}if(r)return r}return r};var zr=80;A("===",zr);A("!==",zr);var je=30;A("??",je);var We=130,ze=20;A("**",We,!0);A("**=",ze,!0);var Jr=90;A("in",Jr);A("of",Jr);var Je=20,Ve=100;A(">>>",Ve);A(">>>=",Je,!0);var dr=20;A("||=",dr,!0);A("&&=",dr,!0);A("??=",dr,!0);H("true",!0);H("false",!1);H("null",null);C("undefined",200,()=>[]);H("NaN",NaN);H("Infinity",1/0);var hr=20;S("?",hr,(r,e,t)=>r&&(e=h(hr-1))&&I(o=>o===58)&&(t=h(hr-1),["?",r,e,t]));var Ye=20;A("=>",Ye,!0);var Ze=20;_("...",Ze);var Vr=170;S("?.",Vr,(r,e)=>{if(!r)return;let t=s.space();return t===40?(d(),["?.()",r,h(0,41)||null]):t===91?(d(),["?.[]",r,h(0,93)]):(e=h(Vr),e?["?.",r,e]:void 0)});var z=140;_("typeof",z);_("void",z);_("delete",z);C("new",z,()=>k(".target")?(d(7),["new.target"]):["new",h(z)]);var qe=20,Yr=200;s.prop=r=>Y(r)!==58;j("[]",Yr);j("{}",Yr);A(":",qe-1,!0);var xe=170,er=96,be=36,rt=123,et=92,tt={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Zr=()=>{let r=[];for(let e="",t;(t=c.charCodeAt(l))!==er;)t?t===et?(d(),e+=tt[c[l]]||c[l],d()):t===be&&c.charCodeAt(l+1)===rt?(e&&r.push([,e]),e="",d(2),r.push(h(0,125))):(e+=c[l],d(),t=c.charCodeAt(l),t===er&&e&&r.push([,e])):N("Unterminated template");return d(),r},ot=T[er];T[er]=(r,e)=>r&&e<xe?s.asi&&s.newline?void 0:(d(),["``",r,...Zr()]):r?ot?.(r,e):(d(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(Zr()));s.string["'"]=!0;s.number={"0x":16,"0b":2,"0o":8};var nt=92,it=117,st=123,pt=125,ft=183,ut=s.id,qr=r=>r>=48&&r<=57||r>=65&&r<=70||r>=97&&r<=102,lt=(r=l+2,e,t=0,o=0)=>{if(c.charCodeAt(l)!==nt||c.charCodeAt(l+1)!==it)return 0;if(c.charCodeAt(r)===st){for(;qr(e=c.charCodeAt(++r));)t=t*16+(e<=57?e-48:(e&31)+9);return r>l+3&&t<=1114111&&c.charCodeAt(r)===pt?r-l+1:0}for(;o<4&&qr(c.charCodeAt(r+o));)o++;return o===4?6:0};s.id=r=>ut(r)||r===ft||lt();var Ar=5,mt=10,yr=r=>{let e=l,t=h(mt-1);return t==null?r:r==="let"&&(t==="in"||t==="of")?(O(e),r):t[0]==="in"||t[0]==="of"?[t[0],[r,t[1]],t[2]]:t[0]===","?[r,...t.slice(1)]:[r,t]};C("let",Ar+1,()=>yr("let"));C("const",Ar+1,()=>yr("const"));C("var",Ar+1,()=>yr("var"));var tr=5,ct=59,B=()=>(s.space()===123||N("Expected {"),d(),h(tr-.5,125)||null),U=()=>s.space()!==123?h(tr+.5):(d(),h(tr-.5,125)||null),at=()=>{let r=l;return s.space()===ct&&d(),s.space(),k("else")?(d(4),!0):(O(r),!1)};C("if",tr+1,()=>{s.space();let r=["if",P(),U()];return at()&&r.push(U()),r});var dt=200;C("function",dt,()=>{s.space();let r=!1;c[l]==="*"&&(r=!0,d(),s.space());let e=I(s.id);return e&&s.space(),r?["function*",e,P()||null,B()]:["function",e,P()||null,B()]});var or=140,Cr=20;_("await",or);C("yield",or,()=>(s.space(),c[l]==="*"?(d(),s.space(),["yield*",h(Cr)]):["yield",h(Cr)]));C("async",or,()=>{if(s.space(),k("function"))return["async",h(or)];let r=h(Cr-.5);return r&&["async",r]});var wr=200;var ht=90,At=175;_("static",At);A("instanceof",ht);S("#",wr,r=>{if(r)return;let e=I(s.id);return e?"#"+e:void 0});C("class",wr,()=>{s.space();let r=I(s.id)||null;if(r==="extends")r=null,s.space();else{if(s.space(),!k("extends"))return["class",r,null,B()];d(7),s.space()}return["class",r,h(wr),B()]});var gr=47,yt=92;S("/",140,r=>{let e=c.charCodeAt(l);if(r||e===gr||e===42||e===43||e===63||e===61)return;let t=I(n=>n===yt?2:n&&n!==gr);c.charCodeAt(l)===gr||N("Unterminated regex"),d();let o=I(n=>n===103||n===105||n===109||n===115||n===117||n===121);return o?["//",t,o]:["//",t]});var K=5,J=125,V=59;C("while",K+1,()=>(s.space(),["while",P(),U()]));C("do",K+1,()=>(r=>(s.space(),d(5),s.space(),["do",r,P()]))(U()));C("for",K+1,()=>(s.space(),k("await")?(d(5),s.space(),["for await",P(),U()]):["for",P(),U()]));C("break",K+1,()=>{s.asi&&(s.newline=!1);let r=l;s.space();let e=c.charCodeAt(l);if(!e||e===J||e===V||s.newline)return["break"];let t=I(s.id);if(!t)return["break"];s.space();let o=c.charCodeAt(l);return!o||o===J||o===V||s.newline?["break",t]:(O(r),["break"])});C("continue",K+1,()=>{s.asi&&(s.newline=!1);let r=l;s.space();let e=c.charCodeAt(l);if(!e||e===J||e===V||s.newline)return["continue"];let t=I(s.id);if(!t)return["continue"];s.space();let o=c.charCodeAt(l);return!o||o===J||o===V||s.newline?["continue",t]:(O(r),["continue"])});C("return",K+1,()=>{s.asi&&(s.newline=!1);let r=s.space();return!r||r===J||r===V||s.newline?["return"]:["return",h(K)]});var Er=5;C("try",Er+1,()=>{let r=["try",B()];return s.space(),k("catch")&&(d(5),s.space(),r.push(["catch",Y()===40?P():null,B()])),s.space(),k("finally")&&(d(7),r.push(["finally",B()])),r});C("throw",Er+1,()=>{if(s.asi&&(s.newline=!1),s.space(),s.newline)throw SyntaxError("Unexpected newline after throw");return["throw",h(Er)]});var re=5,Ct=20,xr=58,wt=59,ee=125,Sr=0,te=(r,e=r.length,t=r.charCodeAt(0),o=T[t])=>T[t]=(n,p,m)=>k(r)&&!n&&Sr||o?.(n,p,m);te("case");te("default");var br=r=>{let e=[];for(;(r=s.space())!==ee&&!k("case")&&!k("default");){if(r===wt){d();continue}e.push(h(re-.5))||N()}return e.length>1?[";",...e]:e[0]||null},gt=()=>{s.space()===123||N("Expected {"),d(),Sr++;let r=[];try{for(;s.space()!==ee;)if(k("case")){O(l+4),s.space();let e=h(Ct-.5);s.space()===xr&&d(),r.push(["case",e,br()])}else k("default")?(O(l+7),s.space()===xr&&d(),r.push(["default",br()])):N("Expected case or default")}finally{Sr--}return d(),r};C("switch",re+1,()=>s.space()===40&&["switch",P(),...gt()]);var oe=5;C("debugger",oe+1,()=>["debugger"]);C("with",oe+1,()=>(s.space(),["with",P(),U()]));var kr=5,Q=10,ne=42,Et=T[ne];T[ne]=(r,e)=>r?Et?.(r,e):(d(),"*");S("from",Q+1,r=>r?r[0]!=="="&&r[0]!==","&&(s.space(),["from",r,h(Q+1)]):!1);S("as",Q+2,r=>r?(s.space(),["as",r,h(Q+2)]):!1);C("import",kr,()=>k(".meta")?(d(5),["import.meta"]):["import",h(Q)]);C("export",kr,()=>(s.space(),k("default")?(d(7),["export",["default",h(Q)]]):["export",h(kr)]));var Tr=20,St=10,kt=13,Tt=40,ie=41,se=123,pe=125,It=(r,e)=>{for(;r<e;){let t=c.charCodeAt(r++);if(t===St||t===kt)return!0}return!1},fe=r=>e=>{if(e)return;let t=l;if(s.space(),s.semi||It(t,l))return!1;let o=I(s.id);if(!o||(s.space(),c.charCodeAt(l)!==Tt))return!1;d();let n=h(0,ie);return s.space(),c.charCodeAt(l)!==se?!1:(d(),[r,o,n,h(0,pe)])};S("get",Tr-1,fe("get"));S("set",Tr-1,fe("set"));S("(",Tr-1,r=>{if(!r)return;let e;if(Array.isArray(r)&&r[0]==="static"&&(e="static",r=r[1]),typeof r!="string"&&!(Array.isArray(r)&&r[0]===void 0))return;let t=h(0,ie)||null;if(s.space(),c.charCodeAt(l)!==se)return;d();let o=[":",r,["=>",["()",t],h(0,pe)||null]];return e?[e,o]:o});s.comment["#!"]=`
|
|
9
|
+
`;var le=32,_r=10,Nt=59,Rt=125,_t=91,Ot=40,Rr=$.asi??$[";"],Pt=s._baseSpace??=s.space,vt=s._baseStep??=s.step,Ir=r=>Array.isArray(r)||typeof r=="string",Bt=(r,e)=>{for(;(e=c.charCodeAt(r))<=le;){if(e===_r)return!0;r++}return!1},Lt=(r=l,e)=>{for(;r-- >0&&(e=c.charCodeAt(r))<=le;)if(e===_r)return!0;return!1};s.space=(r,e)=>{for(;;){for(e=l,r=Pt();e<l;)if(c.charCodeAt(e++)===_r){s.newline=!0;break}if(r===Nt&&Bt(l+1)){O(l+1),s.newline=s.semi=!0;continue}return r}};s.enter=()=>s.newline=s.semi=!1;s.exit=(r,e)=>{e===Rt&&(s.newline=!0,s.semi=!1)};s.step=(r,e,t,o)=>{if(s.semi&&e>=Rr)return!1;if(r&&!Ir(r))return null;if(Ir(r)&&(s.semi||(t===_t||t===Ot)&&Lt()))return ue(r,e,o)??null;let n=s.newline;return vt(r,e,t,o)??(Ir(r)&&n?ue(r,e,o)??null:null)};var Nr=0,Mt=2e3,ue=s.asi=(r,e,t,o,n)=>{if(e>=Rr||Nr>=Mt)return;s.semi=!1;let p=l;Nr++;try{o=t(Rr-.5)}finally{Nr--}if(!(!o||l===p))return n=o?.[0]===";"?o.slice(1):[o],r?.[0]===";"?(r.push(...n),r):[";",r,...n]};var ce=(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?ce(r[1],e):(()=>{throw Error("Invalid assignment target")})(),me={"=":(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 me)f(r,(e,t)=>(t=i(t),ce(e,(o,n,p)=>me[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 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")})();f("++",(r,e)=>Or(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));f("--",(r,e)=>Or(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var ae=(...r)=>(r=r.map(i),e=>{let t;for(let o of r)t=o(e);return t});f(",",ae);f(";",ae);var D=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",nr=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&&nr("Missing index"),r=i(r),e=i(e),t=>{let o=e(t);return D(o)?void 0:r(t)[o]}));f(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],D(e)?()=>{}:t=>r(t)[e]));f("()",(r,e)=>{if(e===void 0)return r==null?nr("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(p=>p==null||t(p));t(e)&&nr("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 Pr(r,(n,p,m)=>n[p](...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]==="{}"),Pr=(r,e,t,o)=>r==null?nr("Empty ()"):r[0]==="()"&&r.length==2?Pr(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)),F=Pr;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 Ut=r=>{throw Error(r)};f("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));f("**=",(r,e)=>(L(r)||Ut("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 Dt=r=>{throw Error(r)};f(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));f(">>>=",(r,e)=>(L(r)||Dt("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]>>>=e(n))));var Ft=r=>r[0]?.[0]===","?r[0].slice(1):r,G=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...n]=r,p=Ft(n);if(o==="{}"){let m=[];for(let u of p){if(Array.isArray(u)&&u[0]==="..."){let w={};for(let R in e)m.includes(R)||(w[R]=e[R]);t[u[1]]=w;break}let a,y,g;typeof u=="string"?a=y=u:u[0]==="="?(typeof u[1]=="string"?a=y=u[1]:[,a,y]=u[1],g=u[2]):[,a,y]=u,m.push(a);let E=e[a];E===void 0&&g&&(E=i(g)(t)),G(y,E,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 g=e[m++];g===void 0&&y&&(g=i(y)(t)),G(a,g,t)}}},vr=(...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=>G(t,n(p),p)}return i(e)}),e=>{for(let t of r)t(e)});f("let",vr);f("const",vr);f("var",vr);var ir=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=>G(t,e(o),o)}return L(r)||ir("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]=e(n))});f("||=",(r,e)=>(L(r)||ir("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]||=e(n))));f("&&=",(r,e)=>(L(r)||ir("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]&&=e(n))));f("??=",(r,e)=>(L(r)||ir("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 v=[];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((E,w)=>y[E]=a[w]),n&&(y[n]=a.slice(o));let g=new Proxy(y,{get:(E,w)=>w in E?E[w]:u?.[w],set:(E,w,R)=>((w in E?E:u)[w]=R,!0),has:(E,w)=>w in E||(u?w in u:!1)});try{let E=e(g);return m?void 0:E}catch(E){if(E===v)return E[0];throw E}}});f("...",r=>(r=i(r),e=>Object.entries(r(e))));f("?.",(r,e)=>(r=i(r),D(e)?()=>{}:t=>r(t)?.[e]));f("?.[]",(r,e)=>(r=i(r),e=i(e),t=>{let o=e(t);return D(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]==="?."){let n=i(r[1]),p=r[2];return D(p)?()=>{}:m=>n(m)?.[p]?.(...t(m))}if(r[0]==="?.[]"){let n=i(r[1]),p=i(r[2]);return m=>{let u=n(m),a=p(m);return D(a)?void 0:u?.[a]?.(...t(m))}}if(r[0]==="."){let n=i(r[1]),p=r[2];return D(p)?()=>{}:m=>n(m)?.[p]?.(...t(m))}if(r[0]==="[]"&&r.length===3){let n=i(r[1]),p=i(r[2]);return m=>{let u=n(m),a=p(m);return D(a)?void 0:u?.[a]?.(...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 sr=Symbol("accessor");f("get",(r,e)=>(e=e?i(e):()=>{},t=>[[sr,r,{get:function(){let o=Object.create(t||{});return o.this=this,e(o)}}]]));f("set",(r,e,t)=>(t=t?i(t):()=>{},o=>[[sr,r,{set:function(n){let p=Object.create(o||{});p.this=this,p[e]=n,t(p)}}]]));var Gt=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);f("{}",(r,e)=>{if(e!==void 0)return;if(!Gt(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]===sr){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 g={};o.forEach((w,R)=>g[w]=y[R]),n&&(g[n]=y.slice(p));let E=new Proxy(g,{get:(w,R)=>R in w?w[R]:u[R],set:(w,R,Ae)=>((R in w?w:u)[R]=Ae,!0),has:(w,R)=>R in w||R in u});try{return t(E)}catch(w){if(w===v)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 Xt=Symbol("static"),Kt=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 Kt("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,g]of a)y==="constructor"?p.prototype.__constructor__=g:p.prototype[y]=g}return r&&(o[r]=p),p}));f("static",r=>(r=i(r),e=>[[Xt,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 M=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===M)break;if(n===X)continue;if(n===v)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===M)break;if(n===X)continue;if(n===v)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===M)break;if(u===X)continue;if(u===v)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 Qt(o,n,e);if(t==="of")return Ht(o,n,e)}});var Ht=(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?G(r,u,n):n[r]=u;try{p=t(n)}catch(a){if(a===M)break;if(a===X)continue;if(a===v)return a[0];throw a}}return o||(n[r]=m),p}},Qt=(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?G(r,u,n):n[r]=u;try{p=t(n)}catch(a){if(a===M)break;if(a===X)continue;if(a===v)return a[0];throw a}}return o||(n[r]=m),p}};f("break",()=>()=>{throw M});f("continue",()=>()=>{throw X});f("return",r=>(r=r!==void 0?i(r):null,e=>{throw v[0]=r?.(e),v}));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===M||y===X||y===v)throw y;if(n!=null&&p){let g=n in u,E=u[n];u[n]=y;try{a=p(u)}finally{g?u[n]=E: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===M)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 de=new WeakMap,$t=(r,...e)=>typeof r=="string"?i(s(r)):de.get(r)||de.set(r,jt(r,e)).get(r),he=57344,jt=(r,e)=>{let t=r.reduce((p,m,u)=>p+(u?String.fromCharCode(he+u-1):"")+m,""),o=s(t),n=p=>{if(typeof p=="string"&&p.length===1){let m=p.charCodeAt(0)-he,u;if(m>=0&&m<e.length)return u=e[m],Wt(u)?u:[,u]}return Array.isArray(p)?p.map(n):p};return i(n(o))},Wt=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),zt=$t;export{ur as access,A as binary,i as compile,c as cur,zt as default,N as err,h as expr,j as group,Jt as id,l as idx,C as keyword,H as literal,Br as loc,T as lookup,fr as nary,I as next,f as operator,pr as operators,P as parens,s as parse,Y as peek,$ as prec,O as seek,d as skip,S as token,_ as unary,k as word};
|
package/justin.min.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var u,l,
|
|
1
|
+
var u,l,d=r=>(u=0,l=r,d.enter?.(),r=y(),l[u]?v():r||""),v=(r="Unexpected token",t=u,e=l.slice(0,t).split(`
|
|
2
2
|
`),o=e.pop(),i=l.slice(Math.max(0,t-40),t),p="\u032D",m=(l[t]||" ")+p,f=l.slice(t+1,t+20))=>{throw SyntaxError(`${r} at ${e.length+1}:${o.length+1}
|
|
3
3
|
${l[t-41]!==`
|
|
4
|
-
`,""+i}${m}${f}`)},
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},
|
|
6
|
-
`,"/*":"*/"};var
|
|
7
|
-
`)for(;l.charCodeAt(o)>=
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
4
|
+
`,""+i}${m}${f}`)},ir=(r,t=u)=>(Array.isArray(r)&&(r.loc=t),r),L=(r,t=u,e)=>{for(;e=r(l.charCodeAt(u));)u+=e;return l.slice(t,u)},C=(r=1)=>l[u+=r],M=r=>u=r,y=(r=0,t)=>{let e,o,i;for(t&&d.enter?.(r,t);(e=d.space())&&e!==t&&(i=d.step(o,r,e,y));)o=i;return t&&(e==t?(u++,d.exit?.(r,t)):v("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),o},sr=(r=u)=>{for(;l.charCodeAt(r)<=32;)r++;return l.charCodeAt(r)},Rt=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,pr=(r,t=r.length)=>l.substr(u,t)===r&&!d.id(l.charCodeAt(u+t)),Lt=()=>(C(),y(0,41)),w=[],nr={},I=(r,t=32,e,o=r.charCodeAt(0),i=r.length,p=w[o],m=r.toUpperCase()!==r,f,A)=>(t=nr[r]=!p&&nr[r]||t,w[o]=(h,S,g,E=u)=>(f=g,(g?r==g:(i<2||r.charCodeAt(1)===l.charCodeAt(u+1)&&(i<3||l.substr(u,i)==r))&&(!m||!d.id(l.charCodeAt(u+i)))&&(f=g=r))&&S<t&&(u+=i,(A=e(h))?ir(A,E):(u=E,f=0,!m&&!p&&!h&&v()),A)||p?.(h,S,f))),c=(r,t,e=!1)=>I(r,t,o=>o&&(i=>i&&[r,o,i])(y(t-(e?.5:0)))),k=(r,t,e)=>I(r,t,o=>e?o&&[r,o]:!o&&(o=y(t-.5))&&[r,o]),P=(r,t)=>I(r,200,e=>!e&&[,t]),J=(r,t,e)=>I(r,t,(o,i)=>(i=y(t-(e?.5:0)),o?.[0]!==r&&(o=[r,o||null]),i?.[0]===r?o.push(...i.slice(1)):o.push(i||null),o)),U=(r,t)=>I(r[0],t,e=>!e&&[r,y(0,r.charCodeAt(1))||null]),V=(r,t)=>I(r[0],t,e=>e&&[r,e,y(0,r.charCodeAt(1))||null]),D=(r,t,e,o=r.charCodeAt(0),i=r.length,p=w[o],m)=>w[o]=(f,A,h,S=u)=>!f&&(h?r==h:(i<2||l.substr(u,i)==r)&&(h=r))&&A<t&&!d.id(l.charCodeAt(u+i))&&(!d.prop||d.prop(u+i))&&(M(u+i),(m=e())?ir(m,S):M(S),m)||p?.(f,A,h);d.space=r=>{for(;(r=l.charCodeAt(u))<=32;)u++;return r};d.step=(r,t,e,o,i)=>(i=w[e])&&i(r,t)||(r?null:L(d.id)||null);var z={},s=(r,t,e=z[r])=>z[r]=(...o)=>t(...o)||e?.(...o),n=r=>Array.isArray(r)?r[0]==null?(t=>()=>t)(r[1]):z[r[0]]?.(...r.slice(1))??v(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:t=>t?.[r];var G=46,_=48,X=57,Ur=69,_r=101,Br=43,ar=45,F=95,mr=110,Mr=97,Dr=102,Fr=65,Gr=70,fr=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),Y=r=>{let t=fr(L(e=>e===G&&l.charCodeAt(u+1)!==G||e>=_&&e<=X||e===F||((e===Ur||e===_r)&&((e=l.charCodeAt(u+1))>=_&&e<=X||e===Br||e===ar)?2:0)));return l.charCodeAt(u)===mr?(C(),[,BigInt(t)]):(r=+t)!=r?v():[,r]},Xr={2:r=>r===48||r===49||r===F,8:r=>r>=48&&r<=55||r===F,16:r=>r>=_&&r<=X||r>=Mr&&r<=Dr||r>=Fr&&r<=Gr||r===F};d.number=null;w[G]=r=>!r&&l.charCodeAt(u+1)!==G&&Y();for(let r=_;r<=X;r++)w[r]=t=>t?void 0:Y();w[_]=r=>{if(r)return;let t=d.number;if(t){for(let[e,o]of Object.entries(t))if(e[0]==="0"&&l[u+1]?.toLowerCase()===e[1]){C(2);let i=fr(L(Xr[o]));return l.charCodeAt(u)===mr?(C(),[,BigInt("0"+e[1]+i)]):[,parseInt(i,o)]}}return Y()};var $r=92,ur=34,lr=39,cr=117,dr=120,Qr=123,Hr=125,Ar=10,jr=13,Kr={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},hr=r=>r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:-1,gr=r=>(t,e,o="",i=String.fromCharCode(r))=>{if(t||!d.string?.[i])return;C();let p=()=>{let m=l.charCodeAt(u+1);if(m===Ar)return 2;if(m===jr)return l.charCodeAt(u+2)===Ar?3:2;if(m===dr||m===cr&&l.charCodeAt(u+2)!==Qr){let f=m===dr?2:4,A=0,h;for(let S=0;S<f;S++){if((h=hr(l.charCodeAt(u+2+S)))<0)return o+=l[u+1],2;A=A*16+h}return o+=String.fromCharCode(A),2+f}if(m===cr){let f=0,A=u+3,h;for(;(h=hr(l.charCodeAt(A)))>=0;)f=f*16+h,A++;return A>u+3&&f<=1114111&&l.charCodeAt(A)===Hr?(o+=String.fromCodePoint(f),A-u+1):(o+=l[u+1],2)}return o+=Kr[l[u+1]]||l[u+1],2};return L(m=>m-r&&(m!==$r?(o+=l[u],1):p())),l[u]===i?C():v("Bad string"),[,o]};w[ur]=gr(ur);w[lr]=gr(lr);d.string={'"':!0};var Wr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>c(r,Wr,!0));var zr=30,Jr=40,Vr=140;k("!",Vr);c("||",zr);c("&&",Jr);var Yr=50,Zr=60,qr=70,yr=100,xr=140;c("|",Yr);c("&",qr);c("^",Zr);c(">>",yr);c("<<",yr);k("~",xr);var $=90;c("<",$);c(">",$);c("<=",$);c(">=",$);var Cr=80;c("==",Cr);c("!=",Cr);var Sr=110,Z=120,Er=140;c("+",Sr);c("-",Sr);c("*",Z);c("/",Z);c("%",Z);k("+",Er);k("-",Er);var Q=150;I("++",Q,r=>r?["++",r,null]:["++",y(Q-1)]);I("--",Q,r=>r?["--",r,null]:["--",y(Q-1)]);var br=5,rt=10;J(",",rt);J(";",br,!0);var tt=170;U("()",tt);var q=170;V("[]",q);c(".",q);V("()",q);var et=32,ot=d.space;d.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};var x;d.space=()=>{x||(x=Object.entries(d.comment).map(([i,p])=>[i,p,i.charCodeAt(0)]));for(var r;r=ot();){for(var t=0,e;e=x[t++];)if(r===e[2]&&l.substr(u,e[0].length)===e[0]){var o=u+e[0].length;if(e[1]===`
|
|
7
|
+
`)for(;l.charCodeAt(o)>=et;)o++;else{for(;l[o]&&l.substr(o,e[1].length)!==e[1];)o++;l[o]&&(o+=e[1].length)}M(o),r=0;break}if(r)return r}return r};var wr=80;c("===",wr);c("!==",wr);var nt=30;c("??",nt);var it=130,st=20;c("**",it,!0);c("**=",st,!0);var Ir=90;c("in",Ir);c("of",Ir);var pt=20,mt=100;c(">>>",mt);c(">>>=",pt,!0);var b=20;c("||=",b,!0);c("&&=",b,!0);c("??=",b,!0);P("true",!0);P("false",!1);P("null",null);D("undefined",200,()=>[]);P("NaN",NaN);P("Infinity",1/0);var rr=20;I("?",rr,(r,t,e)=>r&&(t=y(rr-1))&&L(o=>o===58)&&(e=y(rr-1),["?",r,t,e]));var ft=20;c("=>",ft,!0);var ut=20;k("...",ut);var kr=170;I("?.",kr,(r,t)=>{if(!r)return;let e=d.space();return e===40?(C(),["?.()",r,y(0,41)||null]):e===91?(C(),["?.[]",r,y(0,93)]):(t=y(kr),t?["?.",r,t]:void 0)});var B=140;k("typeof",B);k("void",B);k("delete",B);D("new",B,()=>pr(".target")?(C(7),["new.target"]):["new",y(B)]);var lt=20,vr=200;d.prop=r=>sr(r)!==58;U("[]",vr);U("{}",vr);c(":",lt-1,!0);var ct=170,H=96,dt=36,At=123,ht=92,gt={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Nr=()=>{let r=[];for(let t="",e;(e=l.charCodeAt(u))!==H;)e?e===ht?(C(),t+=gt[l[u]]||l[u],C()):e===dt&&l.charCodeAt(u+1)===At?(t&&r.push([,t]),t="",C(2),r.push(y(0,125))):(t+=l[u],C(),e=l.charCodeAt(u),e===H&&t&&r.push([,t])):v("Unterminated template");return C(),r},yt=w[H];w[H]=(r,t)=>r&&t<ct?d.asi&&d.newline?void 0:(C(),["``",r,...Nr()]):r?yt?.(r,t):(C(),(e=>e.length<2&&e[0]?.[0]===void 0?e[0]||[,""]:["`",...e])(Nr()));d.string["'"]=!0;d.number={"0x":16,"0b":2,"0o":8};var Rr=(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?Rr(r[1],t):(()=>{throw Error("Invalid assignment target")})(),Or={"=":(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 Or)s(r,(t,e)=>(e=n(e),Rr(t,(o,i,p)=>Or[r](o,i,e(p)))));s("!",r=>(r=n(r),t=>!r(t)));s("||",(r,t)=>(r=n(r),t=n(t),e=>r(e)||t(e)));s("&&",(r,t)=>(r=n(r),t=n(t),e=>r(e)&&t(e)));s("~",r=>(r=n(r),t=>~r(t)));s("|",(r,t)=>(r=n(r),t=n(t),e=>r(e)|t(e)));s("&",(r,t)=>(r=n(r),t=n(t),e=>r(e)&t(e)));s("^",(r,t)=>(r=n(r),t=n(t),e=>r(e)^t(e)));s(">>",(r,t)=>(r=n(r),t=n(t),e=>r(e)>>t(e)));s("<<",(r,t)=>(r=n(r),t=n(t),e=>r(e)<<t(e)));s(">",(r,t)=>(r=n(r),t=n(t),e=>r(e)>t(e)));s("<",(r,t)=>(r=n(r),t=n(t),e=>r(e)<t(e)));s(">=",(r,t)=>(r=n(r),t=n(t),e=>r(e)>=t(e)));s("<=",(r,t)=>(r=n(r),t=n(t),e=>r(e)<=t(e)));s("==",(r,t)=>(r=n(r),t=n(t),e=>r(e)==t(e)));s("!=",(r,t)=>(r=n(r),t=n(t),e=>r(e)!=t(e)));s("+",(r,t)=>t!==void 0?(r=n(r),t=n(t),e=>r(e)+t(e)):(r=n(r),e=>+r(e)));s("-",(r,t)=>t!==void 0?(r=n(r),t=n(t),e=>r(e)-t(e)):(r=n(r),e=>-r(e)));s("*",(r,t)=>(r=n(r),t=n(t),e=>r(e)*t(e)));s("/",(r,t)=>(r=n(r),t=n(t),e=>r(e)/t(e)));s("%",(r,t)=>(r=n(r),t=n(t),e=>r(e)%t(e)));var tr=(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?tr(r[1],t):(()=>{throw Error("Invalid increment target")})();s("++",(r,t)=>tr(r,t===null?(e,o)=>e[o]++:(e,o)=>++e[o]));s("--",(r,t)=>tr(r,t===null?(e,o)=>e[o]--:(e,o)=>--e[o]));var Lr=(...r)=>(r=r.map(n),t=>{let e;for(let o of r)e=o(t);return e});s(",",Lr);s(";",Lr);var O=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",j=r=>{throw Error(r)};s("[]",(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&&j("Missing index"),r=n(r),t=n(t),e=>{let o=t(e);return O(o)?void 0:r(e)[o]}));s(".",(r,t)=>(r=n(r),t=t[0]?t:t[1],O(t)?()=>{}:e=>r(e)[t]));s("()",(r,t)=>{if(t===void 0)return r==null?j("Empty ()"):n(r);let e=i=>i?.[0]===","&&i.slice(1).some(p=>p==null||e(p));e(t)&&j("Empty argument");let o=t?t[0]===","?(t=t.slice(1).map(n),i=>t.map(p=>p(i))):(t=n(t),i=>[t(i)]):()=>[];return er(r,(i,p,m)=>i[p](...o(m)))});var N=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&N(r[1])||r[0]==="{}"),er=(r,t,e,o)=>r==null?j("Empty ()"):r[0]==="()"&&r.length==2?er(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)),R=er;s("===",(r,t)=>(r=n(r),t=n(t),e=>r(e)===t(e)));s("!==",(r,t)=>(r=n(r),t=n(t),e=>r(e)!==t(e)));s("??",(r,t)=>(r=n(r),t=n(t),e=>r(e)??t(e)));var Ct=r=>{throw Error(r)};s("**",(r,t)=>(r=n(r),t=n(t),e=>r(e)**t(e)));s("**=",(r,t)=>(N(r)||Ct("Invalid assignment target"),t=n(t),R(r,(e,o,i)=>e[o]**=t(i))));s("in",(r,t)=>(r=n(r),t=n(t),e=>r(e)in t(e)));var St=r=>{throw Error(r)};s(">>>",(r,t)=>(r=n(r),t=n(t),e=>r(e)>>>t(e)));s(">>>=",(r,t)=>(N(r)||St("Invalid assignment target"),t=n(t),R(r,(e,o,i)=>e[o]>>>=t(i))));var Et=r=>r[0]?.[0]===","?r[0].slice(1):r,a=(r,t,e)=>{if(typeof r=="string"){e[r]=t;return}let[o,...i]=r,p=Et(i);if(o==="{}"){let m=[];for(let f of p){if(Array.isArray(f)&&f[0]==="..."){let E={};for(let T in t)m.includes(T)||(E[T]=t[T]);e[f[1]]=E;break}let A,h,S;typeof f=="string"?A=h=f:f[0]==="="?(typeof f[1]=="string"?A=h=f[1]:[,A,h]=f[1],S=f[2]):[,A,h]=f,m.push(A);let g=t[A];g===void 0&&S&&(g=n(S)(e)),a(h,g,e)}}else if(o==="[]"){let m=0;for(let f of p){if(f===null){m++;continue}if(Array.isArray(f)&&f[0]==="..."){e[f[1]]=t.slice(m);break}let A=f,h;Array.isArray(f)&&f[0]==="="&&([,A,h]=f);let S=t[m++];S===void 0&&h&&(S=n(h)(e)),a(A,S,e)}}},or=(...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"?p=>{p[e]=i(p)}:p=>a(e,i(p),p)}return n(t)}),t=>{for(let e of r)e(t)});s("let",or);s("const",or);s("var",or);var K=r=>{throw Error(r)};s("=",(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=>a(e,t(o),o)}return N(r)||K("Invalid assignment target"),t=n(t),R(r,(e,o,i)=>e[o]=t(i))});s("||=",(r,t)=>(N(r)||K("Invalid assignment target"),t=n(t),R(r,(e,o,i)=>e[o]||=t(i))));s("&&=",(r,t)=>(N(r)||K("Invalid assignment target"),t=n(t),R(r,(e,o,i)=>e[o]&&=t(i))));s("??=",(r,t)=>(N(r)||K("Invalid assignment target"),t=n(t),R(r,(e,o,i)=>e[o]??=t(i))));s("?",(r,t,e)=>(r=n(r),t=n(t),e=n(e),o=>r(o)?t(o):e(o)));var wt=[];s("=>",(r,t)=>{r=r?.[0]==="()"?r[1]:r;let e=r?r[0]===","?r.slice(1):[r]:[],o=-1,i=null,p=e[e.length-1];Array.isArray(p)&&p[0]==="..."&&(o=e.length-1,i=p[1],e.length--);let m=t?.[0]==="{}";return t=n(m?["{",t[1]]:t),f=>(...A)=>{let h={};e.forEach((g,E)=>h[g]=A[E]),i&&(h[i]=A.slice(o));let S=new Proxy(h,{get:(g,E)=>E in g?g[E]:f?.[E],set:(g,E,T)=>((E in g?g:f)[E]=T,!0),has:(g,E)=>E in g||(f?E in f:!1)});try{let g=t(S);return m?void 0:g}catch(g){if(g===wt)return g[0];throw g}}});s("...",r=>(r=n(r),t=>Object.entries(r(t))));s("?.",(r,t)=>(r=n(r),O(t)?()=>{}:e=>r(e)?.[t]));s("?.[]",(r,t)=>(r=n(r),t=n(t),e=>{let o=t(e);return O(o)?void 0:r(e)?.[o]}));s("?.()",(r,t)=>{let e=t?t[0]===","?(t=t.slice(1).map(n),i=>t.map(p=>p(i))):(t=n(t),i=>[t(i)]):()=>[];if(r[0]==="?."){let i=n(r[1]),p=r[2];return O(p)?()=>{}:m=>i(m)?.[p]?.(...e(m))}if(r[0]==="?.[]"){let i=n(r[1]),p=n(r[2]);return m=>{let f=i(m),A=p(m);return O(A)?void 0:f?.[A]?.(...e(m))}}if(r[0]==="."){let i=n(r[1]),p=r[2];return O(p)?()=>{}:m=>i(m)?.[p]?.(...e(m))}if(r[0]==="[]"&&r.length===3){let i=n(r[1]),p=n(r[2]);return m=>{let f=i(m),A=p(m);return O(A)?void 0:f?.[A]?.(...e(m))}}let o=n(r);return i=>o(i)?.(...e(i))});s("typeof",r=>(r=n(r),t=>typeof r(t)));s("void",r=>(r=n(r),t=>(r(t),void 0)));s("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});s("new",r=>{let t=n(r?.[0]==="()"?r[1]:r),e=r?.[0]==="()"?r[2]:null,o=e?e[0]===","?(i=>p=>i.map(m=>m(p)))(e.slice(1).map(n)):(i=>p=>[i(p)])(n(e)):()=>[];return i=>new(t(i))(...o(i))});var W=Symbol("accessor");s("get",(r,t)=>(t=t?n(t):()=>{},e=>[[W,r,{get:function(){let o=Object.create(e||{});return o.this=this,t(o)}}]]));s("set",(r,t,e)=>(e=e?n(e):()=>{},o=>[[W,r,{set:function(i){let p=Object.create(o||{});p.this=this,p[t]=i,e(p)}}]]));var It=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);s("{}",(r,t)=>{if(t!==void 0)return;if(!It(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={},p={};for(let m of e.flatMap(f=>f(o)))if(m[0]===W){let[,f,A]=m;p[f]={...p[f],...A,configurable:!0,enumerable:!0}}else i[m[0]]=m[1];for(let m in p)Object.defineProperty(i,m,p[m]);return i}});s("{",r=>(r=r?n(r):()=>{},t=>r(Object.create(t))));s(":",(r,t)=>(t=n(t),Array.isArray(r)?(r=n(r),e=>[[r(e),t(e)]]):e=>[[r,t(e)]]));s("`",(...r)=>(r=r.map(n),t=>r.map(e=>e(t)).join("")));s("``",(r,...t)=>{r=n(r);let e=[],o=[];for(let p of t)Array.isArray(p)&&p[0]===void 0?e.push(p[1]):o.push(n(p));let i=Object.assign([...e],{raw:e});return p=>r(p)(i,...o.map(m=>m(p)))});var Pr=new WeakMap,kt=(r,...t)=>typeof r=="string"?n(d(r)):Pr.get(r)||Pr.set(r,vt(r,t)).get(r),Tr=57344,vt=(r,t)=>{let e=r.reduce((p,m,f)=>p+(f?String.fromCharCode(Tr+f-1):"")+m,""),o=d(e),i=p=>{if(typeof p=="string"&&p.length===1){let m=p.charCodeAt(0)-Tr,f;if(m>=0&&m<t.length)return f=t[m],Nt(f)?f:[,f]}return Array.isArray(p)?p.map(i):p};return n(i(o))},Nt=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Ot=kt;export{V as access,c as binary,n as compile,l as cur,Ot as default,v as err,y as expr,U as group,Rt as id,u as idx,D as keyword,P as literal,ir as loc,w as lookup,J as nary,L as next,s as operator,z as operators,Lt as parens,d as parse,sr as peek,nr as prec,M as seek,C as skip,I as token,k as unary,pr as word};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "subscript",
|
|
3
|
-
"version": "10.4.
|
|
3
|
+
"version": "10.4.9",
|
|
4
4
|
"description": "Modular expression parser & evaluator",
|
|
5
5
|
"main": "subscript.js",
|
|
6
6
|
"module": "subscript.js",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@playwright/test": "^1.57.0",
|
|
78
78
|
"esbuild": "^0.27.2",
|
|
79
|
+
"oxc-parser": "^0.130.0",
|
|
79
80
|
"terser": "^5.44.1",
|
|
80
81
|
"tst": "^9.2.1"
|
|
81
82
|
}
|
package/parse.js
CHANGED
|
@@ -43,24 +43,13 @@ export let idx, cur,
|
|
|
43
43
|
let cc, token, newNode;
|
|
44
44
|
if (end) parse.enter?.(p, end);
|
|
45
45
|
|
|
46
|
-
while ((cc = space()) && cc !== end && (newNode = step(token, p, cc, expr))) token = newNode;
|
|
46
|
+
while ((cc = parse.space()) && cc !== end && (newNode = parse.step(token, p, cc, expr))) token = newNode;
|
|
47
47
|
|
|
48
48
|
if (end) cc == end ? (idx++, parse.exit?.(p, end)) : err('Unclosed ' + String.fromCharCode(end - (end > 42 ? 2 : 1)));
|
|
49
49
|
|
|
50
50
|
return token;
|
|
51
51
|
},
|
|
52
52
|
|
|
53
|
-
// one Pratt iteration: try operator, else identifier (only at start). Returns
|
|
54
|
-
// truthy node or null (never `false`/`undefined`, so wrapper overrides can
|
|
55
|
-
// chain via `??`).
|
|
56
|
-
step = (a, p, cc, expr, fn) => ((fn = lookup[cc]) && fn(a, p)) || (a ? null : next(parse.id) || null),
|
|
57
|
-
|
|
58
|
-
// skip space chars, return first non-space character
|
|
59
|
-
space = (cc) => {
|
|
60
|
-
while ((cc = cur.charCodeAt(idx)) <= SPACE) idx++;
|
|
61
|
-
return cc;
|
|
62
|
-
},
|
|
63
|
-
|
|
64
53
|
// peek at next non-space char without modifying idx
|
|
65
54
|
peek = (from = idx) => { while (cur.charCodeAt(from) <= SPACE) from++; return cur.charCodeAt(from); },
|
|
66
55
|
|
|
@@ -139,20 +128,17 @@ export let idx, cur,
|
|
|
139
128
|
(seek(idx + l), (r = map()) ? loc(r, from) : seek(from), r) ||
|
|
140
129
|
prev?.(a, curPrec, curOp);
|
|
141
130
|
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
get: () => step,
|
|
154
|
-
set: fn => (step = fn)
|
|
155
|
-
});
|
|
131
|
+
// Skip space chars, return first non-space character.
|
|
132
|
+
// Wrappers (comment, asi) compose by reading the previous parse.space first.
|
|
133
|
+
parse.space = (cc) => {
|
|
134
|
+
while ((cc = cur.charCodeAt(idx)) <= SPACE) idx++;
|
|
135
|
+
return cc;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// One Pratt iteration: try operator, else identifier (only at start).
|
|
139
|
+
// Returns truthy node or null so wrapper overrides can chain via `??`.
|
|
140
|
+
parse.step = (a, p, cc, expr, fn) =>
|
|
141
|
+
((fn = lookup[cc]) && fn(a, p)) || (a ? null : next(parse.id) || null);
|
|
156
142
|
|
|
157
143
|
// === Compile: AST → Evaluator ===
|
|
158
144
|
|
package/subscript.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var s,p,
|
|
2
|
-
`),o=e.pop(),n=p.slice(Math.max(0,t-40),t),m="\u032D",f=(p[t]||" ")+m,
|
|
1
|
+
var s,p,d=r=>(s=0,p=r,d.enter?.(),r=g(),p[s]?S():r||""),S=(r="Unexpected token",t=s,e=p.slice(0,t).split(`
|
|
2
|
+
`),o=e.pop(),n=p.slice(Math.max(0,t-40),t),m="\u032D",f=(p[t]||" ")+m,A=p.slice(t+1,t+20))=>{throw SyntaxError(`${r} at ${e.length+1}:${o.length+1}
|
|
3
3
|
${p[t-41]!==`
|
|
4
|
-
`,""+n}${f}${
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},
|
|
4
|
+
`,""+n}${f}${A}`)},W=(r,t=s)=>(Array.isArray(r)&&(r.loc=t),r),I=(r,t=s,e)=>{for(;e=r(p.charCodeAt(s));)s+=e;return p.slice(t,s)},w=(r=1)=>p[s+=r],v=r=>s=r,g=(r=0,t)=>{let e,o,n;for(t&&d.enter?.(r,t);(e=d.space())&&e!==t&&(n=d.step(o,r,e,g));)o=n;return t&&(e==t?(s++,d.exit?.(r,t)):S("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),o},Qr=(r=s)=>{for(;p.charCodeAt(r)<=32;)r++;return p.charCodeAt(r)},Hr=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,vr=(r,t=r.length)=>p.substr(s,t)===r&&!d.id(p.charCodeAt(s+t)),Gr=()=>(w(),g(0,41)),c=[],G={},E=(r,t=32,e,o=r.charCodeAt(0),n=r.length,m=c[o],f=r.toUpperCase()!==r,A,h)=>(t=G[r]=!m&&G[r]||t,c[o]=(C,y,U,H=s)=>(A=U,(U?r==U:(n<2||r.charCodeAt(1)===p.charCodeAt(s+1)&&(n<3||p.substr(s,n)==r))&&(!f||!d.id(p.charCodeAt(s+n)))&&(A=U=r))&&y<t&&(s+=n,(h=e(C))?W(h,H):(s=H,A=0,!f&&!m&&!C&&S()),h)||m?.(C,y,A))),u=(r,t,e=!1)=>E(r,t,o=>o&&(n=>n&&[r,o,n])(g(t-(e?.5:0)))),_=(r,t,e)=>E(r,t,o=>e?o&&[r,o]:!o&&(o=g(t-.5))&&[r,o]),Wr=(r,t)=>E(r,200,e=>!e&&[,t]),N=(r,t,e)=>E(r,t,(o,n)=>(n=g(t-(e?.5:0)),o?.[0]!==r&&(o=[r,o||null]),n?.[0]===r?o.push(...n.slice(1)):o.push(n||null),o)),z=(r,t)=>E(r[0],t,e=>!e&&[r,g(0,r.charCodeAt(1))||null]),$=(r,t)=>E(r[0],t,e=>e&&[r,e,g(0,r.charCodeAt(1))||null]),zr=(r,t,e,o=r.charCodeAt(0),n=r.length,m=c[o],f)=>c[o]=(A,h,C,y=s)=>!A&&(C?r==C:(n<2||p.substr(s,n)==r)&&(C=r))&&h<t&&!d.id(p.charCodeAt(s+n))&&(!d.prop||d.prop(s+n))&&(v(s+n),(f=e())?W(f,y):v(y),f)||m?.(A,h,C);d.space=r=>{for(;(r=p.charCodeAt(s))<=32;)s++;return r};d.step=(r,t,e,o,n)=>(n=c[e])&&n(r,t)||(r?null:I(d.id)||null);var F={},l=(r,t,e=F[r])=>F[r]=(...o)=>t(...o)||e?.(...o),i=r=>Array.isArray(r)?r[0]==null?(t=>()=>t)(r[1]):F[r[0]]?.(...r.slice(1))??S(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:t=>t?.[r];var T=46,R=48,k=57,ur=69,fr=101,Ar=43,dr=45,P=95,J=110,hr=97,Cr=102,cr=65,gr=70,K=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),B=r=>{let t=K(I(e=>e===T&&p.charCodeAt(s+1)!==T||e>=R&&e<=k||e===P||((e===ur||e===fr)&&((e=p.charCodeAt(s+1))>=R&&e<=k||e===Ar||e===dr)?2:0)));return p.charCodeAt(s)===J?(w(),[,BigInt(t)]):(r=+t)!=r?S():[,r]},yr={2:r=>r===48||r===49||r===P,8:r=>r>=48&&r<=55||r===P,16:r=>r>=R&&r<=k||r>=hr&&r<=Cr||r>=cr&&r<=gr||r===P};d.number=null;c[T]=r=>!r&&p.charCodeAt(s+1)!==T&&B();for(let r=R;r<=k;r++)c[r]=t=>t?void 0:B();c[R]=r=>{if(r)return;let t=d.number;if(t){for(let[e,o]of Object.entries(t))if(e[0]==="0"&&p[s+1]?.toLowerCase()===e[1]){w(2);let n=K(I(yr[o]));return p.charCodeAt(s)===J?(w(),[,BigInt("0"+e[1]+n)]):[,parseInt(n,o)]}}return B()};var Er=92,V=34,Y=39,Z=117,q=120,Sr=123,wr=125,x=10,_r=13,Ir={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},j=r=>r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:-1,a=r=>(t,e,o="",n=String.fromCharCode(r))=>{if(t||!d.string?.[n])return;w();let m=()=>{let f=p.charCodeAt(s+1);if(f===x)return 2;if(f===_r)return p.charCodeAt(s+2)===x?3:2;if(f===q||f===Z&&p.charCodeAt(s+2)!==Sr){let A=f===q?2:4,h=0,C;for(let y=0;y<A;y++){if((C=j(p.charCodeAt(s+2+y)))<0)return o+=p[s+1],2;h=h*16+C}return o+=String.fromCharCode(h),2+A}if(f===Z){let A=0,h=s+3,C;for(;(C=j(p.charCodeAt(h)))>=0;)A=A*16+C,h++;return h>s+3&&A<=1114111&&p.charCodeAt(h)===wr?(o+=String.fromCodePoint(A),h-s+1):(o+=p[s+1],2)}return o+=Ir[p[s+1]]||p[s+1],2};return I(f=>f-r&&(f!==Er?(o+=p[s],1):m())),p[s]===n?w():S("Bad string"),[,o]};c[V]=a(V);c[Y]=a(Y);d.string={'"':!0};var Rr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>u(r,Rr,!0));var Ur=30,Pr=40,Tr=140;_("!",Tr);u("||",Ur);u("&&",Pr);var kr=50,Lr=60,Dr=70,b=100,Mr=140;u("|",kr);u("&",Dr);u("^",Lr);u(">>",b);u("<<",b);_("~",Mr);var L=90;u("<",L);u(">",L);u("<=",L);u(">=",L);var rr=80;u("==",rr);u("!=",rr);var tr=110,X=120,er=140;u("+",tr);u("-",tr);u("*",X);u("/",X);u("%",X);_("+",er);_("-",er);var D=150;E("++",D,r=>r?["++",r,null]:["++",g(D-1)]);E("--",D,r=>r?["--",r,null]:["--",g(D-1)]);var Fr=5,Nr=10;N(",",Nr);N(";",Fr,!0);var $r=170;z("()",$r);var O=170;$("[]",O);u(".",O);$("()",O);var nr=(r,t,e,o)=>typeof r=="string"?n=>t(n,r,n):r[0]==="."?(e=i(r[1]),o=r[2],n=>t(e(n),o,n)):r[0]==="[]"&&r.length===3?(e=i(r[1]),o=i(r[2]),n=>t(e(n),o(n),n)):r[0]==="()"&&r.length===2?nr(r[1],t):(()=>{throw Error("Invalid assignment target")})(),or={"=":(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 or)l(r,(t,e)=>(e=i(e),nr(t,(o,n,m)=>or[r](o,n,e(m)))));l("!",r=>(r=i(r),t=>!r(t)));l("||",(r,t)=>(r=i(r),t=i(t),e=>r(e)||t(e)));l("&&",(r,t)=>(r=i(r),t=i(t),e=>r(e)&&t(e)));l("~",r=>(r=i(r),t=>~r(t)));l("|",(r,t)=>(r=i(r),t=i(t),e=>r(e)|t(e)));l("&",(r,t)=>(r=i(r),t=i(t),e=>r(e)&t(e)));l("^",(r,t)=>(r=i(r),t=i(t),e=>r(e)^t(e)));l(">>",(r,t)=>(r=i(r),t=i(t),e=>r(e)>>t(e)));l("<<",(r,t)=>(r=i(r),t=i(t),e=>r(e)<<t(e)));l(">",(r,t)=>(r=i(r),t=i(t),e=>r(e)>t(e)));l("<",(r,t)=>(r=i(r),t=i(t),e=>r(e)<t(e)));l(">=",(r,t)=>(r=i(r),t=i(t),e=>r(e)>=t(e)));l("<=",(r,t)=>(r=i(r),t=i(t),e=>r(e)<=t(e)));l("==",(r,t)=>(r=i(r),t=i(t),e=>r(e)==t(e)));l("!=",(r,t)=>(r=i(r),t=i(t),e=>r(e)!=t(e)));l("+",(r,t)=>t!==void 0?(r=i(r),t=i(t),e=>r(e)+t(e)):(r=i(r),e=>+r(e)));l("-",(r,t)=>t!==void 0?(r=i(r),t=i(t),e=>r(e)-t(e)):(r=i(r),e=>-r(e)));l("*",(r,t)=>(r=i(r),t=i(t),e=>r(e)*t(e)));l("/",(r,t)=>(r=i(r),t=i(t),e=>r(e)/t(e)));l("%",(r,t)=>(r=i(r),t=i(t),e=>r(e)%t(e)));var Q=(r,t,e,o)=>typeof r=="string"?n=>t(n,r):r[0]==="."?(e=i(r[1]),o=r[2],n=>t(e(n),o)):r[0]==="[]"&&r.length===3?(e=i(r[1]),o=i(r[2]),n=>t(e(n),o(n))):r[0]==="()"&&r.length===2?Q(r[1],t):(()=>{throw Error("Invalid increment target")})();l("++",(r,t)=>Q(r,t===null?(e,o)=>e[o]++:(e,o)=>++e[o]));l("--",(r,t)=>Q(r,t===null?(e,o)=>e[o]--:(e,o)=>--e[o]));var ir=(...r)=>(r=r.map(i),t=>{let e;for(let o of r)e=o(t);return e});l(",",ir);l(";",ir);var sr=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",M=r=>{throw Error(r)};l("[]",(r,t)=>t===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(e=>e==null?(()=>{}):e[0]==="..."?(e=i(e[1]),o=>e(o)):(e=i(e),o=>[e(o)])),e=>r.flatMap(o=>o(e))):(t==null&&M("Missing index"),r=i(r),t=i(t),e=>{let o=t(e);return sr(o)?void 0:r(e)[o]}));l(".",(r,t)=>(r=i(r),t=t[0]?t:t[1],sr(t)?()=>{}:e=>r(e)[t]));l("()",(r,t)=>{if(t===void 0)return r==null?M("Empty ()"):i(r);let e=n=>n?.[0]===","&&n.slice(1).some(m=>m==null||e(m));e(t)&&M("Empty argument");let o=t?t[0]===","?(t=t.slice(1).map(i),n=>t.map(m=>m(n))):(t=i(t),n=>[t(n)]):()=>[];return pr(r,(n,m,f)=>n[m](...o(f)))});var pr=(r,t,e,o)=>r==null?M("Empty ()"):r[0]==="()"&&r.length==2?pr(r[1],t):typeof r=="string"?n=>t(n,r,n):r[0]==="."?(e=i(r[1]),o=r[2],n=>t(e(n),o,n)):r[0]==="?."?(e=i(r[1]),o=r[2],n=>{let m=e(n);return m==null?void 0:t(m,o,n)}):r[0]==="[]"&&r.length===3?(e=i(r[1]),o=i(r[2]),n=>t(e(n),o(n),n)):r[0]==="?.[]"?(e=i(r[1]),o=i(r[2]),n=>{let m=e(n);return m==null?void 0:t(m,o(n),n)}):(r=i(r),n=>t([r(n)],0,n));var lr=new WeakMap,Br=(r,...t)=>typeof r=="string"?i(d(r)):lr.get(r)||lr.set(r,Xr(r,t)).get(r),mr=57344,Xr=(r,t)=>{let e=r.reduce((m,f,A)=>m+(A?String.fromCharCode(mr+A-1):"")+f,""),o=d(e),n=m=>{if(typeof m=="string"&&m.length===1){let f=m.charCodeAt(0)-mr,A;if(f>=0&&f<t.length)return A=t[f],Or(A)?A:[,A]}return Array.isArray(m)?m.map(n):m};return i(n(o))},Or=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),vt=Br;export{$ as access,u as binary,i as compile,p as cur,vt as default,S as err,g as expr,z as group,Hr as id,s as idx,zr as keyword,Wr as literal,W as loc,c as lookup,N as nary,I as next,l as operator,F as operators,Gr as parens,d as parse,Qr as peek,G as prec,v as seek,w as skip,E as token,_ as unary,vr as word};
|