subscript 9.2.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +115 -169
  2. package/feature/access.js +67 -7
  3. package/feature/accessor.js +49 -0
  4. package/feature/asi.js +15 -0
  5. package/feature/async.js +45 -0
  6. package/feature/block.js +41 -0
  7. package/feature/class.js +69 -0
  8. package/feature/collection.js +40 -0
  9. package/feature/comment.js +25 -5
  10. package/feature/destruct.js +33 -0
  11. package/feature/function.js +44 -0
  12. package/feature/group.js +39 -9
  13. package/feature/if.js +23 -38
  14. package/feature/literal.js +13 -0
  15. package/feature/loop.js +107 -106
  16. package/feature/module.js +42 -0
  17. package/feature/number.js +41 -38
  18. package/feature/op/arithmetic.js +29 -0
  19. package/feature/op/arrow.js +33 -0
  20. package/feature/op/assign-logical.js +33 -0
  21. package/feature/op/assignment.js +47 -0
  22. package/feature/op/bitwise-unsigned.js +17 -0
  23. package/feature/op/bitwise.js +29 -0
  24. package/feature/op/comparison.js +19 -0
  25. package/feature/op/defer.js +15 -0
  26. package/feature/op/equality.js +16 -0
  27. package/feature/op/identity.js +15 -0
  28. package/feature/op/increment.js +23 -0
  29. package/feature/op/logical.js +21 -0
  30. package/feature/op/membership.js +17 -0
  31. package/feature/op/nullish.js +13 -0
  32. package/feature/op/optional.js +61 -0
  33. package/feature/op/pow.js +19 -0
  34. package/feature/op/range.js +26 -0
  35. package/feature/op/spread.js +15 -0
  36. package/feature/op/ternary.js +15 -0
  37. package/feature/op/type.js +18 -0
  38. package/feature/op/unary.js +41 -0
  39. package/feature/prop.js +34 -0
  40. package/feature/regex.js +31 -0
  41. package/feature/seq.js +21 -0
  42. package/feature/string.js +24 -17
  43. package/feature/switch.js +48 -0
  44. package/feature/template.js +39 -0
  45. package/feature/try.js +57 -0
  46. package/feature/unit.js +35 -0
  47. package/feature/var.js +51 -41
  48. package/jessie.js +31 -0
  49. package/jessie.min.js +8 -0
  50. package/justin.js +39 -48
  51. package/justin.min.js +8 -4
  52. package/package.json +15 -16
  53. package/parse.js +153 -0
  54. package/subscript.d.ts +45 -5
  55. package/subscript.js +62 -22
  56. package/subscript.min.js +5 -4
  57. package/util/bundle.js +507 -0
  58. package/util/stringify.js +172 -0
  59. package/feature/add.js +0 -22
  60. package/feature/array.js +0 -11
  61. package/feature/arrow.js +0 -23
  62. package/feature/assign.js +0 -11
  63. package/feature/bitwise.js +0 -11
  64. package/feature/bool.js +0 -5
  65. package/feature/call.js +0 -15
  66. package/feature/compare.js +0 -11
  67. package/feature/control.js +0 -142
  68. package/feature/increment.js +0 -11
  69. package/feature/logic.js +0 -11
  70. package/feature/mult.js +0 -25
  71. package/feature/object.js +0 -17
  72. package/feature/optional.js +0 -23
  73. package/feature/pow.js +0 -5
  74. package/feature/shift.js +0 -12
  75. package/feature/spread.js +0 -6
  76. package/feature/ternary.js +0 -10
  77. package/src/compile.d.ts +0 -17
  78. package/src/compile.js +0 -28
  79. package/src/const.js +0 -45
  80. package/src/parse.d.ts +0 -22
  81. package/src/parse.js +0 -113
  82. package/src/stringify.js +0 -27
  83. /package/{LICENSE → license} +0 -0
