subscript 10.1.8 → 10.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- <h1 align="center">sub<sub><sup> ✦ </sup></sub>script</h1>
1
+ <h1 align="center"><em>sub</em>script</h1>
2
2
 
3
- <p align="center">Tiny expression parser & evaluator.</p>
3
+ <p align="center">Modular expression parser & evaluator</p>
4
4
  <div align="center">
5
5
 
6
6
  [![build](https://github.com/dy/subscript/actions/workflows/node.js.yml/badge.svg)](https://github.com/dy/subscript/actions/workflows/node.js.yml) [![npm](https://img.shields.io/npm/v/subscript)](http://npmjs.org/subscript) [![size](https://img.shields.io/bundlephobia/minzip/subscript?label=size)](https://bundlephobia.com/package/subscript) [![microjs](https://img.shields.io/badge/µjs-subscript-darkslateblue)](http://microjs.com/#subscript) <!--[![demo](https://img.shields.io/badge/play-%F0%9F%9A%80-white)](https://dy.github.io/subscript/)-->
@@ -15,16 +15,18 @@ let fn = subscript('a + b * 2')
15
15
  fn({ a: 1, b: 3 }) // 7
16
16
  ```
17
17
 
18
- * **Fast** — Pratt parser engine, see [benchmarks](#performance)
19
- * **Portable** — universal expression format, see [spec](./spec.md)
20
- * **Extensible** — pluggable syntax, see [playground](https://dy.github.io/subscript/)
21
- * **Metacircular** — can parse and compile itself
22
- * **Safe** — sandboxed, blocks `__proto__`, `constructor`, no global access
18
+ * **Modular** — 40+ pluggable syntax features, see [playground](https://dy.github.io/subscript/)
19
+ * **Universal** — minimal syntax tree, see [spec](./spec.md)
20
+ * **Fast** — efficient parser, see [benchmarks](#performance)
21
+ * **Small** — ~2KB core, runs in browser/node
22
+ * **Safe** — sandboxed, no prototype access
23
+ * **Metacircular** — parses and compiles itself
23
24
 
25
+ _Useful for_: templates, calculators, sandboxes, safe eval, language subsets, custom DSLs, preprocessors.
24
26
 
25
27
  ## Presets
26
28
 
27
- **Subscript** – common expressions:
29
+ [**Subscript**](./docs.md#subscript) – common expressions:
28
30
 
29
31
  ```js
30
32
  import subscript from 'subscript'
@@ -32,7 +34,7 @@ import subscript from 'subscript'
32
34
  subscript('a.b + c * 2')({ a: { b: 1 }, c: 3 }) // 7
33
35
  ```
34
36
 
35
- **Justin** – JSON + expressions + templates + arrows:
37
+ [**Justin**](./docs.md#justin) – JSON + expressions + templates + arrows:
36
38
 
37
39
  ```js
38
40
  import justin from 'subscript/justin.js'
@@ -41,7 +43,7 @@ justin('{ x: a?.b ?? 0, y: [1, ...rest] }')({ a: null, rest: [2, 3] })
41
43
  // { x: 0, y: [1, 2, 3] }
42
44
  ```
43
45
 
44
- **Jessie** – JSON + expressions + statements, functions (JS subset):
46
+ [**Jessie**](./docs.md#jessie) – JSON + expressions + statements, functions (JS subset):
45
47
 
46
48
  ```js
47
49
  import jessie from 'subscript/jessie.js'
@@ -58,12 +60,33 @@ fn({}) // 120
58
60
 
59
61
  See [docs](./docs.md#presets) for full description.
60
62
 
63
+
64
+ ## Syntax tree
65
+
66
+ Expressions parse to minimal JSON-compatible tree structure:
67
+
68
+ ```js
69
+ import { parse } from 'subscript'
70
+
71
+ parse('a + b * 2')
72
+ // ['+', 'a', ['*', 'b', [, 2]]]
73
+
74
+ // node kinds
75
+ 'x' // identifier — resolve from context
76
+ [, value] // literal — return as-is (empty slot = data)
77
+ [op, ...args] // operation — apply operator
78
+ ```
79
+
80
+ See [spec.md](./spec.md).
81
+
82
+
83
+
61
84
  ## Extension
62
85
 
63
86
  Add operators, literals or custom syntax:
64
87
 
65
88
  ```js
66
- import { binary, operator, compile } from 'subscript/justin.js'
89
+ import justin, { binary, operator, compile } from 'subscript/justin.js'
67
90
 
68
91
  // add intersection operator
69
92
  binary('∩', 80) // register parser
@@ -71,38 +94,13 @@ operator('∩', (a, b) => ( // register compiler
71
94
  a = compile(a), b = compile(b),
72
95
  ctx => a(ctx).filter(x => b(ctx).includes(x))
73
96
  ))
74
- ```
75
97
 
76
- ```js
77
- import justin from 'subscript/justin.js'
78
98
  justin('[1,2,3] ∩ [2,3,4]')({}) // [2, 3]
79
99
  ```
80
100
 
81
101
  See [docs.md](./docs.md) for full API.
82
102
 
83
103
 
84
- ## Syntax Tree
85
-
86
- Expressions parse to a minimal JSON-compatible syntax tree:
87
-
88
- ```js
89
- import { parse } from 'subscript'
90
-
91
- parse('a + b * 2')
92
- // ['+', 'a', ['*', 'b', [, 2]]]
93
- ```
94
-
95
- Three forms:
96
-
97
- ```js
98
- 'x' // identifier — resolve from context
99
- [, value] // literal — return as-is (empty slot = data)
100
- [op, ...args] // operation — apply operator
101
- ```
102
-
103
- See [spec.md](./spec.md).
104
-
105
-
106
104
  ## Safety
107
105
 
108
106
  Blocked by default:
@@ -118,8 +116,18 @@ subscript('constructor.constructor("alert(1)")()')({})
118
116
  ## Performance
119
117
 
120
118
  ```
121
- Parse 30k: subscript 150ms · justin 183ms · jsep 270ms · expr-eval 480ms · jexl 1056ms
122
- Eval 30k: new Function 7ms · subscript 15ms · jsep+eval 30ms · expr-eval 72ms
119
+ Parse 30k:
120
+ subscript 150ms
121
+ justin 183ms
122
+ jsep 270ms
123
+ expr-eval 480ms
124
+ jexl 1056ms
125
+
126
+ Eval 30k:
127
+ new Function 7ms
128
+ subscript 15ms
129
+ jsep+eval 30ms
130
+ expr-eval 72ms
123
131
  ```
124
132
 
125
133
  ## Utils
@@ -161,11 +169,11 @@ console.log(await bundle('main.js', {
161
169
  <!-- * [glsl-transpiler](https://github.com/stackgl/glsl-transpiler) -->
162
170
  <!-- * [piezo](https://github.com/dy/piezo) -->
163
171
 
164
- <!--
165
- ## Refs
166
172
 
167
- [jsep](https://github.com/EricSmekens/jsep), [jexl](https://github.com/TomFrost/Jexl), [expr-eval](https://github.com/silentmatt/expr-eval), [math.js](https://mathjs.org/).
173
+ ## Alternatives
174
+
175
+ <sup>[cel-js](https://github.com/marcbachmann/cel-js?tab=readme-ov-file), [jsep](https://github.com/EricSmekens/jsep), [jexl](https://github.com/TomFrost/Jexl), [expr-eval](https://github.com/silentmatt/expr-eval), [math.js](https://mathjs.org/), [mozjexl](https://github.com/mozilla/mozjexl), [jexpr](https://github.com/justinfagnani/jexpr), [expression-eval](https://github.com/donmccurdy/expression-eval), [string-math](https://github.com/devrafalko/string-math), [nerdamer](https://github.com/jiggzson/nerdamer), [math-codegen](https://github.com/mauriciopoppe/math-codegen), [math-parser](https://www.npmjs.com/package/math-parser), [nx-compile](https://github.com/nx-js/compiler-util), [built-in-math-eval](https://github.com/mauriciopoppe/built-in-math-eval)</sup>
168
176
 
169
- [mozjexl](https://github.com/mozilla/mozjexl), [jexpr](https://github.com/justinfagnani/jexpr), [expression-eval](https://github.com/donmccurdy/expression-eval), [string-math](https://github.com/devrafalko/string-math), [nerdamer](https://github.com/jiggzson/nerdamer), [math-codegen](https://github.com/mauriciopoppe/math-codegen), [math-parser](https://www.npmjs.com/package/math-parser), [nx-compile](https://github.com/nx-js/compiler-util), [built-in-math-eval](https://github.com/mauriciopoppe/built-in-math-eval) -->
177
+ <br>
170
178
 
171
179
  <p align=center><a href="https://github.com/krsnzd/license/">ॐ</a></p>
package/feature/async.js CHANGED
@@ -1,6 +1,5 @@
1
1
  // Async/await/yield: async function, async arrow, await, yield expressions
2
- import { unary, expr, skip, space, cur, idx, word, operator, compile } from '../parse.js';
3
- import { keyword } from './block.js';
2
+ import { unary, expr, skip, space, keyword, cur, idx, word, operator, compile } from '../parse.js';
4
3
 
5
4
  const PREFIX = 140, ASSIGN = 20;
6
5
 
package/feature/class.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // Class declarations and expressions
2
2
  // class A extends B { ... }
3
- import { binary, unary, token, expr, space, next, parse, literal, word, operator, compile, skip, cur, idx } from '../parse.js';
4
- import { keyword, block } from './block.js';
3
+ import { binary, unary, token, expr, space, next, parse, keyword, literal, word, operator, compile, skip, cur, idx } from '../parse.js';
4
+ import { block } from './if.js';
5
5
 
6
6
  const TOKEN = 200, PREFIX = 140, COMP = 90;
7
7
  const STATIC = Symbol('static');
@@ -12,11 +12,14 @@
12
12
  * ['{}', 'a'] → ['{}', 'a'] object shorthand {a}
13
13
  * ['{}', [':', k, v]] → ['{}', ...] object literal
14
14
  */
15
- import { group, binary, operator, compile } from '../parse.js';
15
+ import { group, binary, operator, compile, parse, peek } from '../parse.js';
16
16
  import { ACC } from './accessor.js';
17
17
 
18
18
  const ASSIGN = 20, TOKEN = 200;
19
19
 
20
+ // Allow {keyword: value} - prevent keyword match before colon
21
+ parse.prop = pos => peek(pos) !== 58;
22
+
20
23
  // Object inner: null, string, or array starting with : , ... get set
21
24
  const isObject = a => a == null || typeof a === 'string' || [':', ',', '...', 'get', 'set'].includes(a[0]);
22
25
 
@@ -1,7 +1,7 @@
1
1
  // Function declarations and expressions
2
- import { space, next, parse, parens, expr, operator, compile, cur, idx, skip } from '../parse.js';
3
- import { RETURN } from './control.js';
4
- import { keyword, block } from './block.js';
2
+ import { space, next, parse, keyword, parens, expr, operator, compile, cur, idx, skip } from '../parse.js';
3
+ import { block } from './if.js';
4
+ import { RETURN } from './op/arrow.js';
5
5
 
6
6
  const TOKEN = 200;
7
7
 
package/feature/group.js CHANGED
@@ -1,15 +1,6 @@
1
- import { nary, group, operator, compile } from '../parse.js';
1
+ import { group } from '../parse.js';
2
2
 
3
- const STATEMENT = 5, SEQ = 10, ACCESS = 170;
3
+ const ACCESS = 170;
4
4
 
5
5
  // (a,b,c), (a) — uses ACCESS to avoid conflict with ?.
6
6
  group('()', ACCESS);
7
-
8
- // Sequences
9
- nary(',', SEQ);
10
- nary(';', STATEMENT, true); // right-assoc to allow same-prec statements
11
-
12
- // Compile sequences - returns last evaluated value
13
- const seq = (...args) => (args = args.map(compile), ctx => { let r; for (const a of args) r = a(ctx); return r; });
14
- operator(',', seq);
15
- operator(';', seq);
package/feature/if.js CHANGED
@@ -1,14 +1,22 @@
1
1
  // If/else statement - else consumed internally
2
- import { space, skip, parens, word, idx, seek, operator, compile } from '../parse.js';
3
- import { body, keyword } from './block.js';
2
+ import { parse, space, skip, expr, err, keyword, parens, word, idx, seek, operator, compile } from '../parse.js';
4
3
 
5
4
  const STATEMENT = 5, SEMI = 59;
6
5
 
7
- // Check for `else` after optional semicolon
6
+ // block() - parse required { body }
7
+ export const block = () =>
8
+ (space() === 123 || err('Expected {'), skip(), expr(STATEMENT - .5, 125) || null);
9
+
10
+ // body() - parse { body } or single statement
11
+ export const body = () =>
12
+ space() !== 123 ? expr(STATEMENT + .5) : (skip(), expr(STATEMENT - .5, 125) || null);
13
+
14
+ // Check for `else` after optional semicolon (use parse.space to consume comments)
8
15
  const checkElse = () => {
9
16
  const from = idx;
10
- if (space() === SEMI) skip();
11
- space();
17
+ const sp = parse.space || space;
18
+ if (sp() === SEMI) skip();
19
+ sp();
12
20
  if (word('else')) return skip(4), true;
13
21
  return seek(from), false;
14
22
  };
@@ -7,8 +7,7 @@
7
7
  * [, undefined] serializes to [null, null] which would compile to null.
8
8
  * [] serializes to [] and compiles back to undefined.
9
9
  */
10
- import { literal } from '../parse.js';
11
- import { keyword } from './block.js';
10
+ import { literal, keyword } from '../parse.js';
12
11
 
13
12
  literal('true', true);
14
13
  literal('false', false);
package/feature/loop.js CHANGED
@@ -1,10 +1,10 @@
1
1
  // Loops: while, do-while, for, for await, break, continue, return
2
- import { expr, skip, space, parse, word, parens, cur, idx, operator, compile, next, seek } from '../parse.js';
3
- import { body, keyword } from './block.js';
4
- import { destructure } from './destruct.js';
5
- import { BREAK, CONTINUE, RETURN } from './control.js';
2
+ import { expr, skip, space, parse, word, keyword, parens, cur, idx, operator, compile, next, seek } from '../parse.js';
3
+ import { RETURN } from './op/arrow.js';
4
+ import { body } from './if.js';
5
+ import { destructure } from './var.js';
6
6
 
7
- export { BREAK, CONTINUE, RETURN };
7
+ export const BREAK = Symbol('break'), CONTINUE = Symbol('continue');
8
8
 
9
9
  const STATEMENT = 5, CBRACE = 125, SEMI = 59;
10
10
 
package/feature/module.js CHANGED
@@ -9,8 +9,7 @@
9
9
  * export { a } from './x' → ['export', ['from', ['{}', ...], path]]
10
10
  * export const x = 1 → ['export', decl]
11
11
  */
12
- import { token, expr, space, lookup, skip, word } from '../parse.js';
13
- import { keyword } from './block.js';
12
+ import { token, expr, space, keyword, lookup, skip, word } from '../parse.js';
14
13
 
15
14
  const STATEMENT = 5, SEQ = 10, STAR = 42;
16
15
 
package/feature/number.js CHANGED
@@ -48,7 +48,9 @@ lookup[_0] = a => {
48
48
  for (const [pre, base] of Object.entries(cfg)) {
49
49
  if (pre[0] === '0' && cur[idx + 1]?.toLowerCase() === pre[1]) {
50
50
  skip(2);
51
- return [, parseInt(strip(next(charTest[base])), base)];
51
+ const str = strip(next(charTest[base]));
52
+ if (cur.charCodeAt(idx) === _n) { skip(); return [, BigInt('0' + pre[1] + str)]; }
53
+ return [, parseInt(str, base)];
52
54
  }
53
55
  }
54
56
  }
@@ -6,7 +6,9 @@
6
6
  * Common in: JS, TS, Java, C#, Kotlin, Scala
7
7
  */
8
8
  import { binary, operator, compile } from '../../parse.js';
9
- import { RETURN } from '../control.js';
9
+
10
+ // RETURN: array to hold value - reused, no allocation per throw
11
+ export const RETURN = [];
10
12
 
11
13
  const ASSIGN = 20;
12
14
 
@@ -4,7 +4,7 @@
4
4
  * ||= &&= ??= + destructuring support for let/const/var
5
5
  */
6
6
  import { binary, operator, compile } from '../../parse.js';
7
- import { destructure } from '../destruct.js';
7
+ import { destructure } from '../var.js';
8
8
  import { isLval, prop } from '../access.js';
9
9
 
10
10
  const ASSIGN = 20;
@@ -8,8 +8,7 @@
8
8
  *
9
9
  * JS-specific keywords
10
10
  */
11
- import { unary, operator, compile, skip, expr, word } from '../../parse.js';
12
- import { keyword } from '../block.js';
11
+ import { unary, keyword, operator, compile, skip, expr, word } from '../../parse.js';
13
12
 
14
13
  const PREFIX = 140;
15
14
 
@@ -1,8 +1,8 @@
1
1
  // Additional JS statements: debugger, with (parse-only)
2
2
  // debugger → ['debugger']
3
3
  // with (obj) body → ['with', obj, body]
4
- import { space, parens } from '../parse.js';
5
- import { keyword, body } from './block.js';
4
+ import { space, keyword, parens } from '../parse.js';
5
+ import { body } from './if.js';
6
6
 
7
7
  const STATEMENT = 5;
8
8
 
package/feature/switch.js CHANGED
@@ -1,8 +1,7 @@
1
1
  // Switch/case/default
2
2
  // AST: ['switch', val, ['case', test, body], ['default', body], ...]
3
- import { expr, skip, space, parens, operator, compile, idx, err, seek, parse, lookup, word, cur } from '../parse.js';
4
- import { keyword } from './block.js';
5
- import { BREAK } from './control.js';
3
+ import { expr, skip, space, keyword, parens, operator, compile, idx, err, seek, parse, lookup, word, cur } from '../parse.js';
4
+ import { BREAK } from './loop.js';
6
5
 
7
6
  const STATEMENT = 5, ASSIGN = 20, COLON = 58, SEMI = 59, CBRACE = 125;
8
7
 
package/feature/try.js CHANGED
@@ -1,14 +1,27 @@
1
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 './control.js';
2
+ // AST (faithful): ['try', body, ['catch', param, handler]?, ['finally', cleanup]?]
3
+ // Note: body/handler are raw block results, param is raw parens result
4
+ import { space, parse, keyword, parens, expr, word, skip, operator, compile } from '../parse.js';
5
+ import { block } from './if.js';
6
+ import { RETURN } from './op/arrow.js';import { BREAK, CONTINUE } from './loop.js';
6
7
 
7
8
  const STATEMENT = 5;
8
9
 
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()]);
10
+ // try { body } [catch (param) { handler }] [finally { cleanup }]
11
+ keyword('try', STATEMENT + 1, () => {
12
+ const node = ['try', block()];
13
+ space();
14
+ if (word('catch')) {
15
+ skip(5); space();
16
+ node.push(['catch', parens(), block()]);
17
+ }
18
+ space();
19
+ if (word('finally')) {
20
+ skip(7);
21
+ node.push(['finally', block()]);
22
+ }
23
+ return node;
24
+ });
12
25
 
13
26
  keyword('throw', STATEMENT + 1, () => {
14
27
  parse.asi && (parse.newline = false);
@@ -17,39 +30,33 @@ keyword('throw', STATEMENT + 1, () => {
17
30
  return ['throw', expr(STATEMENT)];
18
31
  });
19
32
 
20
- // Compile
21
- operator('try', tryBody => {
33
+ // Compile try - normalize in compiler, not parser
34
+ operator('try', (tryBody, ...clauses) => {
22
35
  tryBody = tryBody ? compile(tryBody) : null;
23
- return ctx => tryBody?.(ctx);
24
- });
25
36
 
26
- operator('catch', (tryNode, catchName, catchBody) => {
27
- const tryBody = tryNode?.[1] ? compile(tryNode[1]) : null;
28
- catchBody = catchBody ? compile(catchBody) : null;
37
+ let catchClause = clauses.find(c => c?.[0] === 'catch');
38
+ let finallyClause = clauses.find(c => c?.[0] === 'finally');
39
+
40
+ const catchParam = catchClause?.[1];
41
+ const catchBody = catchClause?.[2] ? compile(catchClause[2]) : null;
42
+ const finallyBody = finallyClause?.[1] ? compile(finallyClause[1]) : null;
43
+
29
44
  return ctx => {
30
45
  let result;
31
46
  try {
32
47
  result = tryBody?.(ctx);
33
48
  } catch (e) {
34
49
  if (e === BREAK || e === CONTINUE || e === RETURN) throw e;
35
- if (catchName !== null && catchBody) {
36
- const had = catchName in ctx, orig = ctx[catchName];
37
- ctx[catchName] = e;
50
+ if (catchParam !== null && catchParam !== undefined && catchBody) {
51
+ const had = catchParam in ctx, orig = ctx[catchParam];
52
+ ctx[catchParam] = e;
38
53
  try { result = catchBody(ctx); }
39
- finally { had ? ctx[catchName] = orig : delete ctx[catchName]; }
40
- } else if (catchName === null) throw e;
54
+ finally { had ? ctx[catchParam] = orig : delete ctx[catchParam]; }
55
+ } else if (!catchBody) throw e;
56
+ }
57
+ finally {
58
+ finallyBody?.(ctx);
41
59
  }
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
60
  return result;
54
61
  };
55
62
  });
package/feature/var.js CHANGED
@@ -8,12 +8,55 @@
8
8
  * for (let x in o) → ['for', ['in', ['let', 'x'], 'o'], body]
9
9
  * var x → ['var', 'x'] (acts as assignment target)
10
10
  */
11
- import { expr, space, operator, compile } from '../parse.js';
12
- import { keyword } from './block.js';
13
- import { destructure } from './destruct.js';
11
+ import { expr, space, keyword, operator, compile } from '../parse.js';
14
12
 
15
13
  const STATEMENT = 5, SEQ = 10, ASSIGN = 20;
16
14
 
15
+ // Flatten comma into array: [',', a, b, c] → [a, b, c]
16
+ const flatten = items => items[0]?.[0] === ',' ? items[0].slice(1) : items;
17
+
18
+ // Destructure value into context
19
+ export const destructure = (pattern, value, ctx) => {
20
+ if (typeof pattern === 'string') { ctx[pattern] = value; return; }
21
+ const [op, ...raw] = pattern;
22
+ const items = flatten(raw);
23
+ if (op === '{}') {
24
+ const used = [];
25
+ for (const item of items) {
26
+ // Rest: {...rest}
27
+ if (Array.isArray(item) && item[0] === '...') {
28
+ const rest = {};
29
+ for (const k in value) if (!used.includes(k)) rest[k] = value[k];
30
+ ctx[item[1]] = rest;
31
+ break;
32
+ }
33
+ let key, binding, def;
34
+ // Shorthand: {x} → item is 'x'
35
+ // With default: {x = 1} → ['=', 'x', default]
36
+ // Rename: {x: y} → [':', 'x', 'y']
37
+ if (typeof item === 'string') { key = binding = item }
38
+ else if (item[0] === '=') { typeof item[1] === 'string' ? (key = binding = item[1]) : ([, key, binding] = item[1]); def = item[2] }
39
+ else { [, key, binding] = item }
40
+ used.push(key);
41
+ let val = value[key];
42
+ if (val === undefined && def) val = compile(def)(ctx);
43
+ destructure(binding, val, ctx);
44
+ }
45
+ }
46
+ else if (op === '[]') {
47
+ let i = 0;
48
+ for (const item of items) {
49
+ if (item === null) { i++; continue; }
50
+ if (Array.isArray(item) && item[0] === '...') { ctx[item[1]] = value.slice(i); break; }
51
+ let binding = item, def;
52
+ if (Array.isArray(item) && item[0] === '=') [, binding, def] = item;
53
+ let val = value[i++];
54
+ if (val === undefined && def) val = compile(def)(ctx);
55
+ destructure(binding, val, ctx);
56
+ }
57
+ }
58
+ };
59
+
17
60
  // let/const: expr(SEQ-1) consumes assignment, stops before comma
18
61
  // For for-in/of, return ['in/of', ['let', x], iterable] not ['let', ['in', x, it]]
19
62
  // For comma, return ['let', decl1, decl2, ...] not ['let', [',', ...]]
package/jessie.js CHANGED
@@ -6,13 +6,12 @@
6
6
  */
7
7
  import './justin.js';
8
8
 
9
- // Statement features (var.js must come before destruct.js)
9
+ // Statement features
10
10
  import './feature/var.js';
11
11
  import './feature/function.js';
12
12
  import './feature/async.js';
13
13
  import './feature/class.js';
14
14
  import './feature/regex.js';
15
- import './feature/destruct.js';
16
15
 
17
16
  // Control flow
18
17
  import './feature/if.js';
package/jessie.min.js CHANGED
@@ -1,8 +1,8 @@
1
- var l,m,c=r=>(l=0,m=r,c.newline=!1,r=h(),m[l]?R():r||""),R=(r="Unexpected token",e=l,t=m.slice(0,e).split(`
2
- `),n=t.pop(),o=m.slice(Math.max(0,e-40),e),p="\u032D",f=(m[e]||" ")+p,u=m.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${n.length+1}
1
+ var u,m,c=r=>(u=0,m=r,c.newline=!1,r=a(),m[u]?R():r||""),R=(r="Unexpected token",e=u,t=m.slice(0,e).split(`
2
+ `),n=t.pop(),o=m.slice(Math.max(0,e-40),e),p="\u032D",l=(m[e]||" ")+p,f=m.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${n.length+1}
3
3
  ${m[e-41]!==`
4
- `,""+o}${f}${u}`)},q=(r,e=l)=>(Array.isArray(r)&&(r.loc=e),r),I=(r,e=l,t)=>{for(;t=r(m.charCodeAt(l));)l+=t;return m.slice(e,l)},y=(r=1)=>m[l+=r],P=r=>l=r,h=(r=0,e)=>{let t,n,o,p,f;for(e&&c.asi&&(c.newline=!1);(t=c.space())&&(f=c.newline,1)&&t!==e&&(o=((p=k[t])&&p(n,r))??(n&&f&&c.asi?.(n,r,h))??(!n&&I(c.id)));)n=o;return e&&(t==e?l++:R("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),n},d=c.space=(r,e=l)=>{for(;(r=m.charCodeAt(l))<=32;)c.asi&&r===10&&(c.newline=!0),l++;return r},_r=(r=l)=>{for(;m.charCodeAt(r)<=32;)r++;return m.charCodeAt(r)},Tt=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,N=(r,e=r.length)=>m.substr(l,e)===r&&!c.id(m.charCodeAt(l+e)),v=()=>(y(),h(0,41)),k=[],j={},T=(r,e=32,t,n=r.charCodeAt(0),o=r.length,p=k[n],f=r.toUpperCase()!==r,u,a)=>(e=j[r]=!p&&j[r]||e,k[n]=(w,S,C,E=l)=>(u=C,(C?r==C:(o<2||r.charCodeAt(1)===m.charCodeAt(l+1)&&(o<3||m.substr(l,o)==r))&&(!f||!c.id(m.charCodeAt(l+o)))&&(u=C=r))&&S<e&&(l+=o,(a=t(w))?q(a,E):(l=E,u=0,!f&&!p&&R()),a)||p?.(w,S,u))),A=(r,e,t=!1)=>T(r,e,n=>n&&(o=>o&&[r,n,o])(h(e-(t?.5:0)))),O=(r,e,t)=>T(r,e,n=>t?n&&[r,n]:!n&&(n=h(e-.5))&&[r,n]),H=(r,e)=>T(r,200,t=>!t&&[,e]),ur=(r,e,t)=>T(r,e,(n,o)=>(o=h(e-(t?.5:0)),n?.[0]!==r&&(n=[r,n||null]),o?.[0]===r?n.push(...o.slice(1)):n.push(o||null),n)),W=(r,e)=>T(r[0],e,t=>!t&&[r,h(0,r.charCodeAt(1))||null]),lr=(r,e)=>T(r[0],e,t=>t&&[r,t,h(0,r.charCodeAt(1))||null]),fr={},s=(r,e,t=fr[r])=>fr[r]=(...n)=>e(...n)||t?.(...n),i=r=>Array.isArray(r)?r[0]==null?(e=>()=>e)(r[1]):fr[r[0]]?.(...r.slice(1))??R(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var b=46,z=48,rr=57,me=69,de=101,he=43,ae=45,x=95,Ae=110,ye=97,ge=102,we=65,Ee=70,Or=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),cr=r=>{let e=Or(I(t=>t===b&&m.charCodeAt(l+1)!==b||t>=z&&t<=rr||t===x||((t===me||t===de)&&((t=m.charCodeAt(l+1))>=z&&t<=rr||t===he||t===ae)?2:0)));return m.charCodeAt(l)===Ae?(y(),[,BigInt(e)]):(r=+e)!=r?R():[,r]},Ce={2:r=>r===48||r===49||r===x,8:r=>r>=48&&r<=55||r===x,16:r=>r>=z&&r<=rr||r>=ye&&r<=ge||r>=we&&r<=Ee||r===x};c.number=null;k[b]=r=>!r&&m.charCodeAt(l+1)!==b&&cr();for(let r=z;r<=rr;r++)k[r]=e=>e?void 0:cr();k[z]=r=>{if(r)return;let e=c.number;if(e){for(let[t,n]of Object.entries(e))if(t[0]==="0"&&m[l+1]?.toLowerCase()===t[1])return y(2),[,parseInt(Or(I(Ce[n])),n)]}return cr()};var Se=92,vr=34,Pr=39,ke={n:`
5
- `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Mr=r=>(e,t,n="")=>{if(!(e||!c.string?.[String.fromCharCode(r)]))return y(),I(o=>o-r&&(o===Se?(n+=ke[m[l+1]]||m[l+1],2):(n+=m[l],1))),m[l]===String.fromCharCode(r)?y():R("Bad string"),[,n]};k[vr]=Mr(vr);k[Pr]=Mr(Pr);c.string={'"':!0};var Te=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>A(r,Te,!0));var Lr=(r,e,t,n)=>typeof r=="string"?o=>e(o,r,o):r[0]==="."?(t=i(r[1]),n=r[2],o=>e(t(o),n,o)):r[0]==="[]"&&r.length===3?(t=i(r[1]),n=i(r[2]),o=>e(t(o),n(o),o)):r[0]==="()"&&r.length===2?Lr(r[1],e):(()=>{throw Error("Invalid assignment target")})(),Ur={"=":(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 Ur)s(r,(e,t)=>(t=i(t),Lr(e,(n,o,p)=>Ur[r](n,o,t(p)))));var Ie=30,Re=40,Fr=140;A("!",Fr);O("!",Fr);A("||",Ie);A("&&",Re);s("!",r=>(r=i(r),e=>!r(e)));s("||",(r,e)=>(r=i(r),e=i(e),t=>r(t)||e(t)));s("&&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&&e(t)));var Ne=50,_e=60,Oe=70,Br=100,ve=140;A("|",Ne);A("&",Oe);A("^",_e);A(">>",Br);A("<<",Br);O("~",ve);s("~",r=>(r=i(r),e=>~r(e)));s("|",(r,e)=>(r=i(r),e=i(e),t=>r(t)|e(t)));s("&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&e(t)));s("^",(r,e)=>(r=i(r),e=i(e),t=>r(t)^e(t)));s(">>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>e(t)));s("<<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<<e(t)));var er=90;A("<",er);A(">",er);A("<=",er);A(">=",er);s(">",(r,e)=>(r=i(r),e=i(e),t=>r(t)>e(t)));s("<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<e(t)));s(">=",(r,e)=>(r=i(r),e=i(e),t=>r(t)>=e(t)));s("<=",(r,e)=>(r=i(r),e=i(e),t=>r(t)<=e(t)));var Gr=80;A("==",Gr);A("!=",Gr);s("==",(r,e)=>(r=i(r),e=i(e),t=>r(t)==e(t)));s("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(t)));var Xr=110,mr=120,Dr=140;A("+",Xr);A("-",Xr);A("*",mr);A("/",mr);A("%",mr);O("+",Dr);O("-",Dr);s("+",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)+e(t)):(r=i(r),t=>+r(t)));s("-",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)-e(t)):(r=i(r),t=>-r(t)));s("*",(r,e)=>(r=i(r),e=i(e),t=>r(t)*e(t)));s("/",(r,e)=>(r=i(r),e=i(e),t=>r(t)/e(t)));s("%",(r,e)=>(r=i(r),e=i(e),t=>r(t)%e(t)));var tr=150;T("++",tr,r=>r?["++",r,null]:["++",h(tr-1)]);T("--",tr,r=>r?["--",r,null]:["--",h(tr-1)]);var dr=(r,e,t,n)=>typeof r=="string"?o=>e(o,r):r[0]==="."?(t=i(r[1]),n=r[2],o=>e(t(o),n)):r[0]==="[]"&&r.length===3?(t=i(r[1]),n=i(r[2]),o=>e(t(o),n(o))):r[0]==="()"&&r.length===2?dr(r[1],e):(()=>{throw Error("Invalid increment target")})();s("++",(r,e)=>dr(r,e===null?(t,n)=>t[n]++:(t,n)=>++t[n]));s("--",(r,e)=>dr(r,e===null?(t,n)=>t[n]--:(t,n)=>--t[n]));var Pe=5,Me=10,Ue=170;W("()",Ue);ur(",",Me);ur(";",Pe,!0);var Kr=(...r)=>(r=r.map(i),e=>{let t;for(let n of r)t=n(e);return t});s(",",Kr);s(";",Kr);var G=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",hr=170;lr("[]",hr);A(".",hr);lr("()",hr);var nr=r=>{throw Error(r)};s("[]",(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]),n=>t(n)):(t=i(t),n=>[t(n)])),t=>r.flatMap(n=>n(t))):(e==null&&nr("Missing index"),r=i(r),e=i(e),t=>{let n=e(t);return G(n)?void 0:r(t)[n]}));s(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],G(e)?()=>{}:t=>r(t)[e]));s("()",(r,e)=>{if(e===void 0)return r==null?nr("Empty ()"):i(r);let t=o=>o?.[0]===","&&o.slice(1).some(p=>p==null||t(p));t(e)&&nr("Empty argument");let n=e?e[0]===","?(e=e.slice(1).map(i),o=>e.map(p=>p(o))):(e=i(e),o=>[e(o)]):()=>[];return ar(r,(o,p,f)=>o[p](...n(f)))});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]==="{}"),ar=(r,e,t,n)=>r==null?nr("Empty ()"):r[0]==="()"&&r.length==2?ar(r[1],e):typeof r=="string"?o=>e(o,r,o):r[0]==="."?(t=i(r[1]),n=r[2],o=>e(t(o),n,o)):r[0]==="?."?(t=i(r[1]),n=r[2],o=>{let p=t(o);return p==null?void 0:e(p,n,o)}):r[0]==="[]"&&r.length===3?(t=i(r[1]),n=i(r[2]),o=>e(t(o),n(o),o)):r[0]==="?.[]"?(t=i(r[1]),n=i(r[2]),o=>{let p=t(o);return p==null?void 0:e(p,n(o),o)}):(r=i(r),o=>e([r(o)],0,o)),X=ar;var Qr=new WeakMap,Le=(r,...e)=>typeof r=="string"?i(c(r)):Qr.get(r)||Qr.set(r,Fe(r,e)).get(r),$r=57344,Fe=(r,e)=>{let t=r.reduce((p,f,u)=>p+(u?String.fromCharCode($r+u-1):"")+f,""),n=c(t),o=p=>{if(typeof p=="string"&&p.length===1){let f=p.charCodeAt(0)-$r,u;if(f>=0&&f<e.length)return u=e[f],Be(u)?u:[,u]}return Array.isArray(p)?p.map(o):p};return i(o(n))},Be=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Hr=Le;var Ge=32,Xe=c.space;c.comment??={"//":`
6
- `,"/*":"*/"};var Ar;c.space=()=>{Ar||(Ar=Object.entries(c.comment).map(([o,p])=>[o,p,o.charCodeAt(0)]));for(var r;r=Xe();){for(var e=0,t;t=Ar[e++];)if(r===t[2]&&m.substr(l,t[0].length)===t[0]){var n=l+t[0].length;if(t[1]===`
7
- `)for(;m.charCodeAt(n)>=Ge;)n++;else{for(;m[n]&&m.substr(n,t[1].length)!==t[1];)n++;m[n]&&(n+=t[1].length)}P(n),r=0;break}if(r)return r}return r};var jr=80;A("===",jr);A("!==",jr);s("===",(r,e)=>(r=i(r),e=i(e),t=>r(t)===e(t)));s("!==",(r,e)=>(r=i(r),e=i(e),t=>r(t)!==e(t)));var De=30;A("??",De);s("??",(r,e)=>(r=i(r),e=i(e),t=>r(t)??e(t)));var Ke=130,Qe=20;A("**",Ke,!0);A("**=",Qe,!0);s("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));var $e=r=>{throw Error(r)};s("**=",(r,e)=>(L(r)||$e("Invalid assignment target"),e=i(e),X(r,(t,n,o)=>t[n]**=e(o))));var Wr=90;A("in",Wr);A("of",Wr);s("in",(r,e)=>(r=i(r),e=i(e),t=>r(t)in e(t)));var He=20,je=100,We=r=>{throw Error(r)};A(">>>",je);A(">>>=",He,!0);s(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));s(">>>=",(r,e)=>(L(r)||We("Invalid assignment target"),e=i(e),X(r,(t,n,o)=>t[n]>>>=e(o))));var ze=r=>r[0]?.[0]===","?r[0].slice(1):r,D=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[n,...o]=r,p=ze(o);if(n==="{}"){let f=[];for(let u of p){if(Array.isArray(u)&&u[0]==="..."){let E={};for(let _ in e)f.includes(_)||(E[_]=e[_]);t[u[1]]=E;break}let a,w,S;typeof u=="string"?a=w=u:u[0]==="="?(typeof u[1]=="string"?a=w=u[1]:[,a,w]=u[1],S=u[2]):[,a,w]=u,f.push(a);let C=e[a];C===void 0&&S&&(C=i(S)(t)),D(w,C,t)}}else if(n==="[]"){let f=0;for(let u of p){if(u===null){f++;continue}if(Array.isArray(u)&&u[0]==="..."){t[u[1]]=e.slice(f);break}let a=u,w;Array.isArray(u)&&u[0]==="="&&([,a,w]=u);let S=e[f++];S===void 0&&w&&(S=i(w)(t)),D(a,S,t)}}};var yr=20,or=r=>{throw Error(r)};A("||=",yr,!0);A("&&=",yr,!0);A("??=",yr,!0);s("=",(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"?n=>{n[t]=e(n)}:n=>D(t,e(n),n)}return L(r)||or("Invalid assignment target"),e=i(e),X(r,(t,n,o)=>t[n]=e(o))});s("||=",(r,e)=>(L(r)||or("Invalid assignment target"),e=i(e),X(r,(t,n,o)=>t[n]||=e(o))));s("&&=",(r,e)=>(L(r)||or("Invalid assignment target"),e=i(e),X(r,(t,n,o)=>t[n]&&=e(o))));s("??=",(r,e)=>(L(r)||or("Invalid assignment target"),e=i(e),X(r,(t,n,o)=>t[n]??=e(o))));var gr=5,zr=123,Jr=125,g=(r,e,t,n=r.charCodeAt(0),o=r.length,p=k[n],f)=>k[n]=(u,a,w,S=l)=>!u&&(w?r==w:(o<2||m.substr(l,o)==r)&&(w=r))&&a<e&&!c.id(m.charCodeAt(l+o))&&_r(l+o)!==58&&(P(l+o),(f=t())?q(f,S):P(S),f)||p?.(u,a,w),wr=(r,e,t,n=r.charCodeAt(0),o=r.length,p=k[n],f)=>k[n]=(u,a,w,S=l)=>u&&(w?r==w:(o<2||m.substr(l,o)==r)&&(w=r))&&a<e&&!c.id(m.charCodeAt(l+o))&&(P(l+o),q(f=t(u),S),f)||p?.(u,a,w),F=()=>(d()===zr||R("Expected {"),y(),h(gr-.5,Jr)||null),B=()=>d()!==zr?h(gr+.5):(y(),h(gr-.5,Jr)||null);H("true",!0);H("false",!1);H("null",null);g("undefined",200,()=>[]);H("NaN",NaN);H("Infinity",1/0);var Er=20;T("?",Er,(r,e,t)=>r&&(e=h(Er-1))&&I(n=>n===58)&&(t=h(Er-1),["?",r,e,t]));s("?",(r,e,t)=>(r=i(r),e=i(e),t=i(t),n=>r(n)?e(n):t(n)));var U=Symbol("break"),K=Symbol("continue"),M=[];var Je=20;A("=>",Je,!0);s("=>",(r,e)=>{r=r?.[0]==="()"?r[1]:r;let t=r?r[0]===","?r.slice(1):[r]:[],n=-1,o=null,p=t[t.length-1];Array.isArray(p)&&p[0]==="..."&&(n=t.length-1,o=p[1],t.length--);let f=e?.[0]==="{}";return e=i(f?["{",e[1]]:e),u=>(...a)=>{let w={};t.forEach((C,E)=>w[C]=a[E]),o&&(w[o]=a.slice(n));let S=new Proxy(w,{get:(C,E)=>E in C?C[E]:u?.[E],set:(C,E,_)=>((E in C?C:u)[E]=_,!0),has:(C,E)=>E in C||(u?E in u:!1)});try{let C=e(S);return f?void 0:C}catch(C){if(C===M)return C[0];throw C}}});var Ve=140;O("...",Ve);s("...",r=>(r=i(r),e=>Object.entries(r(e))));var Vr=170;T("?.",Vr,(r,e)=>{if(!r)return;let t=d();return t===40?(y(),["?.()",r,h(0,41)||null]):t===91?(y(),["?.[]",r,h(0,93)]):(e=h(Vr),e?["?.",r,e]:void 0)});s("?.",(r,e)=>(r=i(r),G(e)?()=>{}:t=>r(t)?.[e]));s("?.[]",(r,e)=>(r=i(r),e=i(e),t=>{let n=e(t);return G(n)?void 0:r(t)?.[n]}));s("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(i),o=>e.map(p=>p(o))):(e=i(e),o=>[e(o)]):()=>[];if(r[0]==="?."){let o=i(r[1]),p=r[2];return G(p)?()=>{}:f=>o(f)?.[p]?.(...t(f))}if(r[0]==="?.[]"){let o=i(r[1]),p=i(r[2]);return f=>{let u=o(f),a=p(f);return G(a)?void 0:u?.[a]?.(...t(f))}}if(r[0]==="."){let o=i(r[1]),p=r[2];return G(p)?()=>{}:f=>o(f)?.[p]?.(...t(f))}if(r[0]==="[]"&&r.length===3){let o=i(r[1]),p=i(r[2]);return f=>{let u=o(f),a=p(f);return G(a)?void 0:u?.[a]?.(...t(f))}}let n=i(r);return o=>n(o)?.(...t(o))});var J=140;O("typeof",J);O("void",J);O("delete",J);g("new",J,()=>N(".target")?(y(7),["new.target"]):["new",h(J)]);s("typeof",r=>(r=i(r),e=>typeof r(e)));s("void",r=>(r=i(r),e=>(r(e),void 0)));s("delete",r=>{if(r[0]==="."){let e=i(r[1]),t=r[2];return n=>delete e(n)[t]}if(r[0]==="[]"){let e=i(r[1]),t=i(r[2]);return n=>delete e(n)[t(n)]}return()=>!0});s("new",r=>{let e=i(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,n=t?t[0]===","?(o=>p=>o.map(f=>f(p)))(t.slice(1).map(i)):(o=>p=>[o(p)])(i(t)):()=>[];return o=>new(e(o))(...n(o))});var ir=Symbol("accessor"),Cr=20,Ye=40,Yr=41,Zr=123,qr=125,xr=r=>e=>{if(e)return;d();let t=I(c.id);if(!t||(d(),m.charCodeAt(l)!==Ye))return!1;y();let n=h(0,Yr);return d(),m.charCodeAt(l)!==Zr?!1:(y(),[r,t,n,h(0,qr)])};T("get",Cr-1,xr("get"));T("set",Cr-1,xr("set"));T("(",Cr-1,r=>{if(!r||typeof r!="string")return;let e=h(0,Yr)||null;if(d(),m.charCodeAt(l)===Zr)return y(),[":",r,["=>",["()",e],h(0,qr)||null]]});s("get",(r,e)=>(e=e?i(e):()=>{},t=>[[ir,r,{get:function(){let n=Object.create(t||{});return n.this=this,e(n)}}]]));s("set",(r,e,t)=>(t=t?i(t):()=>{},n=>[[ir,r,{set:function(o){let p=Object.create(n||{});p.this=this,p[e]=o,t(p)}}]]));var Ze=20,br=200,qe=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);W("[]",br);W("{}",br);A(":",Ze-1,!0);s("{}",(r,e)=>{if(e!==void 0)return;if(!qe(r))return i(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(n=>i(typeof n=="string"?[":",n,n]:n));return n=>{let o={},p={};for(let f of t.flatMap(u=>u(n)))if(f[0]===ir){let[,u,a]=f;p[u]={...p[u],...a,configurable:!0,enumerable:!0}}else o[f[0]]=f[1];for(let f in p)Object.defineProperty(o,f,p[f]);return o}});s("{",r=>(r=r?i(r):()=>{},e=>r(Object.create(e))));s(":",(r,e)=>(e=i(e),Array.isArray(r)?(r=i(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));var xe=170,sr=96,be=36,rt=123,et=92,tt={n:`
8
- `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},re=()=>{let r=[];for(let e="",t;(t=m.charCodeAt(l))!==sr;)t?t===et?(y(),e+=tt[m[l]]||m[l],y()):t===be&&m.charCodeAt(l+1)===rt?(e&&r.push([,e]),e="",y(2),r.push(h(0,125))):(e+=m[l],y(),t=m.charCodeAt(l),t===sr&&e&&r.push([,e])):R("Unterminated template");return y(),r},nt=k[sr];k[sr]=(r,e)=>r&&e<xe?c.asi&&c.newline?void 0:(y(),["``",r,...re()]):r?nt?.(r,e):(y(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(re()));s("`",(...r)=>(r=r.map(i),e=>r.map(t=>t(e)).join("")));s("``",(r,...e)=>{r=i(r);let t=[],n=[];for(let p of e)Array.isArray(p)&&p[0]===void 0?t.push(p[1]):n.push(i(p));let o=Object.assign([...t],{raw:t});return p=>r(p)(o,...n.map(f=>f(p)))});c.string["'"]=!0;c.number={"0x":16,"0b":2,"0o":8};var Sr=5,ot=10,it=20,ee=r=>{let e=h(ot-1);return e?.[0]==="in"||e?.[0]==="of"?[e[0],[r,e[1]],e[2]]:e?.[0]===","?[r,...e.slice(1)]:[r,e]};g("let",Sr+1,()=>ee("let"));g("const",Sr+1,()=>ee("const"));g("var",Sr,()=>(d(),["var",h(it)]));var te=(...r)=>(r=r.map(e=>{if(typeof e=="string")return t=>{t[e]=void 0};if(e[0]==="="){let[,t,n]=e,o=i(n);return typeof t=="string"?p=>{p[t]=o(p)}:p=>D(t,o(p),p)}return i(e)}),e=>{for(let t of r)t(e)});s("let",te);s("const",te);s("var",r=>typeof r=="string"?e=>{e[r]=void 0}:()=>{});var st=200;g("function",st,()=>{d();let r=!1;m[l]==="*"&&(r=!0,y(),d());let e=I(c.id);return e&&d(),r?["function*",e,v()||null,F()]:["function",e,v()||null,F()]});s("function",(r,e,t)=>{t=t?i(t):()=>{};let n=e?e[0]===","?e.slice(1):[e]:[],o=null,p=-1,f=n[n.length-1];return Array.isArray(f)&&f[0]==="..."&&(p=n.length-1,o=f[1],n.length--),u=>{let a=(...w)=>{let S={};n.forEach((E,_)=>S[E]=w[_]),o&&(S[o]=w.slice(p));let C=new Proxy(S,{get:(E,_)=>_ in E?E[_]:u[_],set:(E,_,ce)=>((_ in E?E:u)[_]=ce,!0),has:(E,_)=>_ in E||_ in u});try{return t(C)}catch(E){if(E===M)return E[0];throw E}};return r&&(u[r]=a),a}});s("function*",(r,e,t)=>{throw Error("Generator functions are not supported in evaluation")});var pr=140,kr=20;O("await",pr);g("yield",pr,()=>(d(),m[l]==="*"?(y(),d(),["yield*",h(kr)]):["yield",h(kr)]));g("async",pr,()=>{if(d(),N("function"))return["async",h(pr)];let r=h(kr-.5);return r&&["async",r]});s("async",r=>{let e=i(r);return t=>{let n=e(t);return async function(...o){return n(...o)}}});s("await",r=>(r=i(r),async e=>await r(e)));s("yield",r=>(r=r?i(r):null,e=>{throw{__yield__:r?r(e):void 0}}));s("yield*",r=>(r=i(r),e=>{throw{__yield_all__:r(e)}}));var Tr=200,pt=140,ft=90,ut=Symbol("static");O("static",pt);A("instanceof",ft);T("#",Tr,r=>{if(r)return;let e=I(c.id);return e?"#"+e:void 0});g("class",Tr,()=>{d();let r=I(c.id)||null;if(r==="extends")r=null,d();else{if(d(),!N("extends"))return["class",r,null,F()];y(7),d()}return["class",r,h(Tr),F()]});var lt=r=>{throw Error(r)};s("instanceof",(r,e)=>(r=i(r),e=i(e),t=>r(t)instanceof e(t)));s("class",(r,e,t)=>(e=e?i(e):null,t=t?i(t):null,n=>{let o=e?e(n):Object,p=function(...f){if(!(this instanceof p))return lt("Class constructor must be called with new");let u=e?Reflect.construct(o,f,p):this;return p.prototype.__constructor__&&p.prototype.__constructor__.apply(u,f),u};if(Object.setPrototypeOf(p.prototype,o.prototype),Object.setPrototypeOf(p,o),t){let f=Object.create(n);f.super=o;let u=t(f),a=Array.isArray(u)&&typeof u[0]?.[0]=="string"?u:[];for(let[w,S]of a)w==="constructor"?p.prototype.__constructor__=S:p.prototype[w]=S}return r&&(n[r]=p),p}));s("static",r=>(r=i(r),e=>[[ut,r(e)]]));var ct=140,Ir=47,mt=92,dt=r=>r===mt?2:r&&r!==Ir,ht=r=>r===103||r===105||r===109||r===115||r===117||r===121;T("/",ct,r=>{if(r)return;let e=m.charCodeAt(l);if(e===Ir||e===42||e===43||e===63||e===61)return;let t=I(dt);m.charCodeAt(l)===Ir||R("Unterminated regex"),y();let n=I(ht);try{new RegExp(t,n)}catch(o){R("Invalid regex: "+o.message)}return n?["//",t,n]:["//",t]});s("//",(r,e)=>{let t=new RegExp(r,e||"");return()=>t});var at=5,At=59,yt=()=>{let r=l;return d()===At&&y(),d(),N("else")?(y(4),!0):(P(r),!1)};g("if",at+1,()=>{d();let r=["if",v(),B()];return yt()&&r.push(B()),r});s("if",(r,e,t)=>(r=i(r),e=i(e),t=t!==void 0?i(t):null,n=>r(n)?e(n):t?.(n)));var Q=5,V=125,Y=59;g("while",Q+1,()=>(d(),["while",v(),B()]));g("do",Q+1,()=>(r=>(d(),y(5),d(),["do",r,v()]))(B()));g("for",Q+1,()=>(d(),N("await")?(y(5),d(),["for await",v(),B()]):["for",v(),B()]));g("break",Q+1,()=>{c.asi&&(c.newline=!1);let r=l;d();let e=m.charCodeAt(l);if(!e||e===V||e===Y||c.newline)return["break"];let t=I(c.id);if(!t)return["break"];d();let n=m.charCodeAt(l);return!n||n===V||n===Y||c.newline?["break",t]:(P(r),["break"])});g("continue",Q+1,()=>{c.asi&&(c.newline=!1);let r=l;d();let e=m.charCodeAt(l);if(!e||e===V||e===Y||c.newline)return["continue"];let t=I(c.id);if(!t)return["continue"];d();let n=m.charCodeAt(l);return!n||n===V||n===Y||c.newline?["continue",t]:(P(r),["continue"])});g("return",Q+1,()=>{c.asi&&(c.newline=!1);let r=d();return!r||r===V||r===Y||c.newline?["return"]:["return",h(Q)]});s("while",(r,e)=>(r=i(r),e=i(e),t=>{let n;for(;r(t);)try{n=e(t)}catch(o){if(o===U)break;if(o===K)continue;if(o===M)return o[0];throw o}return n}));s("do",(r,e)=>(r=i(r),e=i(e),t=>{let n;do try{n=r(t)}catch(o){if(o===U)break;if(o===K)continue;if(o===M)return o[0];throw o}while(e(t));return n}));s("for",(r,e)=>{if(Array.isArray(r)&&r[0]===";"){let[,t,n,o]=r;return t=t?i(t):null,n=n?i(n):()=>!0,o=o?i(o):null,e=i(e),p=>{let f;for(t?.(p);n(p);o?.(p))try{f=e(p)}catch(u){if(u===U)break;if(u===K)continue;if(u===M)return u[0];throw u}return f}}if(Array.isArray(r)&&(r[0]==="in"||r[0]==="of")){let[t,n,o]=r;if(Array.isArray(n)&&(n[0]==="let"||n[0]==="const"||n[0]==="var")&&(n=n[1]),t==="in")return wt(n,o,e);if(t==="of")return gt(n,o,e)}});var gt=(r,e,t)=>{e=i(e),t=i(t);let n=Array.isArray(r);return o=>{let p,f=n?null:o[r];for(let u of e(o)){n?D(r,u,o):o[r]=u;try{p=t(o)}catch(a){if(a===U)break;if(a===K)continue;if(a===M)return a[0];throw a}}return n||(o[r]=f),p}},wt=(r,e,t)=>{e=i(e),t=i(t);let n=Array.isArray(r);return o=>{let p,f=n?null:o[r];for(let u in e(o)){n?D(r,u,o):o[r]=u;try{p=t(o)}catch(a){if(a===U)break;if(a===K)continue;if(a===M)return a[0];throw a}}return n||(o[r]=f),p}};s("break",()=>()=>{throw U});s("continue",()=>()=>{throw K});s("return",r=>(r=r!==void 0?i(r):null,e=>{throw M[0]=r?.(e),M}));var Z=5;g("try",Z+1,()=>["try",F()]);wr("catch",Z+1,r=>(d(),["catch",r,v(),F()]));wr("finally",Z+1,r=>["finally",r,F()]);g("throw",Z+1,()=>{if(c.asi&&(c.newline=!1),d(),c.newline)throw SyntaxError("Unexpected newline after throw");return["throw",h(Z)]});s("try",r=>(r=r?i(r):null,e=>r?.(e)));s("catch",(r,e,t)=>{let n=r?.[1]?i(r[1]):null;return t=t?i(t):null,o=>{let p;try{p=n?.(o)}catch(f){if(f===U||f===K||f===M)throw f;if(e!==null&&t){let u=e in o,a=o[e];o[e]=f;try{p=t(o)}finally{u?o[e]=a:delete o[e]}}else if(e===null)throw f}return p}});s("finally",(r,e)=>(r=r?i(r):null,e=e?i(e):null,t=>{let n;try{n=r?.(t)}finally{e?.(t)}return n}));s("throw",r=>(r=i(r),e=>{throw r(e)}));var ie=5,Et=20,ne=58,Ct=59,se=125,Rr=0,pe=(r,e=r.length,t=r.charCodeAt(0),n=k[t])=>k[t]=(o,p,f)=>N(r)&&!o&&Rr||n?.(o,p,f);pe("case");pe("default");var oe=r=>{let e=[];for(;(r=d())!==se&&!N("case")&&!N("default");){if(r===Ct){y();continue}e.push(h(ie-.5))||R()}return e.length>1?[";",...e]:e[0]||null},St=()=>{d()===123||R("Expected {"),y(),Rr++;let r=[];try{for(;d()!==se;)if(N("case")){P(l+4),d();let e=h(Et-.5);d()===ne&&y(),r.push(["case",e,oe()])}else N("default")?(P(l+7),d()===ne&&y(),r.push(["default",oe()])):R("Expected case or default")}finally{Rr--}return y(),r};g("switch",ie+1,()=>d()===40&&["switch",v(),...St()]);s("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 n=r(t),o=!1,p;for(let[u,a]of e)if(o||u===null||u(t)===n)for(o=!0,f=0;f<a.length;f++)try{p=a[f](t)}catch(w){if(w===U)return p;throw w}var f;return p}):t=>r(t)));var fe=5;g("debugger",fe+1,()=>["debugger"]);g("with",fe+1,()=>(d(),["with",v(),B()]));var Nr=5,$=10,ue=42,kt=k[ue];k[ue]=(r,e)=>r?kt?.(r,e):(y(),"*");T("from",$+1,r=>r?r[0]!=="="&&r[0]!==","&&(d(),["from",r,h($+1)]):!1);T("as",$+2,r=>r?(d(),["as",r,h($+2)]):!1);g("import",Nr,()=>N(".meta")?(y(5),["import.meta"]):["import",h($)]);g("export",Nr,()=>(d(),["export",h(Nr)]));g("default",$+1,()=>d()!==58&&(d(),["default",h($)]));s("import",()=>()=>{});s("export",()=>()=>{});s("from",(r,e)=>()=>{});s("as",(r,e)=>()=>{});s("default",r=>i(r));var le=j.asi??j[";"];c.asi=(r,e,t,n,o)=>e<le&&(n=t(le-.5))&&(o=n?.[0]===";"?n.slice(1):[n],r?.[0]===";"?(r.push(...o),r):[";",r,...o]);export{lr as access,A as binary,i as compile,m as cur,Hr as default,R as err,h as expr,W as group,Tt as id,l as idx,H as literal,q as loc,k as lookup,ur as nary,I as next,s as operator,fr as operators,v as parens,c as parse,_r as peek,j as prec,P as seek,y as skip,d as space,T as token,O as unary,N as word};
4
+ `,""+o}${l}${f}`)},Nr=(r,e=u)=>(Array.isArray(r)&&(r.loc=e),r),T=(r,e=u,t)=>{for(;t=r(m.charCodeAt(u));)u+=t;return m.slice(e,u)},h=(r=1)=>m[u+=r],M=r=>u=r,a=(r=0,e)=>{let t,n,o,p,l;for(e&&c.asi&&(c.newline=!1);(t=c.space())&&(l=c.newline,1)&&t!==e&&(o=((p=I[t])&&p(n,r))??(n&&l&&c.asi?.(n,r,a))??(!n&&T(c.id)));)n=o;return e&&(t==e?u++:R("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),n},d=c.space=(r,e=u)=>{for(;(r=m.charCodeAt(u))<=32;)c.asi&&r===10&&(c.newline=!0),u++;return r},Rr=(r=u)=>{for(;m.charCodeAt(r)<=32;)r++;return m.charCodeAt(r)},Et=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,N=(r,e=r.length)=>m.substr(u,e)===r&&!c.id(m.charCodeAt(u+e)),P=()=>(h(),a(0,41)),I=[],j={},k=(r,e=32,t,n=r.charCodeAt(0),o=r.length,p=I[n],l=r.toUpperCase()!==r,f,A)=>(e=j[r]=!p&&j[r]||e,I[n]=(g,S,C,E=u)=>(f=C,(C?r==C:(o<2||r.charCodeAt(1)===m.charCodeAt(u+1)&&(o<3||m.substr(u,o)==r))&&(!l||!c.id(m.charCodeAt(u+o)))&&(f=C=r))&&S<e&&(u+=o,(A=t(g))?Nr(A,E):(u=E,f=0,!l&&!p&&R()),A)||p?.(g,S,f))),y=(r,e,t=!1)=>k(r,e,n=>n&&(o=>o&&[r,n,o])(a(e-(t?.5:0)))),_=(r,e,t)=>k(r,e,n=>t?n&&[r,n]:!n&&(n=a(e-.5))&&[r,n]),H=(r,e)=>k(r,200,t=>!t&&[,e]),fr=(r,e,t)=>k(r,e,(n,o)=>(o=a(e-(t?.5:0)),n?.[0]!==r&&(n=[r,n||null]),o?.[0]===r?n.push(...o.slice(1)):n.push(o||null),n)),W=(r,e)=>k(r[0],e,t=>!t&&[r,a(0,r.charCodeAt(1))||null]),lr=(r,e)=>k(r[0],e,t=>t&&[r,t,a(0,r.charCodeAt(1))||null]),w=(r,e,t,n=r.charCodeAt(0),o=r.length,p=I[n],l)=>I[n]=(f,A,g,S=u)=>!f&&(g?r==g:(o<2||m.substr(u,o)==r)&&(g=r))&&A<e&&!c.id(m.charCodeAt(u+o))&&(!c.prop||c.prop(u+o))&&(M(u+o),(l=t())?Nr(l,S):M(S),l)||p?.(f,A,g),pr={},s=(r,e,t=pr[r])=>pr[r]=(...n)=>e(...n)||t?.(...n),i=r=>Array.isArray(r)?r[0]==null?(e=>()=>e)(r[1]):pr[r[0]]?.(...r.slice(1))??R(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var q=46,z=48,x=57,ue=69,ce=101,me=43,de=45,Z=95,Or=110,ae=97,he=102,ye=65,Ae=70,_r=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),ur=r=>{let e=_r(T(t=>t===q&&m.charCodeAt(u+1)!==q||t>=z&&t<=x||t===Z||((t===ue||t===ce)&&((t=m.charCodeAt(u+1))>=z&&t<=x||t===me||t===de)?2:0)));return m.charCodeAt(u)===Or?(h(),[,BigInt(e)]):(r=+e)!=r?R():[,r]},ge={2:r=>r===48||r===49||r===Z,8:r=>r>=48&&r<=55||r===Z,16:r=>r>=z&&r<=x||r>=ae&&r<=he||r>=ye&&r<=Ae||r===Z};c.number=null;I[q]=r=>!r&&m.charCodeAt(u+1)!==q&&ur();for(let r=z;r<=x;r++)I[r]=e=>e?void 0:ur();I[z]=r=>{if(r)return;let e=c.number;if(e){for(let[t,n]of Object.entries(e))if(t[0]==="0"&&m[u+1]?.toLowerCase()===t[1]){h(2);let o=_r(T(ge[n]));return m.charCodeAt(u)===Or?(h(),[,BigInt("0"+t[1]+o)]):[,parseInt(o,n)]}}return ur()};var we=92,Pr=34,vr=39,Ee={n:`
5
+ `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Mr=r=>(e,t,n="")=>{if(!(e||!c.string?.[String.fromCharCode(r)]))return h(),T(o=>o-r&&(o===we?(n+=Ee[m[u+1]]||m[u+1],2):(n+=m[u],1))),m[u]===String.fromCharCode(r)?h():R("Bad string"),[,n]};I[Pr]=Mr(Pr);I[vr]=Mr(vr);c.string={'"':!0};var Ce=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>y(r,Ce,!0));var Br=(r,e,t,n)=>typeof r=="string"?o=>e(o,r,o):r[0]==="."?(t=i(r[1]),n=r[2],o=>e(t(o),n,o)):r[0]==="[]"&&r.length===3?(t=i(r[1]),n=i(r[2]),o=>e(t(o),n(o),o)):r[0]==="()"&&r.length===2?Br(r[1],e):(()=>{throw Error("Invalid assignment target")})(),Ur={"=":(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 Ur)s(r,(e,t)=>(t=i(t),Br(e,(n,o,p)=>Ur[r](n,o,t(p)))));var Se=30,ke=40,Lr=140;y("!",Lr);_("!",Lr);y("||",Se);y("&&",ke);s("!",r=>(r=i(r),e=>!r(e)));s("||",(r,e)=>(r=i(r),e=i(e),t=>r(t)||e(t)));s("&&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&&e(t)));var Ie=50,Te=60,Ne=70,Fr=100,Re=140;y("|",Ie);y("&",Ne);y("^",Te);y(">>",Fr);y("<<",Fr);_("~",Re);s("~",r=>(r=i(r),e=>~r(e)));s("|",(r,e)=>(r=i(r),e=i(e),t=>r(t)|e(t)));s("&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&e(t)));s("^",(r,e)=>(r=i(r),e=i(e),t=>r(t)^e(t)));s(">>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>e(t)));s("<<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<<e(t)));var b=90;y("<",b);y(">",b);y("<=",b);y(">=",b);s(">",(r,e)=>(r=i(r),e=i(e),t=>r(t)>e(t)));s("<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<e(t)));s(">=",(r,e)=>(r=i(r),e=i(e),t=>r(t)>=e(t)));s("<=",(r,e)=>(r=i(r),e=i(e),t=>r(t)<=e(t)));var Gr=80;y("==",Gr);y("!=",Gr);s("==",(r,e)=>(r=i(r),e=i(e),t=>r(t)==e(t)));s("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(t)));var Xr=110,cr=120,Dr=140;y("+",Xr);y("-",Xr);y("*",cr);y("/",cr);y("%",cr);_("+",Dr);_("-",Dr);s("+",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)+e(t)):(r=i(r),t=>+r(t)));s("-",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)-e(t)):(r=i(r),t=>-r(t)));s("*",(r,e)=>(r=i(r),e=i(e),t=>r(t)*e(t)));s("/",(r,e)=>(r=i(r),e=i(e),t=>r(t)/e(t)));s("%",(r,e)=>(r=i(r),e=i(e),t=>r(t)%e(t)));var rr=150;k("++",rr,r=>r?["++",r,null]:["++",a(rr-1)]);k("--",rr,r=>r?["--",r,null]:["--",a(rr-1)]);var mr=(r,e,t,n)=>typeof r=="string"?o=>e(o,r):r[0]==="."?(t=i(r[1]),n=r[2],o=>e(t(o),n)):r[0]==="[]"&&r.length===3?(t=i(r[1]),n=i(r[2]),o=>e(t(o),n(o))):r[0]==="()"&&r.length===2?mr(r[1],e):(()=>{throw Error("Invalid increment target")})();s("++",(r,e)=>mr(r,e===null?(t,n)=>t[n]++:(t,n)=>++t[n]));s("--",(r,e)=>mr(r,e===null?(t,n)=>t[n]--:(t,n)=>--t[n]));var Oe=5,_e=10;fr(",",_e);fr(";",Oe,!0);var Kr=(...r)=>(r=r.map(i),e=>{let t;for(let n of r)t=n(e);return t});s(",",Kr);s(";",Kr);var Pe=170;W("()",Pe);var F=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",dr=170;lr("[]",dr);y(".",dr);lr("()",dr);var er=r=>{throw Error(r)};s("[]",(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]),n=>t(n)):(t=i(t),n=>[t(n)])),t=>r.flatMap(n=>n(t))):(e==null&&er("Missing index"),r=i(r),e=i(e),t=>{let n=e(t);return F(n)?void 0:r(t)[n]}));s(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],F(e)?()=>{}:t=>r(t)[e]));s("()",(r,e)=>{if(e===void 0)return r==null?er("Empty ()"):i(r);let t=o=>o?.[0]===","&&o.slice(1).some(p=>p==null||t(p));t(e)&&er("Empty argument");let n=e?e[0]===","?(e=e.slice(1).map(i),o=>e.map(p=>p(o))):(e=i(e),o=>[e(o)]):()=>[];return ar(r,(o,p,l)=>o[p](...n(l)))});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]==="{}"),ar=(r,e,t,n)=>r==null?er("Empty ()"):r[0]==="()"&&r.length==2?ar(r[1],e):typeof r=="string"?o=>e(o,r,o):r[0]==="."?(t=i(r[1]),n=r[2],o=>e(t(o),n,o)):r[0]==="?."?(t=i(r[1]),n=r[2],o=>{let p=t(o);return p==null?void 0:e(p,n,o)}):r[0]==="[]"&&r.length===3?(t=i(r[1]),n=i(r[2]),o=>e(t(o),n(o),o)):r[0]==="?.[]"?(t=i(r[1]),n=i(r[2]),o=>{let p=t(o);return p==null?void 0:e(p,n(o),o)}):(r=i(r),o=>e([r(o)],0,o)),G=ar;var Qr=new WeakMap,ve=(r,...e)=>typeof r=="string"?i(c(r)):Qr.get(r)||Qr.set(r,Me(r,e)).get(r),$r=57344,Me=(r,e)=>{let t=r.reduce((p,l,f)=>p+(f?String.fromCharCode($r+f-1):"")+l,""),n=c(t),o=p=>{if(typeof p=="string"&&p.length===1){let l=p.charCodeAt(0)-$r,f;if(l>=0&&l<e.length)return f=e[l],Ue(f)?f:[,f]}return Array.isArray(p)?p.map(o):p};return i(o(n))},Ue=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Hr=ve;var Be=32,Le=c.space;c.comment??={"//":`
6
+ `,"/*":"*/"};var hr;c.space=()=>{hr||(hr=Object.entries(c.comment).map(([o,p])=>[o,p,o.charCodeAt(0)]));for(var r;r=Le();){for(var e=0,t;t=hr[e++];)if(r===t[2]&&m.substr(u,t[0].length)===t[0]){var n=u+t[0].length;if(t[1]===`
7
+ `)for(;m.charCodeAt(n)>=Be;)n++;else{for(;m[n]&&m.substr(n,t[1].length)!==t[1];)n++;m[n]&&(n+=t[1].length)}M(n),r=0;break}if(r)return r}return r};var jr=80;y("===",jr);y("!==",jr);s("===",(r,e)=>(r=i(r),e=i(e),t=>r(t)===e(t)));s("!==",(r,e)=>(r=i(r),e=i(e),t=>r(t)!==e(t)));var Fe=30;y("??",Fe);s("??",(r,e)=>(r=i(r),e=i(e),t=>r(t)??e(t)));var Ge=130,Xe=20;y("**",Ge,!0);y("**=",Xe,!0);s("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));var De=r=>{throw Error(r)};s("**=",(r,e)=>(U(r)||De("Invalid assignment target"),e=i(e),G(r,(t,n,o)=>t[n]**=e(o))));var Wr=90;y("in",Wr);y("of",Wr);s("in",(r,e)=>(r=i(r),e=i(e),t=>r(t)in e(t)));var Ke=20,Qe=100,$e=r=>{throw Error(r)};y(">>>",Qe);y(">>>=",Ke,!0);s(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));s(">>>=",(r,e)=>(U(r)||$e("Invalid assignment target"),e=i(e),G(r,(t,n,o)=>t[n]>>>=e(o))));var yr=5,He=10,je=20,We=r=>r[0]?.[0]===","?r[0].slice(1):r,D=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[n,...o]=r,p=We(o);if(n==="{}"){let l=[];for(let f of p){if(Array.isArray(f)&&f[0]==="..."){let E={};for(let O in e)l.includes(O)||(E[O]=e[O]);t[f[1]]=E;break}let A,g,S;typeof f=="string"?A=g=f:f[0]==="="?(typeof f[1]=="string"?A=g=f[1]:[,A,g]=f[1],S=f[2]):[,A,g]=f,l.push(A);let C=e[A];C===void 0&&S&&(C=i(S)(t)),D(g,C,t)}}else if(n==="[]"){let l=0;for(let f of p){if(f===null){l++;continue}if(Array.isArray(f)&&f[0]==="..."){t[f[1]]=e.slice(l);break}let A=f,g;Array.isArray(f)&&f[0]==="="&&([,A,g]=f);let S=e[l++];S===void 0&&g&&(S=i(g)(t)),D(A,S,t)}}},zr=r=>{let e=a(He-1);return e?.[0]==="in"||e?.[0]==="of"?[e[0],[r,e[1]],e[2]]:e?.[0]===","?[r,...e.slice(1)]:[r,e]};w("let",yr+1,()=>zr("let"));w("const",yr+1,()=>zr("const"));w("var",yr,()=>(d(),["var",a(je)]));var Jr=(...r)=>(r=r.map(e=>{if(typeof e=="string")return t=>{t[e]=void 0};if(e[0]==="="){let[,t,n]=e,o=i(n);return typeof t=="string"?p=>{p[t]=o(p)}:p=>D(t,o(p),p)}return i(e)}),e=>{for(let t of r)t(e)});s("let",Jr);s("const",Jr);s("var",r=>typeof r=="string"?e=>{e[r]=void 0}:()=>{});var Ar=20,tr=r=>{throw Error(r)};y("||=",Ar,!0);y("&&=",Ar,!0);y("??=",Ar,!0);s("=",(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"?n=>{n[t]=e(n)}:n=>D(t,e(n),n)}return U(r)||tr("Invalid assignment target"),e=i(e),G(r,(t,n,o)=>t[n]=e(o))});s("||=",(r,e)=>(U(r)||tr("Invalid assignment target"),e=i(e),G(r,(t,n,o)=>t[n]||=e(o))));s("&&=",(r,e)=>(U(r)||tr("Invalid assignment target"),e=i(e),G(r,(t,n,o)=>t[n]&&=e(o))));s("??=",(r,e)=>(U(r)||tr("Invalid assignment target"),e=i(e),G(r,(t,n,o)=>t[n]??=e(o))));H("true",!0);H("false",!1);H("null",null);w("undefined",200,()=>[]);H("NaN",NaN);H("Infinity",1/0);var gr=20;k("?",gr,(r,e,t)=>r&&(e=a(gr-1))&&T(n=>n===58)&&(t=a(gr-1),["?",r,e,t]));s("?",(r,e,t)=>(r=i(r),e=i(e),t=i(t),n=>r(n)?e(n):t(n)));var v=[],ze=20;y("=>",ze,!0);s("=>",(r,e)=>{r=r?.[0]==="()"?r[1]:r;let t=r?r[0]===","?r.slice(1):[r]:[],n=-1,o=null,p=t[t.length-1];Array.isArray(p)&&p[0]==="..."&&(n=t.length-1,o=p[1],t.length--);let l=e?.[0]==="{}";return e=i(l?["{",e[1]]:e),f=>(...A)=>{let g={};t.forEach((C,E)=>g[C]=A[E]),o&&(g[o]=A.slice(n));let S=new Proxy(g,{get:(C,E)=>E in C?C[E]:f?.[E],set:(C,E,O)=>((E in C?C:f)[E]=O,!0),has:(C,E)=>E in C||(f?E in f:!1)});try{let C=e(S);return l?void 0:C}catch(C){if(C===v)return C[0];throw C}}});var Je=140;_("...",Je);s("...",r=>(r=i(r),e=>Object.entries(r(e))));var Vr=170;k("?.",Vr,(r,e)=>{if(!r)return;let t=d();return t===40?(h(),["?.()",r,a(0,41)||null]):t===91?(h(),["?.[]",r,a(0,93)]):(e=a(Vr),e?["?.",r,e]:void 0)});s("?.",(r,e)=>(r=i(r),F(e)?()=>{}:t=>r(t)?.[e]));s("?.[]",(r,e)=>(r=i(r),e=i(e),t=>{let n=e(t);return F(n)?void 0:r(t)?.[n]}));s("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(i),o=>e.map(p=>p(o))):(e=i(e),o=>[e(o)]):()=>[];if(r[0]==="?."){let o=i(r[1]),p=r[2];return F(p)?()=>{}:l=>o(l)?.[p]?.(...t(l))}if(r[0]==="?.[]"){let o=i(r[1]),p=i(r[2]);return l=>{let f=o(l),A=p(l);return F(A)?void 0:f?.[A]?.(...t(l))}}if(r[0]==="."){let o=i(r[1]),p=r[2];return F(p)?()=>{}:l=>o(l)?.[p]?.(...t(l))}if(r[0]==="[]"&&r.length===3){let o=i(r[1]),p=i(r[2]);return l=>{let f=o(l),A=p(l);return F(A)?void 0:f?.[A]?.(...t(l))}}let n=i(r);return o=>n(o)?.(...t(o))});var J=140;_("typeof",J);_("void",J);_("delete",J);w("new",J,()=>N(".target")?(h(7),["new.target"]):["new",a(J)]);s("typeof",r=>(r=i(r),e=>typeof r(e)));s("void",r=>(r=i(r),e=>(r(e),void 0)));s("delete",r=>{if(r[0]==="."){let e=i(r[1]),t=r[2];return n=>delete e(n)[t]}if(r[0]==="[]"){let e=i(r[1]),t=i(r[2]);return n=>delete e(n)[t(n)]}return()=>!0});s("new",r=>{let e=i(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,n=t?t[0]===","?(o=>p=>o.map(l=>l(p)))(t.slice(1).map(i)):(o=>p=>[o(p)])(i(t)):()=>[];return o=>new(e(o))(...n(o))});var nr=Symbol("accessor"),wr=20,Ve=40,Yr=41,Zr=123,qr=125,xr=r=>e=>{if(e)return;d();let t=T(c.id);if(!t||(d(),m.charCodeAt(u)!==Ve))return!1;h();let n=a(0,Yr);return d(),m.charCodeAt(u)!==Zr?!1:(h(),[r,t,n,a(0,qr)])};k("get",wr-1,xr("get"));k("set",wr-1,xr("set"));k("(",wr-1,r=>{if(!r||typeof r!="string")return;let e=a(0,Yr)||null;if(d(),m.charCodeAt(u)===Zr)return h(),[":",r,["=>",["()",e],a(0,qr)||null]]});s("get",(r,e)=>(e=e?i(e):()=>{},t=>[[nr,r,{get:function(){let n=Object.create(t||{});return n.this=this,e(n)}}]]));s("set",(r,e,t)=>(t=t?i(t):()=>{},n=>[[nr,r,{set:function(o){let p=Object.create(n||{});p.this=this,p[e]=o,t(p)}}]]));var Ye=20,br=200;c.prop=r=>Rr(r)!==58;var Ze=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);W("[]",br);W("{}",br);y(":",Ye-1,!0);s("{}",(r,e)=>{if(e!==void 0)return;if(!Ze(r))return i(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(n=>i(typeof n=="string"?[":",n,n]:n));return n=>{let o={},p={};for(let l of t.flatMap(f=>f(n)))if(l[0]===nr){let[,f,A]=l;p[f]={...p[f],...A,configurable:!0,enumerable:!0}}else o[l[0]]=l[1];for(let l in p)Object.defineProperty(o,l,p[l]);return o}});s("{",r=>(r=r?i(r):()=>{},e=>r(Object.create(e))));s(":",(r,e)=>(e=i(e),Array.isArray(r)?(r=i(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));var qe=170,or=96,xe=36,be=123,rt=92,et={n:`
8
+ `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},re=()=>{let r=[];for(let e="",t;(t=m.charCodeAt(u))!==or;)t?t===rt?(h(),e+=et[m[u]]||m[u],h()):t===xe&&m.charCodeAt(u+1)===be?(e&&r.push([,e]),e="",h(2),r.push(a(0,125))):(e+=m[u],h(),t=m.charCodeAt(u),t===or&&e&&r.push([,e])):R("Unterminated template");return h(),r},tt=I[or];I[or]=(r,e)=>r&&e<qe?c.asi&&c.newline?void 0:(h(),["``",r,...re()]):r?tt?.(r,e):(h(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(re()));s("`",(...r)=>(r=r.map(i),e=>r.map(t=>t(e)).join("")));s("``",(r,...e)=>{r=i(r);let t=[],n=[];for(let p of e)Array.isArray(p)&&p[0]===void 0?t.push(p[1]):n.push(i(p));let o=Object.assign([...t],{raw:t});return p=>r(p)(o,...n.map(l=>l(p)))});c.string["'"]=!0;c.number={"0x":16,"0b":2,"0o":8};var ir=5,nt=59,B=()=>(d()===123||R("Expected {"),h(),a(ir-.5,125)||null),X=()=>d()!==123?a(ir+.5):(h(),a(ir-.5,125)||null),ot=()=>{let r=u,e=c.space||d;return e()===nt&&h(),e(),N("else")?(h(4),!0):(M(r),!1)};w("if",ir+1,()=>{d();let r=["if",P(),X()];return ot()&&r.push(X()),r});s("if",(r,e,t)=>(r=i(r),e=i(e),t=t!==void 0?i(t):null,n=>r(n)?e(n):t?.(n)));var it=200;w("function",it,()=>{d();let r=!1;m[u]==="*"&&(r=!0,h(),d());let e=T(c.id);return e&&d(),r?["function*",e,P()||null,B()]:["function",e,P()||null,B()]});s("function",(r,e,t)=>{t=t?i(t):()=>{};let n=e?e[0]===","?e.slice(1):[e]:[],o=null,p=-1,l=n[n.length-1];return Array.isArray(l)&&l[0]==="..."&&(p=n.length-1,o=l[1],n.length--),f=>{let A=(...g)=>{let S={};n.forEach((E,O)=>S[E]=g[O]),o&&(S[o]=g.slice(p));let C=new Proxy(S,{get:(E,O)=>O in E?E[O]:f[O],set:(E,O,le)=>((O in E?E:f)[O]=le,!0),has:(E,O)=>O in E||O in f});try{return t(C)}catch(E){if(E===v)return E[0];throw E}};return r&&(f[r]=A),A}});s("function*",(r,e,t)=>{throw Error("Generator functions are not supported in evaluation")});var sr=140,Er=20;_("await",sr);w("yield",sr,()=>(d(),m[u]==="*"?(h(),d(),["yield*",a(Er)]):["yield",a(Er)]));w("async",sr,()=>{if(d(),N("function"))return["async",a(sr)];let r=a(Er-.5);return r&&["async",r]});s("async",r=>{let e=i(r);return t=>{let n=e(t);return async function(...o){return n(...o)}}});s("await",r=>(r=i(r),async e=>await r(e)));s("yield",r=>(r=r?i(r):null,e=>{throw{__yield__:r?r(e):void 0}}));s("yield*",r=>(r=i(r),e=>{throw{__yield_all__:r(e)}}));var Cr=200,st=140,pt=90,ft=Symbol("static");_("static",st);y("instanceof",pt);k("#",Cr,r=>{if(r)return;let e=T(c.id);return e?"#"+e:void 0});w("class",Cr,()=>{d();let r=T(c.id)||null;if(r==="extends")r=null,d();else{if(d(),!N("extends"))return["class",r,null,B()];h(7),d()}return["class",r,a(Cr),B()]});var lt=r=>{throw Error(r)};s("instanceof",(r,e)=>(r=i(r),e=i(e),t=>r(t)instanceof e(t)));s("class",(r,e,t)=>(e=e?i(e):null,t=t?i(t):null,n=>{let o=e?e(n):Object,p=function(...l){if(!(this instanceof p))return lt("Class constructor must be called with new");let f=e?Reflect.construct(o,l,p):this;return p.prototype.__constructor__&&p.prototype.__constructor__.apply(f,l),f};if(Object.setPrototypeOf(p.prototype,o.prototype),Object.setPrototypeOf(p,o),t){let l=Object.create(n);l.super=o;let f=t(l),A=Array.isArray(f)&&typeof f[0]?.[0]=="string"?f:[];for(let[g,S]of A)g==="constructor"?p.prototype.__constructor__=S:p.prototype[g]=S}return r&&(n[r]=p),p}));s("static",r=>(r=i(r),e=>[[ft,r(e)]]));var ut=140,Sr=47,ct=92,mt=r=>r===ct?2:r&&r!==Sr,dt=r=>r===103||r===105||r===109||r===115||r===117||r===121;k("/",ut,r=>{if(r)return;let e=m.charCodeAt(u);if(e===Sr||e===42||e===43||e===63||e===61)return;let t=T(mt);m.charCodeAt(u)===Sr||R("Unterminated regex"),h();let n=T(dt);try{new RegExp(t,n)}catch(o){R("Invalid regex: "+o.message)}return n?["//",t,n]:["//",t]});s("//",(r,e)=>{let t=new RegExp(r,e||"");return()=>t});var L=Symbol("break"),K=Symbol("continue"),Q=5,V=125,Y=59;w("while",Q+1,()=>(d(),["while",P(),X()]));w("do",Q+1,()=>(r=>(d(),h(5),d(),["do",r,P()]))(X()));w("for",Q+1,()=>(d(),N("await")?(h(5),d(),["for await",P(),X()]):["for",P(),X()]));w("break",Q+1,()=>{c.asi&&(c.newline=!1);let r=u;d();let e=m.charCodeAt(u);if(!e||e===V||e===Y||c.newline)return["break"];let t=T(c.id);if(!t)return["break"];d();let n=m.charCodeAt(u);return!n||n===V||n===Y||c.newline?["break",t]:(M(r),["break"])});w("continue",Q+1,()=>{c.asi&&(c.newline=!1);let r=u;d();let e=m.charCodeAt(u);if(!e||e===V||e===Y||c.newline)return["continue"];let t=T(c.id);if(!t)return["continue"];d();let n=m.charCodeAt(u);return!n||n===V||n===Y||c.newline?["continue",t]:(M(r),["continue"])});w("return",Q+1,()=>{c.asi&&(c.newline=!1);let r=d();return!r||r===V||r===Y||c.newline?["return"]:["return",a(Q)]});s("while",(r,e)=>(r=i(r),e=i(e),t=>{let n;for(;r(t);)try{n=e(t)}catch(o){if(o===L)break;if(o===K)continue;if(o===v)return o[0];throw o}return n}));s("do",(r,e)=>(r=i(r),e=i(e),t=>{let n;do try{n=r(t)}catch(o){if(o===L)break;if(o===K)continue;if(o===v)return o[0];throw o}while(e(t));return n}));s("for",(r,e)=>{if(Array.isArray(r)&&r[0]===";"){let[,t,n,o]=r;return t=t?i(t):null,n=n?i(n):()=>!0,o=o?i(o):null,e=i(e),p=>{let l;for(t?.(p);n(p);o?.(p))try{l=e(p)}catch(f){if(f===L)break;if(f===K)continue;if(f===v)return f[0];throw f}return l}}if(Array.isArray(r)&&(r[0]==="in"||r[0]==="of")){let[t,n,o]=r;if(Array.isArray(n)&&(n[0]==="let"||n[0]==="const"||n[0]==="var")&&(n=n[1]),t==="in")return ht(n,o,e);if(t==="of")return at(n,o,e)}});var at=(r,e,t)=>{e=i(e),t=i(t);let n=Array.isArray(r);return o=>{let p,l=n?null:o[r];for(let f of e(o)){n?D(r,f,o):o[r]=f;try{p=t(o)}catch(A){if(A===L)break;if(A===K)continue;if(A===v)return A[0];throw A}}return n||(o[r]=l),p}},ht=(r,e,t)=>{e=i(e),t=i(t);let n=Array.isArray(r);return o=>{let p,l=n?null:o[r];for(let f in e(o)){n?D(r,f,o):o[r]=f;try{p=t(o)}catch(A){if(A===L)break;if(A===K)continue;if(A===v)return A[0];throw A}}return n||(o[r]=l),p}};s("break",()=>()=>{throw L});s("continue",()=>()=>{throw K});s("return",r=>(r=r!==void 0?i(r):null,e=>{throw v[0]=r?.(e),v}));var kr=5;w("try",kr+1,()=>{let r=["try",B()];return d(),N("catch")&&(h(5),d(),r.push(["catch",P(),B()])),d(),N("finally")&&(h(7),r.push(["finally",B()])),r});w("throw",kr+1,()=>{if(c.asi&&(c.newline=!1),d(),c.newline)throw SyntaxError("Unexpected newline after throw");return["throw",a(kr)]});s("try",(r,...e)=>{r=r?i(r):null;let t=e.find(f=>f?.[0]==="catch"),n=e.find(f=>f?.[0]==="finally"),o=t?.[1],p=t?.[2]?i(t[2]):null,l=n?.[1]?i(n[1]):null;return f=>{let A;try{A=r?.(f)}catch(g){if(g===L||g===K||g===v)throw g;if(o!=null&&p){let S=o in f,C=f[o];f[o]=g;try{A=p(f)}finally{S?f[o]=C:delete f[o]}}else if(!p)throw g}finally{l?.(f)}return A}});s("throw",r=>(r=i(r),e=>{throw r(e)}));var ne=5,yt=20,ee=58,At=59,oe=125,Ir=0,ie=(r,e=r.length,t=r.charCodeAt(0),n=I[t])=>I[t]=(o,p,l)=>N(r)&&!o&&Ir||n?.(o,p,l);ie("case");ie("default");var te=r=>{let e=[];for(;(r=d())!==oe&&!N("case")&&!N("default");){if(r===At){h();continue}e.push(a(ne-.5))||R()}return e.length>1?[";",...e]:e[0]||null},gt=()=>{d()===123||R("Expected {"),h(),Ir++;let r=[];try{for(;d()!==oe;)if(N("case")){M(u+4),d();let e=a(yt-.5);d()===ee&&h(),r.push(["case",e,te()])}else N("default")?(M(u+7),d()===ee&&h(),r.push(["default",te()])):R("Expected case or default")}finally{Ir--}return h(),r};w("switch",ne+1,()=>d()===40&&["switch",P(),...gt()]);s("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 n=r(t),o=!1,p;for(let[f,A]of e)if(o||f===null||f(t)===n)for(o=!0,l=0;l<A.length;l++)try{p=A[l](t)}catch(g){if(g===L)return p;throw g}var l;return p}):t=>r(t)));var se=5;w("debugger",se+1,()=>["debugger"]);w("with",se+1,()=>(d(),["with",P(),X()]));var Tr=5,$=10,pe=42,wt=I[pe];I[pe]=(r,e)=>r?wt?.(r,e):(h(),"*");k("from",$+1,r=>r?r[0]!=="="&&r[0]!==","&&(d(),["from",r,a($+1)]):!1);k("as",$+2,r=>r?(d(),["as",r,a($+2)]):!1);w("import",Tr,()=>N(".meta")?(h(5),["import.meta"]):["import",a($)]);w("export",Tr,()=>(d(),["export",a(Tr)]));w("default",$+1,()=>d()!==58&&(d(),["default",a($)]));s("import",()=>()=>{});s("export",()=>()=>{});s("from",(r,e)=>()=>{});s("as",(r,e)=>()=>{});s("default",r=>i(r));var fe=j.asi??j[";"];c.asi=(r,e,t,n,o)=>e<fe&&(n=t(fe-.5))&&(o=n?.[0]===";"?n.slice(1):[n],r?.[0]===";"?(r.push(...o),r):[";",r,...o]);export{lr as access,y as binary,i as compile,m as cur,Hr as default,R as err,a as expr,W as group,Et as id,u as idx,w as keyword,H as literal,Nr as loc,I as lookup,fr as nary,T as next,s as operator,pr as operators,P as parens,c as parse,Rr as peek,j as prec,M as seek,h as skip,d as space,k as token,_ as unary,N as word};
package/justin.min.js CHANGED
@@ -1,8 +1,8 @@
1
- var m,c,d=r=>(m=0,c=r,d.newline=!1,r=A(),c[m]?N():r||""),N=(r="Unexpected token",e=m,t=c.slice(0,e).split(`
2
- `),o=t.pop(),i=c.slice(Math.max(0,e-40),e),p="\u032D",l=(c[e]||" ")+p,f=c.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
1
+ var l,c,d=r=>(l=0,c=r,d.newline=!1,r=A(),c[l]?a():r||""),a=(r="Unexpected token",e=l,t=c.slice(0,e).split(`
2
+ `),n=t.pop(),i=c.slice(Math.max(0,e-40),e),p="\u032D",f=(c[e]||" ")+p,u=c.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${n.length+1}
3
3
  ${c[e-41]!==`
4
- `,""+i}${l}${f}`)},V=(r,e=m)=>(Array.isArray(r)&&(r.loc=e),r),R=(r,e=m,t)=>{for(;t=r(c.charCodeAt(m));)m+=t;return c.slice(e,m)},h=(r=1)=>c[m+=r],U=r=>m=r,A=(r=0,e)=>{let t,o,i,p,l;for(e&&d.asi&&(d.newline=!1);(t=d.space())&&(l=d.newline,1)&&t!==e&&(i=((p=w[t])&&p(o,r))??(o&&l&&d.asi?.(o,r,A))??(!o&&R(d.id)));)o=i;return e&&(t==e?m++:N("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},v=d.space=(r,e=m)=>{for(;(r=c.charCodeAt(m))<=32;)d.asi&&r===10&&(d.newline=!0),m++;return r},pr=(r=m)=>{for(;c.charCodeAt(r)<=32;)r++;return c.charCodeAt(r)},Te=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,lr=(r,e=r.length)=>c.substr(m,e)===r&&!d.id(c.charCodeAt(m+e)),ae=()=>(h(),A(0,41)),w=[],sr={},E=(r,e=32,t,o=r.charCodeAt(0),i=r.length,p=w[o],l=r.toUpperCase()!==r,f,g)=>(e=sr[r]=!p&&sr[r]||e,w[o]=(C,I,y,S=m)=>(f=y,(y?r==y:(i<2||r.charCodeAt(1)===c.charCodeAt(m+1)&&(i<3||c.substr(m,i)==r))&&(!l||!d.id(c.charCodeAt(m+i)))&&(f=y=r))&&I<e&&(m+=i,(g=t(C))?V(g,S):(m=S,f=0,!l&&!p&&N()),g)||p?.(C,I,f))),u=(r,e,t=!1)=>E(r,e,o=>o&&(i=>i&&[r,o,i])(A(e-(t?.5:0)))),k=(r,e,t)=>E(r,e,o=>t?o&&[r,o]:!o&&(o=A(e-.5))&&[r,o]),P=(r,e)=>E(r,200,t=>!t&&[,e]),Y=(r,e,t)=>E(r,e,(o,i)=>(i=A(e-(t?.5:0)),o?.[0]!==r&&(o=[r,o||null]),i?.[0]===r?o.push(...i.slice(1)):o.push(i||null),o)),_=(r,e)=>E(r[0],e,t=>!t&&[r,A(0,r.charCodeAt(1))||null]),Z=(r,e)=>E(r[0],e,t=>t&&[r,t,A(0,r.charCodeAt(1))||null]),J={},s=(r,e,t=J[r])=>J[r]=(...o)=>e(...o)||t?.(...o),n=r=>Array.isArray(r)?r[0]==null?(e=>()=>e)(r[1]):J[r[0]]?.(...r.slice(1))??N(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var F=46,B=48,G=57,_r=69,Br=101,Mr=43,Dr=45,D=95,Fr=110,Gr=97,Xr=102,$r=65,Qr=70,fr=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),q=r=>{let e=fr(R(t=>t===F&&c.charCodeAt(m+1)!==F||t>=B&&t<=G||t===D||((t===_r||t===Br)&&((t=c.charCodeAt(m+1))>=B&&t<=G||t===Mr||t===Dr)?2:0)));return c.charCodeAt(m)===Fr?(h(),[,BigInt(e)]):(r=+e)!=r?N():[,r]},Hr={2:r=>r===48||r===49||r===D,8:r=>r>=48&&r<=55||r===D,16:r=>r>=B&&r<=G||r>=Gr&&r<=Xr||r>=$r&&r<=Qr||r===D};d.number=null;w[F]=r=>!r&&c.charCodeAt(m+1)!==F&&q();for(let r=B;r<=G;r++)w[r]=e=>e?void 0:q();w[B]=r=>{if(r)return;let e=d.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&c[m+1]?.toLowerCase()===t[1])return h(2),[,parseInt(fr(R(Hr[o])),o)]}return q()};var Kr=92,mr=34,ur=39,jr={n:`
5
- `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},cr=r=>(e,t,o="")=>{if(!(e||!d.string?.[String.fromCharCode(r)]))return h(),R(i=>i-r&&(i===Kr?(o+=jr[c[m+1]]||c[m+1],2):(o+=c[m],1))),c[m]===String.fromCharCode(r)?h():N("Bad string"),[,o]};w[mr]=cr(mr);w[ur]=cr(ur);d.string={'"':!0};var Wr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>u(r,Wr,!0));var Ar=(r,e,t,o)=>typeof r=="string"?i=>e(i,r,i):r[0]==="."?(t=n(r[1]),o=r[2],i=>e(t(i),o,i)):r[0]==="[]"&&r.length===3?(t=n(r[1]),o=n(r[2]),i=>e(t(i),o(i),i)):r[0]==="()"&&r.length===2?Ar(r[1],e):(()=>{throw Error("Invalid assignment target")})(),dr={"=":(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 dr)s(r,(e,t)=>(t=n(t),Ar(e,(o,i,p)=>dr[r](o,i,t(p)))));var zr=30,Jr=40,gr=140;u("!",gr);k("!",gr);u("||",zr);u("&&",Jr);s("!",r=>(r=n(r),e=>!r(e)));s("||",(r,e)=>(r=n(r),e=n(e),t=>r(t)||e(t)));s("&&",(r,e)=>(r=n(r),e=n(e),t=>r(t)&&e(t)));var Vr=50,Yr=60,Zr=70,hr=100,qr=140;u("|",Vr);u("&",Zr);u("^",Yr);u(">>",hr);u("<<",hr);k("~",qr);s("~",r=>(r=n(r),e=>~r(e)));s("|",(r,e)=>(r=n(r),e=n(e),t=>r(t)|e(t)));s("&",(r,e)=>(r=n(r),e=n(e),t=>r(t)&e(t)));s("^",(r,e)=>(r=n(r),e=n(e),t=>r(t)^e(t)));s(">>",(r,e)=>(r=n(r),e=n(e),t=>r(t)>>e(t)));s("<<",(r,e)=>(r=n(r),e=n(e),t=>r(t)<<e(t)));var X=90;u("<",X);u(">",X);u("<=",X);u(">=",X);s(">",(r,e)=>(r=n(r),e=n(e),t=>r(t)>e(t)));s("<",(r,e)=>(r=n(r),e=n(e),t=>r(t)<e(t)));s(">=",(r,e)=>(r=n(r),e=n(e),t=>r(t)>=e(t)));s("<=",(r,e)=>(r=n(r),e=n(e),t=>r(t)<=e(t)));var yr=80;u("==",yr);u("!=",yr);s("==",(r,e)=>(r=n(r),e=n(e),t=>r(t)==e(t)));s("!=",(r,e)=>(r=n(r),e=n(e),t=>r(t)!=e(t)));var Cr=110,x=120,Sr=140;u("+",Cr);u("-",Cr);u("*",x);u("/",x);u("%",x);k("+",Sr);k("-",Sr);s("+",(r,e)=>e!==void 0?(r=n(r),e=n(e),t=>r(t)+e(t)):(r=n(r),t=>+r(t)));s("-",(r,e)=>e!==void 0?(r=n(r),e=n(e),t=>r(t)-e(t)):(r=n(r),t=>-r(t)));s("*",(r,e)=>(r=n(r),e=n(e),t=>r(t)*e(t)));s("/",(r,e)=>(r=n(r),e=n(e),t=>r(t)/e(t)));s("%",(r,e)=>(r=n(r),e=n(e),t=>r(t)%e(t)));var $=150;E("++",$,r=>r?["++",r,null]:["++",A($-1)]);E("--",$,r=>r?["--",r,null]:["--",A($-1)]);var b=(r,e,t,o)=>typeof r=="string"?i=>e(i,r):r[0]==="."?(t=n(r[1]),o=r[2],i=>e(t(i),o)):r[0]==="[]"&&r.length===3?(t=n(r[1]),o=n(r[2]),i=>e(t(i),o(i))):r[0]==="()"&&r.length===2?b(r[1],e):(()=>{throw Error("Invalid increment target")})();s("++",(r,e)=>b(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));s("--",(r,e)=>b(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var xr=5,br=10,re=170;_("()",re);Y(",",br);Y(";",xr,!0);var Er=(...r)=>(r=r.map(n),e=>{let t;for(let o of r)t=o(e);return t});s(",",Er);s(";",Er);var a=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",rr=170;Z("[]",rr);u(".",rr);Z("()",rr);var Q=r=>{throw Error(r)};s("[]",(r,e)=>e===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(t=>t==null?(()=>{}):t[0]==="..."?(t=n(t[1]),o=>t(o)):(t=n(t),o=>[t(o)])),t=>r.flatMap(o=>o(t))):(e==null&&Q("Missing index"),r=n(r),e=n(e),t=>{let o=e(t);return a(o)?void 0:r(t)[o]}));s(".",(r,e)=>(r=n(r),e=e[0]?e:e[1],a(e)?()=>{}:t=>r(t)[e]));s("()",(r,e)=>{if(e===void 0)return r==null?Q("Empty ()"):n(r);let t=i=>i?.[0]===","&&i.slice(1).some(p=>p==null||t(p));t(e)&&Q("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(n),i=>e.map(p=>p(i))):(e=n(e),i=>[e(i)]):()=>[];return er(r,(i,p,l)=>i[p](...o(l)))});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]==="{}"),er=(r,e,t,o)=>r==null?Q("Empty ()"):r[0]==="()"&&r.length==2?er(r[1],e):typeof r=="string"?i=>e(i,r,i):r[0]==="."?(t=n(r[1]),o=r[2],i=>e(t(i),o,i)):r[0]==="?."?(t=n(r[1]),o=r[2],i=>{let p=t(i);return p==null?void 0:e(p,o,i)}):r[0]==="[]"&&r.length===3?(t=n(r[1]),o=n(r[2]),i=>e(t(i),o(i),i)):r[0]==="?.[]"?(t=n(r[1]),o=n(r[2]),i=>{let p=t(i);return p==null?void 0:e(p,o(i),i)}):(r=n(r),i=>e([r(i)],0,i)),O=er;var wr=new WeakMap,ee=(r,...e)=>typeof r=="string"?n(d(r)):wr.get(r)||wr.set(r,te(r,e)).get(r),Ir=57344,te=(r,e)=>{let t=r.reduce((p,l,f)=>p+(f?String.fromCharCode(Ir+f-1):"")+l,""),o=d(t),i=p=>{if(typeof p=="string"&&p.length===1){let l=p.charCodeAt(0)-Ir,f;if(l>=0&&l<e.length)return f=e[l],oe(f)?f:[,f]}return Array.isArray(p)?p.map(i):p};return n(i(o))},oe=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),ne=ee;var ie=32,se=d.space;d.comment??={"//":`
6
- `,"/*":"*/"};var tr;d.space=()=>{tr||(tr=Object.entries(d.comment).map(([i,p])=>[i,p,i.charCodeAt(0)]));for(var r;r=se();){for(var e=0,t;t=tr[e++];)if(r===t[2]&&c.substr(m,t[0].length)===t[0]){var o=m+t[0].length;if(t[1]===`
7
- `)for(;c.charCodeAt(o)>=ie;)o++;else{for(;c[o]&&c.substr(o,t[1].length)!==t[1];)o++;c[o]&&(o+=t[1].length)}U(o),r=0;break}if(r)return r}return r};var kr=80;u("===",kr);u("!==",kr);s("===",(r,e)=>(r=n(r),e=n(e),t=>r(t)===e(t)));s("!==",(r,e)=>(r=n(r),e=n(e),t=>r(t)!==e(t)));var pe=30;u("??",pe);s("??",(r,e)=>(r=n(r),e=n(e),t=>r(t)??e(t)));var le=130,fe=20;u("**",le,!0);u("**=",fe,!0);s("**",(r,e)=>(r=n(r),e=n(e),t=>r(t)**e(t)));var me=r=>{throw Error(r)};s("**=",(r,e)=>(T(r)||me("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]**=e(i))));var Nr=90;u("in",Nr);u("of",Nr);s("in",(r,e)=>(r=n(r),e=n(e),t=>r(t)in e(t)));var ue=20,ce=100,de=r=>{throw Error(r)};u(">>>",ce);u(">>>=",ue,!0);s(">>>",(r,e)=>(r=n(r),e=n(e),t=>r(t)>>>e(t)));s(">>>=",(r,e)=>(T(r)||de("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]>>>=e(i))));var Ae=r=>r[0]?.[0]===","?r[0].slice(1):r,H=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...i]=r,p=Ae(i);if(o==="{}"){let l=[];for(let f of p){if(Array.isArray(f)&&f[0]==="..."){let S={};for(let L in e)l.includes(L)||(S[L]=e[L]);t[f[1]]=S;break}let g,C,I;typeof f=="string"?g=C=f:f[0]==="="?(typeof f[1]=="string"?g=C=f[1]:[,g,C]=f[1],I=f[2]):[,g,C]=f,l.push(g);let y=e[g];y===void 0&&I&&(y=n(I)(t)),H(C,y,t)}}else if(o==="[]"){let l=0;for(let f of p){if(f===null){l++;continue}if(Array.isArray(f)&&f[0]==="..."){t[f[1]]=e.slice(l);break}let g=f,C;Array.isArray(f)&&f[0]==="="&&([,g,C]=f);let I=e[l++];I===void 0&&C&&(I=n(C)(t)),H(g,I,t)}}};var or=20,K=r=>{throw Error(r)};u("||=",or,!0);u("&&=",or,!0);u("??=",or,!0);s("=",(r,e)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let t=r[1];return e=n(e),typeof t=="string"?o=>{o[t]=e(o)}:o=>H(t,e(o),o)}return T(r)||K("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]=e(i))});s("||=",(r,e)=>(T(r)||K("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]||=e(i))));s("&&=",(r,e)=>(T(r)||K("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]&&=e(i))));s("??=",(r,e)=>(T(r)||K("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]??=e(i))));var j=(r,e,t,o=r.charCodeAt(0),i=r.length,p=w[o],l)=>w[o]=(f,g,C,I=m)=>!f&&(C?r==C:(i<2||c.substr(m,i)==r)&&(C=r))&&g<e&&!d.id(c.charCodeAt(m+i))&&pr(m+i)!==58&&(U(m+i),(l=t())?V(l,I):U(I),l)||p?.(f,g,C);P("true",!0);P("false",!1);P("null",null);j("undefined",200,()=>[]);P("NaN",NaN);P("Infinity",1/0);var nr=20;E("?",nr,(r,e,t)=>r&&(e=A(nr-1))&&R(o=>o===58)&&(t=A(nr-1),["?",r,e,t]));s("?",(r,e,t)=>(r=n(r),e=n(e),t=n(t),o=>r(o)?e(o):t(o)));var Rr=[];var ge=20;u("=>",ge,!0);s("=>",(r,e)=>{r=r?.[0]==="()"?r[1]:r;let t=r?r[0]===","?r.slice(1):[r]:[],o=-1,i=null,p=t[t.length-1];Array.isArray(p)&&p[0]==="..."&&(o=t.length-1,i=p[1],t.length--);let l=e?.[0]==="{}";return e=n(l?["{",e[1]]:e),f=>(...g)=>{let C={};t.forEach((y,S)=>C[y]=g[S]),i&&(C[i]=g.slice(o));let I=new Proxy(C,{get:(y,S)=>S in y?y[S]:f?.[S],set:(y,S,L)=>((S in y?y:f)[S]=L,!0),has:(y,S)=>S in y||(f?S in f:!1)});try{let y=e(I);return l?void 0:y}catch(y){if(y===Rr)return y[0];throw y}}});var he=140;k("...",he);s("...",r=>(r=n(r),e=>Object.entries(r(e))));var Tr=170;E("?.",Tr,(r,e)=>{if(!r)return;let t=v();return t===40?(h(),["?.()",r,A(0,41)||null]):t===91?(h(),["?.[]",r,A(0,93)]):(e=A(Tr),e?["?.",r,e]:void 0)});s("?.",(r,e)=>(r=n(r),a(e)?()=>{}:t=>r(t)?.[e]));s("?.[]",(r,e)=>(r=n(r),e=n(e),t=>{let o=e(t);return a(o)?void 0:r(t)?.[o]}));s("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(n),i=>e.map(p=>p(i))):(e=n(e),i=>[e(i)]):()=>[];if(r[0]==="?."){let i=n(r[1]),p=r[2];return a(p)?()=>{}:l=>i(l)?.[p]?.(...t(l))}if(r[0]==="?.[]"){let i=n(r[1]),p=n(r[2]);return l=>{let f=i(l),g=p(l);return a(g)?void 0:f?.[g]?.(...t(l))}}if(r[0]==="."){let i=n(r[1]),p=r[2];return a(p)?()=>{}:l=>i(l)?.[p]?.(...t(l))}if(r[0]==="[]"&&r.length===3){let i=n(r[1]),p=n(r[2]);return l=>{let f=i(l),g=p(l);return a(g)?void 0:f?.[g]?.(...t(l))}}let o=n(r);return i=>o(i)?.(...t(i))});var M=140;k("typeof",M);k("void",M);k("delete",M);j("new",M,()=>lr(".target")?(h(7),["new.target"]):["new",A(M)]);s("typeof",r=>(r=n(r),e=>typeof r(e)));s("void",r=>(r=n(r),e=>(r(e),void 0)));s("delete",r=>{if(r[0]==="."){let e=n(r[1]),t=r[2];return o=>delete e(o)[t]}if(r[0]==="[]"){let e=n(r[1]),t=n(r[2]);return o=>delete e(o)[t(o)]}return()=>!0});s("new",r=>{let e=n(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,o=t?t[0]===","?(i=>p=>i.map(l=>l(p)))(t.slice(1).map(n)):(i=>p=>[i(p)])(n(t)):()=>[];return i=>new(e(i))(...o(i))});var W=Symbol("accessor"),ir=20,ye=40,ar=41,Or=123,vr=125,Pr=r=>e=>{if(e)return;v();let t=R(d.id);if(!t||(v(),c.charCodeAt(m)!==ye))return!1;h();let o=A(0,ar);return v(),c.charCodeAt(m)!==Or?!1:(h(),[r,t,o,A(0,vr)])};E("get",ir-1,Pr("get"));E("set",ir-1,Pr("set"));E("(",ir-1,r=>{if(!r||typeof r!="string")return;let e=A(0,ar)||null;if(v(),c.charCodeAt(m)===Or)return h(),[":",r,["=>",["()",e],A(0,vr)||null]]});s("get",(r,e)=>(e=e?n(e):()=>{},t=>[[W,r,{get:function(){let o=Object.create(t||{});return o.this=this,e(o)}}]]));s("set",(r,e,t)=>(t=t?n(t):()=>{},o=>[[W,r,{set:function(i){let p=Object.create(o||{});p.this=this,p[e]=i,t(p)}}]]));var Ce=20,Lr=200,Se=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);_("[]",Lr);_("{}",Lr);u(":",Ce-1,!0);s("{}",(r,e)=>{if(e!==void 0)return;if(!Se(r))return n(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(o=>n(typeof o=="string"?[":",o,o]:o));return o=>{let i={},p={};for(let l of t.flatMap(f=>f(o)))if(l[0]===W){let[,f,g]=l;p[f]={...p[f],...g,configurable:!0,enumerable:!0}}else i[l[0]]=l[1];for(let l in p)Object.defineProperty(i,l,p[l]);return i}});s("{",r=>(r=r?n(r):()=>{},e=>r(Object.create(e))));s(":",(r,e)=>(e=n(e),Array.isArray(r)?(r=n(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));var Ee=170,z=96,we=36,Ie=123,ke=92,Ne={n:`
8
- `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Ur=()=>{let r=[];for(let e="",t;(t=c.charCodeAt(m))!==z;)t?t===ke?(h(),e+=Ne[c[m]]||c[m],h()):t===we&&c.charCodeAt(m+1)===Ie?(e&&r.push([,e]),e="",h(2),r.push(A(0,125))):(e+=c[m],h(),t=c.charCodeAt(m),t===z&&e&&r.push([,e])):N("Unterminated template");return h(),r},Re=w[z];w[z]=(r,e)=>r&&e<Ee?d.asi&&d.newline?void 0:(h(),["``",r,...Ur()]):r?Re?.(r,e):(h(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(Ur()));s("`",(...r)=>(r=r.map(n),e=>r.map(t=>t(e)).join("")));s("``",(r,...e)=>{r=n(r);let t=[],o=[];for(let p of e)Array.isArray(p)&&p[0]===void 0?t.push(p[1]):o.push(n(p));let i=Object.assign([...t],{raw:t});return p=>r(p)(i,...o.map(l=>l(p)))});d.string["'"]=!0;d.number={"0x":16,"0b":2,"0o":8};export{Z as access,u as binary,n as compile,c as cur,ne as default,N as err,A as expr,_ as group,Te as id,m as idx,P as literal,V as loc,w as lookup,Y as nary,R as next,s as operator,J as operators,ae as parens,d as parse,pr as peek,sr as prec,U as seek,h as skip,v as space,E as token,k as unary,lr as word};
4
+ `,""+i}${f}${u}`)},pr=(r,e=l)=>(Array.isArray(r)&&(r.loc=e),r),v=(r,e=l,t)=>{for(;t=r(c.charCodeAt(l));)l+=t;return c.slice(e,l)},h=(r=1)=>c[l+=r],F=r=>l=r,A=(r=0,e)=>{let t,n,i,p,f;for(e&&d.asi&&(d.newline=!1);(t=d.space())&&(f=d.newline,1)&&t!==e&&(i=((p=w[t])&&p(n,r))??(n&&f&&d.asi?.(n,r,A))??(!n&&v(d.id)));)n=i;return e&&(t==e?l++:a("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),n},O=d.space=(r,e=l)=>{for(;(r=c.charCodeAt(l))<=32;)d.asi&&r===10&&(d.newline=!0),l++;return r},fr=(r=l)=>{for(;c.charCodeAt(r)<=32;)r++;return c.charCodeAt(r)},Le=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,ur=(r,e=r.length)=>c.substr(l,e)===r&&!d.id(c.charCodeAt(l+e)),_e=()=>(h(),A(0,41)),w=[],sr={},E=(r,e=32,t,n=r.charCodeAt(0),i=r.length,p=w[n],f=r.toUpperCase()!==r,u,g)=>(e=sr[r]=!p&&sr[r]||e,w[n]=(C,I,y,S=l)=>(u=y,(y?r==y:(i<2||r.charCodeAt(1)===c.charCodeAt(l+1)&&(i<3||c.substr(l,i)==r))&&(!f||!d.id(c.charCodeAt(l+i)))&&(u=y=r))&&I<e&&(l+=i,(g=t(C))?pr(g,S):(l=S,u=0,!f&&!p&&a()),g)||p?.(C,I,u))),m=(r,e,t=!1)=>E(r,e,n=>n&&(i=>i&&[r,n,i])(A(e-(t?.5:0)))),N=(r,e,t)=>E(r,e,n=>t?n&&[r,n]:!n&&(n=A(e-.5))&&[r,n]),L=(r,e)=>E(r,200,t=>!t&&[,e]),V=(r,e,t)=>E(r,e,(n,i)=>(i=A(e-(t?.5:0)),n?.[0]!==r&&(n=[r,n||null]),i?.[0]===r?n.push(...i.slice(1)):n.push(i||null),n)),U=(r,e)=>E(r[0],e,t=>!t&&[r,A(0,r.charCodeAt(1))||null]),Y=(r,e)=>E(r[0],e,t=>t&&[r,t,A(0,r.charCodeAt(1))||null]),T=(r,e,t,n=r.charCodeAt(0),i=r.length,p=w[n],f)=>w[n]=(u,g,C,I=l)=>!u&&(C?r==C:(i<2||c.substr(l,i)==r)&&(C=r))&&g<e&&!d.id(c.charCodeAt(l+i))&&(!d.prop||d.prop(l+i))&&(F(l+i),(f=t())?pr(f,I):F(I),f)||p?.(u,g,C),J={},s=(r,e,t=J[r])=>J[r]=(...n)=>e(...n)||t?.(...n),o=r=>Array.isArray(r)?r[0]==null?(e=>()=>e)(r[1]):J[r[0]]?.(...r.slice(1))??a(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var X=46,B=48,$=57,Dr=69,Fr=101,Gr=43,Xr=45,G=95,lr=110,$r=97,Qr=102,Hr=65,jr=70,mr=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),Z=r=>{let e=mr(v(t=>t===X&&c.charCodeAt(l+1)!==X||t>=B&&t<=$||t===G||((t===Dr||t===Fr)&&((t=c.charCodeAt(l+1))>=B&&t<=$||t===Gr||t===Xr)?2:0)));return c.charCodeAt(l)===lr?(h(),[,BigInt(e)]):(r=+e)!=r?a():[,r]},Kr={2:r=>r===48||r===49||r===G,8:r=>r>=48&&r<=55||r===G,16:r=>r>=B&&r<=$||r>=$r&&r<=Qr||r>=Hr&&r<=jr||r===G};d.number=null;w[X]=r=>!r&&c.charCodeAt(l+1)!==X&&Z();for(let r=B;r<=$;r++)w[r]=e=>e?void 0:Z();w[B]=r=>{if(r)return;let e=d.number;if(e){for(let[t,n]of Object.entries(e))if(t[0]==="0"&&c[l+1]?.toLowerCase()===t[1]){h(2);let i=mr(v(Kr[n]));return c.charCodeAt(l)===lr?(h(),[,BigInt("0"+t[1]+i)]):[,parseInt(i,n)]}}return Z()};var Wr=92,cr=34,dr=39,zr={n:`
5
+ `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Ar=r=>(e,t,n="")=>{if(!(e||!d.string?.[String.fromCharCode(r)]))return h(),v(i=>i-r&&(i===Wr?(n+=zr[c[l+1]]||c[l+1],2):(n+=c[l],1))),c[l]===String.fromCharCode(r)?h():a("Bad string"),[,n]};w[cr]=Ar(cr);w[dr]=Ar(dr);d.string={'"':!0};var Jr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>m(r,Jr,!0));var hr=(r,e,t,n)=>typeof r=="string"?i=>e(i,r,i):r[0]==="."?(t=o(r[1]),n=r[2],i=>e(t(i),n,i)):r[0]==="[]"&&r.length===3?(t=o(r[1]),n=o(r[2]),i=>e(t(i),n(i),i)):r[0]==="()"&&r.length===2?hr(r[1],e):(()=>{throw Error("Invalid assignment target")})(),gr={"=":(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 gr)s(r,(e,t)=>(t=o(t),hr(e,(n,i,p)=>gr[r](n,i,t(p)))));var Vr=30,Yr=40,yr=140;m("!",yr);N("!",yr);m("||",Vr);m("&&",Yr);s("!",r=>(r=o(r),e=>!r(e)));s("||",(r,e)=>(r=o(r),e=o(e),t=>r(t)||e(t)));s("&&",(r,e)=>(r=o(r),e=o(e),t=>r(t)&&e(t)));var Zr=50,qr=60,xr=70,Cr=100,br=140;m("|",Zr);m("&",xr);m("^",qr);m(">>",Cr);m("<<",Cr);N("~",br);s("~",r=>(r=o(r),e=>~r(e)));s("|",(r,e)=>(r=o(r),e=o(e),t=>r(t)|e(t)));s("&",(r,e)=>(r=o(r),e=o(e),t=>r(t)&e(t)));s("^",(r,e)=>(r=o(r),e=o(e),t=>r(t)^e(t)));s(">>",(r,e)=>(r=o(r),e=o(e),t=>r(t)>>e(t)));s("<<",(r,e)=>(r=o(r),e=o(e),t=>r(t)<<e(t)));var Q=90;m("<",Q);m(">",Q);m("<=",Q);m(">=",Q);s(">",(r,e)=>(r=o(r),e=o(e),t=>r(t)>e(t)));s("<",(r,e)=>(r=o(r),e=o(e),t=>r(t)<e(t)));s(">=",(r,e)=>(r=o(r),e=o(e),t=>r(t)>=e(t)));s("<=",(r,e)=>(r=o(r),e=o(e),t=>r(t)<=e(t)));var Sr=80;m("==",Sr);m("!=",Sr);s("==",(r,e)=>(r=o(r),e=o(e),t=>r(t)==e(t)));s("!=",(r,e)=>(r=o(r),e=o(e),t=>r(t)!=e(t)));var Er=110,q=120,Ir=140;m("+",Er);m("-",Er);m("*",q);m("/",q);m("%",q);N("+",Ir);N("-",Ir);s("+",(r,e)=>e!==void 0?(r=o(r),e=o(e),t=>r(t)+e(t)):(r=o(r),t=>+r(t)));s("-",(r,e)=>e!==void 0?(r=o(r),e=o(e),t=>r(t)-e(t)):(r=o(r),t=>-r(t)));s("*",(r,e)=>(r=o(r),e=o(e),t=>r(t)*e(t)));s("/",(r,e)=>(r=o(r),e=o(e),t=>r(t)/e(t)));s("%",(r,e)=>(r=o(r),e=o(e),t=>r(t)%e(t)));var H=150;E("++",H,r=>r?["++",r,null]:["++",A(H-1)]);E("--",H,r=>r?["--",r,null]:["--",A(H-1)]);var x=(r,e,t,n)=>typeof r=="string"?i=>e(i,r):r[0]==="."?(t=o(r[1]),n=r[2],i=>e(t(i),n)):r[0]==="[]"&&r.length===3?(t=o(r[1]),n=o(r[2]),i=>e(t(i),n(i))):r[0]==="()"&&r.length===2?x(r[1],e):(()=>{throw Error("Invalid increment target")})();s("++",(r,e)=>x(r,e===null?(t,n)=>t[n]++:(t,n)=>++t[n]));s("--",(r,e)=>x(r,e===null?(t,n)=>t[n]--:(t,n)=>--t[n]));var re=5,ee=10;V(",",ee);V(";",re,!0);var wr=(...r)=>(r=r.map(o),e=>{let t;for(let n of r)t=n(e);return t});s(",",wr);s(";",wr);var te=170;U("()",te);var R=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",b=170;Y("[]",b);m(".",b);Y("()",b);var j=r=>{throw Error(r)};s("[]",(r,e)=>e===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(t=>t==null?(()=>{}):t[0]==="..."?(t=o(t[1]),n=>t(n)):(t=o(t),n=>[t(n)])),t=>r.flatMap(n=>n(t))):(e==null&&j("Missing index"),r=o(r),e=o(e),t=>{let n=e(t);return R(n)?void 0:r(t)[n]}));s(".",(r,e)=>(r=o(r),e=e[0]?e:e[1],R(e)?()=>{}:t=>r(t)[e]));s("()",(r,e)=>{if(e===void 0)return r==null?j("Empty ()"):o(r);let t=i=>i?.[0]===","&&i.slice(1).some(p=>p==null||t(p));t(e)&&j("Empty argument");let n=e?e[0]===","?(e=e.slice(1).map(o),i=>e.map(p=>p(i))):(e=o(e),i=>[e(i)]):()=>[];return rr(r,(i,p,f)=>i[p](...n(f)))});var k=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&k(r[1])||r[0]==="{}"),rr=(r,e,t,n)=>r==null?j("Empty ()"):r[0]==="()"&&r.length==2?rr(r[1],e):typeof r=="string"?i=>e(i,r,i):r[0]==="."?(t=o(r[1]),n=r[2],i=>e(t(i),n,i)):r[0]==="?."?(t=o(r[1]),n=r[2],i=>{let p=t(i);return p==null?void 0:e(p,n,i)}):r[0]==="[]"&&r.length===3?(t=o(r[1]),n=o(r[2]),i=>e(t(i),n(i),i)):r[0]==="?.[]"?(t=o(r[1]),n=o(r[2]),i=>{let p=t(i);return p==null?void 0:e(p,n(i),i)}):(r=o(r),i=>e([r(i)],0,i)),P=rr;var Nr=new WeakMap,ne=(r,...e)=>typeof r=="string"?o(d(r)):Nr.get(r)||Nr.set(r,oe(r,e)).get(r),ar=57344,oe=(r,e)=>{let t=r.reduce((p,f,u)=>p+(u?String.fromCharCode(ar+u-1):"")+f,""),n=d(t),i=p=>{if(typeof p=="string"&&p.length===1){let f=p.charCodeAt(0)-ar,u;if(f>=0&&f<e.length)return u=e[f],ie(u)?u:[,u]}return Array.isArray(p)?p.map(i):p};return o(i(n))},ie=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),se=ne;var pe=32,fe=d.space;d.comment??={"//":`
6
+ `,"/*":"*/"};var er;d.space=()=>{er||(er=Object.entries(d.comment).map(([i,p])=>[i,p,i.charCodeAt(0)]));for(var r;r=fe();){for(var e=0,t;t=er[e++];)if(r===t[2]&&c.substr(l,t[0].length)===t[0]){var n=l+t[0].length;if(t[1]===`
7
+ `)for(;c.charCodeAt(n)>=pe;)n++;else{for(;c[n]&&c.substr(n,t[1].length)!==t[1];)n++;c[n]&&(n+=t[1].length)}F(n),r=0;break}if(r)return r}return r};var vr=80;m("===",vr);m("!==",vr);s("===",(r,e)=>(r=o(r),e=o(e),t=>r(t)===e(t)));s("!==",(r,e)=>(r=o(r),e=o(e),t=>r(t)!==e(t)));var ue=30;m("??",ue);s("??",(r,e)=>(r=o(r),e=o(e),t=>r(t)??e(t)));var le=130,me=20;m("**",le,!0);m("**=",me,!0);s("**",(r,e)=>(r=o(r),e=o(e),t=>r(t)**e(t)));var ce=r=>{throw Error(r)};s("**=",(r,e)=>(k(r)||ce("Invalid assignment target"),e=o(e),P(r,(t,n,i)=>t[n]**=e(i))));var kr=90;m("in",kr);m("of",kr);s("in",(r,e)=>(r=o(r),e=o(e),t=>r(t)in e(t)));var de=20,Ae=100,ge=r=>{throw Error(r)};m(">>>",Ae);m(">>>=",de,!0);s(">>>",(r,e)=>(r=o(r),e=o(e),t=>r(t)>>>e(t)));s(">>>=",(r,e)=>(k(r)||ge("Invalid assignment target"),e=o(e),P(r,(t,n,i)=>t[n]>>>=e(i))));var tr=5,he=10,ye=20,Ce=r=>r[0]?.[0]===","?r[0].slice(1):r,M=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[n,...i]=r,p=Ce(i);if(n==="{}"){let f=[];for(let u of p){if(Array.isArray(u)&&u[0]==="..."){let S={};for(let _ in e)f.includes(_)||(S[_]=e[_]);t[u[1]]=S;break}let g,C,I;typeof u=="string"?g=C=u:u[0]==="="?(typeof u[1]=="string"?g=C=u[1]:[,g,C]=u[1],I=u[2]):[,g,C]=u,f.push(g);let y=e[g];y===void 0&&I&&(y=o(I)(t)),M(C,y,t)}}else if(n==="[]"){let f=0;for(let u of p){if(u===null){f++;continue}if(Array.isArray(u)&&u[0]==="..."){t[u[1]]=e.slice(f);break}let g=u,C;Array.isArray(u)&&u[0]==="="&&([,g,C]=u);let I=e[f++];I===void 0&&C&&(I=o(C)(t)),M(g,I,t)}}},Or=r=>{let e=A(he-1);return e?.[0]==="in"||e?.[0]==="of"?[e[0],[r,e[1]],e[2]]:e?.[0]===","?[r,...e.slice(1)]:[r,e]};T("let",tr+1,()=>Or("let"));T("const",tr+1,()=>Or("const"));T("var",tr,()=>(O(),["var",A(ye)]));var Rr=(...r)=>(r=r.map(e=>{if(typeof e=="string")return t=>{t[e]=void 0};if(e[0]==="="){let[,t,n]=e,i=o(n);return typeof t=="string"?p=>{p[t]=i(p)}:p=>M(t,i(p),p)}return o(e)}),e=>{for(let t of r)t(e)});s("let",Rr);s("const",Rr);s("var",r=>typeof r=="string"?e=>{e[r]=void 0}:()=>{});var nr=20,K=r=>{throw Error(r)};m("||=",nr,!0);m("&&=",nr,!0);m("??=",nr,!0);s("=",(r,e)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let t=r[1];return e=o(e),typeof t=="string"?n=>{n[t]=e(n)}:n=>M(t,e(n),n)}return k(r)||K("Invalid assignment target"),e=o(e),P(r,(t,n,i)=>t[n]=e(i))});s("||=",(r,e)=>(k(r)||K("Invalid assignment target"),e=o(e),P(r,(t,n,i)=>t[n]||=e(i))));s("&&=",(r,e)=>(k(r)||K("Invalid assignment target"),e=o(e),P(r,(t,n,i)=>t[n]&&=e(i))));s("??=",(r,e)=>(k(r)||K("Invalid assignment target"),e=o(e),P(r,(t,n,i)=>t[n]??=e(i))));L("true",!0);L("false",!1);L("null",null);T("undefined",200,()=>[]);L("NaN",NaN);L("Infinity",1/0);var or=20;E("?",or,(r,e,t)=>r&&(e=A(or-1))&&v(n=>n===58)&&(t=A(or-1),["?",r,e,t]));s("?",(r,e,t)=>(r=o(r),e=o(e),t=o(t),n=>r(n)?e(n):t(n)));var Se=[],Ee=20;m("=>",Ee,!0);s("=>",(r,e)=>{r=r?.[0]==="()"?r[1]:r;let t=r?r[0]===","?r.slice(1):[r]:[],n=-1,i=null,p=t[t.length-1];Array.isArray(p)&&p[0]==="..."&&(n=t.length-1,i=p[1],t.length--);let f=e?.[0]==="{}";return e=o(f?["{",e[1]]:e),u=>(...g)=>{let C={};t.forEach((y,S)=>C[y]=g[S]),i&&(C[i]=g.slice(n));let I=new Proxy(C,{get:(y,S)=>S in y?y[S]:u?.[S],set:(y,S,_)=>((S in y?y:u)[S]=_,!0),has:(y,S)=>S in y||(u?S in u:!1)});try{let y=e(I);return f?void 0:y}catch(y){if(y===Se)return y[0];throw y}}});var Ie=140;N("...",Ie);s("...",r=>(r=o(r),e=>Object.entries(r(e))));var Pr=170;E("?.",Pr,(r,e)=>{if(!r)return;let t=O();return t===40?(h(),["?.()",r,A(0,41)||null]):t===91?(h(),["?.[]",r,A(0,93)]):(e=A(Pr),e?["?.",r,e]:void 0)});s("?.",(r,e)=>(r=o(r),R(e)?()=>{}:t=>r(t)?.[e]));s("?.[]",(r,e)=>(r=o(r),e=o(e),t=>{let n=e(t);return R(n)?void 0:r(t)?.[n]}));s("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(o),i=>e.map(p=>p(i))):(e=o(e),i=>[e(i)]):()=>[];if(r[0]==="?."){let i=o(r[1]),p=r[2];return R(p)?()=>{}:f=>i(f)?.[p]?.(...t(f))}if(r[0]==="?.[]"){let i=o(r[1]),p=o(r[2]);return f=>{let u=i(f),g=p(f);return R(g)?void 0:u?.[g]?.(...t(f))}}if(r[0]==="."){let i=o(r[1]),p=r[2];return R(p)?()=>{}:f=>i(f)?.[p]?.(...t(f))}if(r[0]==="[]"&&r.length===3){let i=o(r[1]),p=o(r[2]);return f=>{let u=i(f),g=p(f);return R(g)?void 0:u?.[g]?.(...t(f))}}let n=o(r);return i=>n(i)?.(...t(i))});var D=140;N("typeof",D);N("void",D);N("delete",D);T("new",D,()=>ur(".target")?(h(7),["new.target"]):["new",A(D)]);s("typeof",r=>(r=o(r),e=>typeof r(e)));s("void",r=>(r=o(r),e=>(r(e),void 0)));s("delete",r=>{if(r[0]==="."){let e=o(r[1]),t=r[2];return n=>delete e(n)[t]}if(r[0]==="[]"){let e=o(r[1]),t=o(r[2]);return n=>delete e(n)[t(n)]}return()=>!0});s("new",r=>{let e=o(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,n=t?t[0]===","?(i=>p=>i.map(f=>f(p)))(t.slice(1).map(o)):(i=>p=>[i(p)])(o(t)):()=>[];return i=>new(e(i))(...n(i))});var W=Symbol("accessor"),ir=20,we=40,Tr=41,Lr=123,_r=125,Ur=r=>e=>{if(e)return;O();let t=v(d.id);if(!t||(O(),c.charCodeAt(l)!==we))return!1;h();let n=A(0,Tr);return O(),c.charCodeAt(l)!==Lr?!1:(h(),[r,t,n,A(0,_r)])};E("get",ir-1,Ur("get"));E("set",ir-1,Ur("set"));E("(",ir-1,r=>{if(!r||typeof r!="string")return;let e=A(0,Tr)||null;if(O(),c.charCodeAt(l)===Lr)return h(),[":",r,["=>",["()",e],A(0,_r)||null]]});s("get",(r,e)=>(e=e?o(e):()=>{},t=>[[W,r,{get:function(){let n=Object.create(t||{});return n.this=this,e(n)}}]]));s("set",(r,e,t)=>(t=t?o(t):()=>{},n=>[[W,r,{set:function(i){let p=Object.create(n||{});p.this=this,p[e]=i,t(p)}}]]));var Ne=20,Br=200;d.prop=r=>fr(r)!==58;var ae=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);U("[]",Br);U("{}",Br);m(":",Ne-1,!0);s("{}",(r,e)=>{if(e!==void 0)return;if(!ae(r))return o(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(n=>o(typeof n=="string"?[":",n,n]:n));return n=>{let i={},p={};for(let f of t.flatMap(u=>u(n)))if(f[0]===W){let[,u,g]=f;p[u]={...p[u],...g,configurable:!0,enumerable:!0}}else i[f[0]]=f[1];for(let f in p)Object.defineProperty(i,f,p[f]);return i}});s("{",r=>(r=r?o(r):()=>{},e=>r(Object.create(e))));s(":",(r,e)=>(e=o(e),Array.isArray(r)?(r=o(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));var ve=170,z=96,ke=36,Oe=123,Re=92,Pe={n:`
8
+ `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Mr=()=>{let r=[];for(let e="",t;(t=c.charCodeAt(l))!==z;)t?t===Re?(h(),e+=Pe[c[l]]||c[l],h()):t===ke&&c.charCodeAt(l+1)===Oe?(e&&r.push([,e]),e="",h(2),r.push(A(0,125))):(e+=c[l],h(),t=c.charCodeAt(l),t===z&&e&&r.push([,e])):a("Unterminated template");return h(),r},Te=w[z];w[z]=(r,e)=>r&&e<ve?d.asi&&d.newline?void 0:(h(),["``",r,...Mr()]):r?Te?.(r,e):(h(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(Mr()));s("`",(...r)=>(r=r.map(o),e=>r.map(t=>t(e)).join("")));s("``",(r,...e)=>{r=o(r);let t=[],n=[];for(let p of e)Array.isArray(p)&&p[0]===void 0?t.push(p[1]):n.push(o(p));let i=Object.assign([...t],{raw:t});return p=>r(p)(i,...n.map(f=>f(p)))});d.string["'"]=!0;d.number={"0x":16,"0b":2,"0o":8};export{Y as access,m as binary,o as compile,c as cur,se as default,a as err,A as expr,U as group,Le as id,l as idx,T as keyword,L as literal,pr as loc,w as lookup,V as nary,v as next,s as operator,J as operators,_e as parens,d as parse,fr as peek,sr as prec,F as seek,h as skip,O as space,E as token,N as unary,ur as word};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "subscript",
3
- "version": "10.1.8",
4
- "description": "Tiny expression parser & evaluator",
3
+ "version": "10.3.1",
4
+ "description": "Modular expression parser & evaluator",
5
5
  "main": "subscript.js",
6
6
  "module": "subscript.js",
7
7
  "browser": "subscript.js",
@@ -29,8 +29,9 @@
29
29
  ],
30
30
  "scripts": {
31
31
  "build": "esbuild subscript.js --bundle --minify --format=esm --outfile=subscript.min.js && esbuild justin.js --bundle --minify --format=esm --outfile=justin.min.js && esbuild jessie.js --bundle --minify --format=esm --outfile=jessie.min.js",
32
- "prepublishOnly": "npm run build",
32
+ "prepublishOnly": "npm run build && npm run test:e2e",
33
33
  "test": "node --import ./test/https-loader.js test/test.js",
34
+ "test:e2e": "npx playwright test test/index.spec.js",
34
35
  "check-types": "tsc --noEmit subscript.d.ts"
35
36
  },
36
37
  "repository": {
@@ -38,34 +39,25 @@
38
39
  "url": "git+https://github.com/dy/subscript.git"
39
40
  },
40
41
  "keywords": [
41
- "jexl",
42
- "jsep",
42
+ "parser",
43
43
  "expression",
44
+ "language",
45
+ "dsl",
46
+ "syntax",
47
+ "modular",
48
+ "extensible",
49
+ "pratt",
44
50
  "evaluator",
45
- "parser",
46
- "evaluation",
47
- "math",
48
- "arithmetic",
51
+ "compiler",
52
+ "ast",
49
53
  "justin",
50
- "eval",
51
- "math-eval",
52
- "math-evaluator",
53
- "math-expression-evaluator",
54
- "calculation",
55
54
  "jessie",
56
- "jessica",
57
- "eval",
58
- "dsl",
59
- "json",
60
- "calculator",
61
- "calc",
62
- "math.js",
63
- "mathjs",
64
- "math-codegen",
65
- "math-parser",
55
+ "jsep",
56
+ "jexl",
57
+ "sandboxed",
58
+ "safe-eval",
66
59
  "formula",
67
- "operator",
68
- "overload"
60
+ "template"
69
61
  ],
70
62
  "author": "Dmitry Iv.",
71
63
  "license": "ISC",
package/parse.js CHANGED
@@ -89,7 +89,6 @@ export let idx, cur,
89
89
  prec = {},
90
90
 
91
91
  // create operator checker/mapper - for symbols and special cases
92
- // For prefix word operators, prefer keyword() from block.js
93
92
  token = (
94
93
  op,
95
94
  p = SPACE,
@@ -130,10 +129,23 @@ export let idx, cur,
130
129
 
131
130
  group = (op, p) => token(op[0], p, a => (!a && [op, expr(0, op.charCodeAt(1)) || null])),
132
131
 
133
- access = (op, p) => token(op[0], p, a => (a && [op, a, expr(0, op.charCodeAt(1)) || null]));
132
+ access = (op, p) => token(op[0], p, a => (a && [op, a, expr(0, op.charCodeAt(1)) || null])),
133
+
134
+ // keyword(op, prec, fn) - prefix word token with property name support
135
+ // parse.prop set by collection.js to prevent matching {keyword: value}
136
+ keyword = (op, prec, map, c = op.charCodeAt(0), l = op.length, prev = lookup[c], r) =>
137
+ lookup[c] = (a, curPrec, curOp, from = idx) =>
138
+ !a &&
139
+ (curOp ? op == curOp : (l < 2 || cur.substr(idx, l) == op) && (curOp = op)) &&
140
+ curPrec < prec &&
141
+ !parse.id(cur.charCodeAt(idx + l)) &&
142
+ (!parse.prop || parse.prop(idx + l)) &&
143
+ (seek(idx + l), (r = map()) ? loc(r, from) : seek(from), r) ||
144
+ prev?.(a, curPrec, curOp);
134
145
 
135
146
  // === Compile: AST → Evaluator ===
136
147
 
148
+
137
149
  // Operator registry
138
150
  export const operators = {};
139
151
 
package/subscript.js CHANGED
@@ -24,7 +24,8 @@ import './feature/op/equality.js'; // == !=
24
24
  import './feature/op/arithmetic.js'; // + - * / %
25
25
  import './feature/op/increment.js'; // ++ --
26
26
 
27
- import './feature/group.js'; // Grouping: (a), sequences: a, b; a; b
27
+ import './feature/seq.js'; // Sequences: a, b; a; b
28
+ import './feature/group.js'; // Grouping: (a)
28
29
  import './feature/access.js'; // Property access: a.b, a[b], f(), [a,b]
29
30
 
30
31
  import { parse, compile } from './parse.js';
package/subscript.min.js CHANGED
@@ -1,5 +1,5 @@
1
- var l,u,f=r=>(l=0,u=r,f.newline=!1,r=A(),u[l]?g():r||""),g=(r="Unexpected token",e=l,t=u.slice(0,e).split(`
2
- `),o=t.pop(),i=u.slice(Math.max(0,e-40),e),p="\u032D",c=(u[e]||" ")+p,d=u.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
1
+ var s,u,f=r=>(s=0,u=r,f.newline=!1,r=h(),u[s]?g():r||""),g=(r="Unexpected token",e=s,t=u.slice(0,e).split(`
2
+ `),o=t.pop(),n=u.slice(Math.max(0,e-40),e),p="\u032D",d=(u[e]||" ")+p,A=u.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
3
3
  ${u[e-41]!==`
4
- `,""+i}${c}${d}`)},nr=(r,e=l)=>(Array.isArray(r)&&(r.loc=e),r),E=(r,e=l,t)=>{for(;t=r(u.charCodeAt(l));)l+=t;return u.slice(e,l)},y=(r=1)=>u[l+=r],Or=r=>l=r,A=(r=0,e)=>{let t,o,i,p,c;for(e&&f.asi&&(f.newline=!1);(t=f.space())&&(c=f.newline,1)&&t!==e&&(i=((p=h[t])&&p(o,r))??(o&&c&&f.asi?.(o,r,A))??(!o&&E(f.id)));)o=i;return e&&(t==e?l++:g("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},Lr=f.space=(r,e=l)=>{for(;(r=u.charCodeAt(l))<=32;)f.asi&&r===10&&(f.newline=!0),l++;return r},Nr=(r=l)=>{for(;u.charCodeAt(r)<=32;)r++;return u.charCodeAt(r)},$r=f.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,kr=(r,e=r.length)=>u.substr(l,e)===r&&!f.id(u.charCodeAt(l+e)),Fr=()=>(y(),A(0,41)),h=[],v={},C=(r,e=32,t,o=r.charCodeAt(0),i=r.length,p=h[o],c=r.toUpperCase()!==r,d,M)=>(e=v[r]=!p&&v[r]||e,h[o]=(Q,B,_,H=l)=>(d=_,(_?r==_:(i<2||r.charCodeAt(1)===u.charCodeAt(l+1)&&(i<3||u.substr(l,i)==r))&&(!c||!f.id(u.charCodeAt(l+i)))&&(d=_=r))&&B<e&&(l+=i,(M=t(Q))?nr(M,H):(l=H,d=0,!c&&!p&&g()),M)||p?.(Q,B,d))),m=(r,e,t=!1)=>C(r,e,o=>o&&(i=>i&&[r,o,i])(A(e-(t?.5:0)))),S=(r,e,t)=>C(r,e,o=>t?o&&[r,o]:!o&&(o=A(e-.5))&&[r,o]),Xr=(r,e)=>C(r,200,t=>!t&&[,e]),L=(r,e,t)=>C(r,e,(o,i)=>(i=A(e-(t?.5:0)),o?.[0]!==r&&(o=[r,o||null]),i?.[0]===r?o.push(...i.slice(1)):o.push(i||null),o)),G=(r,e)=>C(r[0],e,t=>!t&&[r,A(0,r.charCodeAt(1))||null]),N=(r,e)=>C(r[0],e,t=>t&&[r,t,A(0,r.charCodeAt(1))||null]),O={},s=(r,e,t=O[r])=>O[r]=(...o)=>e(...o)||t?.(...o),n=r=>Array.isArray(r)?r[0]==null?(e=>()=>e)(r[1]):O[r[0]]?.(...r.slice(1))??g(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var P=46,w=48,T=57,ir=69,sr=101,lr=43,pr=45,I=95,ur=110,mr=97,fr=102,cr=65,dr=70,W=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),$=r=>{let e=W(E(t=>t===P&&u.charCodeAt(l+1)!==P||t>=w&&t<=T||t===I||((t===ir||t===sr)&&((t=u.charCodeAt(l+1))>=w&&t<=T||t===lr||t===pr)?2:0)));return u.charCodeAt(l)===ur?(y(),[,BigInt(e)]):(r=+e)!=r?g():[,r]},Ar={2:r=>r===48||r===49||r===I,8:r=>r>=48&&r<=55||r===I,16:r=>r>=w&&r<=T||r>=mr&&r<=fr||r>=cr&&r<=dr||r===I};f.number=null;h[P]=r=>!r&&u.charCodeAt(l+1)!==P&&$();for(let r=w;r<=T;r++)h[r]=e=>e?void 0:$();h[w]=r=>{if(r)return;let e=f.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&u[l+1]?.toLowerCase()===t[1])return y(2),[,parseInt(W(E(Ar[o])),o)]}return $()};var hr=92,z=34,J=39,Cr={n:`
5
- `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},K=r=>(e,t,o="")=>{if(!(e||!f.string?.[String.fromCharCode(r)]))return y(),E(i=>i-r&&(i===hr?(o+=Cr[u[l+1]]||u[l+1],2):(o+=u[l],1))),u[l]===String.fromCharCode(r)?y():g("Bad string"),[,o]};h[z]=K(z);h[J]=K(J);f.string={'"':!0};var gr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>m(r,gr,!0));var Y=(r,e,t,o)=>typeof r=="string"?i=>e(i,r,i):r[0]==="."?(t=n(r[1]),o=r[2],i=>e(t(i),o,i)):r[0]==="[]"&&r.length===3?(t=n(r[1]),o=n(r[2]),i=>e(t(i),o(i),i)):r[0]==="()"&&r.length===2?Y(r[1],e):(()=>{throw Error("Invalid assignment target")})(),V={"=":(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 V)s(r,(e,t)=>(t=n(t),Y(e,(o,i,p)=>V[r](o,i,t(p)))));var yr=30,Sr=40,Z=140;m("!",Z);S("!",Z);m("||",yr);m("&&",Sr);s("!",r=>(r=n(r),e=>!r(e)));s("||",(r,e)=>(r=n(r),e=n(e),t=>r(t)||e(t)));s("&&",(r,e)=>(r=n(r),e=n(e),t=>r(t)&&e(t)));var Er=50,wr=60,_r=70,q=100,Ir=140;m("|",Er);m("&",_r);m("^",wr);m(">>",q);m("<<",q);S("~",Ir);s("~",r=>(r=n(r),e=>~r(e)));s("|",(r,e)=>(r=n(r),e=n(e),t=>r(t)|e(t)));s("&",(r,e)=>(r=n(r),e=n(e),t=>r(t)&e(t)));s("^",(r,e)=>(r=n(r),e=n(e),t=>r(t)^e(t)));s(">>",(r,e)=>(r=n(r),e=n(e),t=>r(t)>>e(t)));s("<<",(r,e)=>(r=n(r),e=n(e),t=>r(t)<<e(t)));var U=90;m("<",U);m(">",U);m("<=",U);m(">=",U);s(">",(r,e)=>(r=n(r),e=n(e),t=>r(t)>e(t)));s("<",(r,e)=>(r=n(r),e=n(e),t=>r(t)<e(t)));s(">=",(r,e)=>(r=n(r),e=n(e),t=>r(t)>=e(t)));s("<=",(r,e)=>(r=n(r),e=n(e),t=>r(t)<=e(t)));var x=80;m("==",x);m("!=",x);s("==",(r,e)=>(r=n(r),e=n(e),t=>r(t)==e(t)));s("!=",(r,e)=>(r=n(r),e=n(e),t=>r(t)!=e(t)));var j=110,k=120,a=140;m("+",j);m("-",j);m("*",k);m("/",k);m("%",k);S("+",a);S("-",a);s("+",(r,e)=>e!==void 0?(r=n(r),e=n(e),t=>r(t)+e(t)):(r=n(r),t=>+r(t)));s("-",(r,e)=>e!==void 0?(r=n(r),e=n(e),t=>r(t)-e(t)):(r=n(r),t=>-r(t)));s("*",(r,e)=>(r=n(r),e=n(e),t=>r(t)*e(t)));s("/",(r,e)=>(r=n(r),e=n(e),t=>r(t)/e(t)));s("%",(r,e)=>(r=n(r),e=n(e),t=>r(t)%e(t)));var R=150;C("++",R,r=>r?["++",r,null]:["++",A(R-1)]);C("--",R,r=>r?["--",r,null]:["--",A(R-1)]);var F=(r,e,t,o)=>typeof r=="string"?i=>e(i,r):r[0]==="."?(t=n(r[1]),o=r[2],i=>e(t(i),o)):r[0]==="[]"&&r.length===3?(t=n(r[1]),o=n(r[2]),i=>e(t(i),o(i))):r[0]==="()"&&r.length===2?F(r[1],e):(()=>{throw Error("Invalid increment target")})();s("++",(r,e)=>F(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));s("--",(r,e)=>F(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var Pr=5,Tr=10,Ur=170;G("()",Ur);L(",",Tr);L(";",Pr,!0);var b=(...r)=>(r=r.map(n),e=>{let t;for(let o of r)t=o(e);return t});s(",",b);s(";",b);var rr=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",X=170;N("[]",X);m(".",X);N("()",X);var D=r=>{throw Error(r)};s("[]",(r,e)=>e===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(t=>t==null?(()=>{}):t[0]==="..."?(t=n(t[1]),o=>t(o)):(t=n(t),o=>[t(o)])),t=>r.flatMap(o=>o(t))):(e==null&&D("Missing index"),r=n(r),e=n(e),t=>{let o=e(t);return rr(o)?void 0:r(t)[o]}));s(".",(r,e)=>(r=n(r),e=e[0]?e:e[1],rr(e)?()=>{}:t=>r(t)[e]));s("()",(r,e)=>{if(e===void 0)return r==null?D("Empty ()"):n(r);let t=i=>i?.[0]===","&&i.slice(1).some(p=>p==null||t(p));t(e)&&D("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(n),i=>e.map(p=>p(i))):(e=n(e),i=>[e(i)]):()=>[];return er(r,(i,p,c)=>i[p](...o(c)))});var er=(r,e,t,o)=>r==null?D("Empty ()"):r[0]==="()"&&r.length==2?er(r[1],e):typeof r=="string"?i=>e(i,r,i):r[0]==="."?(t=n(r[1]),o=r[2],i=>e(t(i),o,i)):r[0]==="?."?(t=n(r[1]),o=r[2],i=>{let p=t(i);return p==null?void 0:e(p,o,i)}):r[0]==="[]"&&r.length===3?(t=n(r[1]),o=n(r[2]),i=>e(t(i),o(i),i)):r[0]==="?.[]"?(t=n(r[1]),o=n(r[2]),i=>{let p=t(i);return p==null?void 0:e(p,o(i),i)}):(r=n(r),i=>e([r(i)],0,i));var tr=new WeakMap,Rr=(r,...e)=>typeof r=="string"?n(f(r)):tr.get(r)||tr.set(r,Dr(r,e)).get(r),or=57344,Dr=(r,e)=>{let t=r.reduce((p,c,d)=>p+(d?String.fromCharCode(or+d-1):"")+c,""),o=f(t),i=p=>{if(typeof p=="string"&&p.length===1){let c=p.charCodeAt(0)-or,d;if(c>=0&&c<e.length)return d=e[c],Mr(d)?d:[,d]}return Array.isArray(p)?p.map(i):p};return n(i(o))},Mr=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),ue=Rr;export{N as access,m as binary,n as compile,u as cur,ue as default,g as err,A as expr,G as group,$r as id,l as idx,Xr as literal,nr as loc,h as lookup,L as nary,E as next,s as operator,O as operators,Fr as parens,f as parse,Nr as peek,v as prec,Or as seek,y as skip,Lr as space,C as token,S as unary,kr as word};
4
+ `,""+n}${d}${A}`)},W=(r,e=s)=>(Array.isArray(r)&&(r.loc=e),r),_=(r,e=s,t)=>{for(;t=r(u.charCodeAt(s));)s+=t;return u.slice(e,s)},y=(r=1)=>u[s+=r],v=r=>s=r,h=(r=0,e)=>{let t,o,n,p,d;for(e&&f.asi&&(f.newline=!1);(t=f.space())&&(d=f.newline,1)&&t!==e&&(n=((p=c[t])&&p(o,r))??(o&&d&&f.asi?.(o,r,h))??(!o&&_(f.id)));)o=n;return e&&(t==e?s++:g("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},Lr=f.space=(r,e=s)=>{for(;(r=u.charCodeAt(s))<=32;)f.asi&&r===10&&(f.newline=!0),s++;return r},Nr=(r=s)=>{for(;u.charCodeAt(r)<=32;)r++;return u.charCodeAt(r)},$r=f.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,Fr=(r,e=r.length)=>u.substr(s,e)===r&&!f.id(u.charCodeAt(s+e)),Or=()=>(y(),h(0,41)),c=[],G={},C=(r,e=32,t,o=r.charCodeAt(0),n=r.length,p=c[o],d=r.toUpperCase()!==r,A,w)=>(e=G[r]=!p&&G[r]||e,c[o]=(S,I,U,H=s)=>(A=U,(U?r==U:(n<2||r.charCodeAt(1)===u.charCodeAt(s+1)&&(n<3||u.substr(s,n)==r))&&(!d||!f.id(u.charCodeAt(s+n)))&&(A=U=r))&&I<e&&(s+=n,(w=t(S))?W(w,H):(s=H,A=0,!d&&!p&&g()),w)||p?.(S,I,A))),m=(r,e,t=!1)=>C(r,e,o=>o&&(n=>n&&[r,o,n])(h(e-(t?.5:0)))),E=(r,e,t)=>C(r,e,o=>t?o&&[r,o]:!o&&(o=h(e-.5))&&[r,o]),Xr=(r,e)=>C(r,200,t=>!t&&[,e]),$=(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)),z=(r,e)=>C(r[0],e,t=>!t&&[r,h(0,r.charCodeAt(1))||null]),F=(r,e)=>C(r[0],e,t=>t&&[r,t,h(0,r.charCodeAt(1))||null]),Br=(r,e,t,o=r.charCodeAt(0),n=r.length,p=c[o],d)=>c[o]=(A,w,S,I=s)=>!A&&(S?r==S:(n<2||u.substr(s,n)==r)&&(S=r))&&w<e&&!f.id(u.charCodeAt(s+n))&&(!f.prop||f.prop(s+n))&&(v(s+n),(d=t())?W(d,I):v(I),d)||p?.(A,w,S),N={},l=(r,e,t=N[r])=>N[r]=(...o)=>e(...o)||t?.(...o),i=r=>Array.isArray(r)?r[0]==null?(e=>()=>e)(r[1]):N[r[0]]?.(...r.slice(1))??g(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var R=46,T=48,D=57,lr=69,pr=101,ur=43,mr=45,P=95,J=110,fr=97,dr=102,Ar=65,cr=70,K=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),O=r=>{let e=K(_(t=>t===R&&u.charCodeAt(s+1)!==R||t>=T&&t<=D||t===P||((t===lr||t===pr)&&((t=u.charCodeAt(s+1))>=T&&t<=D||t===ur||t===mr)?2:0)));return u.charCodeAt(s)===J?(y(),[,BigInt(e)]):(r=+e)!=r?g():[,r]},hr={2:r=>r===48||r===49||r===P,8:r=>r>=48&&r<=55||r===P,16:r=>r>=T&&r<=D||r>=fr&&r<=dr||r>=Ar&&r<=cr||r===P};f.number=null;c[R]=r=>!r&&u.charCodeAt(s+1)!==R&&O();for(let r=T;r<=D;r++)c[r]=e=>e?void 0:O();c[T]=r=>{if(r)return;let e=f.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&u[s+1]?.toLowerCase()===t[1]){y(2);let n=K(_(hr[o]));return u.charCodeAt(s)===J?(y(),[,BigInt("0"+t[1]+n)]):[,parseInt(n,o)]}}return O()};var Cr=92,V=34,Y=39,gr={n:`
5
+ `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Z=r=>(e,t,o="")=>{if(!(e||!f.string?.[String.fromCharCode(r)]))return y(),_(n=>n-r&&(n===Cr?(o+=gr[u[s+1]]||u[s+1],2):(o+=u[s],1))),u[s]===String.fromCharCode(r)?y():g("Bad string"),[,o]};c[V]=Z(V);c[Y]=Z(Y);f.string={'"':!0};var yr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>m(r,yr,!0));var x=(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?x(r[1],e):(()=>{throw Error("Invalid assignment target")})(),q={"=":(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 q)l(r,(e,t)=>(t=i(t),x(e,(o,n,p)=>q[r](o,n,t(p)))));var Sr=30,Er=40,j=140;m("!",j);E("!",j);m("||",Sr);m("&&",Er);l("!",r=>(r=i(r),e=>!r(e)));l("||",(r,e)=>(r=i(r),e=i(e),t=>r(t)||e(t)));l("&&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&&e(t)));var wr=50,_r=60,Ir=70,a=100,Tr=140;m("|",wr);m("&",Ir);m("^",_r);m(">>",a);m("<<",a);E("~",Tr);l("~",r=>(r=i(r),e=>~r(e)));l("|",(r,e)=>(r=i(r),e=i(e),t=>r(t)|e(t)));l("&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&e(t)));l("^",(r,e)=>(r=i(r),e=i(e),t=>r(t)^e(t)));l(">>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>e(t)));l("<<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<<e(t)));var M=90;m("<",M);m(">",M);m("<=",M);m(">=",M);l(">",(r,e)=>(r=i(r),e=i(e),t=>r(t)>e(t)));l("<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<e(t)));l(">=",(r,e)=>(r=i(r),e=i(e),t=>r(t)>=e(t)));l("<=",(r,e)=>(r=i(r),e=i(e),t=>r(t)<=e(t)));var b=80;m("==",b);m("!=",b);l("==",(r,e)=>(r=i(r),e=i(e),t=>r(t)==e(t)));l("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(t)));var rr=110,X=120,er=140;m("+",rr);m("-",rr);m("*",X);m("/",X);m("%",X);E("+",er);E("-",er);l("+",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)+e(t)):(r=i(r),t=>+r(t)));l("-",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)-e(t)):(r=i(r),t=>-r(t)));l("*",(r,e)=>(r=i(r),e=i(e),t=>r(t)*e(t)));l("/",(r,e)=>(r=i(r),e=i(e),t=>r(t)/e(t)));l("%",(r,e)=>(r=i(r),e=i(e),t=>r(t)%e(t)));var k=150;C("++",k,r=>r?["++",r,null]:["++",h(k-1)]);C("--",k,r=>r?["--",r,null]:["--",h(k-1)]);var B=(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?B(r[1],e):(()=>{throw Error("Invalid increment target")})();l("++",(r,e)=>B(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));l("--",(r,e)=>B(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var Ur=5,Pr=10;$(",",Pr);$(";",Ur,!0);var tr=(...r)=>(r=r.map(i),e=>{let t;for(let o of r)t=o(e);return t});l(",",tr);l(";",tr);var Rr=170;z("()",Rr);var or=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",Q=170;F("[]",Q);m(".",Q);F("()",Q);var L=r=>{throw Error(r)};l("[]",(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&&L("Missing index"),r=i(r),e=i(e),t=>{let o=e(t);return or(o)?void 0:r(t)[o]}));l(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],or(e)?()=>{}:t=>r(t)[e]));l("()",(r,e)=>{if(e===void 0)return r==null?L("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(p=>p==null||t(p));t(e)&&L("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 nr(r,(n,p,d)=>n[p](...o(d)))});var nr=(r,e,t,o)=>r==null?L("Empty ()"):r[0]==="()"&&r.length==2?nr(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));var ir=new WeakMap,Dr=(r,...e)=>typeof r=="string"?i(f(r)):ir.get(r)||ir.set(r,Mr(r,e)).get(r),sr=57344,Mr=(r,e)=>{let t=r.reduce((p,d,A)=>p+(A?String.fromCharCode(sr+A-1):"")+d,""),o=f(t),n=p=>{if(typeof p=="string"&&p.length===1){let d=p.charCodeAt(0)-sr,A;if(d>=0&&d<e.length)return A=e[d],kr(A)?A:[,A]}return Array.isArray(p)?p.map(n):p};return i(n(o))},kr=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),de=Dr;export{F as access,m as binary,i as compile,u as cur,de as default,g as err,h as expr,z as group,$r as id,s as idx,Br as keyword,Xr as literal,W as loc,c as lookup,$ as nary,_ as next,l as operator,N as operators,Or as parens,f as parse,Nr as peek,G as prec,v as seek,y as skip,Lr as space,C as token,E as unary,Fr as word};
package/util/stringify.js CHANGED
@@ -94,10 +94,20 @@ generator('break', () => 'break');
94
94
  generator('continue', () => 'continue');
95
95
  generator('throw', a => 'throw ' + codegen(a));
96
96
 
97
- // Try/Catch - nested structure
98
- generator('try', body => 'try { ' + codegen(body) + ' }');
99
- generator('catch', (tryExpr, param, body) => codegen(tryExpr) + ' catch (' + codegen(param) + ') { ' + codegen(body) + ' }');
100
- generator('finally', (expr, body) => codegen(expr) + ' finally { ' + codegen(body) + ' }');
97
+ // Try/Catch - semi-faithful: ['try', body, ['catch', param, handler]?, ['finally', cleanup]?]
98
+ generator('try', (body, ...clauses) => {
99
+ let result = 'try { ' + codegen(body) + ' }';
100
+ for (const clause of clauses) {
101
+ if (clause?.[0] === 'catch') {
102
+ result += ' catch (' + codegen(clause[1]) + ') { ' + codegen(clause[2]) + ' }';
103
+ } else if (clause?.[0] === 'finally') {
104
+ result += ' finally { ' + codegen(clause[1]) + ' }';
105
+ }
106
+ }
107
+ return result;
108
+ });
109
+ generator('catch', (param, body) => 'catch (' + codegen(param) + ') { ' + codegen(body) + ' }');
110
+ generator('finally', body => 'finally { ' + codegen(body) + ' }');
101
111
 
102
112
  // Functions
103
113
  generator('function', (name, params, body) => {
package/feature/block.js DELETED
@@ -1,39 +0,0 @@
1
- // Block parsing helpers
2
- import { expr, skip, space, lookup, err, parse, seek, cur, idx, parens, loc, operator, compile, peek } from '../parse.js';
3
-
4
- const STATEMENT = 5, OBRACE = 123, CBRACE = 125;
5
-
6
- // keyword(op, prec, fn) - prefix-only word token with object property support
7
- // keyword('while', 6, () => ['while', parens(), body()])
8
- // keyword('break', 6, () => ['break'])
9
- // Allows property names: {while:1} won't match keyword, falls back to identifier
10
- export const keyword = (op, prec, map, c = op.charCodeAt(0), l = op.length, prev = lookup[c], r) =>
11
- lookup[c] = (a, curPrec, curOp, from = idx) =>
12
- !a &&
13
- (curOp ? op == curOp : (l < 2 || cur.substr(idx, l) == op) && (curOp = op)) &&
14
- curPrec < prec &&
15
- !parse.id(cur.charCodeAt(idx + l)) &&
16
- peek(idx + l) !== 58 && // allow {keyword:value}
17
- (seek(idx + l), (r = map()) ? loc(r, from) : seek(from), r) ||
18
- prev?.(a, curPrec, curOp);
19
-
20
- // infix(op, prec, fn) - infix word token (requires left operand)
21
- // infix('catch', 6, a => ['catch', a, parens(), block()])
22
- // infix('finally', 6, a => ['finally', a, block()])
23
- // attaches .loc to array results for source mapping
24
- export const infix = (op, prec, map, c = op.charCodeAt(0), l = op.length, prev = lookup[c], r) =>
25
- lookup[c] = (a, curPrec, curOp, from = idx) =>
26
- a &&
27
- (curOp ? op == curOp : (l < 2 || cur.substr(idx, l) == op) && (curOp = op)) &&
28
- curPrec < prec &&
29
- !parse.id(cur.charCodeAt(idx + l)) &&
30
- (seek(idx + l), loc(r = map(a), from), r) ||
31
- prev?.(a, curPrec, curOp);
32
-
33
- // block() - parse required { body }
34
- export const block = () =>
35
- (space() === OBRACE || err('Expected {'), skip(), expr(STATEMENT - .5, CBRACE) || null);
36
-
37
- // body() - parse { body } or single statement
38
- export const body = () =>
39
- space() !== OBRACE ? expr(STATEMENT + .5) : (skip(), expr(STATEMENT - .5, CBRACE) || null);
@@ -1,3 +0,0 @@
1
- // Control flow symbols (shared by loop, group, switch, try, function)
2
- // RETURN is array to hold value - reused, no allocation per throw
3
- export const BREAK = Symbol('break'), CONTINUE = Symbol('continue'), RETURN = [];
@@ -1,51 +0,0 @@
1
- /**
2
- * Destructuring patterns and binding
3
- *
4
- * Handles: [a, b] = arr, {x, y} = obj, [a, ...rest] = arr, {x = default} = obj
5
- */
6
- import { compile } from '../parse.js';
7
-
8
- // Flatten comma into array: [',', a, b, c] → [a, b, c]
9
- const flatten = items => items[0]?.[0] === ',' ? items[0].slice(1) : items;
10
-
11
- // Destructure value into context
12
- export const destructure = (pattern, value, ctx) => {
13
- if (typeof pattern === 'string') { ctx[pattern] = value; return; }
14
- const [op, ...raw] = pattern;
15
- const items = flatten(raw);
16
- if (op === '{}') {
17
- const used = [];
18
- for (const item of items) {
19
- // Rest: {...rest}
20
- if (Array.isArray(item) && item[0] === '...') {
21
- const rest = {};
22
- for (const k in value) if (!used.includes(k)) rest[k] = value[k];
23
- ctx[item[1]] = rest;
24
- break;
25
- }
26
- let key, binding, def;
27
- // Shorthand: {x} → item is 'x'
28
- // With default: {x = 1} → ['=', 'x', default]
29
- // Rename: {x: y} → [':', 'x', 'y']
30
- if (typeof item === 'string') { key = binding = item }
31
- else if (item[0] === '=') { typeof item[1] === 'string' ? (key = binding = item[1]) : ([, key, binding] = item[1]); def = item[2] }
32
- else { [, key, binding] = item }
33
- used.push(key);
34
- let val = value[key];
35
- if (val === undefined && def) val = compile(def)(ctx);
36
- destructure(binding, val, ctx);
37
- }
38
- }
39
- else if (op === '[]') {
40
- let i = 0;
41
- for (const item of items) {
42
- if (item === null) { i++; continue; }
43
- if (Array.isArray(item) && item[0] === '...') { ctx[item[1]] = value.slice(i); break; }
44
- let binding = item, def;
45
- if (Array.isArray(item) && item[0] === '=') [, binding, def] = item;
46
- let val = value[i++];
47
- if (val === undefined && def) val = compile(def)(ctx);
48
- destructure(binding, val, ctx);
49
- }
50
- }
51
- };