subscript 10.3.4 → 10.3.6
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/feature/asi.js +26 -2
- package/feature/unicode.js +23 -0
- package/jessie.js +3 -0
- package/jessie.min.js +7 -7
- package/justin.min.js +8 -8
- package/package.json +2 -2
- package/parse.js +2 -17
- package/subscript.min.js +5 -5
package/feature/asi.js
CHANGED
|
@@ -1,18 +1,42 @@
|
|
|
1
1
|
// ASI: newline at `;` precedence level triggers nary `;`
|
|
2
|
-
import { parse, prec } from '../parse.js';
|
|
2
|
+
import { parse, prec, cur, idx, seek } from '../parse.js';
|
|
3
3
|
|
|
4
4
|
// Set prec.asi before importing to customize (default: prec[';'])
|
|
5
5
|
const lvl = prec.asi ?? prec[';'];
|
|
6
6
|
|
|
7
|
+
const SPACE = 32, LF = 10, SEMI = 59, space = parse.space;
|
|
8
|
+
|
|
9
|
+
const lineBreak = (i = idx, c) => {
|
|
10
|
+
while ((c = cur.charCodeAt(i)) <= SPACE) {
|
|
11
|
+
if (c === LF) return true;
|
|
12
|
+
i++;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
parse.space = () => {
|
|
17
|
+
let cc;
|
|
18
|
+
while ((cc = space()) === SEMI && lineBreak(idx + 1)) {
|
|
19
|
+
seek(idx + 1);
|
|
20
|
+
parse.newline = true;
|
|
21
|
+
}
|
|
22
|
+
return cc;
|
|
23
|
+
};
|
|
24
|
+
|
|
7
25
|
let asiDepth = 0;
|
|
8
26
|
const MAX_ASI_DEPTH = 100;
|
|
9
27
|
|
|
10
28
|
parse.asi = (a, p, expr, b, items) => {
|
|
11
29
|
if (p >= lvl || asiDepth >= MAX_ASI_DEPTH) return;
|
|
30
|
+
// Bail if the inner expr didn't actually consume anything. Without this, a
|
|
31
|
+
// lookup handler that returns a non-array sentinel (e.g. switch.js's
|
|
32
|
+
// `reserve` flagging `case`/`default` inside a switch body) lets expr return
|
|
33
|
+
// a truthy token without advancing idx, and the outer ASI loop appends to its
|
|
34
|
+
// semicolon-list forever.
|
|
35
|
+
const beforeIdx = idx;
|
|
12
36
|
asiDepth++;
|
|
13
37
|
try { b = expr(lvl - .5); }
|
|
14
38
|
finally { asiDepth--; }
|
|
15
|
-
if (!b) return;
|
|
39
|
+
if (!b || idx === beforeIdx) return;
|
|
16
40
|
items = b?.[0] === ';' ? b.slice(1) : [b];
|
|
17
41
|
return a?.[0] === ';' ? (a.push(...items), a) : [';', a, ...items];
|
|
18
42
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Unicode identifier extensions for JS/Jessie source.
|
|
2
|
+
// Raw escape spelling is preserved in AST identifiers.
|
|
3
|
+
import { parse, cur, idx } from '../parse.js';
|
|
4
|
+
|
|
5
|
+
const BSLASH = 92, U = 117, LBRACE = 123, RBRACE = 125, MIDDOT = 183;
|
|
6
|
+
|
|
7
|
+
const id = parse.id,
|
|
8
|
+
hex = c =>
|
|
9
|
+
(c >= 48 && c <= 57) ||
|
|
10
|
+
(c >= 65 && c <= 70) ||
|
|
11
|
+
(c >= 97 && c <= 102),
|
|
12
|
+
|
|
13
|
+
uesc = (n = idx + 2, c, cp = 0, i = 0) => {
|
|
14
|
+
if (cur.charCodeAt(idx) !== BSLASH || cur.charCodeAt(idx + 1) !== U) return 0;
|
|
15
|
+
if (cur.charCodeAt(n) === LBRACE) {
|
|
16
|
+
while (hex(c = cur.charCodeAt(++n))) cp = cp * 16 + (c <= 57 ? c - 48 : (c & 31) + 9);
|
|
17
|
+
return n > idx + 3 && cp <= 0x10ffff && cur.charCodeAt(n) === RBRACE ? n - idx + 1 : 0;
|
|
18
|
+
}
|
|
19
|
+
while (i < 4 && hex(cur.charCodeAt(n + i))) i++;
|
|
20
|
+
return i === 4 ? 6 : 0;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
parse.id = c => id(c) || c === MIDDOT || uesc();
|
package/jessie.js
CHANGED
package/jessie.min.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),n=t.pop(),o=m.slice(Math.max(0,e-40),e),
|
|
1
|
+
var fr,p,m,c=r=>(p=0,m=r,c.newline=!1,r=a(),m[p]?R():r||""),R=(r="Unexpected token",e=p,t=m.slice(0,e).split(`
|
|
2
|
+
`),n=t.pop(),o=m.slice(Math.max(0,e-40),e),s="\u032D",u=(m[e]||" ")+s,l=m.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${n.length+1}
|
|
3
3
|
${m[e-41]!==`
|
|
4
|
-
`,""+o}${
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
6
|
-
`,"/*":"*/"};var Ar;c.space=()=>{Ar||(Ar=Object.entries(c.comment).map(([o,
|
|
7
|
-
`)for(;m.charCodeAt(n)>=
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
4
|
+
`,""+o}${u}${l}`)},Or=(r,e=p)=>(Array.isArray(r)&&(r.loc=e),r),N=(r,e=p,t)=>{for(;t=r(m.charCodeAt(p));)p+=t;return m.slice(e,p)},h=(r=1)=>m[p+=r],_=r=>p=r,a=(r=0,e)=>{let t,n,o,s,u;for(e&&c.asi&&(c.newline=!1);(t=c.space())&&(u=c.newline,1)&&t!==e&&(o=(n&&t===91&&fr&&c.asi?.(n,r,a)||null)??((s=T[t])&&s(n,r))??(n&&u&&c.asi?.(n,r,a))??(!n&&N(c.id)));)n=o;return e&&(t==e?(p++,e===125&&c.asi&&(c.newline=!0)):R("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),n},d=(r,e=p)=>{for(fr=!1;(r=m.charCodeAt(p))<=32;)c.asi&&r===10&&(c.newline=fr=!0),p++;return r},_r=(r=p)=>{for(;m.charCodeAt(r)<=32;)r++;return m.charCodeAt(r)},Ft=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,I=(r,e=r.length)=>m.substr(p,e)===r&&!c.id(m.charCodeAt(p+e)),v=()=>(h(),a(0,41)),T=[],j={},k=(r,e=32,t,n=r.charCodeAt(0),o=r.length,s=T[n],u=r.toUpperCase()!==r,l,A)=>(e=j[r]=!s&&j[r]||e,T[n]=(w,S,E,C=p)=>(l=E,(E?r==E:(o<2||r.charCodeAt(1)===m.charCodeAt(p+1)&&(o<3||m.substr(p,o)==r))&&(!u||!c.id(m.charCodeAt(p+o)))&&(l=E=r))&&S<e&&(p+=o,(A=t(w))?Or(A,C):(p=C,l=0,!u&&!s&&!w&&R()),A)||s?.(w,S,l))),y=(r,e,t=!1)=>k(r,e,n=>n&&(o=>o&&[r,n,o])(a(e-(t?.5:0)))),P=(r,e,t)=>k(r,e,n=>t?n&&[r,n]:!n&&(n=a(e-.5))&&[r,n]),$=(r,e)=>k(r,200,t=>!t&&[,e]),pr=(r,e,t)=>k(r,e,(n,o)=>(o=a(e-(t?.5:0)),n?.[0]!==r&&(n=[r,n||null]),o?.[0]===r?n.push(...o.slice(1)):n.push(o||null),n)),W=(r,e)=>k(r[0],e,t=>!t&&[r,a(0,r.charCodeAt(1))||null]),ur=(r,e)=>k(r[0],e,t=>t&&[r,t,a(0,r.charCodeAt(1))||null]),g=(r,e,t,n=r.charCodeAt(0),o=r.length,s=T[n],u)=>T[n]=(l,A,w,S=p)=>!l&&(w?r==w:(o<2||m.substr(p,o)==r)&&(w=r))&&A<e&&!c.id(m.charCodeAt(p+o))&&(!c.prop||c.prop(p+o))&&(_(p+o),(u=t())?Or(u,S):_(S),u)||s?.(l,A,w);Object.defineProperty(c,"space",{configurable:!0,enumerable:!0,get:()=>d,set:r=>d=r});var lr={},f=(r,e,t=lr[r])=>lr[r]=(...n)=>e(...n)||t?.(...n),i=r=>Array.isArray(r)?r[0]==null?(e=>()=>e)(r[1]):lr[r[0]]?.(...r.slice(1))??R(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var q=46,z=48,x=57,me=69,de=101,ae=43,he=45,Z=95,Pr=110,Ae=97,ye=102,we=65,ge=70,vr=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),cr=r=>{let e=vr(N(t=>t===q&&m.charCodeAt(p+1)!==q||t>=z&&t<=x||t===Z||((t===me||t===de)&&((t=m.charCodeAt(p+1))>=z&&t<=x||t===ae||t===he)?2:0)));return m.charCodeAt(p)===Pr?(h(),[,BigInt(e)]):(r=+e)!=r?R():[,r]},Ce={2:r=>r===48||r===49||r===Z,8:r=>r>=48&&r<=55||r===Z,16:r=>r>=z&&r<=x||r>=Ae&&r<=ye||r>=we&&r<=ge||r===Z};c.number=null;T[q]=r=>!r&&m.charCodeAt(p+1)!==q&&cr();for(let r=z;r<=x;r++)T[r]=e=>e?void 0:cr();T[z]=r=>{if(r)return;let e=c.number;if(e){for(let[t,n]of Object.entries(e))if(t[0]==="0"&&m[p+1]?.toLowerCase()===t[1]){h(2);let o=vr(N(Ce[n]));return m.charCodeAt(p)===Pr?(h(),[,BigInt("0"+t[1]+o)]):[,parseInt(o,n)]}}return cr()};var Ee=92,Mr=34,Br=39,Se={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Lr=r=>(e,t,n="")=>{if(!(e||!c.string?.[String.fromCharCode(r)]))return h(),N(o=>o-r&&(o===Ee?(n+=Se[m[p+1]]||m[p+1],2):(n+=m[p],1))),m[p]===String.fromCharCode(r)?h():R("Bad string"),[,n]};T[Mr]=Lr(Mr);T[Br]=Lr(Br);c.string={'"':!0};var ke=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>y(r,ke,!0));var Fr=(r,e,t,n)=>typeof r=="string"?o=>e(o,r,o):r[0]==="."?(t=i(r[1]),n=r[2],o=>e(t(o),n,o)):r[0]==="[]"&&r.length===3?(t=i(r[1]),n=i(r[2]),o=>e(t(o),n(o),o)):r[0]==="()"&&r.length===2?Fr(r[1],e):(()=>{throw Error("Invalid assignment target")})(),Ur={"=":(r,e,t)=>r[e]=t,"+=":(r,e,t)=>r[e]+=t,"-=":(r,e,t)=>r[e]-=t,"*=":(r,e,t)=>r[e]*=t,"/=":(r,e,t)=>r[e]/=t,"%=":(r,e,t)=>r[e]%=t,"|=":(r,e,t)=>r[e]|=t,"&=":(r,e,t)=>r[e]&=t,"^=":(r,e,t)=>r[e]^=t,">>=":(r,e,t)=>r[e]>>=t,"<<=":(r,e,t)=>r[e]<<=t};for(let r in Ur)f(r,(e,t)=>(t=i(t),Fr(e,(n,o,s)=>Ur[r](n,o,t(s)))));var Ie=30,Te=40,Ne=140;P("!",Ne);y("||",Ie);y("&&",Te);f("!",r=>(r=i(r),e=>!r(e)));f("||",(r,e)=>(r=i(r),e=i(e),t=>r(t)||e(t)));f("&&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&&e(t)));var Re=50,Oe=60,_e=70,Dr=100,Pe=140;y("|",Re);y("&",_e);y("^",Oe);y(">>",Dr);y("<<",Dr);P("~",Pe);f("~",r=>(r=i(r),e=>~r(e)));f("|",(r,e)=>(r=i(r),e=i(e),t=>r(t)|e(t)));f("&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&e(t)));f("^",(r,e)=>(r=i(r),e=i(e),t=>r(t)^e(t)));f(">>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>e(t)));f("<<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<<e(t)));var b=90;y("<",b);y(">",b);y("<=",b);y(">=",b);f(">",(r,e)=>(r=i(r),e=i(e),t=>r(t)>e(t)));f("<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<e(t)));f(">=",(r,e)=>(r=i(r),e=i(e),t=>r(t)>=e(t)));f("<=",(r,e)=>(r=i(r),e=i(e),t=>r(t)<=e(t)));var Gr=80;y("==",Gr);y("!=",Gr);f("==",(r,e)=>(r=i(r),e=i(e),t=>r(t)==e(t)));f("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(t)));var Xr=110,mr=120,Hr=140;y("+",Xr);y("-",Xr);y("*",mr);y("/",mr);y("%",mr);P("+",Hr);P("-",Hr);f("+",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)+e(t)):(r=i(r),t=>+r(t)));f("-",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)-e(t)):(r=i(r),t=>-r(t)));f("*",(r,e)=>(r=i(r),e=i(e),t=>r(t)*e(t)));f("/",(r,e)=>(r=i(r),e=i(e),t=>r(t)/e(t)));f("%",(r,e)=>(r=i(r),e=i(e),t=>r(t)%e(t)));var rr=150;k("++",rr,r=>r?["++",r,null]:["++",a(rr-1)]);k("--",rr,r=>r?["--",r,null]:["--",a(rr-1)]);var dr=(r,e,t,n)=>typeof r=="string"?o=>e(o,r):r[0]==="."?(t=i(r[1]),n=r[2],o=>e(t(o),n)):r[0]==="[]"&&r.length===3?(t=i(r[1]),n=i(r[2]),o=>e(t(o),n(o))):r[0]==="()"&&r.length===2?dr(r[1],e):(()=>{throw Error("Invalid increment target")})();f("++",(r,e)=>dr(r,e===null?(t,n)=>t[n]++:(t,n)=>++t[n]));f("--",(r,e)=>dr(r,e===null?(t,n)=>t[n]--:(t,n)=>--t[n]));var ve=5,Me=10;pr(",",Me);pr(";",ve,!0);var Kr=(...r)=>(r=r.map(i),e=>{let t;for(let n of r)t=n(e);return t});f(",",Kr);f(";",Kr);var Be=170;W("()",Be);var F=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",ar=170;ur("[]",ar);y(".",ar);ur("()",ar);var er=r=>{throw Error(r)};f("[]",(r,e)=>e===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(t=>t==null?(()=>{}):t[0]==="..."?(t=i(t[1]),n=>t(n)):(t=i(t),n=>[t(n)])),t=>r.flatMap(n=>n(t))):(e==null&&er("Missing index"),r=i(r),e=i(e),t=>{let n=e(t);return F(n)?void 0:r(t)[n]}));f(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],F(e)?()=>{}:t=>r(t)[e]));f("()",(r,e)=>{if(e===void 0)return r==null?er("Empty ()"):i(r);let t=o=>o?.[0]===","&&o.slice(1).some(s=>s==null||t(s));t(e)&&er("Empty argument");let n=e?e[0]===","?(e=e.slice(1).map(i),o=>e.map(s=>s(o))):(e=i(e),o=>[e(o)]):()=>[];return hr(r,(o,s,u)=>o[s](...n(u)))});var B=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&B(r[1])||r[0]==="{}"),hr=(r,e,t,n)=>r==null?er("Empty ()"):r[0]==="()"&&r.length==2?hr(r[1],e):typeof r=="string"?o=>e(o,r,o):r[0]==="."?(t=i(r[1]),n=r[2],o=>e(t(o),n,o)):r[0]==="?."?(t=i(r[1]),n=r[2],o=>{let s=t(o);return s==null?void 0:e(s,n,o)}):r[0]==="[]"&&r.length===3?(t=i(r[1]),n=i(r[2]),o=>e(t(o),n(o),o)):r[0]==="?.[]"?(t=i(r[1]),n=i(r[2]),o=>{let s=t(o);return s==null?void 0:e(s,n(o),o)}):(r=i(r),o=>e([r(o)],0,o)),D=hr;var Qr=new WeakMap,Le=(r,...e)=>typeof r=="string"?i(c(r)):Qr.get(r)||Qr.set(r,Ue(r,e)).get(r),$r=57344,Ue=(r,e)=>{let t=r.reduce((s,u,l)=>s+(l?String.fromCharCode($r+l-1):"")+u,""),n=c(t),o=s=>{if(typeof s=="string"&&s.length===1){let u=s.charCodeAt(0)-$r,l;if(u>=0&&u<e.length)return l=e[u],Fe(l)?l:[,l]}return Array.isArray(s)?s.map(o):s};return i(o(n))},Fe=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),jr=Le;var De=32,Ge=c.space;c.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};var Ar;c.space=()=>{Ar||(Ar=Object.entries(c.comment).map(([o,s])=>[o,s,o.charCodeAt(0)]));for(var r;r=Ge();){for(var e=0,t;t=Ar[e++];)if(r===t[2]&&m.substr(p,t[0].length)===t[0]){var n=p+t[0].length;if(t[1]===`
|
|
7
|
+
`)for(;m.charCodeAt(n)>=De;)n++;else{for(;m[n]&&m.substr(n,t[1].length)!==t[1];)n++;m[n]&&(n+=t[1].length)}_(n),r=0;break}if(r)return r}return r};var Wr=80;y("===",Wr);y("!==",Wr);f("===",(r,e)=>(r=i(r),e=i(e),t=>r(t)===e(t)));f("!==",(r,e)=>(r=i(r),e=i(e),t=>r(t)!==e(t)));var Xe=30;y("??",Xe);f("??",(r,e)=>(r=i(r),e=i(e),t=>r(t)??e(t)));var He=130,Ke=20;y("**",He,!0);y("**=",Ke,!0);f("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));var Qe=r=>{throw Error(r)};f("**=",(r,e)=>(B(r)||Qe("Invalid assignment target"),e=i(e),D(r,(t,n,o)=>t[n]**=e(o))));var zr=90;y("in",zr);y("of",zr);f("in",(r,e)=>(r=i(r),e=i(e),t=>r(t)in e(t)));var $e=20,je=100,We=r=>{throw Error(r)};y(">>>",je);y(">>>=",$e,!0);f(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));f(">>>=",(r,e)=>(B(r)||We("Invalid assignment target"),e=i(e),D(r,(t,n,o)=>t[n]>>>=e(o))));var yr=5,ze=10,Je=20,Ve=r=>r[0]?.[0]===","?r[0].slice(1):r,X=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[n,...o]=r,s=Ve(o);if(n==="{}"){let u=[];for(let l of s){if(Array.isArray(l)&&l[0]==="..."){let C={};for(let O in e)u.includes(O)||(C[O]=e[O]);t[l[1]]=C;break}let A,w,S;typeof l=="string"?A=w=l:l[0]==="="?(typeof l[1]=="string"?A=w=l[1]:[,A,w]=l[1],S=l[2]):[,A,w]=l,u.push(A);let E=e[A];E===void 0&&S&&(E=i(S)(t)),X(w,E,t)}}else if(n==="[]"){let u=0;for(let l of s){if(l===null){u++;continue}if(Array.isArray(l)&&l[0]==="..."){t[l[1]]=e.slice(u);break}let A=l,w;Array.isArray(l)&&l[0]==="="&&([,A,w]=l);let S=e[u++];S===void 0&&w&&(S=i(w)(t)),X(A,S,t)}}},Jr=r=>{if(r==="let"){let t=p;if(d(),I("in")){_(t);return}_(t)}let e=a(ze-1);return e?.[0]==="in"||e?.[0]==="of"?[e[0],[r,e[1]],e[2]]:e?.[0]===","?[r,...e.slice(1)]:[r,e]};g("let",yr+1,()=>Jr("let"));g("const",yr+1,()=>Jr("const"));g("var",yr,()=>(d(),["var",a(Je)]));var Vr=(...r)=>(r=r.map(e=>{if(typeof e=="string")return t=>{t[e]=void 0};if(e[0]==="="){let[,t,n]=e,o=i(n);return typeof t=="string"?s=>{s[t]=o(s)}:s=>X(t,o(s),s)}return i(e)}),e=>{for(let t of r)t(e)});f("let",Vr);f("const",Vr);f("var",r=>typeof r=="string"?e=>{e[r]=void 0}:()=>{});var wr=20,tr=r=>{throw Error(r)};y("||=",wr,!0);y("&&=",wr,!0);y("??=",wr,!0);f("=",(r,e)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let t=r[1];return e=i(e),typeof t=="string"?n=>{n[t]=e(n)}:n=>X(t,e(n),n)}return B(r)||tr("Invalid assignment target"),e=i(e),D(r,(t,n,o)=>t[n]=e(o))});f("||=",(r,e)=>(B(r)||tr("Invalid assignment target"),e=i(e),D(r,(t,n,o)=>t[n]||=e(o))));f("&&=",(r,e)=>(B(r)||tr("Invalid assignment target"),e=i(e),D(r,(t,n,o)=>t[n]&&=e(o))));f("??=",(r,e)=>(B(r)||tr("Invalid assignment target"),e=i(e),D(r,(t,n,o)=>t[n]??=e(o))));$("true",!0);$("false",!1);$("null",null);g("undefined",200,()=>[]);$("NaN",NaN);$("Infinity",1/0);var gr=20;k("?",gr,(r,e,t)=>r&&(e=a(gr-1))&&N(n=>n===58)&&(t=a(gr-1),["?",r,e,t]));f("?",(r,e,t)=>(r=i(r),e=i(e),t=i(t),n=>r(n)?e(n):t(n)));var M=[],Ye=20;y("=>",Ye,!0);f("=>",(r,e)=>{r=r?.[0]==="()"?r[1]:r;let t=r?r[0]===","?r.slice(1):[r]:[],n=-1,o=null,s=t[t.length-1];Array.isArray(s)&&s[0]==="..."&&(n=t.length-1,o=s[1],t.length--);let u=e?.[0]==="{}";return e=i(u?["{",e[1]]:e),l=>(...A)=>{let w={};t.forEach((E,C)=>w[E]=A[C]),o&&(w[o]=A.slice(n));let S=new Proxy(w,{get:(E,C)=>C in E?E[C]:l?.[C],set:(E,C,O)=>((C in E?E:l)[C]=O,!0),has:(E,C)=>C in E||(l?C in l:!1)});try{let E=e(S);return u?void 0:E}catch(E){if(E===M)return E[0];throw E}}});var Ze=140;P("...",Ze);f("...",r=>(r=i(r),e=>Object.entries(r(e))));var Yr=170;k("?.",Yr,(r,e)=>{if(!r)return;let t=d();return t===40?(h(),["?.()",r,a(0,41)||null]):t===91?(h(),["?.[]",r,a(0,93)]):(e=a(Yr),e?["?.",r,e]:void 0)});f("?.",(r,e)=>(r=i(r),F(e)?()=>{}:t=>r(t)?.[e]));f("?.[]",(r,e)=>(r=i(r),e=i(e),t=>{let n=e(t);return F(n)?void 0:r(t)?.[n]}));f("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(i),o=>e.map(s=>s(o))):(e=i(e),o=>[e(o)]):()=>[];if(r[0]==="?."){let o=i(r[1]),s=r[2];return F(s)?()=>{}:u=>o(u)?.[s]?.(...t(u))}if(r[0]==="?.[]"){let o=i(r[1]),s=i(r[2]);return u=>{let l=o(u),A=s(u);return F(A)?void 0:l?.[A]?.(...t(u))}}if(r[0]==="."){let o=i(r[1]),s=r[2];return F(s)?()=>{}:u=>o(u)?.[s]?.(...t(u))}if(r[0]==="[]"&&r.length===3){let o=i(r[1]),s=i(r[2]);return u=>{let l=o(u),A=s(u);return F(A)?void 0:l?.[A]?.(...t(u))}}let n=i(r);return o=>n(o)?.(...t(o))});var J=140;P("typeof",J);P("void",J);P("delete",J);g("new",J,()=>I(".target")?(h(7),["new.target"]):["new",a(J)]);f("typeof",r=>(r=i(r),e=>typeof r(e)));f("void",r=>(r=i(r),e=>(r(e),void 0)));f("delete",r=>{if(r[0]==="."){let e=i(r[1]),t=r[2];return n=>delete e(n)[t]}if(r[0]==="[]"){let e=i(r[1]),t=i(r[2]);return n=>delete e(n)[t(n)]}return()=>!0});f("new",r=>{let e=i(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,n=t?t[0]===","?(o=>s=>o.map(u=>u(s)))(t.slice(1).map(i)):(o=>s=>[o(s)])(i(t)):()=>[];return o=>new(e(o))(...n(o))});var nr=Symbol("accessor"),Cr=20,qe=40,Zr=41,qr=123,xr=125,br=r=>e=>{if(e)return;d();let t=N(c.id);if(!t||(d(),m.charCodeAt(p)!==qe))return!1;h();let n=a(0,Zr);return d(),m.charCodeAt(p)!==qr?!1:(h(),[r,t,n,a(0,xr)])};k("get",Cr-1,br("get"));k("set",Cr-1,br("set"));k("(",Cr-1,r=>{if(!r||typeof r!="string")return;let e=a(0,Zr)||null;if(d(),m.charCodeAt(p)===qr)return h(),[":",r,["=>",["()",e],a(0,xr)||null]]});f("get",(r,e)=>(e=e?i(e):()=>{},t=>[[nr,r,{get:function(){let n=Object.create(t||{});return n.this=this,e(n)}}]]));f("set",(r,e,t)=>(t=t?i(t):()=>{},n=>[[nr,r,{set:function(o){let s=Object.create(n||{});s.this=this,s[e]=o,t(s)}}]]));var xe=20,re=200;c.prop=r=>_r(r)!==58;var be=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);W("[]",re);W("{}",re);y(":",xe-1,!0);f("{}",(r,e)=>{if(e!==void 0)return;if(!be(r))return i(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(n=>i(typeof n=="string"?[":",n,n]:n));return n=>{let o={},s={};for(let u of t.flatMap(l=>l(n)))if(u[0]===nr){let[,l,A]=u;s[l]={...s[l],...A,configurable:!0,enumerable:!0}}else o[u[0]]=u[1];for(let u in s)Object.defineProperty(o,u,s[u]);return o}});f("{",r=>(r=r?i(r):()=>{},e=>r(Object.create(e))));f(":",(r,e)=>(e=i(e),Array.isArray(r)?(r=i(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));var rt=170,or=96,et=36,tt=123,nt=92,ot={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},ee=()=>{let r=[];for(let e="",t;(t=m.charCodeAt(p))!==or;)t?t===nt?(h(),e+=ot[m[p]]||m[p],h()):t===et&&m.charCodeAt(p+1)===tt?(e&&r.push([,e]),e="",h(2),r.push(a(0,125))):(e+=m[p],h(),t=m.charCodeAt(p),t===or&&e&&r.push([,e])):R("Unterminated template");return h(),r},it=T[or];T[or]=(r,e)=>r&&e<rt?c.asi&&c.newline?void 0:(h(),["``",r,...ee()]):r?it?.(r,e):(h(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(ee()));f("`",(...r)=>(r=r.map(i),e=>r.map(t=>t(e)).join("")));f("``",(r,...e)=>{r=i(r);let t=[],n=[];for(let s of e)Array.isArray(s)&&s[0]===void 0?t.push(s[1]):n.push(i(s));let o=Object.assign([...t],{raw:t});return s=>r(s)(o,...n.map(u=>u(s)))});c.string["'"]=!0;c.number={"0x":16,"0b":2,"0o":8};var st=92,ft=117,lt=123,pt=125,ut=183,ct=c.id,te=r=>r>=48&&r<=57||r>=65&&r<=70||r>=97&&r<=102,mt=(r=p+2,e,t=0,n=0)=>{if(m.charCodeAt(p)!==st||m.charCodeAt(p+1)!==ft)return 0;if(m.charCodeAt(r)===lt){for(;te(e=m.charCodeAt(++r));)t=t*16+(e<=57?e-48:(e&31)+9);return r>p+3&&t<=1114111&&m.charCodeAt(r)===pt?r-p+1:0}for(;n<4&&te(m.charCodeAt(r+n));)n++;return n===4?6:0};c.id=r=>ct(r)||r===ut||mt();var ir=5,dt=59,L=()=>(d()===123||R("Expected {"),h(),a(ir-.5,125)||null),G=()=>d()!==123?a(ir+.5):(h(),a(ir-.5,125)||null),at=()=>{let r=p;return d()===dt&&h(),d(),I("else")?(h(4),!0):(_(r),!1)};g("if",ir+1,()=>{d();let r=["if",v(),G()];return at()&&r.push(G()),r});f("if",(r,e,t)=>(r=i(r),e=i(e),t=t!==void 0?i(t):null,n=>r(n)?e(n):t?.(n)));var ht=200;g("function",ht,()=>{d();let r=!1;m[p]==="*"&&(r=!0,h(),d());let e=N(c.id);return e&&d(),r?["function*",e,v()||null,L()]:["function",e,v()||null,L()]});f("function",(r,e,t)=>{t=t?i(t):()=>{};let n=e?e[0]===","?e.slice(1):[e]:[],o=null,s=-1,u=n[n.length-1];return Array.isArray(u)&&u[0]==="..."&&(s=n.length-1,o=u[1],n.length--),l=>{let A=(...w)=>{let S={};n.forEach((C,O)=>S[C]=w[O]),o&&(S[o]=w.slice(s));let E=new Proxy(S,{get:(C,O)=>O in C?C[O]:l[O],set:(C,O,ce)=>((O in C?C:l)[O]=ce,!0),has:(C,O)=>O in C||O in l});try{return t(E)}catch(C){if(C===M)return C[0];throw C}};return r&&(l[r]=A),A}});f("function*",(r,e,t)=>{throw Error("Generator functions are not supported in evaluation")});var sr=140,Er=20;P("await",sr);g("yield",sr,()=>(d(),m[p]==="*"?(h(),d(),["yield*",a(Er)]):["yield",a(Er)]));g("async",sr,()=>{if(d(),I("function"))return["async",a(sr)];let r=a(Er-.5);return r&&["async",r]});f("async",r=>{let e=i(r);return t=>{let n=e(t);return async function(...o){return n(...o)}}});f("await",r=>(r=i(r),async e=>await r(e)));f("yield",r=>(r=r?i(r):null,e=>{throw{__yield__:r?r(e):void 0}}));f("yield*",r=>(r=i(r),e=>{throw{__yield_all__:r(e)}}));var Sr=200,At=140,yt=90,wt=Symbol("static");P("static",At);y("instanceof",yt);k("#",Sr,r=>{if(r)return;let e=N(c.id);return e?"#"+e:void 0});g("class",Sr,()=>{d();let r=N(c.id)||null;if(r==="extends")r=null,d();else{if(d(),!I("extends"))return["class",r,null,L()];h(7),d()}return["class",r,a(Sr),L()]});var gt=r=>{throw Error(r)};f("instanceof",(r,e)=>(r=i(r),e=i(e),t=>r(t)instanceof e(t)));f("class",(r,e,t)=>(e=e?i(e):null,t=t?i(t):null,n=>{let o=e?e(n):Object,s=function(...u){if(!(this instanceof s))return gt("Class constructor must be called with new");let l=e?Reflect.construct(o,u,s):this;return s.prototype.__constructor__&&s.prototype.__constructor__.apply(l,u),l};if(Object.setPrototypeOf(s.prototype,o.prototype),Object.setPrototypeOf(s,o),t){let u=Object.create(n);u.super=o;let l=t(u),A=Array.isArray(l)&&typeof l[0]?.[0]=="string"?l:[];for(let[w,S]of A)w==="constructor"?s.prototype.__constructor__=S:s.prototype[w]=S}return r&&(n[r]=s),s}));f("static",r=>(r=i(r),e=>[[wt,r(e)]]));var Ct=140,kr=47,Et=92,St=r=>r===Et?2:r&&r!==kr,kt=r=>r===103||r===105||r===109||r===115||r===117||r===121;k("/",Ct,r=>{if(r)return;let e=m.charCodeAt(p);if(e===kr||e===42||e===43||e===63||e===61)return;let t=N(St);m.charCodeAt(p)===kr||R("Unterminated regex"),h();let n=N(kt);try{new RegExp(t,n)}catch(o){R("Invalid regex: "+o.message)}return n?["//",t,n]:["//",t]});f("//",(r,e)=>{let t=new RegExp(r,e||"");return()=>t});var U=Symbol("break"),H=Symbol("continue"),K=5,V=125,Y=59;g("while",K+1,()=>(d(),["while",v(),G()]));g("do",K+1,()=>(r=>(d(),h(5),d(),["do",r,v()]))(G()));g("for",K+1,()=>(d(),I("await")?(h(5),d(),["for await",v(),G()]):["for",v(),G()]));g("break",K+1,()=>{c.asi&&(c.newline=!1);let r=p;d();let e=m.charCodeAt(p);if(!e||e===V||e===Y||c.newline)return["break"];let t=N(c.id);if(!t)return["break"];d();let n=m.charCodeAt(p);return!n||n===V||n===Y||c.newline?["break",t]:(_(r),["break"])});g("continue",K+1,()=>{c.asi&&(c.newline=!1);let r=p;d();let e=m.charCodeAt(p);if(!e||e===V||e===Y||c.newline)return["continue"];let t=N(c.id);if(!t)return["continue"];d();let n=m.charCodeAt(p);return!n||n===V||n===Y||c.newline?["continue",t]:(_(r),["continue"])});g("return",K+1,()=>{c.asi&&(c.newline=!1);let r=d();return!r||r===V||r===Y||c.newline?["return"]:["return",a(K)]});f("while",(r,e)=>(r=i(r),e=i(e),t=>{let n;for(;r(t);)try{n=e(t)}catch(o){if(o===U)break;if(o===H)continue;if(o===M)return o[0];throw o}return n}));f("do",(r,e)=>(r=i(r),e=i(e),t=>{let n;do try{n=r(t)}catch(o){if(o===U)break;if(o===H)continue;if(o===M)return o[0];throw o}while(e(t));return n}));f("for",(r,e)=>{if(Array.isArray(r)&&r[0]===";"){let[,t,n,o]=r;return t=t?i(t):null,n=n?i(n):()=>!0,o=o?i(o):null,e=i(e),s=>{let u;for(t?.(s);n(s);o?.(s))try{u=e(s)}catch(l){if(l===U)break;if(l===H)continue;if(l===M)return l[0];throw l}return u}}if(Array.isArray(r)&&(r[0]==="in"||r[0]==="of")){let[t,n,o]=r;if(Array.isArray(n)&&(n[0]==="let"||n[0]==="const"||n[0]==="var")&&(n=n[1]),t==="in")return Tt(n,o,e);if(t==="of")return It(n,o,e)}});var It=(r,e,t)=>{e=i(e),t=i(t);let n=Array.isArray(r);return o=>{let s,u=n?null:o[r];for(let l of e(o)){n?X(r,l,o):o[r]=l;try{s=t(o)}catch(A){if(A===U)break;if(A===H)continue;if(A===M)return A[0];throw A}}return n||(o[r]=u),s}},Tt=(r,e,t)=>{e=i(e),t=i(t);let n=Array.isArray(r);return o=>{let s,u=n?null:o[r];for(let l in e(o)){n?X(r,l,o):o[r]=l;try{s=t(o)}catch(A){if(A===U)break;if(A===H)continue;if(A===M)return A[0];throw A}}return n||(o[r]=u),s}};f("break",()=>()=>{throw U});f("continue",()=>()=>{throw H});f("return",r=>(r=r!==void 0?i(r):null,e=>{throw M[0]=r?.(e),M}));var Ir=5;g("try",Ir+1,()=>{let r=["try",L()];return d(),I("catch")&&(h(5),d(),r.push(["catch",v(),L()])),d(),I("finally")&&(h(7),r.push(["finally",L()])),r});g("throw",Ir+1,()=>{if(c.asi&&(c.newline=!1),d(),c.newline)throw SyntaxError("Unexpected newline after throw");return["throw",a(Ir)]});f("try",(r,...e)=>{r=r?i(r):null;let t=e.find(l=>l?.[0]==="catch"),n=e.find(l=>l?.[0]==="finally"),o=t?.[1],s=t?.[2]?i(t[2]):null,u=n?.[1]?i(n[1]):null;return l=>{let A;try{A=r?.(l)}catch(w){if(w===U||w===H||w===M)throw w;if(o!=null&&s){let S=o in l,E=l[o];l[o]=w;try{A=s(l)}finally{S?l[o]=E:delete l[o]}}else if(!s)throw w}finally{u?.(l)}return A}});f("throw",r=>(r=i(r),e=>{throw r(e)}));var ie=5,Nt=20,ne=58,Rt=59,se=125,Tr=0,fe=(r,e=r.length,t=r.charCodeAt(0),n=T[t])=>T[t]=(o,s,u)=>I(r)&&!o&&Tr||n?.(o,s,u);fe("case");fe("default");var oe=r=>{let e=[];for(;(r=d())!==se&&!I("case")&&!I("default");){if(r===Rt){h();continue}e.push(a(ie-.5))||R()}return e.length>1?[";",...e]:e[0]||null},Ot=()=>{d()===123||R("Expected {"),h(),Tr++;let r=[];try{for(;d()!==se;)if(I("case")){_(p+4),d();let e=a(Nt-.5);d()===ne&&h(),r.push(["case",e,oe()])}else I("default")?(_(p+7),d()===ne&&h(),r.push(["default",oe()])):R("Expected case or default")}finally{Tr--}return h(),r};g("switch",ie+1,()=>d()===40&&["switch",v(),...Ot()]);f("switch",(r,...e)=>(r=i(r),e.length?(e=e.map(t=>[t[0]==="case"?i(t[1]):null,(t[0]==="case"?t[2]:t[1])?.[0]===";"?(t[0]==="case"?t[2]:t[1]).slice(1).map(i):(t[0]==="case"?t[2]:t[1])?[i(t[0]==="case"?t[2]:t[1])]:[]]),t=>{let n=r(t),o=!1,s;for(let[l,A]of e)if(o||l===null||l(t)===n)for(o=!0,u=0;u<A.length;u++)try{s=A[u](t)}catch(w){if(w===U)return s;throw w}var u;return s}):t=>r(t)));var le=5;g("debugger",le+1,()=>["debugger"]);g("with",le+1,()=>(d(),["with",v(),G()]));var Nr=5,Q=10,pe=42,_t=T[pe];T[pe]=(r,e)=>r?_t?.(r,e):(h(),"*");k("from",Q+1,r=>r?r[0]!=="="&&r[0]!==","&&(d(),["from",r,a(Q+1)]):!1);k("as",Q+2,r=>r?(d(),["as",r,a(Q+2)]):!1);g("import",Nr,()=>I(".meta")?(h(5),["import.meta"]):["import",a(Q)]);g("export",Nr,()=>(d(),["export",a(Nr)]));g("default",Q+1,()=>d()!==58&&(d(),["default",a(Q)]));f("import",()=>()=>{});f("export",()=>()=>{});f("from",(r,e)=>()=>{});f("as",(r,e)=>()=>{});f("default",r=>i(r));var ue=j.asi??j[";"],Pt=32,vt=10,Mt=59,Bt=c.space,Lt=(r=p,e)=>{for(;(e=m.charCodeAt(r))<=Pt;){if(e===vt)return!0;r++}};c.space=()=>{let r;for(;(r=Bt())===Mt&&Lt(p+1);)_(p+1),c.newline=!0;return r};var Rr=0,Ut=100;c.asi=(r,e,t,n,o)=>{if(e>=ue||Rr>=Ut)return;let s=p;Rr++;try{n=t(ue-.5)}finally{Rr--}if(!(!n||p===s))return o=n?.[0]===";"?n.slice(1):[n],r?.[0]===";"?(r.push(...o),r):[";",r,...o]};export{ur as access,y as binary,i as compile,m as cur,jr as default,R as err,a as expr,W as group,Ft as id,p as idx,g as keyword,$ as literal,Or as loc,T as lookup,pr as nary,N as next,f as operator,lr as operators,v as parens,c as parse,_r as peek,j as prec,_ as seek,h as skip,d as space,k as token,P as unary,I as word};
|
package/justin.min.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),n=t.pop(),i=
|
|
3
|
-
${
|
|
4
|
-
`,""+i}${
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
6
|
-
`,"/*":"*/"};var nr;d.space=()=>{nr||(nr=Object.entries(d.comment).map(([i,p])=>[i,p,i.charCodeAt(0)]));for(var r;r=
|
|
7
|
-
`)for(;
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
1
|
+
var V,f,m,d=r=>(f=0,m=r,d.newline=!1,r=A(),m[f]?k():r||""),k=(r="Unexpected token",e=f,t=m.slice(0,e).split(`
|
|
2
|
+
`),n=t.pop(),i=m.slice(Math.max(0,e-40),e),p="\u032D",l=(m[e]||" ")+p,u=m.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${n.length+1}
|
|
3
|
+
${m[e-41]!==`
|
|
4
|
+
`,""+i}${l}${u}`)},lr=(r,e=f)=>(Array.isArray(r)&&(r.loc=e),r),v=(r,e=f,t)=>{for(;t=r(m.charCodeAt(f));)f+=t;return m.slice(e,f)},h=(r=1)=>m[f+=r],L=r=>f=r,A=(r=0,e)=>{let t,n,i,p,l;for(e&&d.asi&&(d.newline=!1);(t=d.space())&&(l=d.newline,1)&&t!==e&&(i=(n&&t===91&&V&&d.asi?.(n,r,A)||null)??((p=I[t])&&p(n,r))??(n&&l&&d.asi?.(n,r,A))??(!n&&v(d.id)));)n=i;return e&&(t==e?(f++,e===125&&d.asi&&(d.newline=!0)):k("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),n},N=(r,e=f)=>{for(V=!1;(r=m.charCodeAt(f))<=32;)d.asi&&r===10&&(d.newline=V=!0),f++;return r},ur=(r=f)=>{for(;m.charCodeAt(r)<=32;)r++;return m.charCodeAt(r)},_e=d.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,G=(r,e=r.length)=>m.substr(f,e)===r&&!d.id(m.charCodeAt(f+e)),Ue=()=>(h(),A(0,41)),I=[],fr={},E=(r,e=32,t,n=r.charCodeAt(0),i=r.length,p=I[n],l=r.toUpperCase()!==r,u,g)=>(e=fr[r]=!p&&fr[r]||e,I[n]=(C,w,y,S=f)=>(u=y,(y?r==y:(i<2||r.charCodeAt(1)===m.charCodeAt(f+1)&&(i<3||m.substr(f,i)==r))&&(!l||!d.id(m.charCodeAt(f+i)))&&(u=y=r))&&w<e&&(f+=i,(g=t(C))?lr(g,S):(f=S,u=0,!l&&!p&&!C&&k()),g)||p?.(C,w,u))),c=(r,e,t=!1)=>E(r,e,n=>n&&(i=>i&&[r,n,i])(A(e-(t?.5:0)))),a=(r,e,t)=>E(r,e,n=>t?n&&[r,n]:!n&&(n=A(e-.5))&&[r,n]),_=(r,e)=>E(r,200,t=>!t&&[,e]),Z=(r,e,t)=>E(r,e,(n,i)=>(i=A(e-(t?.5:0)),n?.[0]!==r&&(n=[r,n||null]),i?.[0]===r?n.push(...i.slice(1)):n.push(i||null),n)),B=(r,e)=>E(r[0],e,t=>!t&&[r,A(0,r.charCodeAt(1))||null]),q=(r,e)=>E(r[0],e,t=>t&&[r,t,A(0,r.charCodeAt(1))||null]),T=(r,e,t,n=r.charCodeAt(0),i=r.length,p=I[n],l)=>I[n]=(u,g,C,w=f)=>!u&&(C?r==C:(i<2||m.substr(f,i)==r)&&(C=r))&&g<e&&!d.id(m.charCodeAt(f+i))&&(!d.prop||d.prop(f+i))&&(L(f+i),(l=t())?lr(l,w):L(w),l)||p?.(u,g,C);Object.defineProperty(d,"space",{configurable:!0,enumerable:!0,get:()=>N,set:r=>N=r});var Y={},s=(r,e,t=Y[r])=>Y[r]=(...n)=>e(...n)||t?.(...n),o=r=>Array.isArray(r)?r[0]==null?(e=>()=>e)(r[1]):Y[r[0]]?.(...r.slice(1))??k(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var $=46,M=48,Q=57,Dr=69,Fr=101,Gr=43,Xr=45,X=95,mr=110,$r=97,Qr=102,jr=65,Hr=70,cr=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),x=r=>{let e=cr(v(t=>t===$&&m.charCodeAt(f+1)!==$||t>=M&&t<=Q||t===X||((t===Dr||t===Fr)&&((t=m.charCodeAt(f+1))>=M&&t<=Q||t===Gr||t===Xr)?2:0)));return m.charCodeAt(f)===mr?(h(),[,BigInt(e)]):(r=+e)!=r?k():[,r]},Kr={2:r=>r===48||r===49||r===X,8:r=>r>=48&&r<=55||r===X,16:r=>r>=M&&r<=Q||r>=$r&&r<=Qr||r>=jr&&r<=Hr||r===X};d.number=null;I[$]=r=>!r&&m.charCodeAt(f+1)!==$&&x();for(let r=M;r<=Q;r++)I[r]=e=>e?void 0:x();I[M]=r=>{if(r)return;let e=d.number;if(e){for(let[t,n]of Object.entries(e))if(t[0]==="0"&&m[f+1]?.toLowerCase()===t[1]){h(2);let i=cr(v(Kr[n]));return m.charCodeAt(f)===mr?(h(),[,BigInt("0"+t[1]+i)]):[,parseInt(i,n)]}}return x()};var Wr=92,dr=34,Ar=39,zr={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},gr=r=>(e,t,n="")=>{if(!(e||!d.string?.[String.fromCharCode(r)]))return h(),v(i=>i-r&&(i===Wr?(n+=zr[m[f+1]]||m[f+1],2):(n+=m[f],1))),m[f]===String.fromCharCode(r)?h():k("Bad string"),[,n]};I[dr]=gr(dr);I[Ar]=gr(Ar);d.string={'"':!0};var Jr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>c(r,Jr,!0));var yr=(r,e,t,n)=>typeof r=="string"?i=>e(i,r,i):r[0]==="."?(t=o(r[1]),n=r[2],i=>e(t(i),n,i)):r[0]==="[]"&&r.length===3?(t=o(r[1]),n=o(r[2]),i=>e(t(i),n(i),i)):r[0]==="()"&&r.length===2?yr(r[1],e):(()=>{throw Error("Invalid assignment target")})(),hr={"=":(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 hr)s(r,(e,t)=>(t=o(t),yr(e,(n,i,p)=>hr[r](n,i,t(p)))));var Vr=30,Yr=40,Zr=140;a("!",Zr);c("||",Vr);c("&&",Yr);s("!",r=>(r=o(r),e=>!r(e)));s("||",(r,e)=>(r=o(r),e=o(e),t=>r(t)||e(t)));s("&&",(r,e)=>(r=o(r),e=o(e),t=>r(t)&&e(t)));var qr=50,xr=60,br=70,Cr=100,re=140;c("|",qr);c("&",br);c("^",xr);c(">>",Cr);c("<<",Cr);a("~",re);s("~",r=>(r=o(r),e=>~r(e)));s("|",(r,e)=>(r=o(r),e=o(e),t=>r(t)|e(t)));s("&",(r,e)=>(r=o(r),e=o(e),t=>r(t)&e(t)));s("^",(r,e)=>(r=o(r),e=o(e),t=>r(t)^e(t)));s(">>",(r,e)=>(r=o(r),e=o(e),t=>r(t)>>e(t)));s("<<",(r,e)=>(r=o(r),e=o(e),t=>r(t)<<e(t)));var j=90;c("<",j);c(">",j);c("<=",j);c(">=",j);s(">",(r,e)=>(r=o(r),e=o(e),t=>r(t)>e(t)));s("<",(r,e)=>(r=o(r),e=o(e),t=>r(t)<e(t)));s(">=",(r,e)=>(r=o(r),e=o(e),t=>r(t)>=e(t)));s("<=",(r,e)=>(r=o(r),e=o(e),t=>r(t)<=e(t)));var Sr=80;c("==",Sr);c("!=",Sr);s("==",(r,e)=>(r=o(r),e=o(e),t=>r(t)==e(t)));s("!=",(r,e)=>(r=o(r),e=o(e),t=>r(t)!=e(t)));var Er=110,b=120,wr=140;c("+",Er);c("-",Er);c("*",b);c("/",b);c("%",b);a("+",wr);a("-",wr);s("+",(r,e)=>e!==void 0?(r=o(r),e=o(e),t=>r(t)+e(t)):(r=o(r),t=>+r(t)));s("-",(r,e)=>e!==void 0?(r=o(r),e=o(e),t=>r(t)-e(t)):(r=o(r),t=>-r(t)));s("*",(r,e)=>(r=o(r),e=o(e),t=>r(t)*e(t)));s("/",(r,e)=>(r=o(r),e=o(e),t=>r(t)/e(t)));s("%",(r,e)=>(r=o(r),e=o(e),t=>r(t)%e(t)));var H=150;E("++",H,r=>r?["++",r,null]:["++",A(H-1)]);E("--",H,r=>r?["--",r,null]:["--",A(H-1)]);var rr=(r,e,t,n)=>typeof r=="string"?i=>e(i,r):r[0]==="."?(t=o(r[1]),n=r[2],i=>e(t(i),n)):r[0]==="[]"&&r.length===3?(t=o(r[1]),n=o(r[2]),i=>e(t(i),n(i))):r[0]==="()"&&r.length===2?rr(r[1],e):(()=>{throw Error("Invalid increment target")})();s("++",(r,e)=>rr(r,e===null?(t,n)=>t[n]++:(t,n)=>++t[n]));s("--",(r,e)=>rr(r,e===null?(t,n)=>t[n]--:(t,n)=>--t[n]));var ee=5,te=10;Z(",",te);Z(";",ee,!0);var Ir=(...r)=>(r=r.map(o),e=>{let t;for(let n of r)t=n(e);return t});s(",",Ir);s(";",Ir);var ne=170;B("()",ne);var P=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",er=170;q("[]",er);c(".",er);q("()",er);var K=r=>{throw Error(r)};s("[]",(r,e)=>e===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(t=>t==null?(()=>{}):t[0]==="..."?(t=o(t[1]),n=>t(n)):(t=o(t),n=>[t(n)])),t=>r.flatMap(n=>n(t))):(e==null&&K("Missing index"),r=o(r),e=o(e),t=>{let n=e(t);return P(n)?void 0:r(t)[n]}));s(".",(r,e)=>(r=o(r),e=e[0]?e:e[1],P(e)?()=>{}:t=>r(t)[e]));s("()",(r,e)=>{if(e===void 0)return r==null?K("Empty ()"):o(r);let t=i=>i?.[0]===","&&i.slice(1).some(p=>p==null||t(p));t(e)&&K("Empty argument");let n=e?e[0]===","?(e=e.slice(1).map(o),i=>e.map(p=>p(i))):(e=o(e),i=>[e(i)]):()=>[];return tr(r,(i,p,l)=>i[p](...n(l)))});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]==="{}"),tr=(r,e,t,n)=>r==null?K("Empty ()"):r[0]==="()"&&r.length==2?tr(r[1],e):typeof r=="string"?i=>e(i,r,i):r[0]==="."?(t=o(r[1]),n=r[2],i=>e(t(i),n,i)):r[0]==="?."?(t=o(r[1]),n=r[2],i=>{let p=t(i);return p==null?void 0:e(p,n,i)}):r[0]==="[]"&&r.length===3?(t=o(r[1]),n=o(r[2]),i=>e(t(i),n(i),i)):r[0]==="?.[]"?(t=o(r[1]),n=o(r[2]),i=>{let p=t(i);return p==null?void 0:e(p,n(i),i)}):(r=o(r),i=>e([r(i)],0,i)),R=tr;var ar=new WeakMap,oe=(r,...e)=>typeof r=="string"?o(d(r)):ar.get(r)||ar.set(r,ie(r,e)).get(r),Nr=57344,ie=(r,e)=>{let t=r.reduce((p,l,u)=>p+(u?String.fromCharCode(Nr+u-1):"")+l,""),n=d(t),i=p=>{if(typeof p=="string"&&p.length===1){let l=p.charCodeAt(0)-Nr,u;if(l>=0&&l<e.length)return u=e[l],se(u)?u:[,u]}return Array.isArray(p)?p.map(i):p};return o(i(n))},se=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),pe=oe;var fe=32,le=d.space;d.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};var nr;d.space=()=>{nr||(nr=Object.entries(d.comment).map(([i,p])=>[i,p,i.charCodeAt(0)]));for(var r;r=le();){for(var e=0,t;t=nr[e++];)if(r===t[2]&&m.substr(f,t[0].length)===t[0]){var n=f+t[0].length;if(t[1]===`
|
|
7
|
+
`)for(;m.charCodeAt(n)>=fe;)n++;else{for(;m[n]&&m.substr(n,t[1].length)!==t[1];)n++;m[n]&&(n+=t[1].length)}L(n),r=0;break}if(r)return r}return r};var kr=80;c("===",kr);c("!==",kr);s("===",(r,e)=>(r=o(r),e=o(e),t=>r(t)===e(t)));s("!==",(r,e)=>(r=o(r),e=o(e),t=>r(t)!==e(t)));var ue=30;c("??",ue);s("??",(r,e)=>(r=o(r),e=o(e),t=>r(t)??e(t)));var me=130,ce=20;c("**",me,!0);c("**=",ce,!0);s("**",(r,e)=>(r=o(r),e=o(e),t=>r(t)**e(t)));var de=r=>{throw Error(r)};s("**=",(r,e)=>(O(r)||de("Invalid assignment target"),e=o(e),R(r,(t,n,i)=>t[n]**=e(i))));var vr=90;c("in",vr);c("of",vr);s("in",(r,e)=>(r=o(r),e=o(e),t=>r(t)in e(t)));var Ae=20,ge=100,he=r=>{throw Error(r)};c(">>>",ge);c(">>>=",Ae,!0);s(">>>",(r,e)=>(r=o(r),e=o(e),t=>r(t)>>>e(t)));s(">>>=",(r,e)=>(O(r)||he("Invalid assignment target"),e=o(e),R(r,(t,n,i)=>t[n]>>>=e(i))));var or=5,ye=10,Ce=20,Se=r=>r[0]?.[0]===","?r[0].slice(1):r,D=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[n,...i]=r,p=Se(i);if(n==="{}"){let l=[];for(let u of p){if(Array.isArray(u)&&u[0]==="..."){let S={};for(let U in e)l.includes(U)||(S[U]=e[U]);t[u[1]]=S;break}let g,C,w;typeof u=="string"?g=C=u:u[0]==="="?(typeof u[1]=="string"?g=C=u[1]:[,g,C]=u[1],w=u[2]):[,g,C]=u,l.push(g);let y=e[g];y===void 0&&w&&(y=o(w)(t)),D(C,y,t)}}else if(n==="[]"){let l=0;for(let u of p){if(u===null){l++;continue}if(Array.isArray(u)&&u[0]==="..."){t[u[1]]=e.slice(l);break}let g=u,C;Array.isArray(u)&&u[0]==="="&&([,g,C]=u);let w=e[l++];w===void 0&&C&&(w=o(C)(t)),D(g,w,t)}}},Or=r=>{if(r==="let"){let t=f;if(N(),G("in")){L(t);return}L(t)}let e=A(ye-1);return e?.[0]==="in"||e?.[0]==="of"?[e[0],[r,e[1]],e[2]]:e?.[0]===","?[r,...e.slice(1)]:[r,e]};T("let",or+1,()=>Or("let"));T("const",or+1,()=>Or("const"));T("var",or,()=>(N(),["var",A(Ce)]));var Pr=(...r)=>(r=r.map(e=>{if(typeof e=="string")return t=>{t[e]=void 0};if(e[0]==="="){let[,t,n]=e,i=o(n);return typeof t=="string"?p=>{p[t]=i(p)}:p=>D(t,i(p),p)}return o(e)}),e=>{for(let t of r)t(e)});s("let",Pr);s("const",Pr);s("var",r=>typeof r=="string"?e=>{e[r]=void 0}:()=>{});var ir=20,W=r=>{throw Error(r)};c("||=",ir,!0);c("&&=",ir,!0);c("??=",ir,!0);s("=",(r,e)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let t=r[1];return e=o(e),typeof t=="string"?n=>{n[t]=e(n)}:n=>D(t,e(n),n)}return O(r)||W("Invalid assignment target"),e=o(e),R(r,(t,n,i)=>t[n]=e(i))});s("||=",(r,e)=>(O(r)||W("Invalid assignment target"),e=o(e),R(r,(t,n,i)=>t[n]||=e(i))));s("&&=",(r,e)=>(O(r)||W("Invalid assignment target"),e=o(e),R(r,(t,n,i)=>t[n]&&=e(i))));s("??=",(r,e)=>(O(r)||W("Invalid assignment target"),e=o(e),R(r,(t,n,i)=>t[n]??=e(i))));_("true",!0);_("false",!1);_("null",null);T("undefined",200,()=>[]);_("NaN",NaN);_("Infinity",1/0);var sr=20;E("?",sr,(r,e,t)=>r&&(e=A(sr-1))&&v(n=>n===58)&&(t=A(sr-1),["?",r,e,t]));s("?",(r,e,t)=>(r=o(r),e=o(e),t=o(t),n=>r(n)?e(n):t(n)));var Ee=[],we=20;c("=>",we,!0);s("=>",(r,e)=>{r=r?.[0]==="()"?r[1]:r;let t=r?r[0]===","?r.slice(1):[r]:[],n=-1,i=null,p=t[t.length-1];Array.isArray(p)&&p[0]==="..."&&(n=t.length-1,i=p[1],t.length--);let l=e?.[0]==="{}";return e=o(l?["{",e[1]]:e),u=>(...g)=>{let C={};t.forEach((y,S)=>C[y]=g[S]),i&&(C[i]=g.slice(n));let w=new Proxy(C,{get:(y,S)=>S in y?y[S]:u?.[S],set:(y,S,U)=>((S in y?y:u)[S]=U,!0),has:(y,S)=>S in y||(u?S in u:!1)});try{let y=e(w);return l?void 0:y}catch(y){if(y===Ee)return y[0];throw y}}});var Ie=140;a("...",Ie);s("...",r=>(r=o(r),e=>Object.entries(r(e))));var Rr=170;E("?.",Rr,(r,e)=>{if(!r)return;let t=N();return t===40?(h(),["?.()",r,A(0,41)||null]):t===91?(h(),["?.[]",r,A(0,93)]):(e=A(Rr),e?["?.",r,e]:void 0)});s("?.",(r,e)=>(r=o(r),P(e)?()=>{}:t=>r(t)?.[e]));s("?.[]",(r,e)=>(r=o(r),e=o(e),t=>{let n=e(t);return P(n)?void 0:r(t)?.[n]}));s("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(o),i=>e.map(p=>p(i))):(e=o(e),i=>[e(i)]):()=>[];if(r[0]==="?."){let i=o(r[1]),p=r[2];return P(p)?()=>{}:l=>i(l)?.[p]?.(...t(l))}if(r[0]==="?.[]"){let i=o(r[1]),p=o(r[2]);return l=>{let u=i(l),g=p(l);return P(g)?void 0:u?.[g]?.(...t(l))}}if(r[0]==="."){let i=o(r[1]),p=r[2];return P(p)?()=>{}:l=>i(l)?.[p]?.(...t(l))}if(r[0]==="[]"&&r.length===3){let i=o(r[1]),p=o(r[2]);return l=>{let u=i(l),g=p(l);return P(g)?void 0:u?.[g]?.(...t(l))}}let n=o(r);return i=>n(i)?.(...t(i))});var F=140;a("typeof",F);a("void",F);a("delete",F);T("new",F,()=>G(".target")?(h(7),["new.target"]):["new",A(F)]);s("typeof",r=>(r=o(r),e=>typeof r(e)));s("void",r=>(r=o(r),e=>(r(e),void 0)));s("delete",r=>{if(r[0]==="."){let e=o(r[1]),t=r[2];return n=>delete e(n)[t]}if(r[0]==="[]"){let e=o(r[1]),t=o(r[2]);return n=>delete e(n)[t(n)]}return()=>!0});s("new",r=>{let e=o(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,n=t?t[0]===","?(i=>p=>i.map(l=>l(p)))(t.slice(1).map(o)):(i=>p=>[i(p)])(o(t)):()=>[];return i=>new(e(i))(...n(i))});var z=Symbol("accessor"),pr=20,ae=40,Tr=41,Lr=123,_r=125,Ur=r=>e=>{if(e)return;N();let t=v(d.id);if(!t||(N(),m.charCodeAt(f)!==ae))return!1;h();let n=A(0,Tr);return N(),m.charCodeAt(f)!==Lr?!1:(h(),[r,t,n,A(0,_r)])};E("get",pr-1,Ur("get"));E("set",pr-1,Ur("set"));E("(",pr-1,r=>{if(!r||typeof r!="string")return;let e=A(0,Tr)||null;if(N(),m.charCodeAt(f)===Lr)return h(),[":",r,["=>",["()",e],A(0,_r)||null]]});s("get",(r,e)=>(e=e?o(e):()=>{},t=>[[z,r,{get:function(){let n=Object.create(t||{});return n.this=this,e(n)}}]]));s("set",(r,e,t)=>(t=t?o(t):()=>{},n=>[[z,r,{set:function(i){let p=Object.create(n||{});p.this=this,p[e]=i,t(p)}}]]));var Ne=20,Br=200;d.prop=r=>ur(r)!==58;var ke=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);B("[]",Br);B("{}",Br);c(":",Ne-1,!0);s("{}",(r,e)=>{if(e!==void 0)return;if(!ke(r))return o(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(n=>o(typeof n=="string"?[":",n,n]:n));return n=>{let i={},p={};for(let l of t.flatMap(u=>u(n)))if(l[0]===z){let[,u,g]=l;p[u]={...p[u],...g,configurable:!0,enumerable:!0}}else i[l[0]]=l[1];for(let l in p)Object.defineProperty(i,l,p[l]);return i}});s("{",r=>(r=r?o(r):()=>{},e=>r(Object.create(e))));s(":",(r,e)=>(e=o(e),Array.isArray(r)?(r=o(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));var ve=170,J=96,Oe=36,Pe=123,Re=92,Te={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Mr=()=>{let r=[];for(let e="",t;(t=m.charCodeAt(f))!==J;)t?t===Re?(h(),e+=Te[m[f]]||m[f],h()):t===Oe&&m.charCodeAt(f+1)===Pe?(e&&r.push([,e]),e="",h(2),r.push(A(0,125))):(e+=m[f],h(),t=m.charCodeAt(f),t===J&&e&&r.push([,e])):k("Unterminated template");return h(),r},Le=I[J];I[J]=(r,e)=>r&&e<ve?d.asi&&d.newline?void 0:(h(),["``",r,...Mr()]):r?Le?.(r,e):(h(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(Mr()));s("`",(...r)=>(r=r.map(o),e=>r.map(t=>t(e)).join("")));s("``",(r,...e)=>{r=o(r);let t=[],n=[];for(let p of e)Array.isArray(p)&&p[0]===void 0?t.push(p[1]):n.push(o(p));let i=Object.assign([...t],{raw:t});return p=>r(p)(i,...n.map(l=>l(p)))});d.string["'"]=!0;d.number={"0x":16,"0b":2,"0o":8};export{q as access,c as binary,o as compile,m as cur,pe as default,k as err,A as expr,B as group,_e as id,f as idx,T as keyword,_ as literal,lr as loc,I as lookup,Z as nary,v as next,s as operator,Y as operators,Ue as parens,d as parse,ur as peek,fr as prec,L as seek,h as skip,N as space,E as token,a as unary,G as word};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "subscript",
|
|
3
|
-
"version": "10.3.
|
|
3
|
+
"version": "10.3.6",
|
|
4
4
|
"description": "Modular expression parser & evaluator",
|
|
5
5
|
"main": "subscript.js",
|
|
6
6
|
"module": "subscript.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
],
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "esbuild subscript.js --bundle --minify --format=esm --outfile=subscript.min.js && esbuild justin.js --bundle --minify --format=esm --outfile=justin.min.js && esbuild jessie.js --bundle --minify --format=esm --outfile=jessie.min.js",
|
|
32
|
-
"prepublishOnly": "npm run build && npm run test:e2e",
|
|
32
|
+
"prepublishOnly": "npm run build && npm run test && npm run test:e2e",
|
|
33
33
|
"test": "node --import ./test/https-loader.js test/test.js",
|
|
34
34
|
"test:e2e": "npx playwright test test/index.spec.js",
|
|
35
35
|
"check-types": "tsc --noEmit subscript.d.ts"
|
package/parse.js
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
1
|
// Pratt parser core + operator registry + compile
|
|
2
2
|
// Character codes
|
|
3
|
-
const SPACE = 32
|
|
4
|
-
|
|
5
|
-
const hex = c =>
|
|
6
|
-
(c >= 48 && c <= 57) ||
|
|
7
|
-
(c >= 65 && c <= 70) ||
|
|
8
|
-
(c >= 97 && c <= 102),
|
|
9
|
-
|
|
10
|
-
uesc = (n = idx + 2, c, cp = 0, i = 0) => {
|
|
11
|
-
if (cur.charCodeAt(idx) !== BSLASH || cur.charCodeAt(idx + 1) !== U) return 0;
|
|
12
|
-
if (cur.charCodeAt(n) === LBRACE) {
|
|
13
|
-
while (hex(c = cur.charCodeAt(++n))) cp = cp * 16 + (c <= 57 ? c - 48 : (c & 31) + 9);
|
|
14
|
-
return n > idx + 3 && cp <= 0x10ffff && cur.charCodeAt(n) === RBRACE ? n - idx + 1 : 0;
|
|
15
|
-
}
|
|
16
|
-
while (i < 4 && hex(cur.charCodeAt(n + i))) i++;
|
|
17
|
-
return i === 4 ? 6 : 0;
|
|
18
|
-
};
|
|
3
|
+
const SPACE = 32;
|
|
19
4
|
|
|
20
5
|
let lineBreak;
|
|
21
6
|
|
|
@@ -42,7 +27,7 @@ export let idx, cur,
|
|
|
42
27
|
|
|
43
28
|
// advance until condition meets
|
|
44
29
|
next = (is, from = idx, l) => {
|
|
45
|
-
while (l = is(cur.charCodeAt(idx))
|
|
30
|
+
while (l = is(cur.charCodeAt(idx))) idx += l;
|
|
46
31
|
return cur.slice(from, idx);
|
|
47
32
|
},
|
|
48
33
|
|
package/subscript.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),
|
|
3
|
-
${
|
|
4
|
-
`,""+
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
1
|
+
var N,s,u,m=r=>(s=0,u=r,m.newline=!1,r=c(),u[s]?y():r||""),y=(r="Unexpected token",e=s,t=u.slice(0,e).split(`
|
|
2
|
+
`),n=t.pop(),o=u.slice(Math.max(0,e-40),e),p="\u032D",d=(u[e]||" ")+p,A=u.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${n.length+1}
|
|
3
|
+
${u[e-41]!==`
|
|
4
|
+
`,""+o}${d}${A}`)},J=(r,e=s)=>(Array.isArray(r)&&(r.loc=e),r),_=(r,e=s,t)=>{for(;t=r(u.charCodeAt(s));)s+=t;return u.slice(e,s)},S=(r=1)=>u[s+=r],G=r=>s=r,c=(r=0,e)=>{let t,n,o,p,d;for(e&&m.asi&&(m.newline=!1);(t=m.space())&&(d=m.newline,1)&&t!==e&&(o=(n&&t===91&&N&&m.asi?.(n,r,c)||null)??((p=h[t])&&p(n,r))??(n&&d&&m.asi?.(n,r,c))??(!n&&_(m.id)));)n=o;return e&&(t==e?(s++,e===125&&m.asi&&(m.newline=!0)):y("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),n},W=(r,e=s)=>{for(N=!1;(r=u.charCodeAt(s))<=32;)m.asi&&r===10&&(m.newline=N=!0),s++;return r},$r=(r=s)=>{for(;u.charCodeAt(r)<=32;)r++;return u.charCodeAt(r)},Fr=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,Or=(r,e=r.length)=>u.substr(s,e)===r&&!m.id(u.charCodeAt(s+e)),Br=()=>(S(),c(0,41)),h=[],z={},g=(r,e=32,t,n=r.charCodeAt(0),o=r.length,p=h[n],d=r.toUpperCase()!==r,A,w)=>(e=z[r]=!p&&z[r]||e,h[n]=(C,I,T,v=s)=>(A=T,(T?r==T:(o<2||r.charCodeAt(1)===u.charCodeAt(s+1)&&(o<3||u.substr(s,o)==r))&&(!d||!m.id(u.charCodeAt(s+o)))&&(A=T=r))&&I<e&&(s+=o,(w=t(C))?J(w,v):(s=v,A=0,!d&&!p&&!C&&y()),w)||p?.(C,I,A))),f=(r,e,t=!1)=>g(r,e,n=>n&&(o=>o&&[r,n,o])(c(e-(t?.5:0)))),E=(r,e,t)=>g(r,e,n=>t?n&&[r,n]:!n&&(n=c(e-.5))&&[r,n]),Xr=(r,e)=>g(r,200,t=>!t&&[,e]),F=(r,e,t)=>g(r,e,(n,o)=>(o=c(e-(t?.5:0)),n?.[0]!==r&&(n=[r,n||null]),o?.[0]===r?n.push(...o.slice(1)):n.push(o||null),n)),K=(r,e)=>g(r[0],e,t=>!t&&[r,c(0,r.charCodeAt(1))||null]),O=(r,e)=>g(r[0],e,t=>t&&[r,t,c(0,r.charCodeAt(1))||null]),Qr=(r,e,t,n=r.charCodeAt(0),o=r.length,p=h[n],d)=>h[n]=(A,w,C,I=s)=>!A&&(C?r==C:(o<2||u.substr(s,o)==r)&&(C=r))&&w<e&&!m.id(u.charCodeAt(s+o))&&(!m.prop||m.prop(s+o))&&(G(s+o),(d=t())?J(d,I):G(I),d)||p?.(A,w,C);Object.defineProperty(m,"space",{configurable:!0,enumerable:!0,get:()=>W,set:r=>W=r});var $={},l=(r,e,t=$[r])=>$[r]=(...n)=>e(...n)||t?.(...n),i=r=>Array.isArray(r)?r[0]==null?(e=>()=>e)(r[1]):$[r[0]]?.(...r.slice(1))??y(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var R=46,P=48,k=57,pr=69,ur=101,mr=43,fr=45,U=95,V=110,dr=97,Ar=102,cr=65,hr=70,Y=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),B=r=>{let e=Y(_(t=>t===R&&u.charCodeAt(s+1)!==R||t>=P&&t<=k||t===U||((t===pr||t===ur)&&((t=u.charCodeAt(s+1))>=P&&t<=k||t===mr||t===fr)?2:0)));return u.charCodeAt(s)===V?(S(),[,BigInt(e)]):(r=+e)!=r?y():[,r]},gr={2:r=>r===48||r===49||r===U,8:r=>r>=48&&r<=55||r===U,16:r=>r>=P&&r<=k||r>=dr&&r<=Ar||r>=cr&&r<=hr||r===U};m.number=null;h[R]=r=>!r&&u.charCodeAt(s+1)!==R&&B();for(let r=P;r<=k;r++)h[r]=e=>e?void 0:B();h[P]=r=>{if(r)return;let e=m.number;if(e){for(let[t,n]of Object.entries(e))if(t[0]==="0"&&u[s+1]?.toLowerCase()===t[1]){S(2);let o=Y(_(gr[n]));return u.charCodeAt(s)===V?(S(),[,BigInt("0"+t[1]+o)]):[,parseInt(o,n)]}}return B()};var Cr=92,Z=34,q=39,yr={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},x=r=>(e,t,n="")=>{if(!(e||!m.string?.[String.fromCharCode(r)]))return S(),_(o=>o-r&&(o===Cr?(n+=yr[u[s+1]]||u[s+1],2):(n+=u[s],1))),u[s]===String.fromCharCode(r)?S():y("Bad string"),[,n]};h[Z]=x(Z);h[q]=x(q);m.string={'"':!0};var Sr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>f(r,Sr,!0));var a=(r,e,t,n)=>typeof r=="string"?o=>e(o,r,o):r[0]==="."?(t=i(r[1]),n=r[2],o=>e(t(o),n,o)):r[0]==="[]"&&r.length===3?(t=i(r[1]),n=i(r[2]),o=>e(t(o),n(o),o)):r[0]==="()"&&r.length===2?a(r[1],e):(()=>{throw Error("Invalid assignment target")})(),j={"=":(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 j)l(r,(e,t)=>(t=i(t),a(e,(n,o,p)=>j[r](n,o,t(p)))));var Er=30,wr=40,_r=140;E("!",_r);f("||",Er);f("&&",wr);l("!",r=>(r=i(r),e=>!r(e)));l("||",(r,e)=>(r=i(r),e=i(e),t=>r(t)||e(t)));l("&&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&&e(t)));var Ir=50,Pr=60,Tr=70,b=100,Ur=140;f("|",Ir);f("&",Tr);f("^",Pr);f(">>",b);f("<<",b);E("~",Ur);l("~",r=>(r=i(r),e=>~r(e)));l("|",(r,e)=>(r=i(r),e=i(e),t=>r(t)|e(t)));l("&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&e(t)));l("^",(r,e)=>(r=i(r),e=i(e),t=>r(t)^e(t)));l(">>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>e(t)));l("<<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<<e(t)));var D=90;f("<",D);f(">",D);f("<=",D);f(">=",D);l(">",(r,e)=>(r=i(r),e=i(e),t=>r(t)>e(t)));l("<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<e(t)));l(">=",(r,e)=>(r=i(r),e=i(e),t=>r(t)>=e(t)));l("<=",(r,e)=>(r=i(r),e=i(e),t=>r(t)<=e(t)));var rr=80;f("==",rr);f("!=",rr);l("==",(r,e)=>(r=i(r),e=i(e),t=>r(t)==e(t)));l("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(t)));var er=110,X=120,tr=140;f("+",er);f("-",er);f("*",X);f("/",X);f("%",X);E("+",tr);E("-",tr);l("+",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)+e(t)):(r=i(r),t=>+r(t)));l("-",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)-e(t)):(r=i(r),t=>-r(t)));l("*",(r,e)=>(r=i(r),e=i(e),t=>r(t)*e(t)));l("/",(r,e)=>(r=i(r),e=i(e),t=>r(t)/e(t)));l("%",(r,e)=>(r=i(r),e=i(e),t=>r(t)%e(t)));var M=150;g("++",M,r=>r?["++",r,null]:["++",c(M-1)]);g("--",M,r=>r?["--",r,null]:["--",c(M-1)]);var Q=(r,e,t,n)=>typeof r=="string"?o=>e(o,r):r[0]==="."?(t=i(r[1]),n=r[2],o=>e(t(o),n)):r[0]==="[]"&&r.length===3?(t=i(r[1]),n=i(r[2]),o=>e(t(o),n(o))):r[0]==="()"&&r.length===2?Q(r[1],e):(()=>{throw Error("Invalid increment target")})();l("++",(r,e)=>Q(r,e===null?(t,n)=>t[n]++:(t,n)=>++t[n]));l("--",(r,e)=>Q(r,e===null?(t,n)=>t[n]--:(t,n)=>--t[n]));var Rr=5,kr=10;F(",",kr);F(";",Rr,!0);var nr=(...r)=>(r=r.map(i),e=>{let t;for(let n of r)t=n(e);return t});l(",",nr);l(";",nr);var Dr=170;K("()",Dr);var or=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",H=170;O("[]",H);f(".",H);O("()",H);var L=r=>{throw Error(r)};l("[]",(r,e)=>e===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(t=>t==null?(()=>{}):t[0]==="..."?(t=i(t[1]),n=>t(n)):(t=i(t),n=>[t(n)])),t=>r.flatMap(n=>n(t))):(e==null&&L("Missing index"),r=i(r),e=i(e),t=>{let n=e(t);return or(n)?void 0:r(t)[n]}));l(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],or(e)?()=>{}:t=>r(t)[e]));l("()",(r,e)=>{if(e===void 0)return r==null?L("Empty ()"):i(r);let t=o=>o?.[0]===","&&o.slice(1).some(p=>p==null||t(p));t(e)&&L("Empty argument");let n=e?e[0]===","?(e=e.slice(1).map(i),o=>e.map(p=>p(o))):(e=i(e),o=>[e(o)]):()=>[];return ir(r,(o,p,d)=>o[p](...n(d)))});var ir=(r,e,t,n)=>r==null?L("Empty ()"):r[0]==="()"&&r.length==2?ir(r[1],e):typeof r=="string"?o=>e(o,r,o):r[0]==="."?(t=i(r[1]),n=r[2],o=>e(t(o),n,o)):r[0]==="?."?(t=i(r[1]),n=r[2],o=>{let p=t(o);return p==null?void 0:e(p,n,o)}):r[0]==="[]"&&r.length===3?(t=i(r[1]),n=i(r[2]),o=>e(t(o),n(o),o)):r[0]==="?.[]"?(t=i(r[1]),n=i(r[2]),o=>{let p=t(o);return p==null?void 0:e(p,n(o),o)}):(r=i(r),o=>e([r(o)],0,o));var sr=new WeakMap,Mr=(r,...e)=>typeof r=="string"?i(m(r)):sr.get(r)||sr.set(r,Lr(r,e)).get(r),lr=57344,Lr=(r,e)=>{let t=r.reduce((p,d,A)=>p+(A?String.fromCharCode(lr+A-1):"")+d,""),n=m(t),o=p=>{if(typeof p=="string"&&p.length===1){let d=p.charCodeAt(0)-lr,A;if(d>=0&&d<e.length)return A=e[d],Nr(A)?A:[,A]}return Array.isArray(p)?p.map(o):p};return i(o(n))},Nr=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Ae=Mr;export{O as access,f as binary,i as compile,u as cur,Ae as default,y as err,c as expr,K as group,Fr as id,s as idx,Qr as keyword,Xr as literal,J as loc,h as lookup,F as nary,_ as next,l as operator,$ as operators,Br as parens,m as parse,$r as peek,z as prec,G as seek,S as skip,W as space,g as token,E as unary,Or as word};
|