package/package.json CHANGED
@@ -1,37 +1,34 @@
1
1
  {
2
2
  "name": "subscript",
3
- "version": "9.2.0",
4
- "description": "Fast and tiny expression evaluator with minimal syntax.",
3
+ "version": "10.0.0",
4
+ "description": "Tiny expression parser & evaluator",
5
5
  "main": "subscript.js",
6
6
  "module": "subscript.js",
7
7
  "browser": "subscript.js",
8
8
  "types": "./subscript.d.ts",
9
9
  "exports": {
10
10
  ".": "./subscript.js",
11
- "./parse": "./src/parse.js",
12
- "./compile": "./src/compile.js",
13
- "./const": "./src/const.js",
11
+ "./parse": "./parse.js",
14
12
  "./justin": "./justin.js",
15
- "./src/*": "./src/*",
16
- "./feature/*": "./feature/*"
13
+ "./jessie": "./jessie.js",
14
+ "./feature/*": "./feature/*",
15
+ "./util/*": "./util/*"
17
16
  },
18
17
  "type": "module",
19
18
  "files": [
20
- "src",
21
19
  "feature",
20
+ "util",
22
21
  "subscript.js",
23
22
  "subscript.min.js",
24
23
  "subscript.d.ts",
24
+ "parse.js",
25
25
  "justin.js",
26
- "justin.min.js"
26
+ "justin.min.js",
27
+ "jessie.js",
28
+ "jessie.min.js"
27
29
  ],
28
- "directories": {
29
- "lib": "lib",
30
- "src": "src",
31
- "test": "test"
32
- },
33
30
  "scripts": {
34
- "build": "esbuild subscript.js --bundle --minify --format=esm --outfile=subscript.min.js && esbuild justin.js --bundle --minify --format=esm --outfile=justin.min.js",
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",
35
32
  "prepublishOnly": "npm run build",
36
33
  "test": "node test/test.js",
37
34
  "check-types": "tsc --noEmit subscript.d.ts"
@@ -79,6 +76,8 @@
79
76
  "devDependencies": {
80
77
  "@playwright/test": "^1.57.0",
81
78
  "esbuild": "^0.27.2",
82
- "tst": "^9.0.0"
79
+ "jsep": "^1.4.0",
80
+ "terser": "^5.44.1",
81
+ "tst": "^9.2.0"
83
82
  }
84
83
  }
package/parse.js ADDED
@@ -0,0 +1,153 @@
1
+ // Pratt parser core + operator registry + compile
2
+ // Character codes
3
+ const SPACE = 32;
4
+
5
+ // current string, index
6
+ export let idx, cur,
7
+
8
+ // parse input string to AST
9
+ parse = s => (idx = 0, cur = s, parse.newline = false, s = expr(), cur[idx] ? err() : s || ''),
10
+
11
+ // display error with context
12
+ err = (msg = 'Unexpected token', at = idx,
13
+ lines = cur.slice(0, at).split('\n'),
14
+ last = lines.pop(),
15
+ before = cur.slice(Math.max(0, at - 40), at),
16
+ ptr = '\u032D',
17
+ chr = (cur[at] || '∅') + ptr,
18
+ after = cur.slice(at + 1, at + 20)
19
+ ) => {
20
+ throw SyntaxError(`${msg} at ${lines.length + 1}:${last.length + 1}\n${(cur[at-41]!=='\n' ? '...' : '') +before}${chr}${after}`)
21
+ },
22
+
23
+ // attach location to node (returns node for chaining)
24
+ loc = (node, at = idx) => (Array.isArray(node) && (node.loc = at), node),
25
+
26
+ // advance until condition meets
27
+ next = (is, from = idx, l) => {
28
+ while (l = is(cur.charCodeAt(idx))) idx += l;
29
+ return cur.slice(from, idx);
30
+ },
31
+
32
+ // advance n characters
33
+ skip = (n=1) => cur[idx+=n],
34
+
35
+ // set position (for backtracking)
36
+ seek = n => idx = n,
37
+
38
+ // a + b - c
39
+ expr = (prec = 0, end) => {
40
+ let cc, token, newNode, fn, prevReserved = parse.reserved, nl;
41
+ if (end) parse.asi && (parse.newline = false);
42
+ parse.reserved = 0;
43
+
44
+ while (
45
+ (cc = parse.space()) &&
46
+ (nl = parse.newline, 1) &&
47
+ cc !== end &&
48
+ (newNode =
49
+ ((fn = lookup[cc]) && fn(token, prec)) ??
50
+ (parse.asi && token && nl && (newNode = parse.asi(token, prec, expr))) ??
51
+ (!token && !parse.reserved && next(parse.id))
52
+ )
53
+ ) token = newNode, parse.reserved = 0;
54
+ parse.reserved = prevReserved;
55
+
56
+ if (end) cc == end ? idx++ : err('Unclosed ' + String.fromCharCode(end - (end > 42 ? 2 : 1)));
57
+
58
+ return token;
59
+ },
60
+
61
+ // skip space chars, return first non-space character
62
+ space = parse.space = (cc, from = idx) => {
63
+ while ((cc = cur.charCodeAt(idx)) <= SPACE) {
64
+ if (parse.asi && cc === 10) parse.newline = true
65
+ idx++
66
+ }
67
+ return cc
68
+ },
69
+
70
+ // is char an id?
71
+ id = parse.id = c =>
72
+ (c >= 48 && c <= 57) ||
73
+ (c >= 65 && c <= 90) ||
74
+ (c >= 97 && c <= 122) ||
75
+ c == 36 || c == 95 ||
76
+ (c >= 192 && c != 215 && c != 247),
77
+
78
+ // check if word matches at current position
79
+ word = (w, l = w.length) => cur.substr(idx, l) === w && !parse.id(cur.charCodeAt(idx + l)),
80
+
81
+ // parse (...) group
82
+ parens = () => (skip(), expr(0, 41)),
83
+
84
+ // operator lookup table
85
+ lookup = [],
86
+
87
+ // create operator checker/mapper
88
+ token = (
89
+ op,
90
+ prec = SPACE,
91
+ map,
92
+ c = op.charCodeAt(0),
93
+ l = op.length,
94
+ prev = lookup[c],
95
+ word = op.toUpperCase() !== op,
96
+ matched, r
97
+ ) => lookup[c] = (a, curPrec, curOp, from = idx) =>
98
+ (matched = curOp,
99
+ (curOp ?
100
+ op == curOp :
101
+ (l < 2 || (op.charCodeAt(1) === cur.charCodeAt(idx + 1) && (l < 3 || cur.substr(idx, l) == op))) && (!word || !parse.id(cur.charCodeAt(idx + l))) && (matched = curOp = op)
102
+ ) &&
103
+ curPrec < prec &&
104
+ (idx += l, (r = map(a)) ? loc(r, from) : (idx = from, matched = 0, word && r !== false && (parse.reserved = 1), !word && !prev && err()), r)
105
+ ) ||
106
+ prev?.(a, curPrec, matched),
107
+
108
+ binary = (op, prec, right = false) => token(op, prec, (a, b) => a && (b = expr(prec - (right ? .5 : 0))) && [op, a, b]),
109
+
110
+ unary = (op, prec, post) => token(op, prec, a => post ? (a && [op, a]) : (!a && (a = expr(prec - .5)) && [op, a])),
111
+
112
+ literal = (op, val) => token(op, 200, a => !a && [, val]),
113
+
114
+ nary = (op, prec, right) => {
115
+ token(op, prec,
116
+ (a, b) => (
117
+ b = expr(prec - (right ? .5 : 0)),
118
+ (
119
+ (a?.[0] !== op) && (a = [op, a || null]),
120
+ b?.[0] === op ? a.push(...b.slice(1)) : a.push(b || null),
121
+ a
122
+ ))
123
+ )
124
+ },
125
+
126
+ group = (op, prec) => token(op[0], prec, a => (!a && [op, expr(0, op.charCodeAt(1)) || null])),
127
+
128
+ access = (op, prec) => token(op[0], prec, a => (a && [op, a, expr(0, op.charCodeAt(1)) || null]));
129
+
130
+ // === Compile: AST → Evaluator ===
131
+
132
+ // Current node being compiled (for error location)
133
+ let curNode;
134
+
135
+ // Compile error with source location
136
+ const compileErr = (msg = 'Compile error', node = curNode) => err(msg, node?.loc);
137
+
138
+ // Operator registry
139
+ export const operators = {};
140
+
141
+ // Register an operator (chainable for overrides)
142
+ export const operator = (op, fn, prev = operators[op]) =>
143
+ (operators[op] = (...args) => fn(...args) || prev?.(...args));
144
+
145
+ // Compile AST to evaluator function
146
+ export const compile = node => (
147
+ curNode = node,
148
+ !Array.isArray(node) ? (node === undefined ? () => undefined : ctx => ctx?.[node]) :
149
+ node[0] === undefined ? (v => () => v)(node[1]) :
150
+ operators[node[0]]?.(...node.slice(1)) ?? compileErr(`Unknown operator: ${node[0]}`)
151
+ );
152
+
153
+ export default parse;
package/subscript.d.ts CHANGED
@@ -1,6 +1,46 @@
1
- import type { OperatorFunction } from './src/compile';
1
+ // AST node types
2
+ export type Identifier = string;
3
+ export type Literal = [undefined, any];
4
+ export type Operation = [string, ...AST[]];
5
+ export type AST = Identifier | Literal | Operation;
2
6
 
3
- export default subscript;
4
- export * from "./src/parse.js";
5
- export * from "./src/compile.js";
6
- declare function subscript(s: string): ((ctx?: any) => any) | OperatorFunction;
7
+ // Evaluator function
8
+ export type Evaluator = (ctx?: any) => any;
9
+
10
+ // Operator compiler: receives args, returns evaluator
11
+ export type Operator = (...args: AST[]) => Evaluator | undefined;
12
+
13
+ // Parse exports
14
+ export let idx: number;
15
+ export let cur: string;
16
+ export function parse(s: string): AST;
17
+ export function err(msg?: string, at?: number): never;
18
+ export function loc<T>(node: T, at?: number): T;
19
+ export function next(is: (c: number) => number, from?: number): string;
20
+ export function skip(n?: number): string;
21
+ export function seek(n: number): number;
22
+ export function expr(prec?: number, end?: number): AST;
23
+ export const lookup: ((a: AST, prec: number, op?: string) => AST)[];
24
+ export function token(op: string, prec?: number, map?: (a: AST) => AST): void;
25
+ export function binary(op: string, prec: number, right?: boolean): void;
26
+ export function unary(op: string, prec: number, post?: boolean): void;
27
+ export function literal(op: string, val: any): void;
28
+ export function nary(op: string, prec: number, right?: boolean): void;
29
+ export function group(op: string, prec: number): void;
30
+ export function access(op: string, prec: number): void;
31
+
32
+ // Compile exports
33
+ export const operators: Record<string, Operator>;
34
+ export function operator(op: string, fn: Operator): void;
35
+ export function compile(node: AST): Evaluator;
36
+
37
+ // Default export
38
+ export default parse;
39
+
40
+ // subscript template tag
41
+ interface Subscript {
42
+ (strings: TemplateStringsArray, ...values: any[]): Evaluator;
43
+ (s: string): Evaluator;
44
+ }
45
+ declare const subscript: Subscript;
46
+ export { subscript };
package/subscript.js CHANGED
@@ -1,24 +1,64 @@
1
1
  /**
2
- * Subscript dialect includes common operators / primitives for all languages
2
+ * subscript: Minimal expression parser + compiler
3
+ *
4
+ * Usage:
5
+ * subscript`a + b`(ctx) - template tag, returns compiled evaluator
6
+ * subscript`a + ${x}`(ctx) - interpolations: primitives, objects, AST nodes
7
+ * subscript('a + b')(ctx) - direct call (no caching)
8
+ *
9
+ * For more features:
10
+ * import { parse, compile } from 'subscript/justin.js' // + JSON, arrows, templates
11
+ * import { parse, compile } from 'subscript/jessie.js' // + statements, functions
3
12
  */
4
- import './feature/number.js'
5
- import './feature/string.js'
6
- import './feature/call.js'
7
- import './feature/access.js'
8
- import './feature/group.js'
9
- import './feature/assign.js'
10
- import './feature/mult.js'
11
- import './feature/add.js'
12
- import './feature/increment.js'
13
- import './feature/bitwise.js'
14
- import './feature/logic.js'
15
- import './feature/compare.js'
16
- import './feature/shift.js'
17
- import compile from './src/compile.js'
18
- import parse from './src/parse.js'
19
-
20
- export { parse, access, binary, unary, nary, group, token } from './src/parse.js'
21
- export { compile, operator } from './src/compile.js'
22
- export { stringify } from './src/stringify.js'
23
-
24
- export default s => compile(parse(s))
13
+
14
+ // Expression features
15
+ import './feature/number.js'; // Decimal numbers: 123, 1.5, 1e3
16
+ import './feature/string.js'; // Double-quoted strings with escapes
17
+
18
+ // Operators (C-family common set) - order matters for token chain performance
19
+ import './feature/op/assignment.js'; // = += -= *= /= %= |= &= ^= >>= <<=
20
+ import './feature/op/logical.js'; // ! && ||
21
+ import './feature/op/bitwise.js'; // ~ | & ^ >> <<
22
+ import './feature/op/comparison.js'; // < > <= >=
23
+ import './feature/op/equality.js'; // == !=
24
+ import './feature/op/arithmetic.js'; // + - * / %
25
+ import './feature/op/increment.js'; // ++ --
26
+
27
+ import './feature/group.js'; // Grouping: (a), sequences: a, b; a; b
28
+ import './feature/access.js'; // Property access: a.b, a[b], f(), [a,b]
29
+
30
+ import { parse, compile } from './parse.js';
31
+ export * from './parse.js';
32
+
33
+ // Cache for compiled templates (keyed by template strings array reference)
34
+ const cache = new WeakMap();
35
+
36
+ // Template tag: subscript`a + b` or subscript`a + ${x}`
37
+ const subscript = (strings, ...values) =>
38
+ // Direct call subscript('code') - strings is just a string
39
+ typeof strings === 'string' ? compile(parse(strings)) :
40
+ // Template literal - use cache
41
+ cache.get(strings) || cache.set(strings, compileTemplate(strings, values)).get(strings);
42
+
43
+ // Compile template with placeholders (using Private Use Area chars)
44
+ const PUA = 0xE000;
45
+ const compileTemplate = (strings, values) => {
46
+ const code = strings.reduce((acc, s, i) => acc + (i ? String.fromCharCode(PUA + i - 1) : '') + s, '');
47
+ const ast = parse(code);
48
+ const inject = node => {
49
+ if (typeof node === 'string' && node.length === 1) {
50
+ let i = node.charCodeAt(0) - PUA, v;
51
+ if (i >= 0 && i < values.length) return v = values[i], isAST(v) ? v : [, v];
52
+ }
53
+ return Array.isArray(node) ? node.map(inject) : node;
54
+ };
55
+ return compile(inject(ast));
56
+ };
57
+
58
+ // Detect AST node vs regular value
59
+ // AST: string (identifier), or array with string/undefined first element
60
+ const isAST = v =>
61
+ typeof v === 'string' ||
62
+ (Array.isArray(v) && (typeof v[0] === 'string' || v[0] === undefined));
63
+
64
+ export default subscript;
package/subscript.min.js CHANGED
@@ -1,4 +1,5 @@
1
- var F=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype";var E,f,I=r=>(E=0,f=r,r=s(),f[E]?R():r||""),R=(r="Unexpected token",o=f.slice(0,E).split(`
2
- `),t=o.pop(),e=f.slice(Math.max(0,E-40),E),m=f.slice(E,E+20))=>{throw SyntaxError(`${r} at ${o.length+1}:${t.length+1} \u2014 ${e}^${m}`)},S=(r,o=E,t)=>{for(;t=r(f.charCodeAt(E));)E+=t;return f.slice(o,E)},l=()=>f[E++],s=(r=0,o)=>{let t,e,m,C;for(;(t=a())&&(m=((C=u[t])&&C(e,r))??(!e&&S(I.id)));)e=m;return o&&(t==o?E++:R("Unclosed "+String.fromCharCode(o-(o>42?2:1)))),e},a=r=>{for(;(r=f.charCodeAt(E))<=32;)E++;return r},dr=I.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,u=[],A=(r,o=32,t,e=r.charCodeAt(0),m=r.length,C=u[e],Y=r.toUpperCase()!==r)=>u[e]=(c,M,T,Z=E)=>(T?r==T:(m<2||f.substr(E,m)==r)&&(T=r))&&M<o&&!(Y&&I.id(f.charCodeAt(E+m)))&&(E+=m,t(c)||(E=Z,!C&&R()))||C?.(c,M,T),n=(r,o,t=!1)=>A(r,o,(e,m)=>e&&(m=s(o-(t?.5:0)))&&[r,e,m]),y=(r,o,t)=>A(r,o,e=>t?e&&[r,e]:!e&&(e=s(o-.5))&&[r,e]),g=(r,o,t)=>{A(r,o,(e,m)=>(m=s(o-(t?.5:0)),e?.[0]!==r&&(e=[r,e||null]),m?.[0]===r?e.push(...m.slice(1)):e.push(m||null),e))},B=(r,o)=>A(r[0],o,t=>!t&&[r,s(0,r.charCodeAt(1))]),N=(r,o)=>A(r[0],o,t=>t&&[r,t,s(0,r.charCodeAt(1))||null]),w=I;var rr=98,or=66,tr=111,er=79,ir=120,pr=88,mr=97,nr=102,Er=65,Cr=70,k=(r,o)=>[,(r=+S(t=>t===46||t>=48&&t<=57||(t===69||t===101?2:0)))!=r?R():r];u[46]=r=>!r&&k();for(let r=49;r<=57;r++)u[r]=o=>o?R():k();u[48]=r=>{if(r)return R();let o=f.charCodeAt(E+1);if(o===rr||o===or){l(),l();let t=S(e=>e===48||e===49);return[,parseInt(t,2)]}if(o===tr||o===er){l(),l();let t=S(e=>e>=48&&e<=55);return[,parseInt(t,8)]}if(o===ir||o===pr){l(),l();let t=S(e=>e>=48&&e<=57||e>=mr&&e<=nr||e>=Er&&e<=Cr);return[,parseInt(t,16)]}return k()};var Rr={n:`
3
- `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},x=r=>(o,t,e="")=>(o&&R("Unexpected string"),l(),S(m=>m-r&&(m===92?(e+=Rr[f[E+1]]||f[E+1],2):(e+=f[E],1))),l()||R("Bad string"),[,e]);u[34]=x(34);u[39]=x(39);var i=r=>Array.isArray(r)?r[0]?G[r[0]].call(...r):()=>r[1]:i.id(r),Xr=i.id=r=>o=>o?.[r],G={},p=(r,o,t=G[r])=>G[r]=(...e)=>o(...e)||t?.(...e),_=(r,o,t,e,m)=>r[0]==="()"&&r.length==2?_(r[1],o,t):typeof r=="string"?C=>o(C,r,C):r[0]==="."?(e=i(r[1]),m=r[2],C=>o(e(C),m,C)):r[0]==="[]"&&r.length===3?(e=i(r[1]),m=i(r[2]),C=>o(e(C),m(C),C)):t?(r=i(r),C=>o([r(C)],0,C)):()=>R("Bad left value"),J=i;N("()",170);p("()",(r,o,t)=>o!==void 0&&(t=o?o[0]===","?(o=o.slice(1).map(e=>e?i(e):err()),e=>o.map(m=>m(e))):(o=i(o),e=>[o(e)]):()=>[],_(r,(e,m,C)=>e[m](...t(C)),!0)));N("[]",170);p("[]",(r,o)=>o?(r=i(r),o=i(o),t=>{let e=o(t);return F(e)?void 0:r(t)[e]}):R());n(".",170);p(".",(r,o)=>(r=i(r),o=o[0]?o:o[1],F(o)?()=>{}:t=>r(t)[o]));B("()",170);p("()",(r,o)=>o===void 0&&(!r&&R("Empty ()"),i(r)));var q=(...r)=>(r=r.map(i),o=>r.map(t=>t(o)).pop());g(",",10),p(",",q);g(";",5,!0),p(";",q);n("=",20,!0);p("=",(r,o)=>(o=i(o),_(r,(t,e,m)=>t[e]=o(m))));n("*",120),p("*",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)*o(t)));n("/",120),p("/",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)/o(t)));n("%",120),p("%",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)%o(t)));n("*=",20,!0);p("*=",(r,o)=>(o=i(o),_(r,(t,e,m)=>t[e]*=o(m))));n("/=",20,!0);p("/=",(r,o)=>(o=i(o),_(r,(t,e,m)=>t[e]/=o(m))));n("%=",20,!0);p("%=",(r,o)=>(o=i(o),_(r,(t,e,m)=>t[e]%=o(m))));n("+",110),p("+",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)+o(t)));n("-",110),p("-",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)-o(t)));y("+",140),p("+",(r,o)=>!o&&(r=i(r),t=>+r(t)));y("-",140),p("-",(r,o)=>!o&&(r=i(r),t=>-r(t)));n("+=",20,!0);p("+=",(r,o)=>(o=i(o),_(r,(t,e,m)=>t[e]+=o(m))));n("-=",20,!0);p("-=",(r,o)=>(o=i(o),_(r,(t,e,m)=>t[e]-=o(m))));A("++",150,r=>r?["++",r,null]:["++",s(149)]);p("++",(r,o)=>_(r,o===null?(t,e)=>t[e]++:(t,e)=>++t[e]));A("--",150,r=>r?["--",r,null]:["--",s(149)]);p("--",(r,o)=>_(r,o===null?(t,e)=>t[e]--:(t,e)=>--t[e]));y("~",140),p("~",(r,o)=>!o&&(r=i(r),t=>~r(t)));n("|",50),p("|",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)|o(t)));n("&",70),p("&",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)&o(t)));n("^",60),p("^",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)^o(t)));y("!",140),p("!",(r,o)=>!o&&(r=i(r),t=>!r(t)));n("||",30);p("||",(r,o)=>(r=i(r),o=i(o),t=>r(t)||o(t)));n("&&",40);p("&&",(r,o)=>(r=i(r),o=i(o),t=>r(t)&&o(t)));n("==",80),p("==",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)==o(t)));n("!=",80),p("!=",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)!=o(t)));n(">",90),p(">",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)>o(t)));n("<",90),p("<",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)<o(t)));n(">=",90),p(">=",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)>=o(t)));n("<=",90),p("<=",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)<=o(t)));n(">>",100),p(">>",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)>>o(t)));n("<<",100),p("<<",(r,o)=>o&&(r=i(r),o=i(o),t=>r(t)<<o(t)));n(">>=",20,!0);p(">>=",(r,o)=>(o=i(o),prop(r,(t,e,m)=>t[e]>>=o(m))));n("<<=",20,!0);p("<<=",(r,o)=>(o=i(o),prop(r,(t,e,m)=>t[e]<<=o(m))));function O(r){if(!r)return"";if(Array.isArray(r)){let[o,...t]=r;return o?o=="[]"||o=="{}"||o=="()"?(t.length>1?O(t.shift()):"")+o[0]+O(t[0])+o[1]:t.length===1?o+O(t[0]):t.length===2?O(t[0])+(o==="."?o:" "+o+" ")+O(t[1]):t.filter(Boolean).map(e=>O(e)).join(o+`
4
- `):JSON.stringify(t[0])}return r}var $o=r=>J(w(r));export{N as access,n as binary,i as compile,$o as default,B as group,g as nary,p as operator,I as parse,O as stringify,A as token,y as unary};
1
+ var f,A,m=r=>(f=0,A=r,m.newline=!1,r=h(),A[f]?S():r||""),S=(r="Unexpected token",e=f,t=A.slice(0,e).split(`
2
+ `),n=t.pop(),o=A.slice(Math.max(0,e-40),e),s="\u032D",u=(A[e]||"\u2205")+s,c=A.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${n.length+1}
3
+ ${(A[e-41]!==`
4
+ `?"...":"")+o}${u}${c}`)},W=(r,e=f)=>(Array.isArray(r)&&(r.loc=e),r),N=(r,e=f,t)=>{for(;t=r(A.charCodeAt(f));)f+=t;return A.slice(e,f)},g=(r=1)=>A[f+=r],z=r=>f=r,h=(r=0,e)=>{let t,n,o,s,u=m.reserved,c;for(e&&m.asi&&(m.newline=!1),m.reserved=0;(t=m.space())&&(c=m.newline,1)&&t!==e&&(o=((s=C[t])&&s(n,r))??(m.asi&&n&&c&&(o=m.asi(n,r,h)))??(!n&&!m.reserved&&N(m.id)));)n=o,m.reserved=0;return m.reserved=u,e&&(t==e?f++:S("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),n},k=m.space=(r,e=f)=>{for(;(r=A.charCodeAt(f))<=32;)m.asi&&r===10&&(m.newline=!0),f++;return r},Zr=m.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,b=(r,e=r.length)=>A.substr(f,e)===r&&!m.id(A.charCodeAt(f+e)),M=()=>(g(),h(0,41)),C=[],v=(r,e=32,t,n=r.charCodeAt(0),o=r.length,s=C[n],u=r.toUpperCase()!==r,c,d)=>C[n]=(y,U,L,x=f)=>(c=L,(L?r==L:(o<2||r.charCodeAt(1)===A.charCodeAt(f+1)&&(o<3||A.substr(f,o)==r))&&(!u||!m.id(A.charCodeAt(f+o)))&&(c=L=r))&&U<e&&(f+=o,(d=t(y))?W(d,x):(f=x,c=0,u&&d!==!1&&(m.reserved=1),!u&&!s&&S()),d)||s?.(y,U,c)),p=(r,e,t=!1)=>v(r,e,(n,o)=>n&&(o=h(e-(t?.5:0)))&&[r,n,o]),T=(r,e,t)=>v(r,e,n=>t?n&&[r,n]:!n&&(n=h(e-.5))&&[r,n]),qr=(r,e)=>v(r,200,t=>!t&&[,e]),J=(r,e,t)=>{v(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))},rr=(r,e)=>v(r[0],e,t=>!t&&[r,h(0,r.charCodeAt(1))||null]),V=(r,e)=>v(r[0],e,t=>t&&[r,t,h(0,r.charCodeAt(1))||null]),er,Cr=(r="Compile error",e=er)=>S(r,e?.loc),G={},l=(r,e,t=G[r])=>G[r]=(...n)=>e(...n)||t?.(...n),i=r=>(er=r,Array.isArray(r)?r[0]===void 0?(e=>()=>e)(r[1]):G[r[0]]?.(...r.slice(1))??Cr(`Unknown operator: ${r[0]}`):r===void 0?()=>{}:e=>e?.[r]);var $=46,_=48,F=57,Er=69,gr=101,wr=43,Sr=45,kr=97,vr=102,Tr=65,Ir=70,Y=r=>[,(r=+N(e=>e===$&&A.charCodeAt(f+1)!==$||e>=_&&e<=F||((e===Er||e===gr)&&((e=A.charCodeAt(f+1))>=_&&e<=F||e===wr||e===Sr)?2:0)))!=r?S():r],Rr={2:r=>r===48||r===49,8:r=>r>=48&&r<=55,16:r=>r>=_&&r<=F||r>=kr&&r<=vr||r>=Tr&&r<=Ir};m.number=null;C[$]=r=>!r&&A.charCodeAt(f+1)!==$&&Y();for(let r=_;r<=F;r++)C[r]=e=>e?void 0:Y();C[_]=r=>{if(r)return;let e=m.number;if(e){for(let[t,n]of Object.entries(e))if(t[0]==="0"&&A[f+1]?.toLowerCase()===t[1])return g(2),[,parseInt(N(Rr[n]),n)]}return Y()};var Nr=92,tr=34,nr=39,Ur={n:`
5
+ `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},or=r=>(e,t,n="")=>{if(!(e||!m.string?.[String.fromCharCode(r)]))return g(),N(o=>o-r&&(o===Nr?(n+=Ur[A[f+1]]||A[f+1],2):(n+=A[f],1))),A[f]===String.fromCharCode(r)?g():S("Bad string"),[,n]};C[tr]=or(tr);C[nr]=or(nr);m.string={'"':!0};var w=20;p("=",w,!0);p("+=",w,!0);p("-=",w,!0);p("*=",w,!0);p("/=",w,!0);p("%=",w,!0);p("|=",w,!0);p("&=",w,!0);p("^=",w,!0);p(">>=",w,!0);p("<<=",w,!0);var E=(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?E(r[1],e):(()=>{throw Error("Invalid assignment target")})();l("=",(r,e)=>(e=i(e),E(r,(t,n,o)=>t[n]=e(o))));l("+=",(r,e)=>(e=i(e),E(r,(t,n,o)=>t[n]+=e(o))));l("-=",(r,e)=>(e=i(e),E(r,(t,n,o)=>t[n]-=e(o))));l("*=",(r,e)=>(e=i(e),E(r,(t,n,o)=>t[n]*=e(o))));l("/=",(r,e)=>(e=i(e),E(r,(t,n,o)=>t[n]/=e(o))));l("%=",(r,e)=>(e=i(e),E(r,(t,n,o)=>t[n]%=e(o))));l("|=",(r,e)=>(e=i(e),E(r,(t,n,o)=>t[n]|=e(o))));l("&=",(r,e)=>(e=i(e),E(r,(t,n,o)=>t[n]&=e(o))));l("^=",(r,e)=>(e=i(e),E(r,(t,n,o)=>t[n]^=e(o))));l(">>=",(r,e)=>(e=i(e),E(r,(t,n,o)=>t[n]>>=e(o))));l("<<=",(r,e)=>(e=i(e),E(r,(t,n,o)=>t[n]<<=e(o))));var Mr=30,_r=40,ir=140;p("!",ir);T("!",ir);p("||",Mr);p("&&",_r);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 Pr=50,Br=60,Dr=70,sr=100,Lr=140;p("|",Pr);p("&",Dr);p("^",Br);p(">>",sr);p("<<",sr);T("~",Lr);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 X=90;p("<",X);p(">",X);p("<=",X);p(">=",X);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 lr=80;p("==",lr);p("!=",lr);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 ur=110,Z=120,fr=140;p("+",ur);p("-",ur);p("*",Z);p("/",Z);p("%",Z);T("+",fr);T("-",fr);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 O=150;v("++",O,r=>r?["++",r,null]:["++",h(O-1)]);v("--",O,r=>r?["--",r,null]:["--",h(O-1)]);var q=(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?q(r[1],e):(()=>{throw Error("Invalid increment target")})();l("++",(r,e)=>q(r,e===null?(t,n)=>t[n]++:(t,n)=>++t[n]));l("--",(r,e)=>q(r,e===null?(t,n)=>t[n]--:(t,n)=>--t[n]));var pr=5,$r=123,Fr=125,I=(r,e,t,n=r.charCodeAt(0),o=r.length,s=C[n],u)=>C[n]=(c,d,y,U=f)=>!c&&(y?r==y:(o<2||A.substr(f,o)==r)&&(y=r))&&d<e&&!m.id(A.charCodeAt(f+o))&&(z(f+o),(u=t())?W(u,U):(z(U),!s&&S()),u)||s?.(c,d,y);var P=()=>k()!==$r?h(pr+.5):(g(),["block",h(pr-.5,Fr)||null]);l("block",r=>r===void 0?()=>{}:(r=i(r),e=>r(e)));var B=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[n,...o]=r;if(n==="{}")for(let s of o){let u,c,d;s[0]==="="?[,[,u,c],d]=s:[,u,c]=s;let y=e[u];y===void 0&&d&&(y=i(d)(t)),B(c,y,t)}else if(n==="[]"){let s=0;for(let u of o){if(u===null){s++;continue}if(Array.isArray(u)&&u[0]==="..."){t[u[1]]=e.slice(s);break}let c=u,d;Array.isArray(u)&&u[0]==="="&&([,c,d]=u);let y=e[s++];y===void 0&&d&&(y=i(d)(t)),B(c,y,t)}}};var Q=Symbol("break"),H=Symbol("continue"),mr=Symbol("return"),D=(r,e)=>{try{return{v:r(e)}}catch(t){if(t?.type===Q)return{b:1};if(t?.type===H)return{c:1};if(t?.type===mr)return{r:1,v:t.value};throw t}},R=5,Xr=125,Or=59;I("while",R+1,()=>(k(),["while",M(),P()]));I("do",R+1,()=>(r=>(k(),g(5),k(),["do",r,M()]))(P()));I("for",R+1,()=>(k(),b("await")?(g(5),k(),["for await",M(),P()]):["for",M(),P()]));I("break",R+1,()=>["break"]);I("continue",R+1,()=>["continue"]);I("return",R+1,()=>{m.asi&&(m.newline=!1),k();let r=A.charCodeAt(f);return!r||r===Xr||r===Or||m.newline?["return"]:["return",h(R)]});l("while",(r,e)=>(r=i(r),e=i(e),t=>{let n,o;for(;r(t)&&!(n=D(e,t)).b;){if(n.r)return n.v;n.c||(o=n.v)}return o}));l("do",(r,e)=>(r=i(r),e=i(e),t=>{let n,o;do{if((n=D(r,t)).b)break;if(n.r)return n.v;n.c||(o=n.v)}while(e(t));return o}));l("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),s=>{let u,c;for(t?.(s);n(s)&&!(u=D(e,s)).b;o?.(s)){if(u.r)return u.v;u.c||(c=u.v)}return c}}if(Array.isArray(r)&&(r[0]==="in"||r[0]==="of")){let[t,n,o]=r;if(Array.isArray(n)&&(n[0]==="let"||n[0]==="const"||n[0]==="var")&&(n=n[1]),t==="in")return Hr(n,o,e);if(t==="of")return Qr(n,o,e)}});var Qr=(r,e,t)=>{e=i(e),t=i(t);let n=Array.isArray(r);return o=>{let s,u,c=n?null:o[r];for(let d of e(o)){if(n?B(r,d,o):o[r]=d,(s=D(t,o)).b)break;if(s.r)return s.v;s.c||(u=s.v)}return n||(o[r]=c),u}},Hr=(r,e,t)=>{e=i(e),t=i(t);let n=Array.isArray(r);return o=>{let s,u,c=n?null:o[r];for(let d in e(o)){if(n?B(r,d,o):o[r]=d,(s=D(t,o)).b)break;if(s.r)return s.v;s.c||(u=s.v)}return n||(o[r]=c),u}};l("break",()=>()=>{throw{type:Q}});l("continue",()=>()=>{throw{type:H}});l("return",r=>(r=r!==void 0?i(r):null,e=>{throw{type:mr,value:r?.(e)}}));var cr=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",j=170;V("[]",j);p(".",j);V("()",j);var a=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]),n=>t(n)):(t=i(t),n=>[t(n)])),t=>r.flatMap(n=>n(t))):(e==null&&a("Missing index"),r=i(r),e=i(e),t=>{let n=e(t);return cr(n)?void 0:r(t)[n]}));l(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],cr(e)?()=>{}:t=>r(t)[e]));l("()",(r,e)=>{if(e===void 0)return r==null?a("Empty ()"):i(r);let t=o=>o?.[0]===","&&o.slice(1).some(s=>s==null||t(s));t(e)&&a("Empty argument");let n=e?e[0]===","?(e=e.slice(1).map(i),o=>e.map(s=>s(o))):(e=i(e),o=>[e(o)]):()=>[];return K(r,(o,s,u)=>o[s](...n(u)),!0)});var Kr=r=>{throw Error(r)},K=(r,e,t,n,o)=>r==null?Kr("Empty ()"):r[0]==="()"&&r.length==2?K(r[1],e,t):typeof r=="string"?s=>e(s,r,s):r[0]==="."?(n=i(r[1]),o=r[2],s=>e(n(s),o,s)):r[0]==="?."?(n=i(r[1]),o=r[2],s=>{let u=n(s);return u==null?void 0:e(u,o,s)}):r[0]==="[]"&&r.length===3?(n=i(r[1]),o=i(r[2]),s=>e(n(s),o(s),s)):r[0]==="?.[]"?(n=i(r[1]),o=i(r[2]),s=>{let u=n(s);return u==null?void 0:e(u,o(s),s)}):(r=i(r),s=>e([r(s)],0,s));var Gr=5,Wr=10,zr=170;rr("()",zr);J(",",Wr);J(";",Gr,!0);var Ar=r=>{throw Error(r)};l("()",(r,e)=>{if(e===void 0)return r==null?Ar("Empty ()"):i(r);let t=o=>o?.[0]===","&&o.slice(1).some(s=>s==null||t(s));t(e)&&Ar("Empty argument");let n=e?e[0]===","?(e=e.slice(1).map(i),o=>e.map(s=>s(o))):(e=i(e),o=>[e(o)]):()=>[];return K(r,(o,s,u)=>o[s](...n(u)),!0)});var dr=(...r)=>(r=r.map(i),e=>{let t;for(let n of r)try{t=n(e)}catch(o){throw(o?.type===Q||o?.type===H)&&(o.value=t),o}return t});l(",",dr);l(";",dr);var hr=new WeakMap,Jr=(r,...e)=>typeof r=="string"?i(m(r)):hr.get(r)||hr.set(r,Vr(r,e)).get(r),yr=57344,Vr=(r,e)=>{let t=r.reduce((s,u,c)=>s+(c?String.fromCharCode(yr+c-1):"")+u,""),n=m(t),o=s=>{if(typeof s=="string"&&s.length===1){let u=s.charCodeAt(0)-yr,c;if(u>=0&&u<e.length)return c=e[u],Yr(c)?c:[,c]}return Array.isArray(s)?s.map(o):s};return i(o(n))},Yr=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),De=Jr;export{V as access,p as binary,i as compile,A as cur,De as default,S as err,h as expr,rr as group,Zr as id,f as idx,qr as literal,W as loc,C as lookup,J as nary,N as next,l as operator,G as operators,M as parens,m as parse,z as seek,g as skip,k as space,v as token,T as unary,b as word};