subscript 10.0.0 → 10.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -50
- package/feature/access.js +9 -8
- package/feature/block.js +1 -4
- package/feature/control.js +2 -0
- package/feature/function.js +1 -1
- package/feature/group.js +2 -28
- package/feature/loop.js +2 -2
- package/feature/op/assignment.js +8 -29
- package/feature/switch.js +1 -1
- package/feature/try.js +1 -1
- package/jessie.min.js +8 -8
- package/justin.min.js +8 -8
- package/package.json +1 -1
- package/parse.js +1 -8
- package/subscript.min.js +5 -5
- package/util/stringify.js +2 -5
package/README.md
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">sub<sub><sup> ✦ </sup></sub>script</h1>
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
<p align="center">Tiny expression parser & evaluator.</p>
|
|
4
|
+
<div align="center">
|
|
5
|
+
|
|
6
|
+
[](https://github.com/dy/subscript/actions/workflows/node.js.yml) [](http://npmjs.org/subscript) [](https://bundlephobia.com/package/subscript) [](http://microjs.com/#subscript) <!--[](https://dy.github.io/subscript/)-->
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
* **Fast** — Pratt parser engine, see [benchmarks](#performance)
|
|
7
|
-
* **Portable** — universal expression format, any compile target
|
|
8
|
-
* **Metacircular** — can parse and compile itself
|
|
9
|
-
* **Extensible** — pluggable syntax for building custom DSL
|
|
8
|
+
</div>
|
|
10
9
|
|
|
11
|
-
## Usage
|
|
12
10
|
|
|
13
11
|
```js
|
|
14
12
|
import subscript from 'subscript'
|
|
@@ -17,24 +15,25 @@ let fn = subscript('a + b * 2')
|
|
|
17
15
|
fn({ a: 1, b: 3 }) // 7
|
|
18
16
|
```
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
* **Safe** — sandboxed, blocks `__proto__`, `constructor`, no global access
|
|
19
|
+
* **Fast** — Pratt parser engine, see [benchmarks](#performance)
|
|
20
|
+
* **Portable** — universal expression format, see [spec](./spec.md)
|
|
21
|
+
* **Extensible** — pluggable syntax, see [DSL builder](https://dy.github.io/subscript/)
|
|
22
|
+
* **Metacircular** — can parse and compile itself
|
|
23
|
+
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
## Presets
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
**Subscript**: common expressions:
|
|
25
28
|
|
|
26
|
-
`a.b a[b] a(b) + - * / % < > <= >= == != ! && || ~ & | ^ << >> ++ -- = += -= *= /=`
|
|
27
29
|
```js
|
|
28
30
|
import subscript from 'subscript'
|
|
29
31
|
|
|
30
32
|
subscript('a.b + c * 2')({ a: { b: 1 }, c: 3 }) // 7
|
|
31
33
|
```
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
**Justin**: JSON + expressions + templates + arrows:
|
|
34
36
|
|
|
35
|
-
JSON + expressions + templates + arrows:
|
|
36
|
-
|
|
37
|
-
`` 'str' 0x 0b === !== ** ?? >>> ?. ? : => ... [] {} ` // /**/ true false null ``
|
|
38
37
|
```js
|
|
39
38
|
import justin from 'subscript/justin.js'
|
|
40
39
|
|
|
@@ -42,11 +41,8 @@ justin('{ x: a?.b ?? 0, y: [1, ...rest] }')({ a: null, rest: [2, 3] })
|
|
|
42
41
|
// { x: 0, y: [1, 2, 3] }
|
|
43
42
|
```
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
JSON + expressions + statements, functions:
|
|
44
|
+
**Jessie**: JSON + expressions + statements, functions (JS subset):
|
|
48
45
|
|
|
49
|
-
`if else for while do let const var function class return throw try catch switch import export /regex/`
|
|
50
46
|
```js
|
|
51
47
|
import jessie from 'subscript/jessie.js'
|
|
52
48
|
|
|
@@ -60,24 +56,7 @@ let fn = jessie(`
|
|
|
60
56
|
fn({}) // 120
|
|
61
57
|
```
|
|
62
58
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
## Parse / Compile
|
|
67
|
-
|
|
68
|
-
Subscript exposes `parse` to build AST and `compile` to create evaluators.
|
|
69
|
-
|
|
70
|
-
```js
|
|
71
|
-
import { parse, compile } from 'subscript'
|
|
72
|
-
|
|
73
|
-
// parse expression
|
|
74
|
-
let tree = parse('a.b + c - 1')
|
|
75
|
-
tree // ['-', ['+', ['.', 'a', 'b'], 'c'], [,1]]
|
|
76
|
-
|
|
77
|
-
// compile tree to evaluable function
|
|
78
|
-
fn = compile(tree)
|
|
79
|
-
fn({ a: {b: 1}, c: 2 }) // 2
|
|
80
|
-
```
|
|
59
|
+
See [docs](./docs.md#presets) for full description.
|
|
81
60
|
|
|
82
61
|
## Extension
|
|
83
62
|
|
|
@@ -102,7 +81,7 @@ See [docs.md](./docs.md) for full API.
|
|
|
102
81
|
|
|
103
82
|
## Syntax Tree
|
|
104
83
|
|
|
105
|
-
Expressions parse to a minimal JSON-compatible
|
|
84
|
+
Expressions parse to a minimal JSON-compatible syntax tree:
|
|
106
85
|
|
|
107
86
|
```js
|
|
108
87
|
import { parse } from 'subscript'
|
|
@@ -111,14 +90,6 @@ parse('a + b * 2')
|
|
|
111
90
|
// ['+', 'a', ['*', 'b', [, 2]]]
|
|
112
91
|
```
|
|
113
92
|
|
|
114
|
-
AST has simplified lispy tree structure (inspired by [frisk](https://ghub.io/frisk) / [nisp](https://github.com/ysmood/nisp)), opposed to [ESTree](https://github.com/estree/estree):
|
|
115
|
-
|
|
116
|
-
* not limited to particular language (JS), can be compiled to different targets;
|
|
117
|
-
* reflects execution sequence, rather than code layout;
|
|
118
|
-
* has minimal overhead, directly maps to operators;
|
|
119
|
-
* simplifies manual evaluation and debugging;
|
|
120
|
-
* has conventional form and one-liner docs:
|
|
121
|
-
|
|
122
93
|
Three forms:
|
|
123
94
|
|
|
124
95
|
```js
|
|
@@ -164,7 +135,7 @@ codegen(['+', ['*', 'min', [,60]], [,'sec']])
|
|
|
164
135
|
|
|
165
136
|
### Bundle
|
|
166
137
|
|
|
167
|
-
|
|
138
|
+
Bundle imports into a single file:
|
|
168
139
|
|
|
169
140
|
```js
|
|
170
141
|
import { bundle } from 'subscript/util/bundle.js'
|
|
@@ -181,11 +152,11 @@ const code = await bundle('subscript/jessie.js')
|
|
|
181
152
|
<!-- * [glsl-transpiler](https://github.com/stackgl/glsl-transpiler) -->
|
|
182
153
|
<!-- * [piezo](https://github.com/dy/piezo) -->
|
|
183
154
|
|
|
184
|
-
|
|
155
|
+
<!--
|
|
185
156
|
## Refs
|
|
186
157
|
|
|
187
158
|
[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/).
|
|
188
159
|
|
|
189
|
-
|
|
160
|
+
[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) -->
|
|
190
161
|
|
|
191
162
|
<p align=center><a href="https://github.com/krsnzd/license/">ॐ</a></p>
|
package/feature/access.js
CHANGED
|
@@ -42,7 +42,8 @@ operator('()', (a, b) => {
|
|
|
42
42
|
const args = !b ? () => [] :
|
|
43
43
|
b[0] === ',' ? (b = b.slice(1).map(compile), ctx => b.map(arg => arg(ctx))) :
|
|
44
44
|
(b = compile(b), ctx => [b(ctx)]);
|
|
45
|
-
|
|
45
|
+
// Inline call handling for x(), a.b(), a[b](), (x)()
|
|
46
|
+
return call(a, (obj, path, ctx) => obj[path](...args(ctx)));
|
|
46
47
|
});
|
|
47
48
|
|
|
48
49
|
// Left-value check (valid assignment target)
|
|
@@ -55,13 +56,10 @@ export const isLval = n =>
|
|
|
55
56
|
n[0] === '{}'
|
|
56
57
|
));
|
|
57
58
|
|
|
58
|
-
//
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
export const prop = (a, fn, generic, obj, path) => (
|
|
63
|
-
a == null ? compileErr('Empty ()') :
|
|
64
|
-
a[0] === '()' && a.length == 2 ? prop(a[1], fn, generic) :
|
|
59
|
+
// Simple call helper (no optional chaining) - handles x(), a.b(), a[b](), (x)()
|
|
60
|
+
const call = (a, fn, obj, path) => (
|
|
61
|
+
a == null ? err('Empty ()') :
|
|
62
|
+
a[0] === '()' && a.length == 2 ? call(a[1], fn) :
|
|
65
63
|
typeof a === 'string' ? ctx => fn(ctx, a, ctx) :
|
|
66
64
|
a[0] === '.' ? (obj = compile(a[1]), path = a[2], ctx => fn(obj(ctx), path, ctx)) :
|
|
67
65
|
a[0] === '?.' ? (obj = compile(a[1]), path = a[2], ctx => { const o = obj(ctx); return o == null ? undefined : fn(o, path, ctx); }) :
|
|
@@ -69,3 +67,6 @@ export const prop = (a, fn, generic, obj, path) => (
|
|
|
69
67
|
a[0] === '?.[]' ? (obj = compile(a[1]), path = compile(a[2]), ctx => { const o = obj(ctx); return o == null ? undefined : fn(o, path(ctx), ctx); }) :
|
|
70
68
|
(a = compile(a), ctx => fn([a(ctx)], 0, ctx))
|
|
71
69
|
);
|
|
70
|
+
|
|
71
|
+
// Export as prop for backward compatibility with other features
|
|
72
|
+
export const prop = call;
|
package/feature/block.js
CHANGED
|
@@ -35,7 +35,4 @@ export const block = () =>
|
|
|
35
35
|
|
|
36
36
|
// body() - parse { body } or single statement
|
|
37
37
|
export const body = () =>
|
|
38
|
-
space() !== OBRACE ? expr(STATEMENT + .5) : (skip(),
|
|
39
|
-
|
|
40
|
-
// Compile
|
|
41
|
-
operator('block', body => body === undefined ? () => {} : (body = compile(body), ctx => body(ctx)));
|
|
38
|
+
space() !== OBRACE ? expr(STATEMENT + .5) : (skip(), expr(STATEMENT - .5, CBRACE) || null);
|
package/feature/function.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Function declarations and expressions
|
|
2
2
|
import { space, next, parse, parens, expr, operator, compile } from '../parse.js';
|
|
3
|
-
import { RETURN } from './
|
|
3
|
+
import { RETURN } from './control.js';
|
|
4
4
|
import { keyword, block } from './block.js';
|
|
5
5
|
|
|
6
6
|
const TOKEN = 200;
|
package/feature/group.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { nary, group, operator, compile } from '../parse.js';
|
|
2
|
-
import { BREAK, CONTINUE } from './loop.js';
|
|
3
|
-
import { prop } from './access.js';
|
|
4
2
|
|
|
5
3
|
const STATEMENT = 5, SEQ = 10, ACCESS = 170;
|
|
6
4
|
|
|
@@ -11,31 +9,7 @@ group('()', ACCESS);
|
|
|
11
9
|
nary(',', SEQ);
|
|
12
10
|
nary(';', STATEMENT, true); // right-assoc to allow same-prec statements
|
|
13
11
|
|
|
14
|
-
// Compile
|
|
15
|
-
const
|
|
16
|
-
operator('()', (a, b) => {
|
|
17
|
-
// Group: (expr) - no second argument means grouping, not call
|
|
18
|
-
if (b === undefined) return a == null ? err('Empty ()') : compile(a);
|
|
19
|
-
// Validate: no sparse arguments in calls
|
|
20
|
-
const hasSparse = n => n?.[0] === ',' && n.slice(1).some(a => a == null || hasSparse(a));
|
|
21
|
-
if (hasSparse(b)) err('Empty argument');
|
|
22
|
-
const args = !b ? () => [] :
|
|
23
|
-
b[0] === ',' ? (b = b.slice(1).map(compile), ctx => b.map(arg => arg(ctx))) :
|
|
24
|
-
(b = compile(b), ctx => [b(ctx)]);
|
|
25
|
-
return prop(a, (obj, path, ctx) => obj[path](...args(ctx)), true);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// sequence returns last evaluated value; catches BREAK/CONTINUE and attaches result
|
|
29
|
-
const seq = (...args) => (args = args.map(compile), ctx => {
|
|
30
|
-
let r;
|
|
31
|
-
for (const arg of args) {
|
|
32
|
-
try { r = arg(ctx); }
|
|
33
|
-
catch (e) {
|
|
34
|
-
if (e?.type === BREAK || e?.type === CONTINUE) { e.value = r; throw e; }
|
|
35
|
-
throw e;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return r;
|
|
39
|
-
});
|
|
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; });
|
|
40
14
|
operator(',', seq);
|
|
41
15
|
operator(';', seq);
|
package/feature/loop.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { expr, skip, space, parse, word, parens, cur, idx, operator, compile } from '../parse.js';
|
|
3
3
|
import { body, keyword } from './block.js';
|
|
4
4
|
import { destructure } from './destruct.js';
|
|
5
|
+
import { BREAK, CONTINUE, RETURN } from './control.js';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
export const BREAK = Symbol('break'), CONTINUE = Symbol('continue'), RETURN = Symbol('return');
|
|
7
|
+
export { BREAK, CONTINUE, RETURN };
|
|
8
8
|
|
|
9
9
|
// Loop body executor - catches control flow and returns status
|
|
10
10
|
export const loop = (body, ctx) => {
|
package/feature/op/assignment.js
CHANGED
|
@@ -8,40 +8,19 @@ import { binary, operator, compile } from '../../parse.js';
|
|
|
8
8
|
|
|
9
9
|
const ASSIGN = 20;
|
|
10
10
|
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// Compound arithmetic
|
|
15
|
-
binary('+=', ASSIGN, true);
|
|
16
|
-
binary('-=', ASSIGN, true);
|
|
17
|
-
binary('*=', ASSIGN, true);
|
|
18
|
-
binary('/=', ASSIGN, true);
|
|
19
|
-
binary('%=', ASSIGN, true);
|
|
20
|
-
|
|
21
|
-
// Compound bitwise
|
|
22
|
-
binary('|=', ASSIGN, true);
|
|
23
|
-
binary('&=', ASSIGN, true);
|
|
24
|
-
binary('^=', ASSIGN, true);
|
|
25
|
-
binary('>>=', ASSIGN, true);
|
|
26
|
-
binary('<<=', ASSIGN, true);
|
|
11
|
+
// Register all assignment operators
|
|
12
|
+
'= += -= *= /= %= |= &= ^= >>= <<='.split(' ').map(op => binary(op, ASSIGN, true));
|
|
27
13
|
|
|
28
14
|
// Simple assign helper for x, a.b, a[b], (x)
|
|
29
15
|
const assign = (a, fn, obj, key) =>
|
|
30
16
|
typeof a === 'string' ? ctx => fn(ctx, a, ctx) :
|
|
31
17
|
a[0] === '.' ? (obj = compile(a[1]), key = a[2], ctx => fn(obj(ctx), key, ctx)) :
|
|
32
18
|
a[0] === '[]' && a.length === 3 ? (obj = compile(a[1]), key = compile(a[2]), ctx => fn(obj(ctx), key(ctx), ctx)) :
|
|
33
|
-
a[0] === '()' && a.length === 2 ? assign(a[1], fn) :
|
|
19
|
+
a[0] === '()' && a.length === 2 ? assign(a[1], fn) :
|
|
34
20
|
(() => { throw Error('Invalid assignment target') })();
|
|
35
21
|
|
|
36
|
-
// Compile
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
operator(
|
|
41
|
-
operator('/=', (a, b) => (b = compile(b), assign(a, (o, k, ctx) => o[k] /= b(ctx))));
|
|
42
|
-
operator('%=', (a, b) => (b = compile(b), assign(a, (o, k, ctx) => o[k] %= b(ctx))));
|
|
43
|
-
operator('|=', (a, b) => (b = compile(b), assign(a, (o, k, ctx) => o[k] |= b(ctx))));
|
|
44
|
-
operator('&=', (a, b) => (b = compile(b), assign(a, (o, k, ctx) => o[k] &= b(ctx))));
|
|
45
|
-
operator('^=', (a, b) => (b = compile(b), assign(a, (o, k, ctx) => o[k] ^= b(ctx))));
|
|
46
|
-
operator('>>=', (a, b) => (b = compile(b), assign(a, (o, k, ctx) => o[k] >>= b(ctx))));
|
|
47
|
-
operator('<<=', (a, b) => (b = compile(b), assign(a, (o, k, ctx) => o[k] <<= b(ctx))));
|
|
22
|
+
// Compile - use Function to generate operator implementations
|
|
23
|
+
const ops = { '=': (o,k,v)=>o[k]=v, '+=': (o,k,v)=>o[k]+=v, '-=': (o,k,v)=>o[k]-=v, '*=': (o,k,v)=>o[k]*=v,
|
|
24
|
+
'/=': (o,k,v)=>o[k]/=v, '%=': (o,k,v)=>o[k]%=v, '|=': (o,k,v)=>o[k]|=v, '&=': (o,k,v)=>o[k]&=v,
|
|
25
|
+
'^=': (o,k,v)=>o[k]^=v, '>>=': (o,k,v)=>o[k]>>=v, '<<=': (o,k,v)=>o[k]<<=v };
|
|
26
|
+
for (const op in ops) operator(op, (a, b) => (b = compile(b), assign(a, (o, k, ctx) => ops[op](o, k, b(ctx)))));
|
package/feature/switch.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// AST: ['switch', val, [';', ['case', test], stmts..., ['default'], stmts...]]
|
|
3
3
|
import { expr, skip, space, parens, operator, compile } from '../parse.js';
|
|
4
4
|
import { keyword, block } from './block.js';
|
|
5
|
-
import { BREAK } from './
|
|
5
|
+
import { BREAK } from './control.js';
|
|
6
6
|
|
|
7
7
|
const STATEMENT = 5, ASSIGN = 20, COLON = 58;
|
|
8
8
|
|
package/feature/try.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// AST: ['catch', ['try', body], param, catchBody] or ['finally', inner, body]
|
|
3
3
|
import { space, parse, parens, expr, operator, compile } from '../parse.js';
|
|
4
4
|
import { keyword, infix, block } from './block.js';
|
|
5
|
-
import { BREAK, CONTINUE, RETURN } from './
|
|
5
|
+
import { BREAK, CONTINUE, RETURN } from './control.js';
|
|
6
6
|
|
|
7
7
|
const STATEMENT = 5;
|
|
8
8
|
|
package/jessie.min.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),o=t.pop(),n=
|
|
3
|
-
${(
|
|
4
|
-
`?"...":"")+n}${
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
6
|
-
`,"/*":"*/"};var
|
|
7
|
-
`)for(;
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
1
|
+
var u,c,m=r=>(u=0,c=r,m.newline=!1,r=A(),c[u]?I():r||""),I=(r="Unexpected token",e=u,t=c.slice(0,e).split(`
|
|
2
|
+
`),o=t.pop(),n=c.slice(Math.max(0,e-40),e),s="\u032D",f=(c[e]||"\u2205")+s,l=c.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
|
|
3
|
+
${(c[e-41]!==`
|
|
4
|
+
`?"...":"")+n}${f}${l}`)},V=(r,e=u)=>(Array.isArray(r)&&(r.loc=e),r),k=(r,e=u,t)=>{for(;t=r(c.charCodeAt(u));)u+=t;return c.slice(e,u)},g=(r=1)=>c[u+=r],G=r=>u=r,A=(r=0,e)=>{let t,o,n,s,f=m.reserved,l;for(e&&m.asi&&(m.newline=!1),m.reserved=0;(t=m.space())&&(l=m.newline,1)&&t!==e&&(n=((s=w[t])&&s(o,r))??(m.asi&&o&&l&&(n=m.asi(o,r,A)))??(!o&&!m.reserved&&k(m.id)));)o=n,m.reserved=0;return m.reserved=f,e&&(t==e?u++:I("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},y=m.space=(r,e=u)=>{for(;(r=c.charCodeAt(u))<=32;)m.asi&&r===10&&(m.newline=!0),u++;return r},mt=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,X=(r,e=r.length)=>c.substr(u,e)===r&&!m.id(c.charCodeAt(u+e)),N=()=>(g(),A(0,41)),w=[],S=(r,e=32,t,o=r.charCodeAt(0),n=r.length,s=w[o],f=r.toUpperCase()!==r,l,h)=>w[o]=(E,T,F,C=u)=>(l=F,(F?r==F:(n<2||r.charCodeAt(1)===c.charCodeAt(u+1)&&(n<3||c.substr(u,n)==r))&&(!f||!m.id(c.charCodeAt(u+n)))&&(l=F=r))&&T<e&&(u+=n,(h=t(E))?V(h,C):(u=C,l=0,f&&h!==!1&&(m.reserved=1),!f&&!s&&I()),h)||s?.(E,T,l)),d=(r,e,t=!1)=>S(r,e,(o,n)=>o&&(n=A(e-(t?.5:0)))&&[r,o,n]),v=(r,e,t)=>S(r,e,o=>t?o&&[r,o]:!o&&(o=A(e-.5))&&[r,o]),P=(r,e)=>S(r,200,t=>!t&&[,e]),sr=(r,e,t)=>{S(r,e,(o,n)=>(n=A(e-(t?.5:0)),o?.[0]!==r&&(o=[r,o||null]),n?.[0]===r?o.push(...n.slice(1)):o.push(n||null),o))},H=(r,e)=>S(r[0],e,t=>!t&&[r,A(0,r.charCodeAt(1))||null]),pr=(r,e)=>S(r[0],e,t=>t&&[r,t,A(0,r.charCodeAt(1))||null]),ir={},p=(r,e,t=ir[r])=>ir[r]=(...o)=>e(...o)||t?.(...o),i=r=>Array.isArray(r)?r[0]===void 0?(e=>()=>e)(r[1]):ir[r[0]]?.(...r.slice(1))??I(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var Y=46,j=48,Z=57,br=69,re=101,ee=43,te=45,oe=97,ne=102,ie=65,se=70,fr=r=>[,(r=+k(e=>e===Y&&c.charCodeAt(u+1)!==Y||e>=j&&e<=Z||((e===br||e===re)&&((e=c.charCodeAt(u+1))>=j&&e<=Z||e===ee||e===te)?2:0)))!=r?I():r],pe={2:r=>r===48||r===49,8:r=>r>=48&&r<=55,16:r=>r>=j&&r<=Z||r>=oe&&r<=ne||r>=ie&&r<=se};m.number=null;w[Y]=r=>!r&&c.charCodeAt(u+1)!==Y&&fr();for(let r=j;r<=Z;r++)w[r]=e=>e?void 0:fr();w[j]=r=>{if(r)return;let e=m.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&c[u+1]?.toLowerCase()===t[1])return g(2),[,parseInt(k(pe[o]),o)]}return fr()};var fe=92,vr=34,Tr=39,le={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Ir=r=>(e,t,o="")=>{if(!(e||!m.string?.[String.fromCharCode(r)]))return g(),k(n=>n-r&&(n===fe?(o+=le[c[u+1]]||c[u+1],2):(o+=c[u],1))),c[u]===String.fromCharCode(r)?g():I("Bad string"),[,o]};w[vr]=Ir(vr);w[Tr]=Ir(Tr);m.string={'"':!0};var ue=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>d(r,ue,!0));var Rr=(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?Rr(r[1],e):(()=>{throw Error("Invalid assignment target")})(),Nr={"=":(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 Nr)p(r,(e,t)=>(t=i(t),Rr(e,(o,n,s)=>Nr[r](o,n,t(s)))));var me=30,ce=40,_r=140;d("!",_r);v("!",_r);d("||",me);d("&&",ce);p("!",r=>(r=i(r),e=>!r(e)));p("||",(r,e)=>(r=i(r),e=i(e),t=>r(t)||e(t)));p("&&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&&e(t)));var de=50,Ae=60,ye=70,Or=100,he=140;d("|",de);d("&",ye);d("^",Ae);d(">>",Or);d("<<",Or);v("~",he);p("~",r=>(r=i(r),e=>~r(e)));p("|",(r,e)=>(r=i(r),e=i(e),t=>r(t)|e(t)));p("&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&e(t)));p("^",(r,e)=>(r=i(r),e=i(e),t=>r(t)^e(t)));p(">>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>e(t)));p("<<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<<e(t)));var q=90;d("<",q);d(">",q);d("<=",q);d(">=",q);p(">",(r,e)=>(r=i(r),e=i(e),t=>r(t)>e(t)));p("<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<e(t)));p(">=",(r,e)=>(r=i(r),e=i(e),t=>r(t)>=e(t)));p("<=",(r,e)=>(r=i(r),e=i(e),t=>r(t)<=e(t)));var Pr=80;d("==",Pr);d("!=",Pr);p("==",(r,e)=>(r=i(r),e=i(e),t=>r(t)==e(t)));p("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(t)));var Mr=110,lr=120,Ur=140;d("+",Mr);d("-",Mr);d("*",lr);d("/",lr);d("%",lr);v("+",Ur);v("-",Ur);p("+",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)+e(t)):(r=i(r),t=>+r(t)));p("-",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)-e(t)):(r=i(r),t=>-r(t)));p("*",(r,e)=>(r=i(r),e=i(e),t=>r(t)*e(t)));p("/",(r,e)=>(r=i(r),e=i(e),t=>r(t)/e(t)));p("%",(r,e)=>(r=i(r),e=i(e),t=>r(t)%e(t)));var x=150;S("++",x,r=>r?["++",r,null]:["++",A(x-1)]);S("--",x,r=>r?["--",r,null]:["--",A(x-1)]);var ur=(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?ur(r[1],e):(()=>{throw Error("Invalid increment target")})();p("++",(r,e)=>ur(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));p("--",(r,e)=>ur(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var ge=5,Ee=10,ae=170;H("()",ae);sr(",",Ee);sr(";",ge,!0);var Lr=(...r)=>(r=r.map(i),e=>{let t;for(let o of r)t=o(e);return t});p(",",Lr);p(";",Lr);var M=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",mr=170;pr("[]",mr);d(".",mr);pr("()",mr);var b=r=>{throw Error(r)};p("[]",(r,e)=>e===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(t=>t==null?(()=>{}):t[0]==="..."?(t=i(t[1]),o=>t(o)):(t=i(t),o=>[t(o)])),t=>r.flatMap(o=>o(t))):(e==null&&b("Missing index"),r=i(r),e=i(e),t=>{let o=e(t);return M(o)?void 0:r(t)[o]}));p(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],M(e)?()=>{}:t=>r(t)[e]));p("()",(r,e)=>{if(e===void 0)return r==null?b("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(s=>s==null||t(s));t(e)&&b("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];return cr(r,(n,s,f)=>n[s](...o(f)))});var O=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&O(r[1])||r[0]==="{}"),cr=(r,e,t,o)=>r==null?b("Empty ()"):r[0]==="()"&&r.length==2?cr(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 s=t(n);return s==null?void 0:e(s,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 s=t(n);return s==null?void 0:e(s,o(n),n)}):(r=i(r),n=>e([r(n)],0,n)),U=cr;var Fr=new WeakMap,Se=(r,...e)=>typeof r=="string"?i(m(r)):Fr.get(r)||Fr.set(r,Ce(r,e)).get(r),Gr=57344,Ce=(r,e)=>{let t=r.reduce((s,f,l)=>s+(l?String.fromCharCode(Gr+l-1):"")+f,""),o=m(t),n=s=>{if(typeof s=="string"&&s.length===1){let f=s.charCodeAt(0)-Gr,l;if(f>=0&&f<e.length)return l=e[f],we(l)?l:[,l]}return Array.isArray(s)?s.map(n):s};return i(n(o))},we=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Xr=Se;var ke=32,ve=m.space;m.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};var dr;m.space=()=>{dr||(dr=Object.entries(m.comment).map(([n,s])=>[n,s,n.charCodeAt(0)]));for(var r;r=ve();){for(var e=0,t;t=dr[e++];)if(r===t[2]&&c.substr(u,t[0].length)===t[0]){var o=u+t[0].length;if(t[1]===`
|
|
7
|
+
`)for(;c.charCodeAt(o)>=ke;)o++;else{for(;c[o]&&c.substr(o,t[1].length)!==t[1];)o++;c[o]&&(o+=t[1].length)}G(o),r=0;break}if(r)return r}return r};var Kr=80;d("===",Kr);d("!==",Kr);p("===",(r,e)=>(r=i(r),e=i(e),t=>r(t)===e(t)));p("!==",(r,e)=>(r=i(r),e=i(e),t=>r(t)!==e(t)));var Te=30;d("??",Te);p("??",(r,e)=>(r=i(r),e=i(e),t=>r(t)??e(t)));var Ie=130,Ne=20;d("**",Ie,!0);d("**=",Ne,!0);p("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));var Re=r=>{throw Error(r)};p("**=",(r,e)=>(O(r)||Re("Invalid assignment target"),e=i(e),U(r,(t,o,n)=>t[o]**=e(n))));var Dr=90;d("in",Dr);d("of",Dr);p("in",(r,e)=>(r=i(r),e=i(e),t=>r(t)in e(t)));var _e=20,Oe=100,Pe=r=>{throw Error(r)};d(">>>",Oe);d(">>>=",_e,!0);p(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));p(">>>=",(r,e)=>(O(r)||Pe("Invalid assignment target"),e=i(e),U(r,(t,o,n)=>t[o]>>>=e(n))));var L=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...n]=r;if(o==="{}")for(let s of n){let f,l,h;s[0]==="="?[,[,f,l],h]=s:[,f,l]=s;let E=e[f];E===void 0&&h&&(E=i(h)(t)),L(l,E,t)}else if(o==="[]"){let s=0;for(let f of n){if(f===null){s++;continue}if(Array.isArray(f)&&f[0]==="..."){t[f[1]]=e.slice(s);break}let l=f,h;Array.isArray(f)&&f[0]==="="&&([,l,h]=f);let E=e[s++];E===void 0&&h&&(E=i(h)(t)),L(l,E,t)}}};var Ar=20,rr=r=>{throw Error(r)};d("||=",Ar,!0);d("&&=",Ar,!0);d("??=",Ar,!0);p("=",(r,e)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let t=r[1];return e=i(e),typeof t=="string"?o=>{o[t]=e(o)}:o=>L(t,e(o),o)}return O(r)||rr("Invalid assignment target"),e=i(e),U(r,(t,o,n)=>t[o]=e(n))});p("||=",(r,e)=>(O(r)||rr("Invalid assignment target"),e=i(e),U(r,(t,o,n)=>t[o]||=e(n))));p("&&=",(r,e)=>(O(r)||rr("Invalid assignment target"),e=i(e),U(r,(t,o,n)=>t[o]&&=e(n))));p("??=",(r,e)=>(O(r)||rr("Invalid assignment target"),e=i(e),U(r,(t,o,n)=>t[o]??=e(n))));P("true",!0);P("false",!1);P("null",null);P("undefined",void 0);P("NaN",NaN);P("Infinity",1/0);var yr=20;S("?",yr,(r,e,t)=>r&&(e=A(yr-1))&&k(o=>o===58)&&(t=A(yr-1),["?",r,e,t]));p("?",(r,e,t)=>(r=i(r),e=i(e),t=i(t),o=>r(o)?e(o):t(o)));var Me=20;d("=>",Me,!0);p("=>",(r,e)=>{r=r[0]==="()"?r[1]:r,r=r?r[0]===","?r.slice(1):[r]:[];let t=-1,o=null;return r.length&&Array.isArray(r[r.length-1])&&r[r.length-1][0]==="..."&&(t=r.length-1,o=r[t][1],r=r.slice(0,-1)),e=i(e[0]==="{}"?e[1]:e),(n=null)=>(n=Object.create(n),(...s)=>(r.forEach((f,l)=>n[f]=s[l]),o&&(n[o]=s.slice(t)),e(n)))});var Ue=140;v("...",Ue);p("...",r=>(r=i(r),e=>Object.entries(r(e))));var Br=170;S("?.",Br,(r,e)=>{if(!r)return;let t=y();return t===40?(g(),["?.()",r,A(0,41)||null]):t===91?(g(),["?.[]",r,A(0,93)]):(e=A(Br),e?["?.",r,e]:void 0)});p("?.",(r,e)=>(r=i(r),M(e)?()=>{}:t=>r(t)?.[e]));p("?.[]",(r,e)=>(r=i(r),e=i(e),t=>{let o=e(t);return M(o)?void 0:r(t)?.[o]}));p("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];if(r[0]==="?."){let n=i(r[1]),s=r[2];return M(s)?()=>{}:f=>n(f)?.[s]?.(...t(f))}if(r[0]==="?.[]"){let n=i(r[1]),s=i(r[2]);return f=>{let l=n(f),h=s(f);return M(h)?void 0:l?.[h]?.(...t(f))}}if(r[0]==="."){let n=i(r[1]),s=r[2];return M(s)?()=>{}:f=>n(f)?.[s]?.(...t(f))}if(r[0]==="[]"&&r.length===3){let n=i(r[1]),s=i(r[2]);return f=>{let l=n(f),h=s(f);return M(h)?void 0:l?.[h]?.(...t(f))}}let o=i(r);return n=>o(n)?.(...t(n))});var er=140;v("typeof",er);v("void",er);v("delete",er);v("new",er);p("typeof",r=>(r=i(r),e=>typeof r(e)));p("void",r=>(r=i(r),e=>(r(e),void 0)));p("delete",r=>{if(r[0]==="."){let e=i(r[1]),t=r[2];return o=>delete e(o)[t]}if(r[0]==="[]"){let e=i(r[1]),t=i(r[2]);return o=>delete e(o)[t(o)]}return()=>!0});p("new",r=>{let e=i(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,o=t?t[0]===","?(n=>s=>n.map(f=>f(s)))(t.slice(1).map(i)):(n=>s=>[n(s)])(i(t)):()=>[];return n=>new(e(n))(...o(n))});var tr=Symbol("accessor"),Qr=20,Le=40,Fe=41,Ge=123,Xe=125,$r=r=>e=>{if(e)return;y();let t=k(m.id);if(!t||(y(),c.charCodeAt(u)!==Le))return!1;g();let o=A(0,Fe);return y(),c.charCodeAt(u)!==Ge?!1:(g(),[r,t,o,A(0,Xe)])};S("get",Qr-1,$r("get"));S("set",Qr-1,$r("set"));p("get",(r,e)=>(e=e?i(e):()=>{},t=>[[tr,r,{get:function(){let o=Object.create(t||{});return o.this=this,e(o)}}]]));p("set",(r,e,t)=>(t=t?i(t):()=>{},o=>[[tr,r,{set:function(n){let s=Object.create(o||{});s.this=this,s[e]=n,t(s)}}]]));var Ke=20,Hr=200;H("[]",Hr);H("{}",Hr);d(":",Ke-1,!0);p("{}",(r,e)=>{if(e!==void 0)return;r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(o=>i(typeof o=="string"?[":",o,o]:o));return o=>{let n={},s={};for(let f of t.flatMap(l=>l(o)))if(f[0]===tr){let[,l,h]=f;s[l]={...s[l],...h,configurable:!0,enumerable:!0}}else n[f[0]]=f[1];for(let f in s)Object.defineProperty(n,f,s[f]);return n}});p(":",(r,e)=>(e=i(e),Array.isArray(r)?(r=i(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));var De=170,or=96,Be=36,Qe=123,$e=92,He={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},jr=()=>{let r=[];for(let e="",t;(t=c.charCodeAt(u))!==or;)t?t===$e?(g(),e+=He[c[u]]||c[u],g()):t===Be&&c.charCodeAt(u+1)===Qe?(e&&r.push([,e]),e="",g(2),r.push(A(0,125))):(e+=c[u],g(),t=c.charCodeAt(u),t===or&&e&&r.push([,e])):I("Unterminated template");return g(),r},je=w[or];w[or]=(r,e)=>r&&e<De?m.asi&&m.newline?void 0:(g(),["``",r,...jr()]):r?je?.(r,e):(g(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(jr()));p("`",(...r)=>(r=r.map(i),e=>r.map(t=>t(e)).join("")));p("``",(r,...e)=>{r=i(r);let t=[],o=[];for(let s of e)Array.isArray(s)&&s[0]===void 0?t.push(s[1]):o.push(i(s));let n=Object.assign([...t],{raw:t});return s=>r(s)(n,...o.map(f=>f(s)))});m.string["'"]=!0;m.number={"0x":16,"0b":2,"0o":8};var hr=5,Wr=123,zr=125,a=(r,e,t,o=r.charCodeAt(0),n=r.length,s=w[o],f)=>w[o]=(l,h,E,T=u)=>!l&&(E?r==E:(n<2||c.substr(u,n)==r)&&(E=r))&&h<e&&!m.id(c.charCodeAt(u+n))&&(G(u+n),(f=t())?V(f,T):(G(T),!s&&I()),f)||s?.(l,h,E),gr=(r,e,t,o=r.charCodeAt(0),n=r.length,s=w[o],f)=>w[o]=(l,h,E,T=u)=>l&&(E?r==E:(n<2||c.substr(u,n)==r)&&(E=r))&&h<e&&!m.id(c.charCodeAt(u+n))&&(G(u+n),V(f=t(l),T),f)||s?.(l,h,E),_=()=>(y()===Wr||I("Expected {"),g(),A(hr-.5,zr)||null),K=()=>y()!==Wr?A(hr+.5):(g(),A(hr-.5,zr)||null);var Er=5,We=10,ze=20,Jr=r=>{let e=A(We-1);return e?.[0]==="in"||e?.[0]==="of"?[e[0],[r,e[1]],e[2]]:e?.[0]===","?[r,...e.slice(1)]:[r,e]};S("let",Er+1,r=>!r&&Jr("let"));S("const",Er+1,r=>!r&&Jr("const"));a("var",Er,()=>(y(),["var",A(ze)]));var Vr=(...r)=>(r=r.map(e=>{if(typeof e=="string")return t=>{t[e]=void 0};if(e[0]==="="){let[,t,o]=e,n=i(o);return typeof t=="string"?s=>{s[t]=n(s)}:s=>L(t,n(s),s)}return i(e)}),e=>{for(let t of r)t(e)});p("let",Vr);p("const",Vr);p("var",r=>typeof r=="string"?e=>{e[r]=void 0}:()=>{});var D=Symbol("break"),W=Symbol("continue"),B=Symbol("return");var Je=200;a("function",Je,()=>{y();let r=k(m.id);return r&&y(),["function",r,N()||null,_()]});p("function",(r,e,t)=>{t=t?i(t):()=>{};let o=e?e[0]===","?e.slice(1):[e]:[],n=null,s=-1,f=o[o.length-1];return Array.isArray(f)&&f[0]==="..."&&(s=o.length-1,n=f[1],o.length--),l=>{let h=(...E)=>{let T={};o.forEach((C,R)=>T[C]=E[R]),n&&(T[n]=E.slice(s));let F=new Proxy(T,{get:(C,R)=>R in C?C[R]:l[R],set:(C,R,xr)=>((R in C?C:l)[R]=xr,!0),has:(C,R)=>R in C||R in l});try{return t(F)}catch(C){if(C?.type===B)return C.value;throw C}};return r&&(l[r]=h),h}});var nr=140,ar=20;v("await",nr);a("yield",nr,()=>(y(),c[u]==="*"?(g(),y(),["yield*",A(ar)]):["yield",A(ar)]));a("async",nr,()=>{if(y(),X("function"))return["async",A(nr)];let r=A(ar-.5);return r&&["async",r]});p("async",r=>{let e=i(r);return t=>{let o=e(t);return async function(...n){return o(...n)}}});p("await",r=>(r=i(r),async e=>await r(e)));p("yield",r=>(r=r?i(r):null,e=>{throw{__yield__:r?r(e):void 0}}));p("yield*",r=>(r=i(r),e=>{throw{__yield_all__:r(e)}}));var Sr=200,Ve=140,Ye=90,Ze=Symbol("static");P("super",Symbol.for("super"));v("static",Ve);d("instanceof",Ye);S("#",Sr,r=>{if(r)return;let e=k(m.id);return e?"#"+e:void 0});a("class",Sr,()=>{y();let r=k(m.id)||null;if(r==="extends")r=null;else if(y(),!X("extends"))return["class",r,null,_()];return y(),["class",r,A(Sr),_()]});var qe=r=>{throw Error(r)};p("instanceof",(r,e)=>(r=i(r),e=i(e),t=>r(t)instanceof e(t)));p("class",(r,e,t)=>(e=e?i(e):null,t=t?i(t):null,o=>{let n=e?e(o):Object,s=function(...f){if(!(this instanceof s))return qe("Class constructor must be called with new");let l=e?Reflect.construct(n,f,s):this;return s.prototype.__constructor__&&s.prototype.__constructor__.apply(l,f),l};if(Object.setPrototypeOf(s.prototype,n.prototype),Object.setPrototypeOf(s,n),t){let f=Object.create(o);f.super=n;let l=t(f),h=Array.isArray(l)&&typeof l[0]?.[0]=="string"?l:[];for(let[E,T]of h)E==="constructor"?s.prototype.__constructor__=T:s.prototype[E]=T}return r&&(o[r]=s),s}));p("static",r=>(r=i(r),e=>[[Ze,r(e)]]));var xe=140,Cr=47,be=92,rt=r=>r===be?2:r&&r!==Cr,et=r=>r===103||r===105||r===109||r===115||r===117||r===121;S("/",xe,r=>{if(r)return;let e=c.charCodeAt(u);if(e===Cr||e===42||e===43||e===63||e===61)return;let t=k(rt);c.charCodeAt(u)===Cr||I("Unterminated regex"),g();try{return[,new RegExp(t,k(et))]}catch(o){I("Invalid regex: "+o.message)}});var tt=5,ot=59,nt=()=>{let r=u;return y()===ot&&g(),y(),X("else")?(g(4),!0):(G(r),!1)};a("if",tt+1,()=>{y();let r=["if",N(),K()];return nt()&&r.push(K()),r});p("if",(r,e,t)=>(r=i(r),e=i(e),t=t!==void 0?i(t):null,o=>r(o)?e(o):t?.(o)));var z=(r,e)=>{try{return{v:r(e)}}catch(t){if(t?.type===D)return{b:1};if(t?.type===W)return{c:1};if(t?.type===B)return{r:1,v:t.value};throw t}},Q=5,it=125,st=59;a("while",Q+1,()=>(y(),["while",N(),K()]));a("do",Q+1,()=>(r=>(y(),g(5),y(),["do",r,N()]))(K()));a("for",Q+1,()=>(y(),X("await")?(g(5),y(),["for await",N(),K()]):["for",N(),K()]));a("break",Q+1,()=>["break"]);a("continue",Q+1,()=>["continue"]);a("return",Q+1,()=>{m.asi&&(m.newline=!1),y();let r=c.charCodeAt(u);return!r||r===it||r===st||m.newline?["return"]:["return",A(Q)]});p("while",(r,e)=>(r=i(r),e=i(e),t=>{let o,n;for(;r(t)&&!(o=z(e,t)).b;){if(o.r)return o.v;o.c||(n=o.v)}return n}));p("do",(r,e)=>(r=i(r),e=i(e),t=>{let o,n;do{if((o=z(r,t)).b)break;if(o.r)return o.v;o.c||(n=o.v)}while(e(t));return n}));p("for",(r,e)=>{if(Array.isArray(r)&&r[0]===";"){let[,t,o,n]=r;return t=t?i(t):null,o=o?i(o):()=>!0,n=n?i(n):null,e=i(e),s=>{let f,l;for(t?.(s);o(s)&&!(f=z(e,s)).b;n?.(s)){if(f.r)return f.v;f.c||(l=f.v)}return l}}if(Array.isArray(r)&&(r[0]==="in"||r[0]==="of")){let[t,o,n]=r;if(Array.isArray(o)&&(o[0]==="let"||o[0]==="const"||o[0]==="var")&&(o=o[1]),t==="in")return ft(o,n,e);if(t==="of")return pt(o,n,e)}});var pt=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let s,f,l=o?null:n[r];for(let h of e(n)){if(o?L(r,h,n):n[r]=h,(s=z(t,n)).b)break;if(s.r)return s.v;s.c||(f=s.v)}return o||(n[r]=l),f}},ft=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let s,f,l=o?null:n[r];for(let h in e(n)){if(o?L(r,h,n):n[r]=h,(s=z(t,n)).b)break;if(s.r)return s.v;s.c||(f=s.v)}return o||(n[r]=l),f}};p("break",()=>()=>{throw{type:D}});p("continue",()=>()=>{throw{type:W}});p("return",r=>(r=r!==void 0?i(r):null,e=>{throw{type:B,value:r?.(e)}}));var J=5;a("try",J+1,()=>["try",_()]);gr("catch",J+1,r=>(y(),["catch",r,N(),_()]));gr("finally",J+1,r=>["finally",r,_()]);a("throw",J+1,()=>{if(m.asi&&(m.newline=!1),y(),m.newline)throw SyntaxError("Unexpected newline after throw");return["throw",A(J)]});p("try",r=>(r=r?i(r):null,e=>r?.(e)));p("catch",(r,e,t)=>{let o=r?.[1]?i(r[1]):null;return t=t?i(t):null,n=>{let s;try{s=o?.(n)}catch(f){if(f?.type===D||f?.type===W||f?.type===B)throw f;if(e!==null&&t){let l=e in n,h=n[e];n[e]=f;try{s=t(n)}finally{l?n[e]=h:delete n[e]}}else if(e===null)throw f}return s}});p("finally",(r,e)=>(r=r?i(r):null,e=e?i(e):null,t=>{let o;try{o=r?.(t)}finally{e?.(t)}return o}));p("throw",r=>(r=i(r),e=>{throw r(e)}));var wr=5,lt=20,Yr=58;a("switch",wr+1,()=>(y(),["switch",N(),_()]));a("case",wr+1,()=>(y(),(r=>(y()===Yr&&g(),["case",r]))(A(lt))));a("default",wr+1,()=>(y()===Yr&&g(),["default"]));p("switch",(r,e)=>{if(r=i(r),!e)return s=>r(s);let t=[],o=e[0]===";"?e.slice(1):[e],n=null;for(let s of o)Array.isArray(s)&&(s[0]==="case"||s[0]==="default")?(n&&t.push(n),n=[s[0]==="case"?i(s[1]):null,[]]):n&&n[1].push(i(s));return n&&t.push(n),s=>{let f=r(s),l=!1,h;for(let[E,T]of t)if(l||E===null||E(s)===f){l=!0;for(let F of T)try{h=F(s)}catch(C){if(C?.type===D)return C.value!==void 0?C.value:h;throw C}}return h}});var kr=5,$=10,Zr=42,ut=w[Zr];w[Zr]=(r,e)=>r?ut?.(r,e):(g(),"*");S("from",$+1,r=>r?r[0]!=="="&&r[0]!==","&&(y(),["from",r,A($+1)]):!1);S("as",$+2,r=>r?(y(),["as",r,A($+2)]):!1);a("import",kr,()=>(y(),["import",A($)]));a("export",kr,()=>(y(),["export",A(kr)]));a("default",$+1,()=>(y(),["default",A($)]));p("import",()=>()=>{});p("export",()=>()=>{});p("from",(r,e)=>()=>{});p("as",(r,e)=>()=>{});p("default",r=>i(r));var qr=5;m.asi=(r,e,t)=>{if(e>=qr)return;let o=t(qr-.5);if(o)return r?.[0]!==";"?[";",r,o]:(r.push(o),r)};export{pr as access,d as binary,i as compile,c as cur,Xr as default,I as err,A as expr,H as group,mt as id,u as idx,P as literal,V as loc,w as lookup,sr as nary,k as next,p as operator,ir as operators,N as parens,m as parse,G as seek,g as skip,y as space,S as token,v as unary,X as word};
|
package/justin.min.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),o=t.pop(),
|
|
3
|
-
${(
|
|
4
|
-
`?"...":"")+
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
6
|
-
`,"/*":"*/"};var
|
|
7
|
-
`)for(;
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
1
|
+
var u,c,f=r=>(u=0,c=r,f.newline=!1,r=A(),c[u]?I():r||""),I=(r="Unexpected token",e=u,t=c.slice(0,e).split(`
|
|
2
|
+
`),o=t.pop(),i=c.slice(Math.max(0,e-40),e),p="\u032D",m=(c[e]||"\u2205")+p,d=c.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
|
|
3
|
+
${(c[e-41]!==`
|
|
4
|
+
`?"...":"")+i}${m}${d}`)},Ir=(r,e=u)=>(Array.isArray(r)&&(r.loc=e),r),v=(r,e=u,t)=>{for(;t=r(c.charCodeAt(u));)u+=t;return c.slice(e,u)},h=(r=1)=>c[u+=r],rr=r=>u=r,A=(r=0,e)=>{let t,o,i,p,m=f.reserved,d;for(e&&f.asi&&(f.newline=!1),f.reserved=0;(t=f.space())&&(d=f.newline,1)&&t!==e&&(i=((p=S[t])&&p(o,r))??(f.asi&&o&&d&&(i=f.asi(o,r,A)))??(!o&&!f.reserved&&v(f.id)));)o=i,f.reserved=0;return f.reserved=m,e&&(t==e?u++:I("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},P=f.space=(r,e=u)=>{for(;(r=c.charCodeAt(u))<=32;)f.asi&&r===10&&(f.newline=!0),u++;return r},ge=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,he=(r,e=r.length)=>c.substr(u,e)===r&&!f.id(c.charCodeAt(u+e)),ye=()=>(h(),A(0,41)),S=[],y=(r,e=32,t,o=r.charCodeAt(0),i=r.length,p=S[o],m=r.toUpperCase()!==r,d,g)=>S[o]=(E,x,T,b=u)=>(d=T,(T?r==T:(i<2||r.charCodeAt(1)===c.charCodeAt(u+1)&&(i<3||c.substr(u,i)==r))&&(!m||!f.id(c.charCodeAt(u+i)))&&(d=T=r))&&x<e&&(u+=i,(g=t(E))?Ir(g,b):(u=b,d=0,m&&g!==!1&&(f.reserved=1),!m&&!p&&I()),g)||p?.(E,x,d)),l=(r,e,t=!1)=>y(r,e,(o,i)=>o&&(i=A(e-(t?.5:0)))&&[r,o,i]),C=(r,e,t)=>y(r,e,o=>t?o&&[r,o]:!o&&(o=A(e-.5))&&[r,o]),k=(r,e)=>y(r,200,t=>!t&&[,e]),K=(r,e,t)=>{y(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=(r,e)=>y(r[0],e,t=>!t&&[r,A(0,r.charCodeAt(1))||null]),j=(r,e)=>y(r[0],e,t=>t&&[r,t,A(0,r.charCodeAt(1))||null]),H={},s=(r,e,t=H[r])=>H[r]=(...o)=>e(...o)||t?.(...o),n=r=>Array.isArray(r)?r[0]===void 0?(e=>()=>e)(r[1]):H[r[0]]?.(...r.slice(1))??I(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var U=46,L=48,_=57,vr=69,wr=101,Nr=43,Or=45,kr=97,Pr=102,Rr=65,Lr=70,W=r=>[,(r=+v(e=>e===U&&c.charCodeAt(u+1)!==U||e>=L&&e<=_||((e===vr||e===wr)&&((e=c.charCodeAt(u+1))>=L&&e<=_||e===Nr||e===Or)?2:0)))!=r?I():r],Tr={2:r=>r===48||r===49,8:r=>r>=48&&r<=55,16:r=>r>=L&&r<=_||r>=kr&&r<=Pr||r>=Rr&&r<=Lr};f.number=null;S[U]=r=>!r&&c.charCodeAt(u+1)!==U&&W();for(let r=L;r<=_;r++)S[r]=e=>e?void 0:W();S[L]=r=>{if(r)return;let e=f.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&c[u+1]?.toLowerCase()===t[1])return h(2),[,parseInt(v(Tr[o]),o)]}return W()};var Ur=92,er=34,tr=39,_r={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},or=r=>(e,t,o="")=>{if(!(e||!f.string?.[String.fromCharCode(r)]))return h(),v(i=>i-r&&(i===Ur?(o+=_r[c[u+1]]||c[u+1],2):(o+=c[u],1))),c[u]===String.fromCharCode(r)?h():I("Bad string"),[,o]};S[er]=or(er);S[tr]=or(tr);f.string={'"':!0};var Mr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>l(r,Mr,!0));var ir=(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?ir(r[1],e):(()=>{throw Error("Invalid assignment target")})(),nr={"=":(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 nr)s(r,(e,t)=>(t=n(t),ir(e,(o,i,p)=>nr[r](o,i,t(p)))));var Fr=30,Br=40,sr=140;l("!",sr);C("!",sr);l("||",Fr);l("&&",Br);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 Dr=50,Gr=60,Xr=70,pr=100,$r=140;l("|",Dr);l("&",Xr);l("^",Gr);l(">>",pr);l("<<",pr);C("~",$r);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 M=90;l("<",M);l(">",M);l("<=",M);l(">=",M);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 mr=80;l("==",mr);l("!=",mr);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 lr=110,z=120,ur=140;l("+",lr);l("-",lr);l("*",z);l("/",z);l("%",z);C("+",ur);C("-",ur);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 F=150;y("++",F,r=>r?["++",r,null]:["++",A(F-1)]);y("--",F,r=>r?["--",r,null]:["--",A(F-1)]);var J=(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?J(r[1],e):(()=>{throw Error("Invalid increment target")})();s("++",(r,e)=>J(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));s("--",(r,e)=>J(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var Qr=5,Hr=10,Kr=170;R("()",Kr);K(",",Hr);K(";",Qr,!0);var fr=(...r)=>(r=r.map(n),e=>{let t;for(let o of r)t=o(e);return t});s(",",fr);s(";",fr);var N=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",V=170;j("[]",V);l(".",V);j("()",V);var B=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&&B("Missing index"),r=n(r),e=n(e),t=>{let o=e(t);return N(o)?void 0:r(t)[o]}));s(".",(r,e)=>(r=n(r),e=e[0]?e:e[1],N(e)?()=>{}:t=>r(t)[e]));s("()",(r,e)=>{if(e===void 0)return r==null?B("Empty ()"):n(r);let t=i=>i?.[0]===","&&i.slice(1).some(p=>p==null||t(p));t(e)&&B("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 Y(r,(i,p,m)=>i[p](...o(m)))});var w=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&w(r[1])||r[0]==="{}"),Y=(r,e,t,o)=>r==null?B("Empty ()"):r[0]==="()"&&r.length==2?Y(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=Y;var cr=new WeakMap,jr=(r,...e)=>typeof r=="string"?n(f(r)):cr.get(r)||cr.set(r,Wr(r,e)).get(r),dr=57344,Wr=(r,e)=>{let t=r.reduce((p,m,d)=>p+(d?String.fromCharCode(dr+d-1):"")+m,""),o=f(t),i=p=>{if(typeof p=="string"&&p.length===1){let m=p.charCodeAt(0)-dr,d;if(m>=0&&m<e.length)return d=e[m],zr(d)?d:[,d]}return Array.isArray(p)?p.map(i):p};return n(i(o))},zr=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Jr=jr;var Vr=32,Yr=f.space;f.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};var Z;f.space=()=>{Z||(Z=Object.entries(f.comment).map(([i,p])=>[i,p,i.charCodeAt(0)]));for(var r;r=Yr();){for(var e=0,t;t=Z[e++];)if(r===t[2]&&c.substr(u,t[0].length)===t[0]){var o=u+t[0].length;if(t[1]===`
|
|
7
|
+
`)for(;c.charCodeAt(o)>=Vr;)o++;else{for(;c[o]&&c.substr(o,t[1].length)!==t[1];)o++;c[o]&&(o+=t[1].length)}rr(o),r=0;break}if(r)return r}return r};var Ar=80;l("===",Ar);l("!==",Ar);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 Zr=30;l("??",Zr);s("??",(r,e)=>(r=n(r),e=n(e),t=>r(t)??e(t)));var qr=130,ar=20;l("**",qr,!0);l("**=",ar,!0);s("**",(r,e)=>(r=n(r),e=n(e),t=>r(t)**e(t)));var xr=r=>{throw Error(r)};s("**=",(r,e)=>(w(r)||xr("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]**=e(i))));var gr=90;l("in",gr);l("of",gr);s("in",(r,e)=>(r=n(r),e=n(e),t=>r(t)in e(t)));var br=20,re=100,ee=r=>{throw Error(r)};l(">>>",re);l(">>>=",br,!0);s(">>>",(r,e)=>(r=n(r),e=n(e),t=>r(t)>>>e(t)));s(">>>=",(r,e)=>(w(r)||ee("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]>>>=e(i))));var D=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...i]=r;if(o==="{}")for(let p of i){let m,d,g;p[0]==="="?[,[,m,d],g]=p:[,m,d]=p;let E=e[m];E===void 0&&g&&(E=n(g)(t)),D(d,E,t)}else if(o==="[]"){let p=0;for(let m of i){if(m===null){p++;continue}if(Array.isArray(m)&&m[0]==="..."){t[m[1]]=e.slice(p);break}let d=m,g;Array.isArray(m)&&m[0]==="="&&([,d,g]=m);let E=e[p++];E===void 0&&g&&(E=n(g)(t)),D(d,E,t)}}};var q=20,G=r=>{throw Error(r)};l("||=",q,!0);l("&&=",q,!0);l("??=",q,!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=>D(t,e(o),o)}return w(r)||G("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]=e(i))});s("||=",(r,e)=>(w(r)||G("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]||=e(i))));s("&&=",(r,e)=>(w(r)||G("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]&&=e(i))));s("??=",(r,e)=>(w(r)||G("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]??=e(i))));k("true",!0);k("false",!1);k("null",null);k("undefined",void 0);k("NaN",NaN);k("Infinity",1/0);var a=20;y("?",a,(r,e,t)=>r&&(e=A(a-1))&&v(o=>o===58)&&(t=A(a-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 te=20;l("=>",te,!0);s("=>",(r,e)=>{r=r[0]==="()"?r[1]:r,r=r?r[0]===","?r.slice(1):[r]:[];let t=-1,o=null;return r.length&&Array.isArray(r[r.length-1])&&r[r.length-1][0]==="..."&&(t=r.length-1,o=r[t][1],r=r.slice(0,-1)),e=n(e[0]==="{}"?e[1]:e),(i=null)=>(i=Object.create(i),(...p)=>(r.forEach((m,d)=>i[m]=p[d]),o&&(i[o]=p.slice(t)),e(i)))});var oe=140;C("...",oe);s("...",r=>(r=n(r),e=>Object.entries(r(e))));var hr=170;y("?.",hr,(r,e)=>{if(!r)return;let t=P();return t===40?(h(),["?.()",r,A(0,41)||null]):t===91?(h(),["?.[]",r,A(0,93)]):(e=A(hr),e?["?.",r,e]:void 0)});s("?.",(r,e)=>(r=n(r),N(e)?()=>{}:t=>r(t)?.[e]));s("?.[]",(r,e)=>(r=n(r),e=n(e),t=>{let o=e(t);return N(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 N(p)?()=>{}:m=>i(m)?.[p]?.(...t(m))}if(r[0]==="?.[]"){let i=n(r[1]),p=n(r[2]);return m=>{let d=i(m),g=p(m);return N(g)?void 0:d?.[g]?.(...t(m))}}if(r[0]==="."){let i=n(r[1]),p=r[2];return N(p)?()=>{}:m=>i(m)?.[p]?.(...t(m))}if(r[0]==="[]"&&r.length===3){let i=n(r[1]),p=n(r[2]);return m=>{let d=i(m),g=p(m);return N(g)?void 0:d?.[g]?.(...t(m))}}let o=n(r);return i=>o(i)?.(...t(i))});var X=140;C("typeof",X);C("void",X);C("delete",X);C("new",X);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(m=>m(p)))(t.slice(1).map(n)):(i=>p=>[i(p)])(n(t)):()=>[];return i=>new(e(i))(...o(i))});var $=Symbol("accessor"),yr=20,ne=40,ie=41,se=123,pe=125,Cr=r=>e=>{if(e)return;P();let t=v(f.id);if(!t||(P(),c.charCodeAt(u)!==ne))return!1;h();let o=A(0,ie);return P(),c.charCodeAt(u)!==se?!1:(h(),[r,t,o,A(0,pe)])};y("get",yr-1,Cr("get"));y("set",yr-1,Cr("set"));s("get",(r,e)=>(e=e?n(e):()=>{},t=>[[$,r,{get:function(){let o=Object.create(t||{});return o.this=this,e(o)}}]]));s("set",(r,e,t)=>(t=t?n(t):()=>{},o=>[[$,r,{set:function(i){let p=Object.create(o||{});p.this=this,p[e]=i,t(p)}}]]));var me=20,Sr=200;R("[]",Sr);R("{}",Sr);l(":",me-1,!0);s("{}",(r,e)=>{if(e!==void 0)return;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 m of t.flatMap(d=>d(o)))if(m[0]===$){let[,d,g]=m;p[d]={...p[d],...g,configurable:!0,enumerable:!0}}else i[m[0]]=m[1];for(let m in p)Object.defineProperty(i,m,p[m]);return i}});s(":",(r,e)=>(e=n(e),Array.isArray(r)?(r=n(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));var le=170,Q=96,ue=36,fe=123,ce=92,de={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Er=()=>{let r=[];for(let e="",t;(t=c.charCodeAt(u))!==Q;)t?t===ce?(h(),e+=de[c[u]]||c[u],h()):t===ue&&c.charCodeAt(u+1)===fe?(e&&r.push([,e]),e="",h(2),r.push(A(0,125))):(e+=c[u],h(),t=c.charCodeAt(u),t===Q&&e&&r.push([,e])):I("Unterminated template");return h(),r},Ae=S[Q];S[Q]=(r,e)=>r&&e<le?f.asi&&f.newline?void 0:(h(),["``",r,...Er()]):r?Ae?.(r,e):(h(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(Er()));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(m=>m(p)))});f.string["'"]=!0;f.number={"0x":16,"0b":2,"0o":8};export{j as access,l as binary,n as compile,c as cur,Jr as default,I as err,A as expr,R as group,ge as id,u as idx,k as literal,Ir as loc,S as lookup,K as nary,v as next,s as operator,H as operators,ye as parens,f as parse,rr as seek,h as skip,P as space,y as token,C as unary,he as word};
|
package/package.json
CHANGED
package/parse.js
CHANGED
|
@@ -129,12 +129,6 @@ export let idx, cur,
|
|
|
129
129
|
|
|
130
130
|
// === Compile: AST → Evaluator ===
|
|
131
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
132
|
// Operator registry
|
|
139
133
|
export const operators = {};
|
|
140
134
|
|
|
@@ -144,10 +138,9 @@ export const operator = (op, fn, prev = operators[op]) =>
|
|
|
144
138
|
|
|
145
139
|
// Compile AST to evaluator function
|
|
146
140
|
export const compile = node => (
|
|
147
|
-
curNode = node,
|
|
148
141
|
!Array.isArray(node) ? (node === undefined ? () => undefined : ctx => ctx?.[node]) :
|
|
149
142
|
node[0] === undefined ? (v => () => v)(node[1]) :
|
|
150
|
-
operators[node[0]]?.(...node.slice(1)) ??
|
|
143
|
+
operators[node[0]]?.(...node.slice(1)) ?? err(`Unknown operator: ${node[0]}`, node?.loc)
|
|
151
144
|
);
|
|
152
145
|
|
|
153
146
|
export default parse;
|
package/subscript.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var f,
|
|
2
|
-
`),
|
|
3
|
-
${(
|
|
4
|
-
`?"...":"")+
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
1
|
+
var l,f,u=r=>(l=0,f=r,u.newline=!1,r=A(),f[l]?y():r||""),y=(r="Unexpected token",e=l,t=f.slice(0,e).split(`
|
|
2
|
+
`),o=t.pop(),i=f.slice(Math.max(0,e-40),e),p="\u032D",c=(f[e]||"\u2205")+p,d=f.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
|
|
3
|
+
${(f[e-41]!==`
|
|
4
|
+
`?"...":"")+i}${c}${d}`)},er=(r,e=l)=>(Array.isArray(r)&&(r.loc=e),r),S=(r,e=l,t)=>{for(;t=r(f.charCodeAt(l));)l+=t;return f.slice(e,l)},E=(r=1)=>f[l+=r],Pr=r=>l=r,A=(r=0,e)=>{let t,o,i,p,c=u.reserved,d;for(e&&u.asi&&(u.newline=!1),u.reserved=0;(t=u.space())&&(d=u.newline,1)&&t!==e&&(i=((p=g[t])&&p(o,r))??(u.asi&&o&&d&&(i=u.asi(o,r,A)))??(!o&&!u.reserved&&S(u.id)));)o=i,u.reserved=0;return u.reserved=c,e&&(t==e?l++:y("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},Ur=u.space=(r,e=l)=>{for(;(r=f.charCodeAt(l))<=32;)u.asi&&r===10&&(u.newline=!0),l++;return r},Mr=u.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,Rr=(r,e=r.length)=>f.substr(l,e)===r&&!u.id(f.charCodeAt(l+e)),Dr=()=>(E(),A(0,41)),g=[],h=(r,e=32,t,o=r.charCodeAt(0),i=r.length,p=g[o],c=r.toUpperCase()!==r,d,I)=>g[o]=(k,X,T,Q=l)=>(d=T,(T?r==T:(i<2||r.charCodeAt(1)===f.charCodeAt(l+1)&&(i<3||f.substr(l,i)==r))&&(!c||!u.id(f.charCodeAt(l+i)))&&(d=T=r))&&X<e&&(l+=i,(I=t(k))?er(I,Q):(l=Q,d=0,c&&I!==!1&&(u.reserved=1),!c&&!p&&y()),I)||p?.(k,X,d)),m=(r,e,t=!1)=>h(r,e,(o,i)=>o&&(i=A(e-(t?.5:0)))&&[r,o,i]),C=(r,e,t)=>h(r,e,o=>t?o&&[r,o]:!o&&(o=A(e-.5))&&[r,o]),Lr=(r,e)=>h(r,200,t=>!t&&[,e]),D=(r,e,t)=>{h(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))},B=(r,e)=>h(r[0],e,t=>!t&&[r,A(0,r.charCodeAt(1))||null]),L=(r,e)=>h(r[0],e,t=>t&&[r,t,A(0,r.charCodeAt(1))||null]),R={},s=(r,e,t=R[r])=>R[r]=(...o)=>e(...o)||t?.(...o),n=r=>Array.isArray(r)?r[0]===void 0?(e=>()=>e)(r[1]):R[r[0]]?.(...r.slice(1))??y(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var _=46,w=48,v=57,tr=69,or=101,nr=43,ir=45,sr=97,lr=102,pr=65,ur=70,$=r=>[,(r=+S(e=>e===_&&f.charCodeAt(l+1)!==_||e>=w&&e<=v||((e===tr||e===or)&&((e=f.charCodeAt(l+1))>=w&&e<=v||e===nr||e===ir)?2:0)))!=r?y():r],mr={2:r=>r===48||r===49,8:r=>r>=48&&r<=55,16:r=>r>=w&&r<=v||r>=sr&&r<=lr||r>=pr&&r<=ur};u.number=null;g[_]=r=>!r&&f.charCodeAt(l+1)!==_&&$();for(let r=w;r<=v;r++)g[r]=e=>e?void 0:$();g[w]=r=>{if(r)return;let e=u.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&f[l+1]?.toLowerCase()===t[1])return E(2),[,parseInt(S(mr[o]),o)]}return $()};var fr=92,H=34,G=39,dr={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},W=r=>(e,t,o="")=>{if(!(e||!u.string?.[String.fromCharCode(r)]))return E(),S(i=>i-r&&(i===fr?(o+=dr[f[l+1]]||f[l+1],2):(o+=f[l],1))),f[l]===String.fromCharCode(r)?E():y("Bad string"),[,o]};g[H]=W(H);g[G]=W(G);u.string={'"':!0};var cr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>m(r,cr,!0));var J=(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?J(r[1],e):(()=>{throw Error("Invalid assignment target")})(),z={"=":(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 z)s(r,(e,t)=>(t=n(t),J(e,(o,i,p)=>z[r](o,i,t(p)))));var Ar=30,gr=40,K=140;m("!",K);C("!",K);m("||",Ar);m("&&",gr);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 hr=50,yr=60,Cr=70,V=100,Sr=140;m("|",hr);m("&",Cr);m("^",yr);m(">>",V);m("<<",V);C("~",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)));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 P=90;m("<",P);m(">",P);m("<=",P);m(">=",P);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 Y=80;m("==",Y);m("!=",Y);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 Z=110,F=120,q=140;m("+",Z);m("-",Z);m("*",F);m("/",F);m("%",F);C("+",q);C("-",q);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 U=150;h("++",U,r=>r?["++",r,null]:["++",A(U-1)]);h("--",U,r=>r?["--",r,null]:["--",A(U-1)]);var N=(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?N(r[1],e):(()=>{throw Error("Invalid increment target")})();s("++",(r,e)=>N(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));s("--",(r,e)=>N(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var Er=5,wr=10,Ir=170;B("()",Ir);D(",",wr);D(";",Er,!0);var x=(...r)=>(r=r.map(n),e=>{let t;for(let o of r)t=o(e);return t});s(",",x);s(";",x);var j=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",O=170;L("[]",O);m(".",O);L("()",O);var M=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&&M("Missing index"),r=n(r),e=n(e),t=>{let o=e(t);return j(o)?void 0:r(t)[o]}));s(".",(r,e)=>(r=n(r),e=e[0]?e:e[1],j(e)?()=>{}:t=>r(t)[e]));s("()",(r,e)=>{if(e===void 0)return r==null?M("Empty ()"):n(r);let t=i=>i?.[0]===","&&i.slice(1).some(p=>p==null||t(p));t(e)&&M("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 a(r,(i,p,c)=>i[p](...o(c)))});var a=(r,e,t,o)=>r==null?M("Empty ()"):r[0]==="()"&&r.length==2?a(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 b=new WeakMap,Tr=(r,...e)=>typeof r=="string"?n(u(r)):b.get(r)||b.set(r,_r(r,e)).get(r),rr=57344,_r=(r,e)=>{let t=r.reduce((p,c,d)=>p+(d?String.fromCharCode(rr+d-1):"")+c,""),o=u(t),i=p=>{if(typeof p=="string"&&p.length===1){let c=p.charCodeAt(0)-rr,d;if(c>=0&&c<e.length)return d=e[c],vr(d)?d:[,d]}return Array.isArray(p)?p.map(i):p};return n(i(o))},vr=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),ne=Tr;export{L as access,m as binary,n as compile,f as cur,ne as default,y as err,A as expr,B as group,Mr as id,l as idx,Lr as literal,er as loc,g as lookup,D as nary,S as next,s as operator,R as operators,Dr as parens,u as parse,Pr as seek,E as skip,Ur as space,h as token,C as unary,Rr as word};
|
package/util/stringify.js
CHANGED
|
@@ -67,8 +67,6 @@ export const codegen = node => {
|
|
|
67
67
|
|
|
68
68
|
// --- Statement generators (need structure) ---
|
|
69
69
|
|
|
70
|
-
generator('block', body => body === undefined ? '{}' : '{ ' + codegen(body) + ' }');
|
|
71
|
-
|
|
72
70
|
// Variables: ['let', decl] or ['let', decl1, decl2, ...]
|
|
73
71
|
const varGen = kw => (...args) => kw + ' ' + args.map(codegen).join(', ');
|
|
74
72
|
generator('let', varGen('let'));
|
|
@@ -76,7 +74,7 @@ generator('const', varGen('const'));
|
|
|
76
74
|
generator('var', varGen('var'));
|
|
77
75
|
|
|
78
76
|
// Control flow
|
|
79
|
-
const wrap = s =>
|
|
77
|
+
const wrap = s => '{ ' + (s ? codegen(s) : '') + ' }';
|
|
80
78
|
generator('if', (cond, then, els) => 'if (' + codegen(cond) + ') ' + wrap(then) + (els ? ' else ' + wrap(els) : ''));
|
|
81
79
|
generator('while', (cond, body) => 'while (' + codegen(cond) + ') ' + wrap(body));
|
|
82
80
|
generator('do', (body, cond) => 'do ' + wrap(body) + ' while (' + codegen(cond) + ')');
|
|
@@ -101,8 +99,7 @@ generator('finally', (expr, body) => codegen(expr) + ' finally { ' + codegen(bod
|
|
|
101
99
|
// Functions
|
|
102
100
|
generator('function', (name, params, body) => {
|
|
103
101
|
const args = !params ? '' : params[0] === ',' ? params.slice(1).map(codegen).join(', ') : codegen(params);
|
|
104
|
-
|
|
105
|
-
return 'function' + (name ? ' ' + name : '') + '(' + args + ') ' + b;
|
|
102
|
+
return 'function' + (name ? ' ' + name : '') + '(' + args + ') ' + wrap(body);
|
|
106
103
|
});
|
|
107
104
|
|
|
108
105
|
generator('=>', (params, body) => {
|