subscript 9.1.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 (82) hide show
  1. package/README.md +123 -171
  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 -6
  10. package/feature/destruct.js +33 -0
  11. package/feature/function.js +44 -0
  12. package/feature/group.js +41 -12
  13. package/feature/if.js +28 -0
  14. package/feature/literal.js +13 -0
  15. package/feature/loop.js +123 -0
  16. package/feature/module.js +42 -0
  17. package/feature/number.js +45 -10
  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 -16
  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 +59 -0
  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 -1
  52. package/package.json +18 -23
  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 -1
  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/increment.js +0 -11
  68. package/feature/logic.js +0 -11
  69. package/feature/mult.js +0 -25
  70. package/feature/object.js +0 -17
  71. package/feature/optional.js +0 -30
  72. package/feature/pow.js +0 -5
  73. package/feature/shift.js +0 -12
  74. package/feature/spread.js +0 -6
  75. package/feature/ternary.js +0 -10
  76. package/src/compile.d.ts +0 -17
  77. package/src/compile.js +0 -28
  78. package/src/const.js +0 -42
  79. package/src/parse.d.ts +0 -22
  80. package/src/parse.js +0 -114
  81. package/src/stringify.js +0 -31
  82. /package/{LICENSE → license} +0 -0
package/feature/var.js ADDED
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Variable declarations: let, const, var
3
+ *
4
+ * AST:
5
+ * let x = 1 → ['let', ['=', 'x', 1]]
6
+ * let x = 1, y = 2 → ['let', ['=', 'x', 1], ['=', 'y', 2]]
7
+ * const {a} = x → ['const', ['=', ['{}', 'a'], 'x']]
8
+ * for (let x in o) → ['for', ['in', ['let', 'x'], 'o'], body]
9
+ * var x → ['var', 'x'] (acts as assignment target)
10
+ */
11
+ import { token, expr, space, operator, compile } from '../parse.js';
12
+ import { keyword } from './block.js';
13
+ import { destructure } from './destruct.js';
14
+
15
+ const STATEMENT = 5, SEQ = 10, ASSIGN = 20;
16
+
17
+ // let/const: expr(SEQ-1) consumes assignment, stops before comma
18
+ // For for-in/of, return ['in/of', ['let', x], iterable] not ['let', ['in', x, it]]
19
+ // For comma, return ['let', decl1, decl2, ...] not ['let', [',', ...]]
20
+ const decl = keyword => {
21
+ let node = expr(SEQ - 1);
22
+ // for (let x in obj) - restructure so for-loop sees in/of at top
23
+ if (node?.[0] === 'in' || node?.[0] === 'of')
24
+ return [node[0], [keyword, node[1]], node[2]];
25
+ // let x = 1, y = 2 - flatten comma into nary let
26
+ if (node?.[0] === ',')
27
+ return [keyword, ...node.slice(1)];
28
+ return [keyword, node];
29
+ };
30
+
31
+ token('let', STATEMENT + 1, a => !a && decl('let'));
32
+ token('const', STATEMENT + 1, a => !a && decl('const'));
33
+
34
+ // var: just declares identifier, assignment happens separately
35
+ // var x = 5 → ['=', ['var', 'x'], 5]
36
+ keyword('var', STATEMENT, () => (space(), ['var', expr(ASSIGN)]));
37
+
38
+ // Compile
39
+ const varOp = (...decls) => {
40
+ decls = decls.map(d => {
41
+ // Just identifier: let x
42
+ if (typeof d === 'string') return ctx => { ctx[d] = undefined; };
43
+ // Assignment: let x = 1
44
+ if (d[0] === '=') {
45
+ const [, pattern, val] = d;
46
+ const v = compile(val);
47
+ if (typeof pattern === 'string') return ctx => { ctx[pattern] = v(ctx); };
48
+ return ctx => destructure(pattern, v(ctx), ctx);
49
+ }
50
+ return compile(d);
51
+ });
52
+ return ctx => { for (const d of decls) d(ctx); };
53
+ };
54
+ operator('let', varOp);
55
+ operator('const', varOp);
56
+ // var just declares the variable (assignment handled by = operator)
57
+ operator('var', name => (typeof name === 'string'
58
+ ? ctx => { ctx[name] = undefined; }
59
+ : () => {}));
package/jessie.js ADDED
@@ -0,0 +1,31 @@
1
+ /**
2
+ * jessie: Practical JS subset
3
+ *
4
+ * Builds on justin with statements: blocks, variables, if/else,
5
+ * loops, functions, try/catch, switch, throw.
6
+ */
7
+ import './justin.js';
8
+
9
+ // Statement features (var.js must come before destruct.js)
10
+ import './feature/var.js';
11
+ import './feature/function.js';
12
+ import './feature/async.js';
13
+ import './feature/class.js';
14
+ import './feature/regex.js';
15
+ import './feature/destruct.js';
16
+
17
+ // Control flow
18
+ import './feature/if.js';
19
+ import './feature/loop.js';
20
+ import './feature/try.js';
21
+ import './feature/switch.js';
22
+
23
+ // Module system
24
+ import './feature/module.js';
25
+ import './feature/accessor.js';
26
+
27
+ // Automatic Semicolon Insertion
28
+ import './feature/asi.js';
29
+
30
+ export * from './parse.js';
31
+ export { default } from './subscript.js';
package/jessie.min.js ADDED
@@ -0,0 +1,8 @@
1
+ var l,d,c=r=>(l=0,d=r,c.newline=!1,r=A(),d[l]?I():r||""),I=(r="Unexpected token",e=l,t=d.slice(0,e).split(`
2
+ `),o=t.pop(),n=d.slice(Math.max(0,e-40),e),s="\u032D",u=(d[e]||"\u2205")+s,f=d.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
3
+ ${(d[e-41]!==`
4
+ `?"...":"")+n}${u}${f}`)},Z=(r,e=l)=>(Array.isArray(r)&&(r.loc=e),r),k=(r,e=l,t)=>{for(;t=r(d.charCodeAt(l));)l+=t;return d.slice(e,l)},E=(r=1)=>d[l+=r],K=r=>l=r,A=(r=0,e)=>{let t,o,n,s,u=c.reserved,f;for(e&&c.asi&&(c.newline=!1),c.reserved=0;(t=c.space())&&(f=c.newline,1)&&t!==e&&(n=((s=C[t])&&s(o,r))??(c.asi&&o&&f&&(n=c.asi(o,r,A)))??(!o&&!c.reserved&&k(c.id)));)o=n,c.reserved=0;return c.reserved=u,e&&(t==e?l++:I("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},h=c.space=(r,e=l)=>{for(;(r=d.charCodeAt(l))<=32;)c.asi&&r===10&&(c.newline=!0),l++;return r},dt=c.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,D=(r,e=r.length)=>d.substr(l,e)===r&&!c.id(d.charCodeAt(l+e)),N=()=>(E(),A(0,41)),C=[],S=(r,e=32,t,o=r.charCodeAt(0),n=r.length,s=C[o],u=r.toUpperCase()!==r,f,y)=>C[o]=(g,T,X,w=l)=>(f=X,(X?r==X:(n<2||r.charCodeAt(1)===d.charCodeAt(l+1)&&(n<3||d.substr(l,n)==r))&&(!u||!c.id(d.charCodeAt(l+n)))&&(f=X=r))&&T<e&&(l+=n,(y=t(g))?Z(y,w):(l=w,f=0,u&&y!==!1&&(c.reserved=1),!u&&!s&&I()),y)||s?.(g,T,f)),m=(r,e,t=!1)=>S(r,e,(o,n)=>o&&(n=A(e-(t?.5:0)))&&[r,o,n]),v=(r,e,t)=>S(r,e,o=>t?o&&[r,o]:!o&&(o=A(e-.5))&&[r,o]),L=(r,e)=>S(r,200,t=>!t&&[,e]),pr=(r,e,t)=>{S(r,e,(o,n)=>(n=A(e-(t?.5:0)),o?.[0]!==r&&(o=[r,o||null]),n?.[0]===r?o.push(...n.slice(1)):o.push(n||null),o))},z=(r,e)=>S(r[0],e,t=>!t&&[r,A(0,r.charCodeAt(1))||null]),ur=(r,e)=>S(r[0],e,t=>t&&[r,t,A(0,r.charCodeAt(1))||null]),Tr,re=(r="Compile error",e=Tr)=>I(r,e?.loc),sr={},p=(r,e,t=sr[r])=>sr[r]=(...o)=>e(...o)||t?.(...o),i=r=>(Tr=r,Array.isArray(r)?r[0]===void 0?(e=>()=>e)(r[1]):sr[r[0]]?.(...r.slice(1))??re(`Unknown operator: ${r[0]}`):r===void 0?()=>{}:e=>e?.[r]);var q=46,J=48,x=57,ee=69,te=101,oe=43,ne=45,ie=97,se=102,pe=65,ue=70,fr=r=>[,(r=+k(e=>e===q&&d.charCodeAt(l+1)!==q||e>=J&&e<=x||((e===ee||e===te)&&((e=d.charCodeAt(l+1))>=J&&e<=x||e===oe||e===ne)?2:0)))!=r?I():r],fe={2:r=>r===48||r===49,8:r=>r>=48&&r<=55,16:r=>r>=J&&r<=x||r>=ie&&r<=se||r>=pe&&r<=ue};c.number=null;C[q]=r=>!r&&d.charCodeAt(l+1)!==q&&fr();for(let r=J;r<=x;r++)C[r]=e=>e?void 0:fr();C[J]=r=>{if(r)return;let e=c.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&d[l+1]?.toLowerCase()===t[1])return E(2),[,parseInt(k(fe[o]),o)]}return fr()};var le=92,Ir=34,Nr=39,me={n:`
5
+ `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Rr=r=>(e,t,o="")=>{if(!(e||!c.string?.[String.fromCharCode(r)]))return E(),k(n=>n-r&&(n===le?(o+=me[d[l+1]]||d[l+1],2):(o+=d[l],1))),d[l]===String.fromCharCode(r)?E():I("Bad string"),[,o]};C[Ir]=Rr(Ir);C[Nr]=Rr(Nr);c.string={'"':!0};var P=20;m("=",P,!0);m("+=",P,!0);m("-=",P,!0);m("*=",P,!0);m("/=",P,!0);m("%=",P,!0);m("|=",P,!0);m("&=",P,!0);m("^=",P,!0);m(">>=",P,!0);m("<<=",P,!0);var _=(r,e,t,o)=>typeof r=="string"?n=>e(n,r,n):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o,n)):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n),n)):r[0]==="()"&&r.length===2?_(r[1],e):(()=>{throw Error("Invalid assignment target")})();p("=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]=e(n))));p("+=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]+=e(n))));p("-=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]-=e(n))));p("*=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]*=e(n))));p("/=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]/=e(n))));p("%=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]%=e(n))));p("|=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]|=e(n))));p("&=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]&=e(n))));p("^=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]^=e(n))));p(">>=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]>>=e(n))));p("<<=",(r,e)=>(e=i(e),_(r,(t,o,n)=>t[o]<<=e(n))));var ce=30,de=40,_r=140;m("!",_r);v("!",_r);m("||",ce);m("&&",de);p("!",r=>(r=i(r),e=>!r(e)));p("||",(r,e)=>(r=i(r),e=i(e),t=>r(t)||e(t)));p("&&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&&e(t)));var Ae=50,he=60,ye=70,Or=100,Ee=140;m("|",Ae);m("&",ye);m("^",he);m(">>",Or);m("<<",Or);v("~",Ee);p("~",r=>(r=i(r),e=>~r(e)));p("|",(r,e)=>(r=i(r),e=i(e),t=>r(t)|e(t)));p("&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&e(t)));p("^",(r,e)=>(r=i(r),e=i(e),t=>r(t)^e(t)));p(">>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>e(t)));p("<<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<<e(t)));var b=90;m("<",b);m(">",b);m("<=",b);m(">=",b);p(">",(r,e)=>(r=i(r),e=i(e),t=>r(t)>e(t)));p("<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<e(t)));p(">=",(r,e)=>(r=i(r),e=i(e),t=>r(t)>=e(t)));p("<=",(r,e)=>(r=i(r),e=i(e),t=>r(t)<=e(t)));var Pr=80;m("==",Pr);m("!=",Pr);p("==",(r,e)=>(r=i(r),e=i(e),t=>r(t)==e(t)));p("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(t)));var Mr=110,lr=120,Ur=140;m("+",Mr);m("-",Mr);m("*",lr);m("/",lr);m("%",lr);v("+",Ur);v("-",Ur);p("+",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)+e(t)):(r=i(r),t=>+r(t)));p("-",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)-e(t)):(r=i(r),t=>-r(t)));p("*",(r,e)=>(r=i(r),e=i(e),t=>r(t)*e(t)));p("/",(r,e)=>(r=i(r),e=i(e),t=>r(t)/e(t)));p("%",(r,e)=>(r=i(r),e=i(e),t=>r(t)%e(t)));var rr=150;S("++",rr,r=>r?["++",r,null]:["++",A(rr-1)]);S("--",rr,r=>r?["--",r,null]:["--",A(rr-1)]);var mr=(r,e,t,o)=>typeof r=="string"?n=>e(n,r):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o)):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n))):r[0]==="()"&&r.length===2?mr(r[1],e):(()=>{throw Error("Invalid increment target")})();p("++",(r,e)=>mr(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));p("--",(r,e)=>mr(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var cr=5,Lr=123,Fr=125,a=(r,e,t,o=r.charCodeAt(0),n=r.length,s=C[o],u)=>C[o]=(f,y,g,T=l)=>!f&&(g?r==g:(n<2||d.substr(l,n)==r)&&(g=r))&&y<e&&!c.id(d.charCodeAt(l+n))&&(K(l+n),(u=t())?Z(u,T):(K(T),!s&&I()),u)||s?.(f,y,g),dr=(r,e,t,o=r.charCodeAt(0),n=r.length,s=C[o],u)=>C[o]=(f,y,g,T=l)=>f&&(g?r==g:(n<2||d.substr(l,n)==r)&&(g=r))&&y<e&&!c.id(d.charCodeAt(l+n))&&(K(l+n),Z(u=t(f),T),u)||s?.(f,y,g),M=()=>(h()===Lr||I("Expected {"),E(),A(cr-.5,Fr)||null),B=()=>h()!==Lr?A(cr+.5):(E(),["block",A(cr-.5,Fr)||null]);p("block",r=>r===void 0?()=>{}:(r=i(r),e=>r(e)));var F=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...n]=r;if(o==="{}")for(let s of n){let u,f,y;s[0]==="="?[,[,u,f],y]=s:[,u,f]=s;let g=e[u];g===void 0&&y&&(g=i(y)(t)),F(f,g,t)}else if(o==="[]"){let s=0;for(let u of n){if(u===null){s++;continue}if(Array.isArray(u)&&u[0]==="..."){t[u[1]]=e.slice(s);break}let f=u,y;Array.isArray(u)&&u[0]==="="&&([,f,y]=u);let g=e[s++];g===void 0&&y&&(g=i(y)(t)),F(f,g,t)}}};var Q=Symbol("break"),j=Symbol("continue"),W=Symbol("return"),V=(r,e)=>{try{return{v:r(e)}}catch(t){if(t?.type===Q)return{b:1};if(t?.type===j)return{c:1};if(t?.type===W)return{r:1,v:t.value};throw t}},$=5,ge=125,ae=59;a("while",$+1,()=>(h(),["while",N(),B()]));a("do",$+1,()=>(r=>(h(),E(5),h(),["do",r,N()]))(B()));a("for",$+1,()=>(h(),D("await")?(E(5),h(),["for await",N(),B()]):["for",N(),B()]));a("break",$+1,()=>["break"]);a("continue",$+1,()=>["continue"]);a("return",$+1,()=>{c.asi&&(c.newline=!1),h();let r=d.charCodeAt(l);return!r||r===ge||r===ae||c.newline?["return"]:["return",A($)]});p("while",(r,e)=>(r=i(r),e=i(e),t=>{let o,n;for(;r(t)&&!(o=V(e,t)).b;){if(o.r)return o.v;o.c||(n=o.v)}return n}));p("do",(r,e)=>(r=i(r),e=i(e),t=>{let o,n;do{if((o=V(r,t)).b)break;if(o.r)return o.v;o.c||(n=o.v)}while(e(t));return n}));p("for",(r,e)=>{if(Array.isArray(r)&&r[0]===";"){let[,t,o,n]=r;return t=t?i(t):null,o=o?i(o):()=>!0,n=n?i(n):null,e=i(e),s=>{let u,f;for(t?.(s);o(s)&&!(u=V(e,s)).b;n?.(s)){if(u.r)return u.v;u.c||(f=u.v)}return f}}if(Array.isArray(r)&&(r[0]==="in"||r[0]==="of")){let[t,o,n]=r;if(Array.isArray(o)&&(o[0]==="let"||o[0]==="const"||o[0]==="var")&&(o=o[1]),t==="in")return we(o,n,e);if(t==="of")return Se(o,n,e)}});var Se=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let s,u,f=o?null:n[r];for(let y of e(n)){if(o?F(r,y,n):n[r]=y,(s=V(t,n)).b)break;if(s.r)return s.v;s.c||(u=s.v)}return o||(n[r]=f),u}},we=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let s,u,f=o?null:n[r];for(let y in e(n)){if(o?F(r,y,n):n[r]=y,(s=V(t,n)).b)break;if(s.r)return s.v;s.c||(u=s.v)}return o||(n[r]=f),u}};p("break",()=>()=>{throw{type:Q}});p("continue",()=>()=>{throw{type:j}});p("return",r=>(r=r!==void 0?i(r):null,e=>{throw{type:W,value:r?.(e)}}));var G=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",hr=170;ur("[]",hr);m(".",hr);ur("()",hr);var Ar=r=>{throw Error(r)};p("[]",(r,e)=>e===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(t=>t==null?(()=>{}):t[0]==="..."?(t=i(t[1]),o=>t(o)):(t=i(t),o=>[t(o)])),t=>r.flatMap(o=>o(t))):(e==null&&Ar("Missing index"),r=i(r),e=i(e),t=>{let o=e(t);return G(o)?void 0:r(t)[o]}));p(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],G(e)?()=>{}:t=>r(t)[e]));p("()",(r,e)=>{if(e===void 0)return r==null?Ar("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(s=>s==null||t(s));t(e)&&Ar("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];return R(r,(n,s,u)=>n[s](...o(u)),!0)});var U=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&U(r[1])||r[0]==="{}"),Ce=r=>{throw Error(r)},R=(r,e,t,o,n)=>r==null?Ce("Empty ()"):r[0]==="()"&&r.length==2?R(r[1],e,t):typeof r=="string"?s=>e(s,r,s):r[0]==="."?(o=i(r[1]),n=r[2],s=>e(o(s),n,s)):r[0]==="?."?(o=i(r[1]),n=r[2],s=>{let u=o(s);return u==null?void 0:e(u,n,s)}):r[0]==="[]"&&r.length===3?(o=i(r[1]),n=i(r[2]),s=>e(o(s),n(s),s)):r[0]==="?.[]"?(o=i(r[1]),n=i(r[2]),s=>{let u=o(s);return u==null?void 0:e(u,n(s),s)}):(r=i(r),s=>e([r(s)],0,s));var ke=5,ve=10,Te=170;z("()",Te);pr(",",ve);pr(";",ke,!0);var Gr=r=>{throw Error(r)};p("()",(r,e)=>{if(e===void 0)return r==null?Gr("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(s=>s==null||t(s));t(e)&&Gr("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];return R(r,(n,s,u)=>n[s](...o(u)),!0)});var Xr=(...r)=>(r=r.map(i),e=>{let t;for(let o of r)try{t=o(e)}catch(n){throw(n?.type===Q||n?.type===j)&&(n.value=t),n}return t});p(",",Xr);p(";",Xr);var Kr=new WeakMap,Ie=(r,...e)=>typeof r=="string"?i(c(r)):Kr.get(r)||Kr.set(r,Ne(r,e)).get(r),Dr=57344,Ne=(r,e)=>{let t=r.reduce((s,u,f)=>s+(f?String.fromCharCode(Dr+f-1):"")+u,""),o=c(t),n=s=>{if(typeof s=="string"&&s.length===1){let u=s.charCodeAt(0)-Dr,f;if(u>=0&&u<e.length)return f=e[u],Re(f)?f:[,f]}return Array.isArray(s)?s.map(n):s};return i(n(o))},Re=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Br=Ie;var _e=32,Oe=c.space;c.comment??={"//":`
6
+ `,"/*":"*/"};var yr;c.space=()=>{yr||(yr=Object.entries(c.comment).map(([n,s])=>[n,s,n.charCodeAt(0)]));for(var r;r=Oe();){for(var e=0,t;t=yr[e++];)if(r===t[2]&&d.substr(l,t[0].length)===t[0]){var o=l+t[0].length;if(t[1]===`
7
+ `)for(;d.charCodeAt(o)>=_e;)o++;else{for(;d[o]&&d.substr(o,t[1].length)!==t[1];)o++;d[o]&&(o+=t[1].length)}K(o),r=0;break}if(r)return r}return r};var Qr=80;m("===",Qr);m("!==",Qr);p("===",(r,e)=>(r=i(r),e=i(e),t=>r(t)===e(t)));p("!==",(r,e)=>(r=i(r),e=i(e),t=>r(t)!==e(t)));var Pe=30;m("??",Pe);p("??",(r,e)=>(r=i(r),e=i(e),t=>r(t)??e(t)));var Me=130,Ue=20;m("**",Me,!0);m("**=",Ue,!0);p("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));var Le=r=>{throw Error(r)};p("**=",(r,e)=>(U(r)||Le("Invalid assignment target"),e=i(e),R(r,(t,o,n)=>t[o]**=e(n))));var $r=90;m("in",$r);m("of",$r);p("in",(r,e)=>(r=i(r),e=i(e),t=>r(t)in e(t)));var Fe=20,Ge=100,Xe=r=>{throw Error(r)};m(">>>",Ge);m(">>>=",Fe,!0);p(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));p(">>>=",(r,e)=>(U(r)||Xe("Invalid assignment target"),e=i(e),R(r,(t,o,n)=>t[o]>>>=e(n))));var Er=20,er=r=>{throw Error(r)};m("||=",Er,!0);m("&&=",Er,!0);m("??=",Er,!0);p("=",(r,e)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let t=r[1];return e=i(e),typeof t=="string"?o=>{o[t]=e(o)}:o=>F(t,e(o),o)}return U(r)||er("Invalid assignment target"),e=i(e),R(r,(t,o,n)=>t[o]=e(n))});p("||=",(r,e)=>(U(r)||er("Invalid assignment target"),e=i(e),R(r,(t,o,n)=>t[o]||=e(n))));p("&&=",(r,e)=>(U(r)||er("Invalid assignment target"),e=i(e),R(r,(t,o,n)=>t[o]&&=e(n))));p("??=",(r,e)=>(U(r)||er("Invalid assignment target"),e=i(e),R(r,(t,o,n)=>t[o]??=e(n))));L("true",!0);L("false",!1);L("null",null);L("undefined",void 0);L("NaN",NaN);L("Infinity",1/0);var gr=20;S("?",gr,(r,e,t)=>r&&(e=A(gr-1))&&k(o=>o===58)&&(t=A(gr-1),["?",r,e,t]));p("?",(r,e,t)=>(r=i(r),e=i(e),t=i(t),o=>r(o)?e(o):t(o)));var Ke=20;m("=>",Ke,!0);p("=>",(r,e)=>{r=r[0]==="()"?r[1]:r,r=r?r[0]===","?r.slice(1):[r]:[];let t=-1,o=null;return r.length&&Array.isArray(r[r.length-1])&&r[r.length-1][0]==="..."&&(t=r.length-1,o=r[t][1],r=r.slice(0,-1)),e=i(e[0]==="{}"?e[1]:e),(n=null)=>(n=Object.create(n),(...s)=>(r.forEach((u,f)=>n[u]=s[f]),o&&(n[o]=s.slice(t)),e(n)))});var De=140;v("...",De);p("...",r=>(r=i(r),e=>Object.entries(r(e))));var Hr=170;S("?.",Hr,(r,e)=>{if(!r)return;let t=h();return t===40?(E(),["?.()",r,A(0,41)||null]):t===91?(E(),["?.[]",r,A(0,93)]):(e=A(Hr),e?["?.",r,e]:void 0)});p("?.",(r,e)=>(r=i(r),G(e)?()=>{}:t=>r(t)?.[e]));p("?.[]",(r,e)=>(r=i(r),e=i(e),t=>{let o=e(t);return G(o)?void 0:r(t)?.[o]}));p("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];if(r[0]==="?."){let n=i(r[1]),s=r[2];return G(s)?()=>{}:u=>n(u)?.[s]?.(...t(u))}if(r[0]==="?.[]"){let n=i(r[1]),s=i(r[2]);return u=>{let f=n(u),y=s(u);return G(y)?void 0:f?.[y]?.(...t(u))}}if(r[0]==="."){let n=i(r[1]),s=r[2];return G(s)?()=>{}:u=>n(u)?.[s]?.(...t(u))}if(r[0]==="[]"&&r.length===3){let n=i(r[1]),s=i(r[2]);return u=>{let f=n(u),y=s(u);return G(y)?void 0:f?.[y]?.(...t(u))}}let o=i(r);return n=>o(n)?.(...t(n))});var tr=140;v("typeof",tr);v("void",tr);v("delete",tr);v("new",tr);p("typeof",r=>(r=i(r),e=>typeof r(e)));p("void",r=>(r=i(r),e=>(r(e),void 0)));p("delete",r=>{if(r[0]==="."){let e=i(r[1]),t=r[2];return o=>delete e(o)[t]}if(r[0]==="[]"){let e=i(r[1]),t=i(r[2]);return o=>delete e(o)[t(o)]}return()=>!0});p("new",r=>{let e=i(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,o=t?t[0]===","?(n=>s=>n.map(u=>u(s)))(t.slice(1).map(i)):(n=>s=>[n(s)])(i(t)):()=>[];return n=>new(e(n))(...o(n))});var or=Symbol("accessor"),jr=20,Be=40,Qe=41,$e=123,He=125,Wr=r=>e=>{if(e)return;h();let t=k(c.id);if(!t||(h(),d.charCodeAt(l)!==Be))return!1;E();let o=A(0,Qe);return h(),d.charCodeAt(l)!==$e?!1:(E(),[r,t,o,A(0,He)])};S("get",jr-1,Wr("get"));S("set",jr-1,Wr("set"));p("get",(r,e)=>(e=e?i(e):()=>{},t=>[[or,r,{get:function(){let o=Object.create(t||{});return o.this=this,e(o)}}]]));p("set",(r,e,t)=>(t=t?i(t):()=>{},o=>[[or,r,{set:function(n){let s=Object.create(o||{});s.this=this,s[e]=n,t(s)}}]]));var je=20,zr=200;z("[]",zr);z("{}",zr);m(":",je-1,!0);p("{}",(r,e)=>{if(e!==void 0)return;r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(o=>i(typeof o=="string"?[":",o,o]:o));return o=>{let n={},s={};for(let u of t.flatMap(f=>f(o)))if(u[0]===or){let[,f,y]=u;s[f]={...s[f],...y,configurable:!0,enumerable:!0}}else n[u[0]]=u[1];for(let u in s)Object.defineProperty(n,u,s[u]);return n}});p(":",(r,e)=>(e=i(e),Array.isArray(r)?(r=i(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));var We=170,nr=96,ze=36,Je=123,Ve=92,Ye={n:`
8
+ `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Jr=()=>{let r=[];for(let e="",t;(t=d.charCodeAt(l))!==nr;)t?t===Ve?(E(),e+=Ye[d[l]]||d[l],E()):t===ze&&d.charCodeAt(l+1)===Je?(e&&r.push([,e]),e="",E(2),r.push(A(0,125))):(e+=d[l],E(),t=d.charCodeAt(l),t===nr&&e&&r.push([,e])):I("Unterminated template");return E(),r},Ze=C[nr];C[nr]=(r,e)=>r&&e<We?c.asi&&c.newline?void 0:(E(),["``",r,...Jr()]):r?Ze?.(r,e):(E(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(Jr()));p("`",(...r)=>(r=r.map(i),e=>r.map(t=>t(e)).join("")));p("``",(r,...e)=>{r=i(r);let t=[],o=[];for(let s of e)Array.isArray(s)&&s[0]===void 0?t.push(s[1]):o.push(i(s));let n=Object.assign([...t],{raw:t});return s=>r(s)(n,...o.map(u=>u(s)))});c.string["'"]=!0;c.number={"0x":16,"0b":2,"0o":8};var ar=5,qe=10,xe=20,Vr=r=>{let e=A(qe-1);return e?.[0]==="in"||e?.[0]==="of"?[e[0],[r,e[1]],e[2]]:e?.[0]===","?[r,...e.slice(1)]:[r,e]};S("let",ar+1,r=>!r&&Vr("let"));S("const",ar+1,r=>!r&&Vr("const"));a("var",ar,()=>(h(),["var",A(xe)]));var Yr=(...r)=>(r=r.map(e=>{if(typeof e=="string")return t=>{t[e]=void 0};if(e[0]==="="){let[,t,o]=e,n=i(o);return typeof t=="string"?s=>{s[t]=n(s)}:s=>F(t,n(s),s)}return i(e)}),e=>{for(let t of r)t(e)});p("let",Yr);p("const",Yr);p("var",r=>typeof r=="string"?e=>{e[r]=void 0}:()=>{});var be=200;a("function",be,()=>{h();let r=k(c.id);return r&&h(),["function",r,N()||null,M()]});p("function",(r,e,t)=>{t=t?i(t):()=>{};let o=e?e[0]===","?e.slice(1):[e]:[],n=null,s=-1,u=o[o.length-1];return Array.isArray(u)&&u[0]==="..."&&(s=o.length-1,n=u[1],o.length--),f=>{let y=(...g)=>{let T={};o.forEach((w,O)=>T[w]=g[O]),n&&(T[n]=g.slice(s));let X=new Proxy(T,{get:(w,O)=>O in w?w[O]:f[O],set:(w,O,br)=>((O in w?w:f)[O]=br,!0),has:(w,O)=>O in w||O in f});try{return t(X)}catch(w){if(w?.type===W)return w.value;throw w}};return r&&(f[r]=y),y}});var ir=140,Sr=20;v("await",ir);a("yield",ir,()=>(h(),d[l]==="*"?(E(),h(),["yield*",A(Sr)]):["yield",A(Sr)]));a("async",ir,()=>{if(h(),D("function"))return["async",A(ir)];let r=A(Sr-.5);return r&&["async",r]});p("async",r=>{let e=i(r);return t=>{let o=e(t);return async function(...n){return o(...n)}}});p("await",r=>(r=i(r),async e=>await r(e)));p("yield",r=>(r=r?i(r):null,e=>{throw{__yield__:r?r(e):void 0}}));p("yield*",r=>(r=i(r),e=>{throw{__yield_all__:r(e)}}));var wr=200,rt=140,et=90,tt=Symbol("static");L("super",Symbol.for("super"));v("static",rt);m("instanceof",et);S("#",wr,r=>{if(r)return;let e=k(c.id);return e?"#"+e:void 0});a("class",wr,()=>{h();let r=k(c.id)||null;if(r==="extends")r=null;else if(h(),!D("extends"))return["class",r,null,M()];return h(),["class",r,A(wr),M()]});var ot=r=>{throw Error(r)};p("instanceof",(r,e)=>(r=i(r),e=i(e),t=>r(t)instanceof e(t)));p("class",(r,e,t)=>(e=e?i(e):null,t=t?i(t):null,o=>{let n=e?e(o):Object,s=function(...u){if(!(this instanceof s))return ot("Class constructor must be called with new");let f=e?Reflect.construct(n,u,s):this;return s.prototype.__constructor__&&s.prototype.__constructor__.apply(f,u),f};if(Object.setPrototypeOf(s.prototype,n.prototype),Object.setPrototypeOf(s,n),t){let u=Object.create(o);u.super=n;let f=t(u),y=Array.isArray(f)&&typeof f[0]?.[0]=="string"?f:[];for(let[g,T]of y)g==="constructor"?s.prototype.__constructor__=T:s.prototype[g]=T}return r&&(o[r]=s),s}));p("static",r=>(r=i(r),e=>[[tt,r(e)]]));var nt=140,Cr=47,it=92,st=r=>r===it?2:r&&r!==Cr,pt=r=>r===103||r===105||r===109||r===115||r===117||r===121;S("/",nt,r=>{if(r)return;let e=d.charCodeAt(l);if(e===Cr||e===42||e===43||e===63||e===61)return;let t=k(st);d.charCodeAt(l)===Cr||I("Unterminated regex"),E();try{return[,new RegExp(t,k(pt))]}catch(o){I("Invalid regex: "+o.message)}});var ut=5,ft=59,lt=()=>{let r=l;return h()===ft&&E(),h(),D("else")?(E(4),!0):(K(r),!1)};a("if",ut+1,()=>{h();let r=["if",N(),B()];return lt()&&r.push(B()),r});p("if",(r,e,t)=>(r=i(r),e=i(e),t=t!==void 0?i(t):null,o=>r(o)?e(o):t?.(o)));var Y=5;a("try",Y+1,()=>["try",M()]);dr("catch",Y+1,r=>(h(),["catch",r,N(),M()]));dr("finally",Y+1,r=>["finally",r,M()]);a("throw",Y+1,()=>{if(c.asi&&(c.newline=!1),h(),c.newline)throw SyntaxError("Unexpected newline after throw");return["throw",A(Y)]});p("try",r=>(r=r?i(r):null,e=>r?.(e)));p("catch",(r,e,t)=>{let o=r?.[1]?i(r[1]):null;return t=t?i(t):null,n=>{let s;try{s=o?.(n)}catch(u){if(u?.type===Q||u?.type===j||u?.type===W)throw u;if(e!==null&&t){let f=e in n,y=n[e];n[e]=u;try{s=t(n)}finally{f?n[e]=y:delete n[e]}}else if(e===null)throw u}return s}});p("finally",(r,e)=>(r=r?i(r):null,e=e?i(e):null,t=>{let o;try{o=r?.(t)}finally{e?.(t)}return o}));p("throw",r=>(r=i(r),e=>{throw r(e)}));var kr=5,mt=20,Zr=58;a("switch",kr+1,()=>(h(),["switch",N(),M()]));a("case",kr+1,()=>(h(),(r=>(h()===Zr&&E(),["case",r]))(A(mt))));a("default",kr+1,()=>(h()===Zr&&E(),["default"]));p("switch",(r,e)=>{if(r=i(r),!e)return s=>r(s);let t=[],o=e[0]===";"?e.slice(1):[e],n=null;for(let s of o)Array.isArray(s)&&(s[0]==="case"||s[0]==="default")?(n&&t.push(n),n=[s[0]==="case"?i(s[1]):null,[]]):n&&n[1].push(i(s));return n&&t.push(n),s=>{let u=r(s),f=!1,y;for(let[g,T]of t)if(f||g===null||g(s)===u){f=!0;for(let X of T)try{y=X(s)}catch(w){if(w?.type===Q)return w.value!==void 0?w.value:y;throw w}}return y}});var vr=5,H=10,qr=42,ct=C[qr];C[qr]=(r,e)=>r?ct?.(r,e):(E(),"*");S("from",H+1,r=>r?r[0]!=="="&&r[0]!==","&&(h(),["from",r,A(H+1)]):!1);S("as",H+2,r=>r?(h(),["as",r,A(H+2)]):!1);a("import",vr,()=>(h(),["import",A(H)]));a("export",vr,()=>(h(),["export",A(vr)]));a("default",H+1,()=>(h(),["default",A(H)]));p("import",()=>()=>{});p("export",()=>()=>{});p("from",(r,e)=>()=>{});p("as",(r,e)=>()=>{});p("default",r=>i(r));var xr=5;c.asi=(r,e,t)=>{if(e>=xr)return;let o=t(xr-.5);if(o)return r?.[0]!==";"?[";",r,o]:(r.push(o),r)};export{ur as access,m as binary,i as compile,d as cur,Br as default,I as err,A as expr,z as group,dt as id,l as idx,L as literal,Z as loc,C as lookup,pr as nary,k as next,p as operator,sr as operators,N as parens,c as parse,K as seek,E as skip,h as space,S as token,v as unary,D as word};
package/justin.js CHANGED
@@ -1,48 +1,39 @@
1
- // no-keywords js, just in https://github.com/endojs/Jessie/issues/66
2
- import { err, token, binary, unary } from './src/parse.js'
3
- import compile, { operator, prop } from './src/compile.js'
4
-
5
- import subscript from './subscript.js'
6
- import './feature/comment.js'
7
- import './feature/pow.js'
8
- import './feature/ternary.js'
9
- import './feature/bool.js'
10
- import './feature/array.js'
11
- import './feature/object.js'
12
- import './feature/arrow.js'
13
- import './feature/optional.js'
14
- import './feature/spread.js'
15
- import { PREC_ASSIGN, PREC_EQ, PREC_LOR, PREC_COMP } from './src/const.js'
16
-
17
- binary('in', PREC_COMP), operator('in', (a, b) => b && (a = compile(a), b = compile(b), ctx => a(ctx) in b(ctx)))
18
-
19
- // register !==, ===
20
- binary('===', PREC_EQ), binary('!==', 9)
21
- operator('===', (a, b) => (a = compile(a), b = compile(b), ctx => a(ctx) === b(ctx)))
22
- operator('!==', (a, b) => (a = compile(a), b = compile(b), ctx => a(ctx) !== b(ctx)))
23
-
24
- // add nullish coalescing
25
- binary('??', PREC_LOR)
26
- operator('??', (a, b) => b && (a = compile(a), b = compile(b), ctx => a(ctx) ?? b(ctx)))
27
- binary('??=', PREC_ASSIGN, true)
28
- operator('??=', (a, b) => (b = compile(b), prop(a, (obj, path, ctx) => (obj[path] ??= b(ctx)))))
29
-
30
- // complete logical assignments
31
- binary('||=', PREC_ASSIGN, true)
32
- operator('||=', (a, b) => (b = compile(b), prop(a, (obj, path, ctx) => (obj[path] ||= b(ctx)))))
33
- binary('&&=', PREC_ASSIGN, true)
34
- operator('&&=', (a, b) => (b = compile(b), prop(a, (obj, path, ctx) => (obj[path] &&= b(ctx)))))
35
-
36
- // unsigned shift
37
- binary('>>>', PREC_EQ)
38
- operator('>>>', (a, b) => (a = compile(a), b = compile(b), ctx => a(ctx) >>> b(ctx)))
39
- binary('>>>=', PREC_ASSIGN, true)
40
- operator('>>>=', (a, b) => (b = compile(b), prop(a, (obj, path, ctx) => (obj[path] >>>= b(ctx)))))
41
-
42
- // add JS literals
43
- token('undefined', 20, a => a ? err() : [, undefined])
44
- token('NaN', 20, a => a ? err() : [, NaN])
45
- token('null', 20, a => a ? err() : [, null])
46
-
47
- export default subscript
48
- export * from './subscript.js'
1
+ /**
2
+ * justin: JSON superset expression language
3
+ *
4
+ * Builds on subscript with JS-specific features:
5
+ * optional chaining, arrow functions, spread, templates.
6
+ */
7
+ import './subscript.js';
8
+ import { parse } from './parse.js';
9
+
10
+ // Add single quotes
11
+ parse.string["'"] = true;
12
+
13
+ // Add hex, binary, octal prefixes
14
+ parse.number = { '0x': 16, '0b': 2, '0o': 8 };
15
+
16
+ import './feature/comment.js';
17
+
18
+ // Extended operators
19
+ // Note: assignment (=) is in subscript, must come BEFORE identity (===)
20
+ import './feature/op/identity.js'; // === !==
21
+ import './feature/op/nullish.js'; // ??
22
+ import './feature/op/pow.js'; // ** **=
23
+ import './feature/op/membership.js'; // in (instanceof is in jessie/class.js)
24
+ import './feature/op/bitwise-unsigned.js'; // >>> >>>=
25
+ import './feature/op/assign-logical.js'; // ||= &&= ??= + destructuring
26
+
27
+ // JS-specific operators (ternary, arrow, spread, optional chaining, typeof/void/delete/new)
28
+ import './feature/literal.js';
29
+ import './feature/op/ternary.js';
30
+ import './feature/op/arrow.js';
31
+ import './feature/op/spread.js';
32
+ import './feature/op/optional.js';
33
+ import './feature/op/unary.js';
34
+
35
+ import './feature/collection.js';
36
+ import './feature/template.js';
37
+
38
+ export * from './parse.js';
39
+ export { default } from './subscript.js';
package/justin.min.js CHANGED
@@ -1 +1,8 @@
1
- let r,t,e=e=>(r=0,t=e,e=a(),t[r]?l():e||""),l=(e="Bad syntax",l=t.slice(0,r).split("\n"),n=l.pop())=>{const i=t.slice(r-108,r).split("\n").pop(),a=t.slice(r,r+108).split("\n").shift();throw EvalError(`${e} at ${l.length}:${n.length} \`${r>=108?"…":""}${i}┃${a}\``,"font-weight: bold")},n=(e,l=r,n)=>{for(;n=e(t.charCodeAt(r));)r+=n;return t.slice(l,r)},i=(e=1,l=r)=>(r+=e,t.slice(l,r)),a=(t=0,i)=>{let a,p,c,d;for(;(a=o())&&(c=((d=s[a])&&d(p,t))??(!p&&n(e.id)));)p=c;return i&&(a==i?r++:l()),p},o=e=>{for(;(e=t.charCodeAt(r))<=32;)r++;return e};e.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||36==r||95==r||r>=192&&215!=r&&247!=r;let s=[],p=(n,i=32,a,o=n.charCodeAt(0),p=n.length,c=s[o],d=n.toUpperCase()!==n)=>s[o]=(o,s,u,f=r)=>(u?n==u:(p<2||t.substr(r,p)==n)&&(u=n))&&s<i&&!(d&&e.id(t.charCodeAt(r+p)))&&(r+=p,a(o)||(r=f,!c&&l()))||c?.(o,s,u),c=(r,t,e=!1)=>p(r,t,((l,n)=>l&&(n=a(t-(e?.5:0)))&&[r,l,n])),d=(r,t,e)=>p(r,t,(l=>e?l&&[r,l]:!l&&(l=a(t-.5))&&[r,l])),u=(r,t,e)=>{p(r,t,((e,l)=>(l=a(t),e?.[0]!==r&&(e=[r,e||null]),l?.[0]===r?e.push(...l.slice(1)):e.push(l||null),e)))},f=(r,t)=>p(r[0],t,(t=>!t&&[r,a(0,r.charCodeAt(1))])),h=(r,t)=>p(r[0],t,(t=>t&&[r,t,a(0,r.charCodeAt(1))||null]));const A=r=>Array.isArray(r)?r[0]?g[r[0]].call(...r):()=>r[1]:A.id(r);A.id=r=>t=>t?.[r];const g={},m=(r,t,e=g[r])=>g[r]=(...r)=>t(...r)||e?.(...r),y=(r,t,e,n,i)=>"()"===r[0]&&2==r.length?y(r[1],t,e):"string"==typeof r?e=>t(e,r,e):"."===r[0]?(n=A(r[1]),i=r[2],r=>t(n(r),i,r)):"[]"===r[0]&&3===r.length?(n=A(r[1]),i=A(r[2]),r=>t(n(r),i(r),r)):e?(r=A(r),e=>t([r(e)],0,e)):()=>l("Bad left value"),v=(r,t)=>[,(r=+n((r=>46===r||r>=48&&r<=57||(69===r||101===r?2:0))))!=r?l():r];s[46]=r=>!r&&v();for(let r=48;r<=57;r++)s[r]=r=>r?l():v();const C={n:"\n",r:"\r",t:"\t",b:"\b",f:"\f",v:"\v"},b=e=>(n,a,o="")=>{for(n&&l("Unexpected string"),i();(a=t.charCodeAt(r))-e;)92===a?(i(),a=i(),o+=C[a]||a):o+=i();return i()||l("Bad string"),[,o]};s[34]=b(34),s[39]=b(39),h("()",170),m("()",((r,t,e)=>void 0!==t&&(e=t?","===t[0]?(t=t.slice(1).map((r=>r?A(r):err())),r=>t.map((t=>t(r)))):(t=A(t),r=>[t(r)]):()=>[],y(r,((r,t,l)=>r[t](...e(l))),!0)))),h("[]",170),m("[]",((r,t)=>t?(r=A(r),t=A(t),e=>r(e)[t(e)]):err())),c(".",170),m(".",((r,t)=>(r=A(r),t=t[0]?t:t[1],e=>r(e)[t]))),f("()",170),m("()",((r,t)=>void 0===t&&(!r&&l("Empty ()"),A(r))));const $=(...r)=>(r=r.map(A),t=>r.map((r=>r(t))).pop());function N(r){if(!r)return"";if(Array.isArray(r)){const[t,...e]=r;return t?"[]"==t||"{}"==t||"()"==t?(e.length>1?N(e.shift()):"")+t[0]+N(e[0])+t[1]:1===e.length?t+N(e[0]):2===e.length?N(e[0])+("."===t?t:" "+t+" ")+N(e[1]):e.filter(Boolean).map((r=>N(r))).join(t+"\n"):JSON.stringify(e[0])}return r}u(",",10),m(",",$),u(";",5),m(";",$),c("=",20,!0),m("=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]=t(l)))))),c("*",120),m("*",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)*t(e)))),c("/",120),m("/",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)/t(e)))),c("%",120),m("%",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)%t(e)))),c("*=",20,!0),m("*=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]*=t(l)))))),c("/=",20,!0),m("/=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]/=t(l)))))),c("%=",20,!0),m("%=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]%=t(l)))))),c("+",110),m("+",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)+t(e)))),c("-",110),m("-",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)-t(e)))),d("+",140),m("+",((r,t)=>!t&&(r=A(r),t=>+r(t)))),d("-",140),m("-",((r,t)=>!t&&(r=A(r),t=>-r(t)))),c("+=",20,!0),m("+=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]+=t(l)))))),c("-=",20,!0),m("-=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]-=t(l)))))),p("++",150,(r=>r?["++",r,null]:["++",a(149)])),m("++",((r,t)=>y(r,null===t?(r,t)=>r[t]++:(r,t)=>++r[t]))),p("--",150,(r=>r?["--",r,null]:["--",a(149)])),m("--",((r,t)=>y(r,null===t?(r,t)=>r[t]--:(r,t)=>--r[t]))),d("~",140),m("~",((r,t)=>!t&&(r=A(r),t=>~r(t)))),c("|",50),m("|",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)|t(e)))),c("&",70),m("&",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)&t(e)))),c("^",60),m("^",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)^t(e)))),d("!",140),m("!",((r,t)=>!t&&(r=A(r),t=>!r(t)))),c("||",30),m("||",((r,t)=>(r=A(r),t=A(t),e=>r(e)||t(e)))),c("&&",40),m("&&",((r,t)=>(r=A(r),t=A(t),e=>r(e)&&t(e)))),c("==",80),m("==",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)==t(e)))),c("!=",80),m("!=",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)!=t(e)))),c(">",90),m(">",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)>t(e)))),c("<",90),m("<",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)<t(e)))),c(">=",90),m(">=",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)>=t(e)))),c("<=",90),m("<=",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)<=t(e)))),c(">>",100),m(">>",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)>>t(e)))),c("<<",100),m("<<",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)<<t(e)))),c(">>=",20,!0),m(">>=",((r,t)=>(t=A(t),prop(r,((r,e,l)=>r[e]>>=t(l)))))),c("<<=",20,!0),m("<<=",((r,t)=>(t=A(t),prop(r,((r,e,l)=>r[e]<<=t(l))))));var j=r=>A(e(r));p("/*",200,((e,l)=>(n((e=>42!==e&&47!==t.charCodeAt(r+1))),i(2),e||a(l)||[]))),p("//",200,((r,t)=>(n((r=>r>=32)),r||a(t)||[]))),c("**",130,!0),m("**",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)**t(e)))),p("?",20,((r,t,e)=>r&&(t=a(19))&&n((r=>58===r))&&["?",r,t,a(19)])),m("?",((r,t,e)=>(r=A(r),t=A(t),e=A(e),l=>r(l)?t(l):e(l)))),p("true",200,(r=>r?err():[,!0])),p("false",200,(r=>r?err():[,!1])),f("[]",200),m("[]",((r,t)=>void 0===t&&(r=(r=r?","===r[0]?r.slice(1):[r]:[]).map((r=>"..."===r[0]?(r=A(r[1]),t=>r(t)):(r=A(r),t=>[r(t)]))),t=>r.flatMap((r=>r(t)))))),f("{}",200),m("{}",((r,t)=>void 0===t&&(r=(r=r?","!==r[0]?[r]:r.slice(1):[]).map((r=>A("string"==typeof r?[":",r,r]:r))),t=>Object.fromEntries(r.flatMap((r=>r(t))))))),c(":",19,!0),m(":",((r,t)=>(t=A(t),Array.isArray(r)?(r=A(r),e=>[[r(e),t(e)]]):e=>[[r,t(e)]]))),c("=>",20,!0),m("=>",((r,t)=>(r=(r="()"===r[0]?r[1]:r)?r=","===r[0]?r.slice(1):[r]:[],t=A("{}"===t[0]?t[1]:t),(e=null)=>(e=Object.create(e),(...l)=>(r.map(((r,t)=>e[r]=l[t])),t(e)))))),c(""),p("?.",170,(r=>r&&["?.",r])),m("?.",(r=>(r=A(r),t=>r(t)||(()=>{})))),p("?.",170,((r,t)=>r&&!(t=a(170))?.map&&["?.",r,t])),m("?.",((r,t)=>t&&(r=A(r),e=>r(e)?.[t]))),m("()",((r,t,e,l,n,i)=>void 0!==t&&"?."===r[0]&&(r[2]||Array.isArray(r[1]))&&(l=t?","===t[0]?(t=t.slice(1).map(A),r=>t.map((t=>t(r)))):(t=A(t),r=>[t(r)]):()=>[],!r[2]&&(r=r[1]),n="[]"===r[0]&&3===r.length?A(r[2]):()=>r[2],e=A(r[1]),r=>e(r)?.[n(r)]?.(...l(r))))),d("...",140),m("...",(r=>(r=A(r),t=>Object.entries(r(t))))),c("in",90),m("in",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)in t(e)))),c("===",80),c("!==",9),m("===",((r,t)=>(r=A(r),t=A(t),e=>r(e)===t(e)))),m("!==",((r,t)=>(r=A(r),t=A(t),e=>r(e)!==t(e)))),c("??",30),m("??",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)??t(e)))),c("??=",20,!0),m("??=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]??=t(l)))))),c("||=",20,!0),m("||=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]||=t(l)))))),c("&&=",20,!0),m("&&=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]&&=t(l)))))),c(">>>",80),m(">>>",((r,t)=>(r=A(r),t=A(t),e=>r(e)>>>t(e)))),c(">>>=",20,!0),m(">>>=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]>>>=t(l)))))),p("undefined",20,(r=>r?l():[,void 0])),p("NaN",20,(r=>r?l():[,NaN])),p("null",20,(r=>r?l():[,null]));export{h as access,c as binary,A as compile,j as default,f as group,u as nary,m as operator,e as parse,N as stringify,p as token,d as unary};
1
+ var f,d,m=r=>(f=0,d=r,m.newline=!1,r=h(),d[f]?k():r||""),k=(r="Unexpected token",e=f,t=d.slice(0,e).split(`
2
+ `),o=t.pop(),n=d.slice(Math.max(0,e-40),e),s="\u032D",u=(d[e]||"\u2205")+s,c=d.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
3
+ ${(d[e-41]!==`
4
+ `?"...":"")+n}${u}${c}`)},x=(r,e=f)=>(Array.isArray(r)&&(r.loc=e),r),R=(r,e=f,t)=>{for(;t=r(d.charCodeAt(f));)f+=t;return d.slice(e,f)},g=(r=1)=>d[f+=r],M=r=>f=r,h=(r=0,e)=>{let t,o,n,s,u=m.reserved,c;for(e&&m.asi&&(m.newline=!1),m.reserved=0;(t=m.space())&&(c=m.newline,1)&&t!==e&&(n=((s=y[t])&&s(o,r))??(m.asi&&o&&c&&(n=m.asi(o,r,h)))??(!o&&!m.reserved&&R(m.id)));)o=n,m.reserved=0;return m.reserved=u,e&&(t==e?f++:k("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},S=m.space=(r,e=f)=>{for(;(r=d.charCodeAt(f))<=32;)m.asi&&r===10&&(m.newline=!0),f++;return r},Be=m.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,fr=(r,e=r.length)=>d.substr(f,e)===r&&!m.id(d.charCodeAt(f+e)),_=()=>(g(),h(0,41)),y=[],C=(r,e=32,t,o=r.charCodeAt(0),n=r.length,s=y[o],u=r.toUpperCase()!==r,c,A)=>y[o]=(E,B,$,lr=f)=>(c=$,($?r==$:(n<2||r.charCodeAt(1)===d.charCodeAt(f+1)&&(n<3||d.substr(f,n)==r))&&(!u||!m.id(d.charCodeAt(f+n)))&&(c=$=r))&&B<e&&(f+=n,(A=t(E))?x(A,lr):(f=lr,c=0,u&&A!==!1&&(m.reserved=1),!u&&!s&&k()),A)||s?.(E,B,c)),l=(r,e,t=!1)=>C(r,e,(o,n)=>o&&(n=h(e-(t?.5:0)))&&[r,o,n]),v=(r,e,t)=>C(r,e,o=>t?o&&[r,o]:!o&&(o=h(e-.5))&&[r,o]),O=(r,e)=>C(r,200,t=>!t&&[,e]),b=(r,e,t)=>{C(r,e,(o,n)=>(n=h(e-(t?.5:0)),o?.[0]!==r&&(o=[r,o||null]),n?.[0]===r?o.push(...n.slice(1)):o.push(n||null),o))},F=(r,e)=>C(r[0],e,t=>!t&&[r,h(0,r.charCodeAt(1))||null]),rr=(r,e)=>C(r[0],e,t=>t&&[r,t,h(0,r.charCodeAt(1))||null]),mr,Br=(r="Compile error",e=mr)=>k(r,e?.loc),q={},p=(r,e,t=q[r])=>q[r]=(...o)=>e(...o)||t?.(...o),i=r=>(mr=r,Array.isArray(r)?r[0]===void 0?(e=>()=>e)(r[1]):q[r[0]]?.(...r.slice(1))??Br(`Unknown operator: ${r[0]}`):r===void 0?()=>{}:e=>e?.[r]);var K=46,D=48,Q=57,Mr=69,_r=101,Fr=43,Dr=45,Gr=97,Xr=102,$r=65,Kr=70,er=r=>[,(r=+R(e=>e===K&&d.charCodeAt(f+1)!==K||e>=D&&e<=Q||((e===Mr||e===_r)&&((e=d.charCodeAt(f+1))>=D&&e<=Q||e===Fr||e===Dr)?2:0)))!=r?k():r],Qr={2:r=>r===48||r===49,8:r=>r>=48&&r<=55,16:r=>r>=D&&r<=Q||r>=Gr&&r<=Xr||r>=$r&&r<=Kr};m.number=null;y[K]=r=>!r&&d.charCodeAt(f+1)!==K&&er();for(let r=D;r<=Q;r++)y[r]=e=>e?void 0:er();y[D]=r=>{if(r)return;let e=m.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&d[f+1]?.toLowerCase()===t[1])return g(2),[,parseInt(R(Qr[o]),o)]}return er()};var Hr=92,cr=34,dr=39,Wr={n:`
5
+ `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Ar=r=>(e,t,o="")=>{if(!(e||!m.string?.[String.fromCharCode(r)]))return g(),R(n=>n-r&&(n===Hr?(o+=Wr[d[f+1]]||d[f+1],2):(o+=d[f],1))),d[f]===String.fromCharCode(r)?g():k("Bad string"),[,o]};y[cr]=Ar(cr);y[dr]=Ar(dr);m.string={'"':!0};var N=20;l("=",N,!0);l("+=",N,!0);l("-=",N,!0);l("*=",N,!0);l("/=",N,!0);l("%=",N,!0);l("|=",N,!0);l("&=",N,!0);l("^=",N,!0);l(">>=",N,!0);l("<<=",N,!0);var I=(r,e,t,o)=>typeof r=="string"?n=>e(n,r,n):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o,n)):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n),n)):r[0]==="()"&&r.length===2?I(r[1],e):(()=>{throw Error("Invalid assignment target")})();p("=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]=e(n))));p("+=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]+=e(n))));p("-=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]-=e(n))));p("*=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]*=e(n))));p("/=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]/=e(n))));p("%=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]%=e(n))));p("|=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]|=e(n))));p("&=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]&=e(n))));p("^=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]^=e(n))));p(">>=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]>>=e(n))));p("<<=",(r,e)=>(e=i(e),I(r,(t,o,n)=>t[o]<<=e(n))));var jr=30,zr=40,hr=140;l("!",hr);v("!",hr);l("||",jr);l("&&",zr);p("!",r=>(r=i(r),e=>!r(e)));p("||",(r,e)=>(r=i(r),e=i(e),t=>r(t)||e(t)));p("&&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&&e(t)));var Jr=50,Vr=60,Yr=70,gr=100,Zr=140;l("|",Jr);l("&",Yr);l("^",Vr);l(">>",gr);l("<<",gr);v("~",Zr);p("~",r=>(r=i(r),e=>~r(e)));p("|",(r,e)=>(r=i(r),e=i(e),t=>r(t)|e(t)));p("&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&e(t)));p("^",(r,e)=>(r=i(r),e=i(e),t=>r(t)^e(t)));p(">>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>e(t)));p("<<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<<e(t)));var H=90;l("<",H);l(">",H);l("<=",H);l(">=",H);p(">",(r,e)=>(r=i(r),e=i(e),t=>r(t)>e(t)));p("<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<e(t)));p(">=",(r,e)=>(r=i(r),e=i(e),t=>r(t)>=e(t)));p("<=",(r,e)=>(r=i(r),e=i(e),t=>r(t)<=e(t)));var yr=80;l("==",yr);l("!=",yr);p("==",(r,e)=>(r=i(r),e=i(e),t=>r(t)==e(t)));p("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(t)));var Cr=110,tr=120,Er=140;l("+",Cr);l("-",Cr);l("*",tr);l("/",tr);l("%",tr);v("+",Er);v("-",Er);p("+",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)+e(t)):(r=i(r),t=>+r(t)));p("-",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)-e(t)):(r=i(r),t=>-r(t)));p("*",(r,e)=>(r=i(r),e=i(e),t=>r(t)*e(t)));p("/",(r,e)=>(r=i(r),e=i(e),t=>r(t)/e(t)));p("%",(r,e)=>(r=i(r),e=i(e),t=>r(t)%e(t)));var W=150;C("++",W,r=>r?["++",r,null]:["++",h(W-1)]);C("--",W,r=>r?["--",r,null]:["--",h(W-1)]);var or=(r,e,t,o)=>typeof r=="string"?n=>e(n,r):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o)):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n))):r[0]==="()"&&r.length===2?or(r[1],e):(()=>{throw Error("Invalid increment target")})();p("++",(r,e)=>or(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));p("--",(r,e)=>or(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var Sr=5,qr=123,xr=125,P=(r,e,t,o=r.charCodeAt(0),n=r.length,s=y[o],u)=>y[o]=(c,A,E,B=f)=>!c&&(E?r==E:(n<2||d.substr(f,n)==r)&&(E=r))&&A<e&&!m.id(d.charCodeAt(f+n))&&(M(f+n),(u=t())?x(u,B):(M(B),!s&&k()),u)||s?.(c,A,E);var G=()=>S()!==qr?h(Sr+.5):(g(),["block",h(Sr-.5,xr)||null]);p("block",r=>r===void 0?()=>{}:(r=i(r),e=>r(e)));var L=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...n]=r;if(o==="{}")for(let s of n){let u,c,A;s[0]==="="?[,[,u,c],A]=s:[,u,c]=s;let E=e[u];E===void 0&&A&&(E=i(A)(t)),L(c,E,t)}else if(o==="[]"){let s=0;for(let u of n){if(u===null){s++;continue}if(Array.isArray(u)&&u[0]==="..."){t[u[1]]=e.slice(s);break}let c=u,A;Array.isArray(u)&&u[0]==="="&&([,c,A]=u);let E=e[s++];E===void 0&&A&&(E=i(A)(t)),L(c,E,t)}}};var j=Symbol("break"),z=Symbol("continue"),vr=Symbol("return"),X=(r,e)=>{try{return{v:r(e)}}catch(t){if(t?.type===j)return{b:1};if(t?.type===z)return{c:1};if(t?.type===vr)return{r:1,v:t.value};throw t}},U=5,br=125,re=59;P("while",U+1,()=>(S(),["while",_(),G()]));P("do",U+1,()=>(r=>(S(),g(5),S(),["do",r,_()]))(G()));P("for",U+1,()=>(S(),fr("await")?(g(5),S(),["for await",_(),G()]):["for",_(),G()]));P("break",U+1,()=>["break"]);P("continue",U+1,()=>["continue"]);P("return",U+1,()=>{m.asi&&(m.newline=!1),S();let r=d.charCodeAt(f);return!r||r===br||r===re||m.newline?["return"]:["return",h(U)]});p("while",(r,e)=>(r=i(r),e=i(e),t=>{let o,n;for(;r(t)&&!(o=X(e,t)).b;){if(o.r)return o.v;o.c||(n=o.v)}return n}));p("do",(r,e)=>(r=i(r),e=i(e),t=>{let o,n;do{if((o=X(r,t)).b)break;if(o.r)return o.v;o.c||(n=o.v)}while(e(t));return n}));p("for",(r,e)=>{if(Array.isArray(r)&&r[0]===";"){let[,t,o,n]=r;return t=t?i(t):null,o=o?i(o):()=>!0,n=n?i(n):null,e=i(e),s=>{let u,c;for(t?.(s);o(s)&&!(u=X(e,s)).b;n?.(s)){if(u.r)return u.v;u.c||(c=u.v)}return c}}if(Array.isArray(r)&&(r[0]==="in"||r[0]==="of")){let[t,o,n]=r;if(Array.isArray(o)&&(o[0]==="let"||o[0]==="const"||o[0]==="var")&&(o=o[1]),t==="in")return te(o,n,e);if(t==="of")return ee(o,n,e)}});var ee=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let s,u,c=o?null:n[r];for(let A of e(n)){if(o?L(r,A,n):n[r]=A,(s=X(t,n)).b)break;if(s.r)return s.v;s.c||(u=s.v)}return o||(n[r]=c),u}},te=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let s,u,c=o?null:n[r];for(let A in e(n)){if(o?L(r,A,n):n[r]=A,(s=X(t,n)).b)break;if(s.r)return s.v;s.c||(u=s.v)}return o||(n[r]=c),u}};p("break",()=>()=>{throw{type:j}});p("continue",()=>()=>{throw{type:z}});p("return",r=>(r=r!==void 0?i(r):null,e=>{throw{type:vr,value:r?.(e)}}));var a=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",ir=170;rr("[]",ir);l(".",ir);rr("()",ir);var nr=r=>{throw Error(r)};p("[]",(r,e)=>e===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(t=>t==null?(()=>{}):t[0]==="..."?(t=i(t[1]),o=>t(o)):(t=i(t),o=>[t(o)])),t=>r.flatMap(o=>o(t))):(e==null&&nr("Missing index"),r=i(r),e=i(e),t=>{let o=e(t);return a(o)?void 0:r(t)[o]}));p(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],a(e)?()=>{}:t=>r(t)[e]));p("()",(r,e)=>{if(e===void 0)return r==null?nr("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(s=>s==null||t(s));t(e)&&nr("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];return w(r,(n,s,u)=>n[s](...o(u)),!0)});var T=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&T(r[1])||r[0]==="{}"),oe=r=>{throw Error(r)},w=(r,e,t,o,n)=>r==null?oe("Empty ()"):r[0]==="()"&&r.length==2?w(r[1],e,t):typeof r=="string"?s=>e(s,r,s):r[0]==="."?(o=i(r[1]),n=r[2],s=>e(o(s),n,s)):r[0]==="?."?(o=i(r[1]),n=r[2],s=>{let u=o(s);return u==null?void 0:e(u,n,s)}):r[0]==="[]"&&r.length===3?(o=i(r[1]),n=i(r[2]),s=>e(o(s),n(s),s)):r[0]==="?.[]"?(o=i(r[1]),n=i(r[2]),s=>{let u=o(s);return u==null?void 0:e(u,n(s),s)}):(r=i(r),s=>e([r(s)],0,s));var ne=5,ie=10,se=170;F("()",se);b(",",ie);b(";",ne,!0);var wr=r=>{throw Error(r)};p("()",(r,e)=>{if(e===void 0)return r==null?wr("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(s=>s==null||t(s));t(e)&&wr("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];return w(r,(n,s,u)=>n[s](...o(u)),!0)});var kr=(...r)=>(r=r.map(i),e=>{let t;for(let o of r)try{t=o(e)}catch(n){throw(n?.type===j||n?.type===z)&&(n.value=t),n}return t});p(",",kr);p(";",kr);var Ir=new WeakMap,pe=(r,...e)=>typeof r=="string"?i(m(r)):Ir.get(r)||Ir.set(r,ue(r,e)).get(r),Nr=57344,ue=(r,e)=>{let t=r.reduce((s,u,c)=>s+(c?String.fromCharCode(Nr+c-1):"")+u,""),o=m(t),n=s=>{if(typeof s=="string"&&s.length===1){let u=s.charCodeAt(0)-Nr,c;if(u>=0&&u<e.length)return c=e[u],le(c)?c:[,c]}return Array.isArray(s)?s.map(n):s};return i(n(o))},le=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),fe=pe;var me=32,ce=m.space;m.comment??={"//":`
6
+ `,"/*":"*/"};var sr;m.space=()=>{sr||(sr=Object.entries(m.comment).map(([n,s])=>[n,s,n.charCodeAt(0)]));for(var r;r=ce();){for(var e=0,t;t=sr[e++];)if(r===t[2]&&d.substr(f,t[0].length)===t[0]){var o=f+t[0].length;if(t[1]===`
7
+ `)for(;d.charCodeAt(o)>=me;)o++;else{for(;d[o]&&d.substr(o,t[1].length)!==t[1];)o++;d[o]&&(o+=t[1].length)}M(o),r=0;break}if(r)return r}return r};var Rr=80;l("===",Rr);l("!==",Rr);p("===",(r,e)=>(r=i(r),e=i(e),t=>r(t)===e(t)));p("!==",(r,e)=>(r=i(r),e=i(e),t=>r(t)!==e(t)));var de=30;l("??",de);p("??",(r,e)=>(r=i(r),e=i(e),t=>r(t)??e(t)));var Ae=130,he=20;l("**",Ae,!0);l("**=",he,!0);p("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));var ge=r=>{throw Error(r)};p("**=",(r,e)=>(T(r)||ge("Invalid assignment target"),e=i(e),w(r,(t,o,n)=>t[o]**=e(n))));var Tr=90;l("in",Tr);l("of",Tr);p("in",(r,e)=>(r=i(r),e=i(e),t=>r(t)in e(t)));var ye=20,Ce=100,Ee=r=>{throw Error(r)};l(">>>",Ce);l(">>>=",ye,!0);p(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));p(">>>=",(r,e)=>(T(r)||Ee("Invalid assignment target"),e=i(e),w(r,(t,o,n)=>t[o]>>>=e(n))));var pr=20,J=r=>{throw Error(r)};l("||=",pr,!0);l("&&=",pr,!0);l("??=",pr,!0);p("=",(r,e)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let t=r[1];return e=i(e),typeof t=="string"?o=>{o[t]=e(o)}:o=>L(t,e(o),o)}return T(r)||J("Invalid assignment target"),e=i(e),w(r,(t,o,n)=>t[o]=e(n))});p("||=",(r,e)=>(T(r)||J("Invalid assignment target"),e=i(e),w(r,(t,o,n)=>t[o]||=e(n))));p("&&=",(r,e)=>(T(r)||J("Invalid assignment target"),e=i(e),w(r,(t,o,n)=>t[o]&&=e(n))));p("??=",(r,e)=>(T(r)||J("Invalid assignment target"),e=i(e),w(r,(t,o,n)=>t[o]??=e(n))));O("true",!0);O("false",!1);O("null",null);O("undefined",void 0);O("NaN",NaN);O("Infinity",1/0);var ur=20;C("?",ur,(r,e,t)=>r&&(e=h(ur-1))&&R(o=>o===58)&&(t=h(ur-1),["?",r,e,t]));p("?",(r,e,t)=>(r=i(r),e=i(e),t=i(t),o=>r(o)?e(o):t(o)));var Se=20;l("=>",Se,!0);p("=>",(r,e)=>{r=r[0]==="()"?r[1]:r,r=r?r[0]===","?r.slice(1):[r]:[];let t=-1,o=null;return r.length&&Array.isArray(r[r.length-1])&&r[r.length-1][0]==="..."&&(t=r.length-1,o=r[t][1],r=r.slice(0,-1)),e=i(e[0]==="{}"?e[1]:e),(n=null)=>(n=Object.create(n),(...s)=>(r.forEach((u,c)=>n[u]=s[c]),o&&(n[o]=s.slice(t)),e(n)))});var ve=140;v("...",ve);p("...",r=>(r=i(r),e=>Object.entries(r(e))));var ar=170;C("?.",ar,(r,e)=>{if(!r)return;let t=S();return t===40?(g(),["?.()",r,h(0,41)||null]):t===91?(g(),["?.[]",r,h(0,93)]):(e=h(ar),e?["?.",r,e]:void 0)});p("?.",(r,e)=>(r=i(r),a(e)?()=>{}:t=>r(t)?.[e]));p("?.[]",(r,e)=>(r=i(r),e=i(e),t=>{let o=e(t);return a(o)?void 0:r(t)?.[o]}));p("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];if(r[0]==="?."){let n=i(r[1]),s=r[2];return a(s)?()=>{}:u=>n(u)?.[s]?.(...t(u))}if(r[0]==="?.[]"){let n=i(r[1]),s=i(r[2]);return u=>{let c=n(u),A=s(u);return a(A)?void 0:c?.[A]?.(...t(u))}}if(r[0]==="."){let n=i(r[1]),s=r[2];return a(s)?()=>{}:u=>n(u)?.[s]?.(...t(u))}if(r[0]==="[]"&&r.length===3){let n=i(r[1]),s=i(r[2]);return u=>{let c=n(u),A=s(u);return a(A)?void 0:c?.[A]?.(...t(u))}}let o=i(r);return n=>o(n)?.(...t(n))});var V=140;v("typeof",V);v("void",V);v("delete",V);v("new",V);p("typeof",r=>(r=i(r),e=>typeof r(e)));p("void",r=>(r=i(r),e=>(r(e),void 0)));p("delete",r=>{if(r[0]==="."){let e=i(r[1]),t=r[2];return o=>delete e(o)[t]}if(r[0]==="[]"){let e=i(r[1]),t=i(r[2]);return o=>delete e(o)[t(o)]}return()=>!0});p("new",r=>{let e=i(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,o=t?t[0]===","?(n=>s=>n.map(u=>u(s)))(t.slice(1).map(i)):(n=>s=>[n(s)])(i(t)):()=>[];return n=>new(e(n))(...o(n))});var Y=Symbol("accessor"),Or=20,we=40,ke=41,Ie=123,Ne=125,Pr=r=>e=>{if(e)return;S();let t=R(m.id);if(!t||(S(),d.charCodeAt(f)!==we))return!1;g();let o=h(0,ke);return S(),d.charCodeAt(f)!==Ie?!1:(g(),[r,t,o,h(0,Ne)])};C("get",Or-1,Pr("get"));C("set",Or-1,Pr("set"));p("get",(r,e)=>(e=e?i(e):()=>{},t=>[[Y,r,{get:function(){let o=Object.create(t||{});return o.this=this,e(o)}}]]));p("set",(r,e,t)=>(t=t?i(t):()=>{},o=>[[Y,r,{set:function(n){let s=Object.create(o||{});s.this=this,s[e]=n,t(s)}}]]));var Re=20,Lr=200;F("[]",Lr);F("{}",Lr);l(":",Re-1,!0);p("{}",(r,e)=>{if(e!==void 0)return;r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(o=>i(typeof o=="string"?[":",o,o]:o));return o=>{let n={},s={};for(let u of t.flatMap(c=>c(o)))if(u[0]===Y){let[,c,A]=u;s[c]={...s[c],...A,configurable:!0,enumerable:!0}}else n[u[0]]=u[1];for(let u in s)Object.defineProperty(n,u,s[u]);return n}});p(":",(r,e)=>(e=i(e),Array.isArray(r)?(r=i(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));var Te=170,Z=96,ae=36,Oe=123,Pe=92,Le={n:`
8
+ `,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Ur=()=>{let r=[];for(let e="",t;(t=d.charCodeAt(f))!==Z;)t?t===Pe?(g(),e+=Le[d[f]]||d[f],g()):t===ae&&d.charCodeAt(f+1)===Oe?(e&&r.push([,e]),e="",g(2),r.push(h(0,125))):(e+=d[f],g(),t=d.charCodeAt(f),t===Z&&e&&r.push([,e])):k("Unterminated template");return g(),r},Ue=y[Z];y[Z]=(r,e)=>r&&e<Te?m.asi&&m.newline?void 0:(g(),["``",r,...Ur()]):r?Ue?.(r,e):(g(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(Ur()));p("`",(...r)=>(r=r.map(i),e=>r.map(t=>t(e)).join("")));p("``",(r,...e)=>{r=i(r);let t=[],o=[];for(let s of e)Array.isArray(s)&&s[0]===void 0?t.push(s[1]):o.push(i(s));let n=Object.assign([...t],{raw:t});return s=>r(s)(n,...o.map(u=>u(s)))});m.string["'"]=!0;m.number={"0x":16,"0b":2,"0o":8};export{rr as access,l as binary,i as compile,d as cur,fe as default,k as err,h as expr,F as group,Be as id,f as idx,O as literal,x as loc,y as lookup,b as nary,R as next,p as operator,q as operators,_ as parens,m as parse,M as seek,g as skip,S as space,C as token,v as unary,fr as word};
package/package.json CHANGED
@@ -1,42 +1,35 @@
1
1
  {
2
2
  "name": "subscript",
3
- "version": "9.1.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": "npm run build-subscript && npm run build-justin",
35
- "min": "npm run min-subscript && npm run min-justin",
36
- "build-subscript": "rollup subscript.js --file subscript.min.js --format esm --name \"Subscript\"",
37
- "min-subscript": "terser subscript.min.js -o subscript.min.js --module -c passes=3 -m",
38
- "build-justin": "rollup justin.js --file justin.min.js --format esm --name \"Justin\"",
39
- "min-justin": "terser justin.min.js -o justin.min.js --module -c passes=3 -m",
31
+ "build": "esbuild subscript.js --bundle --minify --format=esm --outfile=subscript.min.js && esbuild justin.js --bundle --minify --format=esm --outfile=justin.min.js && esbuild jessie.js --bundle --minify --format=esm --outfile=jessie.min.js",
32
+ "prepublishOnly": "npm run build",
40
33
  "test": "node test/test.js",
41
34
  "check-types": "tsc --noEmit subscript.d.ts"
42
35
  },
@@ -81,8 +74,10 @@
81
74
  },
82
75
  "homepage": "https://github.com/dy/subscript#readme",
83
76
  "devDependencies": {
84
- "rollup": "^2.60.2",
85
- "terser": "^5.10.0",
86
- "tst": "^8.0.2"
77
+ "@playwright/test": "^1.57.0",
78
+ "esbuild": "^0.27.2",
79
+ "jsep": "^1.4.0",
80
+ "terser": "^5.44.1",
81
+ "tst": "^9.2.0"
87
82
  }
88
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 };