subscript 10.4.9 → 10.4.11
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/access.js +3 -3
- package/feature/if.js +6 -2
- package/feature/op/optional.js +3 -3
- package/feature/prop.js +3 -3
- package/feature/regex.js +11 -4
- package/feature/template.js +4 -1
- package/jessie.min.js +6 -6
- package/justin.min.js +6 -6
- package/package.json +1 -1
- package/parse.js +19 -1
- package/subscript.d.ts +2 -0
- package/subscript.min.js +4 -4
package/feature/access.js
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
* Property access: a.b, a[b], a(b), [1,2,3] - parse half
|
|
3
3
|
* For private fields (#x), see class.js
|
|
4
4
|
*/
|
|
5
|
-
import { access,
|
|
5
|
+
import { access, member } from '../parse.js';
|
|
6
6
|
|
|
7
7
|
const ACCESS = 170;
|
|
8
8
|
|
|
9
9
|
// a[b]
|
|
10
10
|
access('[]', ACCESS);
|
|
11
11
|
|
|
12
|
-
// a.b
|
|
13
|
-
|
|
12
|
+
// a.b - property name is an IdentifierName (reserved words allowed)
|
|
13
|
+
member('.', ACCESS);
|
|
14
14
|
|
|
15
15
|
// a(b,c,d), a()
|
|
16
16
|
access('()', ACCESS);
|
package/feature/if.js
CHANGED
|
@@ -11,12 +11,16 @@ export const block = () =>
|
|
|
11
11
|
export const body = () =>
|
|
12
12
|
parse.space() !== 123 ? expr(STATEMENT + .5) : (skip(), expr(STATEMENT - .5, 125) || null);
|
|
13
13
|
|
|
14
|
-
// Check for `else` after optional semicolon
|
|
14
|
+
// Check for `else` after optional semicolon. The preceding body may have
|
|
15
|
+
// triggered ASI (`x=1;\n`), leaving `parse.semi=true`. That sticky flag
|
|
16
|
+
// would cause the upcoming else-body's parse.step to bail at the first
|
|
17
|
+
// token (statement-precedence boundary), so we clear it once we've confirmed
|
|
18
|
+
// `else` — the else opens a fresh sub-statement.
|
|
15
19
|
const checkElse = () => {
|
|
16
20
|
const from = idx;
|
|
17
21
|
if (parse.space() === SEMI) skip();
|
|
18
22
|
parse.space();
|
|
19
|
-
if (word('else')) return skip(4), true;
|
|
23
|
+
if (word('else')) return skip(4), parse.semi = false, true;
|
|
20
24
|
return seek(from), false;
|
|
21
25
|
};
|
|
22
26
|
|
package/feature/op/optional.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* a?.[x] → optional computed access
|
|
6
6
|
* a?.() → optional call
|
|
7
7
|
*/
|
|
8
|
-
import { parse, token, expr, skip } from '../../parse.js';
|
|
8
|
+
import { parse, token, expr, skip, propName } from '../../parse.js';
|
|
9
9
|
|
|
10
10
|
const ACCESS = 170;
|
|
11
11
|
|
|
@@ -16,7 +16,7 @@ token('?.', ACCESS, (a, b) => {
|
|
|
16
16
|
if (cc === 40) { skip(); return ['?.()', a, expr(0, 41) || null]; }
|
|
17
17
|
// Optional computed: a?.[x]
|
|
18
18
|
if (cc === 91) { skip(); return ['?.[]', a, expr(0, 93)]; }
|
|
19
|
-
// Optional member: a?.b
|
|
20
|
-
b =
|
|
19
|
+
// Optional member: a?.b - property name is an IdentifierName
|
|
20
|
+
b = propName(ACCESS);
|
|
21
21
|
return b ? ['?.', a, b] : void 0;
|
|
22
22
|
});
|
package/feature/prop.js
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
* Minimal property access: a.b, a[b], f() - parse half
|
|
3
3
|
* For array literals, private fields, see member.js
|
|
4
4
|
*/
|
|
5
|
-
import { access,
|
|
5
|
+
import { access, member, group } from '../parse.js';
|
|
6
6
|
|
|
7
7
|
const ACCESS = 170;
|
|
8
8
|
|
|
9
9
|
// a[b] - computed member access only (no array literal support)
|
|
10
10
|
access('[]', ACCESS);
|
|
11
11
|
|
|
12
|
-
// a.b - dot member access
|
|
13
|
-
|
|
12
|
+
// a.b - dot member access; property name is an IdentifierName
|
|
13
|
+
member('.', ACCESS);
|
|
14
14
|
|
|
15
15
|
// (a) - grouping only (no sequences)
|
|
16
16
|
group('()', ACCESS);
|
package/feature/regex.js
CHANGED
|
@@ -11,13 +11,20 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { token, skip, err, next, idx, cur } from '../parse.js';
|
|
13
13
|
|
|
14
|
-
const SLASH = 47, BSLASH = 92;
|
|
14
|
+
const SLASH = 47, BSLASH = 92, LBRACK = 91, RBRACK = 93;
|
|
15
15
|
|
|
16
16
|
token('/', 140, a => {
|
|
17
|
-
// left operand = division; `//` `/*` `/?` `/+`
|
|
17
|
+
// left operand = division or assignment; `//` `/*` `/?` `/+` = not a regex start
|
|
18
18
|
const c = cur.charCodeAt(idx);
|
|
19
|
-
if (a || c === SLASH || c === 42 || c === 43 || c === 63
|
|
20
|
-
|
|
19
|
+
if (a || c === SLASH || c === 42 || c === 43 || c === 63) return;
|
|
20
|
+
// \x = 2 chars; `/` inside a [...] class is literal (classes don't nest), else `/` ends pattern
|
|
21
|
+
let cls = false;
|
|
22
|
+
const pattern = next(c =>
|
|
23
|
+
c === BSLASH ? 2 :
|
|
24
|
+
c === LBRACK ? (cls = true, 1) :
|
|
25
|
+
c === RBRACK ? (cls = false, 1) :
|
|
26
|
+
c && (cls || c !== SLASH)
|
|
27
|
+
);
|
|
21
28
|
cur.charCodeAt(idx) === SLASH || err('Unterminated regex');
|
|
22
29
|
skip();
|
|
23
30
|
const flags = next(c => c === 103 || c === 105 || c === 109 || c === 115 || c === 117 || c === 121); // gimsuy
|
package/feature/template.js
CHANGED
|
@@ -19,9 +19,12 @@ const parseBody = () => {
|
|
|
19
19
|
return skip(), parts;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
// Collapse a single-part body to that part (string or expression); else keep as ['`', ...parts]
|
|
23
|
+
const wrapBody = p => p.length < 2 && p[0]?.[0] === undefined ? p[0] || [,''] : ['`', ...p];
|
|
24
|
+
|
|
22
25
|
const prev = lookup[BACKTICK];
|
|
23
26
|
// Tagged templates: decline when ASI with newline (return undefined to let ASI handle)
|
|
24
27
|
lookup[BACKTICK] = (a, prec) =>
|
|
25
28
|
a && prec < ACCESS ? (parse.asi && parse.newline ? void 0 : (skip(), ['``', a, ...parseBody()])) : // tagged
|
|
26
|
-
!a ? (skip(), (
|
|
29
|
+
!a ? (skip(), wrapBody(parseBody())) : // plain
|
|
27
30
|
prev?.(a, prec);
|
package/jessie.min.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var l,c,s=r=>(l=0,c=r,s.enter?.(),r=h(),c[l]?N():r||""),N=(r="Unexpected token",e=l,t=c.slice(0,e).split(`
|
|
2
2
|
`),o=t.pop(),n=c.slice(Math.max(0,e-40),e),p="\u032D",m=(c[e]||" ")+p,u=c.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
|
|
3
3
|
${c[e-41]!==`
|
|
4
|
-
`,""+n}${m}${u}`)},
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},
|
|
6
|
-
`,"/*":"*/"};var
|
|
7
|
-
`)for(;c.charCodeAt(o)>=
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
9
|
-
`;var le=32,_r=10,Nt=59,Rt=125,_t=91,Ot=40,Rr=$.asi??$[";"],Pt=s._baseSpace??=s.space,vt=s._baseStep??=s.step,Ir=r=>Array.isArray(r)||typeof r=="string",Bt=(r,e)=>{for(;(e=c.charCodeAt(r))<=le;){if(e===_r)return!0;r++}return!1},Lt=(r=l,e)=>{for(;r-- >0&&(e=c.charCodeAt(r))<=le;)if(e===_r)return!0;return!1};s.space=(r,e)=>{for(;;){for(e=l,r=Pt();e<l;)if(c.charCodeAt(e++)===_r){s.newline=!0;break}if(r===Nt&&Bt(l+1)){O(l+1),s.newline=s.semi=!0;continue}return r}};s.enter=()=>s.newline=s.semi=!1;s.exit=(r,e)=>{e===Rt&&(s.newline=!0,s.semi=!1)};s.step=(r,e,t,o)=>{if(s.semi&&e>=Rr)return!1;if(r&&!Ir(r))return null;if(Ir(r)&&(s.semi||(t===_t||t===Ot)&&Lt()))return ue(r,e,o)??null;let n=s.newline;return vt(r,e,t,o)??(Ir(r)&&n?ue(r,e,o)??null:null)};var Nr=0,Mt=2e3,ue=s.asi=(r,e,t,o,n)=>{if(e>=Rr||Nr>=Mt)return;s.semi=!1;let p=l;Nr++;try{o=t(Rr-.5)}finally{Nr--}if(!(!o||l===p))return n=o?.[0]===";"?o.slice(1):[o],r?.[0]===";"?(r.push(...n),r):[";",r,...n]};var ce=(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?ce(r[1],e):(()=>{throw Error("Invalid assignment target")})(),me={"=":(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 me)f(r,(e,t)=>(t=i(t),ce(e,(o,n,p)=>me[r](o,n,t(p)))));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=>(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)));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)));f("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(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)=>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 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")})();f("++",(r,e)=>Or(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));f("--",(r,e)=>Or(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var ae=(...r)=>(r=r.map(i),e=>{let t;for(let o of r)t=o(e);return t});f(",",ae);f(";",ae);var D=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",nr=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]),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 D(o)?void 0:r(t)[o]}));f(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],D(e)?()=>{}:t=>r(t)[e]));f("()",(r,e)=>{if(e===void 0)return r==null?nr("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(p=>p==null||t(p));t(e)&&nr("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(p=>p(n))):(e=i(e),n=>[e(n)]):()=>[];return Pr(r,(n,p,m)=>n[p](...o(m)))});var L=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&L(r[1])||r[0]==="{}"),Pr=(r,e,t,o)=>r==null?nr("Empty ()"):r[0]==="()"&&r.length==2?Pr(r[1],e):typeof r=="string"?n=>e(n,r,n):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o,n)):r[0]==="?."?(t=i(r[1]),o=r[2],n=>{let p=t(n);return p==null?void 0:e(p,o,n)}):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n),n)):r[0]==="?.[]"?(t=i(r[1]),o=i(r[2]),n=>{let p=t(n);return p==null?void 0:e(p,o(n),n)}):(r=i(r),n=>e([r(n)],0,n)),F=Pr;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 Ut=r=>{throw Error(r)};f("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));f("**=",(r,e)=>(L(r)||Ut("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]**=e(n))));f("in",(r,e)=>(r=i(r),e=i(e),t=>r(t)in e(t)));var Dt=r=>{throw Error(r)};f(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));f(">>>=",(r,e)=>(L(r)||Dt("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]>>>=e(n))));var Ft=r=>r[0]?.[0]===","?r[0].slice(1):r,G=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...n]=r,p=Ft(n);if(o==="{}"){let m=[];for(let u of p){if(Array.isArray(u)&&u[0]==="..."){let w={};for(let R in e)m.includes(R)||(w[R]=e[R]);t[u[1]]=w;break}let a,y,g;typeof u=="string"?a=y=u:u[0]==="="?(typeof u[1]=="string"?a=y=u[1]:[,a,y]=u[1],g=u[2]):[,a,y]=u,m.push(a);let E=e[a];E===void 0&&g&&(E=i(g)(t)),G(y,E,t)}}else if(o==="[]"){let m=0;for(let u of p){if(u===null){m++;continue}if(Array.isArray(u)&&u[0]==="..."){t[u[1]]=e.slice(m);break}let a=u,y;Array.isArray(u)&&u[0]==="="&&([,a,y]=u);let g=e[m++];g===void 0&&y&&(g=i(y)(t)),G(a,g,t)}}},vr=(...r)=>(r=r.map(e=>{if(typeof e=="string")return t=>{t[e]=void 0};if(e[0]==="="){let[,t,o]=e,n=i(o);return typeof t=="string"?p=>{p[t]=n(p)}:p=>G(t,n(p),p)}return i(e)}),e=>{for(let t of r)t(e)});f("let",vr);f("const",vr);f("var",vr);var ir=r=>{throw Error(r)};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"?o=>{o[t]=e(o)}:o=>G(t,e(o),o)}return L(r)||ir("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]=e(n))});f("||=",(r,e)=>(L(r)||ir("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]||=e(n))));f("&&=",(r,e)=>(L(r)||ir("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]&&=e(n))));f("??=",(r,e)=>(L(r)||ir("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]??=e(n))));f("?",(r,e,t)=>(r=i(r),e=i(e),t=i(t),o=>r(o)?e(o):t(o)));var v=[];f("=>",(r,e)=>{r=r?.[0]==="()"?r[1]:r;let t=r?r[0]===","?r.slice(1):[r]:[],o=-1,n=null,p=t[t.length-1];Array.isArray(p)&&p[0]==="..."&&(o=t.length-1,n=p[1],t.length--);let m=e?.[0]==="{}";return e=i(m?["{",e[1]]:e),u=>(...a)=>{let y={};t.forEach((E,w)=>y[E]=a[w]),n&&(y[n]=a.slice(o));let g=new Proxy(y,{get:(E,w)=>w in E?E[w]:u?.[w],set:(E,w,R)=>((w in E?E:u)[w]=R,!0),has:(E,w)=>w in E||(u?w in u:!1)});try{let E=e(g);return m?void 0:E}catch(E){if(E===v)return E[0];throw E}}});f("...",r=>(r=i(r),e=>Object.entries(r(e))));f("?.",(r,e)=>(r=i(r),D(e)?()=>{}:t=>r(t)?.[e]));f("?.[]",(r,e)=>(r=i(r),e=i(e),t=>{let o=e(t);return D(o)?void 0:r(t)?.[o]}));f("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(p=>p(n))):(e=i(e),n=>[e(n)]):()=>[];if(r[0]==="?."){let n=i(r[1]),p=r[2];return D(p)?()=>{}:m=>n(m)?.[p]?.(...t(m))}if(r[0]==="?.[]"){let n=i(r[1]),p=i(r[2]);return m=>{let u=n(m),a=p(m);return D(a)?void 0:u?.[a]?.(...t(m))}}if(r[0]==="."){let n=i(r[1]),p=r[2];return D(p)?()=>{}:m=>n(m)?.[p]?.(...t(m))}if(r[0]==="[]"&&r.length===3){let n=i(r[1]),p=i(r[2]);return m=>{let u=n(m),a=p(m);return D(a)?void 0:u?.[a]?.(...t(m))}}let o=i(r);return n=>o(n)?.(...t(n))});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 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});f("new",r=>{let e=i(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,o=t?t[0]===","?(n=>p=>n.map(m=>m(p)))(t.slice(1).map(i)):(n=>p=>[n(p)])(i(t)):()=>[];return n=>new(e(n))(...o(n))});var sr=Symbol("accessor");f("get",(r,e)=>(e=e?i(e):()=>{},t=>[[sr,r,{get:function(){let o=Object.create(t||{});return o.this=this,e(o)}}]]));f("set",(r,e,t)=>(t=t?i(t):()=>{},o=>[[sr,r,{set:function(n){let p=Object.create(o||{});p.this=this,p[e]=n,t(p)}}]]));var Gt=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);f("{}",(r,e)=>{if(e!==void 0)return;if(!Gt(r))return i(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(o=>i(typeof o=="string"?[":",o,o]:o));return o=>{let n={},p={};for(let m of t.flatMap(u=>u(o)))if(m[0]===sr){let[,u,a]=m;p[u]={...p[u],...a,configurable:!0,enumerable:!0}}else n[m[0]]=m[1];for(let m in p)Object.defineProperty(n,m,p[m]);return n}});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)]]));f("`",(...r)=>(r=r.map(i),e=>r.map(t=>t(e)).join("")));f("``",(r,...e)=>{r=i(r);let t=[],o=[];for(let p of e)Array.isArray(p)&&p[0]===void 0?t.push(p[1]):o.push(i(p));let n=Object.assign([...t],{raw:t});return p=>r(p)(n,...o.map(m=>m(p)))});f("function",(r,e,t)=>{t=t?i(t):()=>{};let o=e?e[0]===","?e.slice(1):[e]:[],n=null,p=-1,m=o[o.length-1];return Array.isArray(m)&&m[0]==="..."&&(p=o.length-1,n=m[1],o.length--),u=>{let a=(...y)=>{let g={};o.forEach((w,R)=>g[w]=y[R]),n&&(g[n]=y.slice(p));let E=new Proxy(g,{get:(w,R)=>R in w?w[R]:u[R],set:(w,R,Ae)=>((R in w?w:u)[R]=Ae,!0),has:(w,R)=>R in w||R in u});try{return t(E)}catch(w){if(w===v)return w[0];throw w}};return r&&(u[r]=a),a}});f("function*",(r,e,t)=>{throw Error("Generator functions are not supported in evaluation")});f("async",r=>{let e=i(r);return t=>{let o=e(t);return async function(...n){return o(...n)}}});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 Xt=Symbol("static"),Kt=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,o=>{let n=e?e(o):Object,p=function(...m){if(!(this instanceof p))return Kt("Class constructor must be called with new");let u=e?Reflect.construct(n,m,p):this;return p.prototype.__constructor__&&p.prototype.__constructor__.apply(u,m),u};if(Object.setPrototypeOf(p.prototype,n.prototype),Object.setPrototypeOf(p,n),t){let m=Object.create(o);m.super=n;let u=t(m),a=Array.isArray(u)&&typeof u[0]?.[0]=="string"?u:[];for(let[y,g]of a)y==="constructor"?p.prototype.__constructor__=g:p.prototype[y]=g}return r&&(o[r]=p),p}));f("static",r=>(r=i(r),e=>[[Xt,r(e)]]));f("//",(r,e)=>{let t=new RegExp(r,e||"");return()=>t});f("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 M=Symbol("break"),X=Symbol("continue");f("while",(r,e)=>(r=i(r),e=i(e),t=>{let o;for(;r(t);)try{o=e(t)}catch(n){if(n===M)break;if(n===X)continue;if(n===v)return n[0];throw n}return o}));f("do",(r,e)=>(r=i(r),e=i(e),t=>{let o;do try{o=r(t)}catch(n){if(n===M)break;if(n===X)continue;if(n===v)return n[0];throw n}while(e(t));return o}));f("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),p=>{let m;for(t?.(p);o(p);n?.(p))try{m=e(p)}catch(u){if(u===M)break;if(u===X)continue;if(u===v)return u[0];throw u}return m}}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 Qt(o,n,e);if(t==="of")return Ht(o,n,e)}});var Ht=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let p,m=o?null:n[r];for(let u of e(n)){o?G(r,u,n):n[r]=u;try{p=t(n)}catch(a){if(a===M)break;if(a===X)continue;if(a===v)return a[0];throw a}}return o||(n[r]=m),p}},Qt=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let p,m=o?null:n[r];for(let u in e(n)){o?G(r,u,n):n[r]=u;try{p=t(n)}catch(a){if(a===M)break;if(a===X)continue;if(a===v)return a[0];throw a}}return o||(n[r]=m),p}};f("break",()=>()=>{throw M});f("continue",()=>()=>{throw X});f("return",r=>(r=r!==void 0?i(r):null,e=>{throw v[0]=r?.(e),v}));f("try",(r,...e)=>{r=r?i(r):null;let t=e.find(u=>u?.[0]==="catch"),o=e.find(u=>u?.[0]==="finally"),n=t?.[1],p=t?.[2]?i(t[2]):null,m=o?.[1]?i(o[1]):null;return u=>{let a;try{a=r?.(u)}catch(y){if(y===M||y===X||y===v)throw y;if(n!=null&&p){let g=n in u,E=u[n];u[n]=y;try{a=p(u)}finally{g?u[n]=E:delete u[n]}}else if(!p)throw y}finally{m?.(u)}return a}});f("throw",r=>(r=i(r),e=>{throw r(e)}));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 o=r(t),n=!1,p;for(let[u,a]of e)if(n||u===null||u(t)===o)for(n=!0,m=0;m<a.length;m++)try{p=a[m](t)}catch(y){if(y===M)return p;throw y}var m;return p}):t=>r(t)));f("import",()=>()=>{});f("export",()=>()=>{});f("from",(r,e)=>()=>{});f("as",(r,e)=>()=>{});f("default",r=>i(r));var de=new WeakMap,$t=(r,...e)=>typeof r=="string"?i(s(r)):de.get(r)||de.set(r,jt(r,e)).get(r),he=57344,jt=(r,e)=>{let t=r.reduce((p,m,u)=>p+(u?String.fromCharCode(he+u-1):"")+m,""),o=s(t),n=p=>{if(typeof p=="string"&&p.length===1){let m=p.charCodeAt(0)-he,u;if(m>=0&&m<e.length)return u=e[m],Wt(u)?u:[,u]}return Array.isArray(p)?p.map(n):p};return i(n(o))},Wt=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),zt=$t;export{ur as access,A as binary,i as compile,c as cur,zt as default,N as err,h as expr,j as group,Jt as id,l as idx,C as keyword,H as literal,Br as loc,T as lookup,fr as nary,I as next,f as operator,pr as operators,P as parens,s as parse,Y as peek,$ as prec,O as seek,d as skip,S as token,_ as unary,k as word};
|
|
4
|
+
`,""+n}${m}${u}`)},Lr=(r,e=l)=>(Array.isArray(r)&&(r.loc=e),r),k=(r,e=l,t)=>{for(;t=r(c.charCodeAt(l));)l+=t;return c.slice(e,l)},d=(r=1)=>c[l+=r],O=r=>l=r,h=(r=0,e)=>{let t,o,n;for(e&&s.enter?.(r,e);(t=s.space())&&t!==e&&(n=s.step(o,r,t,h));)o=n;return e&&(t==e?(l++,s.exit?.(r,e)):N("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},Y=(r=l)=>{for(;c.charCodeAt(r)<=32;)r++;return c.charCodeAt(r)},xt=s.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,T=(r,e=r.length)=>c.substr(l,e)===r&&!s.id(c.charCodeAt(l+e)),P=()=>(d(),h(0,41)),I=[],$={},S=(r,e=32,t,o=r.charCodeAt(0),n=r.length,p=I[o],m=r.toUpperCase()!==r,u,a)=>(e=$[r]=!p&&$[r]||e,I[o]=(y,g,E,w=l)=>(u=E,(E?r==E:(n<2||r.charCodeAt(1)===c.charCodeAt(l+1)&&(n<3||c.substr(l,n)==r))&&(!m||!s.id(c.charCodeAt(l+n)))&&(u=E=r))&&g<e&&(l+=n,(a=t(y))?Lr(a,w):(l=w,u=0,!m&&!p&&!y&&N()),a)||p?.(y,g,u))),A=(r,e,t=!1)=>S(r,e,o=>o&&(n=>n&&[r,o,n])(h(e-(t?.5:0)))),_=(r,e,t)=>S(r,e,o=>t?o&&[r,o]:!o&&(o=h(e-.5))&&[r,o]),H=(r,e)=>S(r,200,t=>!t&&[,e]),fr=(r,e,t)=>S(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)),j=(r,e)=>S(r[0],e,t=>!t&&[r,h(0,r.charCodeAt(1))||null]),ur=(r,e)=>S(r[0],e,t=>t&&[r,t,h(0,r.charCodeAt(1))||null]),lr=(r,e)=>(s.space(),e=c.charCodeAt(l),s.id(e)&&(e<48||e>57)?k(s.id):h(r)),Mr=(r,e)=>S(r,e,t=>t&&(o=>o&&[r,t,o])(lr(e))),C=(r,e,t,o=r.charCodeAt(0),n=r.length,p=I[o],m)=>I[o]=(u,a,y,g=l)=>!u&&(y?r==y:(n<2||c.substr(l,n)==r)&&(y=r))&&a<e&&!s.id(c.charCodeAt(l+n))&&(!s.prop||s.prop(l+n))&&(O(l+n),(m=t())?Lr(m,g):O(g),m)||p?.(u,a,y);s.space=r=>{for(;(r=c.charCodeAt(l))<=32;)l++;return r};s.step=(r,e,t,o,n)=>(n=I[t])&&n(r,e)||(r?null:k(s.id)||null);var pr={},f=(r,e,t=pr[r])=>pr[r]=(...o)=>e(...o)||t?.(...o),i=r=>Array.isArray(r)?r[0]==null?(e=>()=>e)(r[1]):pr[r[0]]?.(...r.slice(1))??N(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var q=46,W=48,x=57,we=69,ge=101,Ee=43,Se=45,Z=95,Ur=110,ke=97,Te=102,Ie=65,Ne=70,Dr=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),mr=r=>{let e=Dr(k(t=>t===q&&c.charCodeAt(l+1)!==q||t>=W&&t<=x||t===Z||((t===we||t===ge)&&((t=c.charCodeAt(l+1))>=W&&t<=x||t===Ee||t===Se)?2:0)));return c.charCodeAt(l)===Ur?(d(),[,BigInt(e)]):(r=+e)!=r?N():[,r]},Re={2:r=>r===48||r===49||r===Z,8:r=>r>=48&&r<=55||r===Z,16:r=>r>=W&&r<=x||r>=ke&&r<=Te||r>=Ie&&r<=Ne||r===Z};s.number=null;I[q]=r=>!r&&c.charCodeAt(l+1)!==q&&mr();for(let r=W;r<=x;r++)I[r]=e=>e?void 0:mr();I[W]=r=>{if(r)return;let e=s.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&c[l+1]?.toLowerCase()===t[1]){d(2);let n=Dr(k(Re[o]));return c.charCodeAt(l)===Ur?(d(),[,BigInt("0"+t[1]+n)]):[,parseInt(n,o)]}}return mr()};var _e=92,Fr=34,Gr=39,Kr=117,Xr=120,Oe=123,Pe=125,Hr=10,Be=13,ve={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},Qr=r=>r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:-1,$r=r=>(e,t,o="",n=String.fromCharCode(r))=>{if(e||!s.string?.[n])return;d();let p=()=>{let m=c.charCodeAt(l+1);if(m===Hr)return 2;if(m===Be)return c.charCodeAt(l+2)===Hr?3:2;if(m===Xr||m===Kr&&c.charCodeAt(l+2)!==Oe){let u=m===Xr?2:4,a=0,y;for(let g=0;g<u;g++){if((y=Qr(c.charCodeAt(l+2+g)))<0)return o+=c[l+1],2;a=a*16+y}return o+=String.fromCharCode(a),2+u}if(m===Kr){let u=0,a=l+3,y;for(;(y=Qr(c.charCodeAt(a)))>=0;)u=u*16+y,a++;return a>l+3&&u<=1114111&&c.charCodeAt(a)===Pe?(o+=String.fromCodePoint(u),a-l+1):(o+=c[l+1],2)}return o+=ve[c[l+1]]||c[l+1],2};return k(m=>m-r&&(m!==_e?(o+=c[l],1):p())),c[l]===n?d():N("Bad string"),[,o]};I[Fr]=$r(Fr);I[Gr]=$r(Gr);s.string={'"':!0};var Le=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>A(r,Le,!0));var Me=30,Ue=40,De=140;_("!",De);A("||",Me);A("&&",Ue);var Fe=50,Ge=60,Ke=70,jr=100,Xe=140;A("|",Fe);A("&",Ke);A("^",Ge);A(">>",jr);A("<<",jr);_("~",Xe);var b=90;A("<",b);A(">",b);A("<=",b);A(">=",b);var Wr=80;A("==",Wr);A("!=",Wr);var zr=110,cr=120,Jr=140;A("+",zr);A("-",zr);A("*",cr);A("/",cr);A("%",cr);_("+",Jr);_("-",Jr);var rr=150;S("++",rr,r=>r?["++",r,null]:["++",h(rr-1)]);S("--",rr,r=>r?["--",r,null]:["--",h(rr-1)]);var He=5,Qe=10;fr(",",Qe);fr(";",He,!0);var $e=170;j("()",$e);var ar=170;ur("[]",ar);Mr(".",ar);ur("()",ar);var je=32,We=s.space;s.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};var dr;s.space=()=>{dr||(dr=Object.entries(s.comment).map(([n,p])=>[n,p,n.charCodeAt(0)]));for(var r;r=We();){for(var e=0,t;t=dr[e++];)if(r===t[2]&&c.substr(l,t[0].length)===t[0]){var o=l+t[0].length;if(t[1]===`
|
|
7
|
+
`)for(;c.charCodeAt(o)>=je;)o++;else{for(;c[o]&&c.substr(o,t[1].length)!==t[1];)o++;c[o]&&(o+=t[1].length)}O(o),r=0;break}if(r)return r}return r};var Vr=80;A("===",Vr);A("!==",Vr);var ze=30;A("??",ze);var Je=130,Ve=20;A("**",Je,!0);A("**=",Ve,!0);var Yr=90;A("in",Yr);A("of",Yr);var Ye=20,Ze=100;A(">>>",Ze);A(">>>=",Ye,!0);var hr=20;A("||=",hr,!0);A("&&=",hr,!0);A("??=",hr,!0);H("true",!0);H("false",!1);H("null",null);C("undefined",200,()=>[]);H("NaN",NaN);H("Infinity",1/0);var Ar=20;S("?",Ar,(r,e,t)=>r&&(e=h(Ar-1))&&k(o=>o===58)&&(t=h(Ar-1),["?",r,e,t]));var qe=20;A("=>",qe,!0);var xe=20;_("...",xe);var Zr=170;S("?.",Zr,(r,e)=>{if(!r)return;let t=s.space();return t===40?(d(),["?.()",r,h(0,41)||null]):t===91?(d(),["?.[]",r,h(0,93)]):(e=lr(Zr),e?["?.",r,e]:void 0)});var z=140;_("typeof",z);_("void",z);_("delete",z);C("new",z,()=>T(".target")?(d(7),["new.target"]):["new",h(z)]);var be=20,qr=200;s.prop=r=>Y(r)!==58;j("[]",qr);j("{}",qr);A(":",be-1,!0);var rt=170,er=96,et=36,tt=123,ot=92,nt={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},xr=()=>{let r=[];for(let e="",t;(t=c.charCodeAt(l))!==er;)t?t===ot?(d(),e+=nt[c[l]]||c[l],d()):t===et&&c.charCodeAt(l+1)===tt?(e&&r.push([,e]),e="",d(2),r.push(h(0,125))):(e+=c[l],d(),t=c.charCodeAt(l),t===er&&e&&r.push([,e])):N("Unterminated template");return d(),r},it=r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r],st=I[er];I[er]=(r,e)=>r&&e<rt?s.asi&&s.newline?void 0:(d(),["``",r,...xr()]):r?st?.(r,e):(d(),it(xr()));s.string["'"]=!0;s.number={"0x":16,"0b":2,"0o":8};var pt=92,ft=117,ut=123,lt=125,mt=183,ct=s.id,br=r=>r>=48&&r<=57||r>=65&&r<=70||r>=97&&r<=102,at=(r=l+2,e,t=0,o=0)=>{if(c.charCodeAt(l)!==pt||c.charCodeAt(l+1)!==ft)return 0;if(c.charCodeAt(r)===ut){for(;br(e=c.charCodeAt(++r));)t=t*16+(e<=57?e-48:(e&31)+9);return r>l+3&&t<=1114111&&c.charCodeAt(r)===lt?r-l+1:0}for(;o<4&&br(c.charCodeAt(r+o));)o++;return o===4?6:0};s.id=r=>ct(r)||r===mt||at();var yr=5,dt=10,Cr=r=>{let e=l,t=h(dt-1);return t==null?r:r==="let"&&(t==="in"||t==="of")?(O(e),r):t[0]==="in"||t[0]==="of"?[t[0],[r,t[1]],t[2]]:t[0]===","?[r,...t.slice(1)]:[r,t]};C("let",yr+1,()=>Cr("let"));C("const",yr+1,()=>Cr("const"));C("var",yr+1,()=>Cr("var"));var tr=5,ht=59,v=()=>(s.space()===123||N("Expected {"),d(),h(tr-.5,125)||null),U=()=>s.space()!==123?h(tr+.5):(d(),h(tr-.5,125)||null),At=()=>{let r=l;return s.space()===ht&&d(),s.space(),T("else")?(d(4),s.semi=!1,!0):(O(r),!1)};C("if",tr+1,()=>{s.space();let r=["if",P(),U()];return At()&&r.push(U()),r});var yt=200;C("function",yt,()=>{s.space();let r=!1;c[l]==="*"&&(r=!0,d(),s.space());let e=k(s.id);return e&&s.space(),r?["function*",e,P()||null,v()]:["function",e,P()||null,v()]});var or=140,wr=20;_("await",or);C("yield",or,()=>(s.space(),c[l]==="*"?(d(),s.space(),["yield*",h(wr)]):["yield",h(wr)]));C("async",or,()=>{if(s.space(),T("function"))return["async",h(or)];let r=h(wr-.5);return r&&["async",r]});var gr=200;var Ct=90,wt=175;_("static",wt);A("instanceof",Ct);S("#",gr,r=>{if(r)return;let e=k(s.id);return e?"#"+e:void 0});C("class",gr,()=>{s.space();let r=k(s.id)||null;if(r==="extends")r=null,s.space();else{if(s.space(),!T("extends"))return["class",r,null,v()];d(7),s.space()}return["class",r,h(gr),v()]});var Er=47,gt=92,Et=91,St=93;S("/",140,r=>{let e=c.charCodeAt(l);if(r||e===Er||e===42||e===43||e===63)return;let t=!1,o=k(p=>p===gt?2:p===Et?(t=!0,1):p===St?(t=!1,1):p&&(t||p!==Er));c.charCodeAt(l)===Er||N("Unterminated regex"),d();let n=k(p=>p===103||p===105||p===109||p===115||p===117||p===121);return n?["//",o,n]:["//",o]});var X=5,J=125,V=59;C("while",X+1,()=>(s.space(),["while",P(),U()]));C("do",X+1,()=>(r=>(s.space(),d(5),s.space(),["do",r,P()]))(U()));C("for",X+1,()=>(s.space(),T("await")?(d(5),s.space(),["for await",P(),U()]):["for",P(),U()]));C("break",X+1,()=>{s.asi&&(s.newline=!1);let r=l;s.space();let e=c.charCodeAt(l);if(!e||e===J||e===V||s.newline)return["break"];let t=k(s.id);if(!t)return["break"];s.space();let o=c.charCodeAt(l);return!o||o===J||o===V||s.newline?["break",t]:(O(r),["break"])});C("continue",X+1,()=>{s.asi&&(s.newline=!1);let r=l;s.space();let e=c.charCodeAt(l);if(!e||e===J||e===V||s.newline)return["continue"];let t=k(s.id);if(!t)return["continue"];s.space();let o=c.charCodeAt(l);return!o||o===J||o===V||s.newline?["continue",t]:(O(r),["continue"])});C("return",X+1,()=>{s.asi&&(s.newline=!1);let r=s.space();return!r||r===J||r===V||s.newline?["return"]:["return",h(X)]});var Sr=5;C("try",Sr+1,()=>{let r=["try",v()];return s.space(),T("catch")&&(d(5),s.space(),r.push(["catch",Y()===40?P():null,v()])),s.space(),T("finally")&&(d(7),r.push(["finally",v()])),r});C("throw",Sr+1,()=>{if(s.asi&&(s.newline=!1),s.space(),s.newline)throw SyntaxError("Unexpected newline after throw");return["throw",h(Sr)]});var te=5,kt=20,re=58,Tt=59,oe=125,kr=0,ne=(r,e=r.length,t=r.charCodeAt(0),o=I[t])=>I[t]=(n,p,m)=>T(r)&&!n&&kr||o?.(n,p,m);ne("case");ne("default");var ee=r=>{let e=[];for(;(r=s.space())!==oe&&!T("case")&&!T("default");){if(r===Tt){d();continue}e.push(h(te-.5))||N()}return e.length>1?[";",...e]:e[0]||null},It=()=>{s.space()===123||N("Expected {"),d(),kr++;let r=[];try{for(;s.space()!==oe;)if(T("case")){O(l+4),s.space();let e=h(kt-.5);s.space()===re&&d(),r.push(["case",e,ee()])}else T("default")?(O(l+7),s.space()===re&&d(),r.push(["default",ee()])):N("Expected case or default")}finally{kr--}return d(),r};C("switch",te+1,()=>s.space()===40&&["switch",P(),...It()]);var ie=5;C("debugger",ie+1,()=>["debugger"]);C("with",ie+1,()=>(s.space(),["with",P(),U()]));var Tr=5,Q=10,se=42,Nt=I[se];I[se]=(r,e)=>r?Nt?.(r,e):(d(),"*");S("from",Q+1,r=>r?r[0]!=="="&&r[0]!==","&&(s.space(),["from",r,h(Q+1)]):!1);S("as",Q+2,r=>r?(s.space(),["as",r,h(Q+2)]):!1);C("import",Tr,()=>T(".meta")?(d(5),["import.meta"]):["import",h(Q)]);C("export",Tr,()=>(s.space(),T("default")?(d(7),["export",["default",h(Q)]]):["export",h(Tr)]));var Ir=20,Rt=10,_t=13,Ot=40,pe=41,fe=123,ue=125,Pt=(r,e)=>{for(;r<e;){let t=c.charCodeAt(r++);if(t===Rt||t===_t)return!0}return!1},le=r=>e=>{if(e)return;let t=l;if(s.space(),s.semi||Pt(t,l))return!1;let o=k(s.id);if(!o||(s.space(),c.charCodeAt(l)!==Ot))return!1;d();let n=h(0,pe);return s.space(),c.charCodeAt(l)!==fe?!1:(d(),[r,o,n,h(0,ue)])};S("get",Ir-1,le("get"));S("set",Ir-1,le("set"));S("(",Ir-1,r=>{if(!r)return;let e;if(Array.isArray(r)&&r[0]==="static"&&(e="static",r=r[1]),typeof r!="string"&&!(Array.isArray(r)&&r[0]===void 0))return;let t=h(0,pe)||null;if(s.space(),c.charCodeAt(l)!==fe)return;d();let o=[":",r,["=>",["()",t],h(0,ue)||null]];return e?[e,o]:o});s.comment["#!"]=`
|
|
9
|
+
`;var ce=32,Or=10,Bt=59,vt=125,Lt=91,Mt=40,_r=$.asi??$[";"],Ut=s._baseSpace??=s.space,Dt=s._baseStep??=s.step,Nr=r=>Array.isArray(r)||typeof r=="string",Ft=(r,e)=>{for(;(e=c.charCodeAt(r))<=ce;){if(e===Or)return!0;r++}return!1},Gt=(r=l,e)=>{for(;r-- >0&&(e=c.charCodeAt(r))<=ce;)if(e===Or)return!0;return!1};s.space=(r,e)=>{for(;;){for(e=l,r=Ut();e<l;)if(c.charCodeAt(e++)===Or){s.newline=!0;break}if(r===Bt&&Ft(l+1)){O(l+1),s.newline=s.semi=!0;continue}return r}};s.enter=()=>s.newline=s.semi=!1;s.exit=(r,e)=>{e===vt&&(s.newline=!0,s.semi=!1)};s.step=(r,e,t,o)=>{if(s.semi&&e>=_r)return!1;if(r&&!Nr(r))return null;if(Nr(r)&&(s.semi||(t===Lt||t===Mt)&&Gt()))return me(r,e,o)??null;let n=s.newline;return Dt(r,e,t,o)??(Nr(r)&&n?me(r,e,o)??null:null)};var Rr=0,Kt=2e3,me=s.asi=(r,e,t,o,n)=>{if(e>=_r||Rr>=Kt)return;s.semi=!1;let p=l;Rr++;try{o=t(_r-.5)}finally{Rr--}if(!(!o||l===p))return n=o?.[0]===";"?o.slice(1):[o],r?.[0]===";"?(r.push(...n),r):[";",r,...n]};var de=(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?de(r[1],e):(()=>{throw Error("Invalid assignment target")})(),ae={"=":(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 ae)f(r,(e,t)=>(t=i(t),de(e,(o,n,p)=>ae[r](o,n,t(p)))));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=>(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)));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)));f("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(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)=>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 Pr=(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?Pr(r[1],e):(()=>{throw Error("Invalid increment target")})();f("++",(r,e)=>Pr(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));f("--",(r,e)=>Pr(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var he=(...r)=>(r=r.map(i),e=>{let t;for(let o of r)t=o(e);return t});f(",",he);f(";",he);var D=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",nr=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]),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 D(o)?void 0:r(t)[o]}));f(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],D(e)?()=>{}:t=>r(t)[e]));f("()",(r,e)=>{if(e===void 0)return r==null?nr("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(p=>p==null||t(p));t(e)&&nr("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(p=>p(n))):(e=i(e),n=>[e(n)]):()=>[];return Br(r,(n,p,m)=>n[p](...o(m)))});var L=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&L(r[1])||r[0]==="{}"),Br=(r,e,t,o)=>r==null?nr("Empty ()"):r[0]==="()"&&r.length==2?Br(r[1],e):typeof r=="string"?n=>e(n,r,n):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o,n)):r[0]==="?."?(t=i(r[1]),o=r[2],n=>{let p=t(n);return p==null?void 0:e(p,o,n)}):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n),n)):r[0]==="?.[]"?(t=i(r[1]),o=i(r[2]),n=>{let p=t(n);return p==null?void 0:e(p,o(n),n)}):(r=i(r),n=>e([r(n)],0,n)),F=Br;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 Xt=r=>{throw Error(r)};f("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));f("**=",(r,e)=>(L(r)||Xt("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]**=e(n))));f("in",(r,e)=>(r=i(r),e=i(e),t=>r(t)in e(t)));var Ht=r=>{throw Error(r)};f(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));f(">>>=",(r,e)=>(L(r)||Ht("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]>>>=e(n))));var Qt=r=>r[0]?.[0]===","?r[0].slice(1):r,G=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...n]=r,p=Qt(n);if(o==="{}"){let m=[];for(let u of p){if(Array.isArray(u)&&u[0]==="..."){let w={};for(let R in e)m.includes(R)||(w[R]=e[R]);t[u[1]]=w;break}let a,y,g;typeof u=="string"?a=y=u:u[0]==="="?(typeof u[1]=="string"?a=y=u[1]:[,a,y]=u[1],g=u[2]):[,a,y]=u,m.push(a);let E=e[a];E===void 0&&g&&(E=i(g)(t)),G(y,E,t)}}else if(o==="[]"){let m=0;for(let u of p){if(u===null){m++;continue}if(Array.isArray(u)&&u[0]==="..."){t[u[1]]=e.slice(m);break}let a=u,y;Array.isArray(u)&&u[0]==="="&&([,a,y]=u);let g=e[m++];g===void 0&&y&&(g=i(y)(t)),G(a,g,t)}}},vr=(...r)=>(r=r.map(e=>{if(typeof e=="string")return t=>{t[e]=void 0};if(e[0]==="="){let[,t,o]=e,n=i(o);return typeof t=="string"?p=>{p[t]=n(p)}:p=>G(t,n(p),p)}return i(e)}),e=>{for(let t of r)t(e)});f("let",vr);f("const",vr);f("var",vr);var ir=r=>{throw Error(r)};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"?o=>{o[t]=e(o)}:o=>G(t,e(o),o)}return L(r)||ir("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]=e(n))});f("||=",(r,e)=>(L(r)||ir("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]||=e(n))));f("&&=",(r,e)=>(L(r)||ir("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]&&=e(n))));f("??=",(r,e)=>(L(r)||ir("Invalid assignment target"),e=i(e),F(r,(t,o,n)=>t[o]??=e(n))));f("?",(r,e,t)=>(r=i(r),e=i(e),t=i(t),o=>r(o)?e(o):t(o)));var B=[];f("=>",(r,e)=>{r=r?.[0]==="()"?r[1]:r;let t=r?r[0]===","?r.slice(1):[r]:[],o=-1,n=null,p=t[t.length-1];Array.isArray(p)&&p[0]==="..."&&(o=t.length-1,n=p[1],t.length--);let m=e?.[0]==="{}";return e=i(m?["{",e[1]]:e),u=>(...a)=>{let y={};t.forEach((E,w)=>y[E]=a[w]),n&&(y[n]=a.slice(o));let g=new Proxy(y,{get:(E,w)=>w in E?E[w]:u?.[w],set:(E,w,R)=>((w in E?E:u)[w]=R,!0),has:(E,w)=>w in E||(u?w in u:!1)});try{let E=e(g);return m?void 0:E}catch(E){if(E===B)return E[0];throw E}}});f("...",r=>(r=i(r),e=>Object.entries(r(e))));f("?.",(r,e)=>(r=i(r),D(e)?()=>{}:t=>r(t)?.[e]));f("?.[]",(r,e)=>(r=i(r),e=i(e),t=>{let o=e(t);return D(o)?void 0:r(t)?.[o]}));f("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(p=>p(n))):(e=i(e),n=>[e(n)]):()=>[];if(r[0]==="?."){let n=i(r[1]),p=r[2];return D(p)?()=>{}:m=>n(m)?.[p]?.(...t(m))}if(r[0]==="?.[]"){let n=i(r[1]),p=i(r[2]);return m=>{let u=n(m),a=p(m);return D(a)?void 0:u?.[a]?.(...t(m))}}if(r[0]==="."){let n=i(r[1]),p=r[2];return D(p)?()=>{}:m=>n(m)?.[p]?.(...t(m))}if(r[0]==="[]"&&r.length===3){let n=i(r[1]),p=i(r[2]);return m=>{let u=n(m),a=p(m);return D(a)?void 0:u?.[a]?.(...t(m))}}let o=i(r);return n=>o(n)?.(...t(n))});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 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});f("new",r=>{let e=i(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,o=t?t[0]===","?(n=>p=>n.map(m=>m(p)))(t.slice(1).map(i)):(n=>p=>[n(p)])(i(t)):()=>[];return n=>new(e(n))(...o(n))});var sr=Symbol("accessor");f("get",(r,e)=>(e=e?i(e):()=>{},t=>[[sr,r,{get:function(){let o=Object.create(t||{});return o.this=this,e(o)}}]]));f("set",(r,e,t)=>(t=t?i(t):()=>{},o=>[[sr,r,{set:function(n){let p=Object.create(o||{});p.this=this,p[e]=n,t(p)}}]]));var $t=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);f("{}",(r,e)=>{if(e!==void 0)return;if(!$t(r))return i(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(o=>i(typeof o=="string"?[":",o,o]:o));return o=>{let n={},p={};for(let m of t.flatMap(u=>u(o)))if(m[0]===sr){let[,u,a]=m;p[u]={...p[u],...a,configurable:!0,enumerable:!0}}else n[m[0]]=m[1];for(let m in p)Object.defineProperty(n,m,p[m]);return n}});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)]]));f("`",(...r)=>(r=r.map(i),e=>r.map(t=>t(e)).join("")));f("``",(r,...e)=>{r=i(r);let t=[],o=[];for(let p of e)Array.isArray(p)&&p[0]===void 0?t.push(p[1]):o.push(i(p));let n=Object.assign([...t],{raw:t});return p=>r(p)(n,...o.map(m=>m(p)))});f("function",(r,e,t)=>{t=t?i(t):()=>{};let o=e?e[0]===","?e.slice(1):[e]:[],n=null,p=-1,m=o[o.length-1];return Array.isArray(m)&&m[0]==="..."&&(p=o.length-1,n=m[1],o.length--),u=>{let a=(...y)=>{let g={};o.forEach((w,R)=>g[w]=y[R]),n&&(g[n]=y.slice(p));let E=new Proxy(g,{get:(w,R)=>R in w?w[R]:u[R],set:(w,R,Ce)=>((R in w?w:u)[R]=Ce,!0),has:(w,R)=>R in w||R in u});try{return t(E)}catch(w){if(w===B)return w[0];throw w}};return r&&(u[r]=a),a}});f("function*",(r,e,t)=>{throw Error("Generator functions are not supported in evaluation")});f("async",r=>{let e=i(r);return t=>{let o=e(t);return async function(...n){return o(...n)}}});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 jt=Symbol("static"),Wt=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,o=>{let n=e?e(o):Object,p=function(...m){if(!(this instanceof p))return Wt("Class constructor must be called with new");let u=e?Reflect.construct(n,m,p):this;return p.prototype.__constructor__&&p.prototype.__constructor__.apply(u,m),u};if(Object.setPrototypeOf(p.prototype,n.prototype),Object.setPrototypeOf(p,n),t){let m=Object.create(o);m.super=n;let u=t(m),a=Array.isArray(u)&&typeof u[0]?.[0]=="string"?u:[];for(let[y,g]of a)y==="constructor"?p.prototype.__constructor__=g:p.prototype[y]=g}return r&&(o[r]=p),p}));f("static",r=>(r=i(r),e=>[[jt,r(e)]]));f("//",(r,e)=>{let t=new RegExp(r,e||"");return()=>t});f("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 M=Symbol("break"),K=Symbol("continue");f("while",(r,e)=>(r=i(r),e=i(e),t=>{let o;for(;r(t);)try{o=e(t)}catch(n){if(n===M)break;if(n===K)continue;if(n===B)return n[0];throw n}return o}));f("do",(r,e)=>(r=i(r),e=i(e),t=>{let o;do try{o=r(t)}catch(n){if(n===M)break;if(n===K)continue;if(n===B)return n[0];throw n}while(e(t));return o}));f("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),p=>{let m;for(t?.(p);o(p);n?.(p))try{m=e(p)}catch(u){if(u===M)break;if(u===K)continue;if(u===B)return u[0];throw u}return m}}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 Jt(o,n,e);if(t==="of")return zt(o,n,e)}});var zt=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let p,m=o?null:n[r];for(let u of e(n)){o?G(r,u,n):n[r]=u;try{p=t(n)}catch(a){if(a===M)break;if(a===K)continue;if(a===B)return a[0];throw a}}return o||(n[r]=m),p}},Jt=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let p,m=o?null:n[r];for(let u in e(n)){o?G(r,u,n):n[r]=u;try{p=t(n)}catch(a){if(a===M)break;if(a===K)continue;if(a===B)return a[0];throw a}}return o||(n[r]=m),p}};f("break",()=>()=>{throw M});f("continue",()=>()=>{throw K});f("return",r=>(r=r!==void 0?i(r):null,e=>{throw B[0]=r?.(e),B}));f("try",(r,...e)=>{r=r?i(r):null;let t=e.find(u=>u?.[0]==="catch"),o=e.find(u=>u?.[0]==="finally"),n=t?.[1],p=t?.[2]?i(t[2]):null,m=o?.[1]?i(o[1]):null;return u=>{let a;try{a=r?.(u)}catch(y){if(y===M||y===K||y===B)throw y;if(n!=null&&p){let g=n in u,E=u[n];u[n]=y;try{a=p(u)}finally{g?u[n]=E:delete u[n]}}else if(!p)throw y}finally{m?.(u)}return a}});f("throw",r=>(r=i(r),e=>{throw r(e)}));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 o=r(t),n=!1,p;for(let[u,a]of e)if(n||u===null||u(t)===o)for(n=!0,m=0;m<a.length;m++)try{p=a[m](t)}catch(y){if(y===M)return p;throw y}var m;return p}):t=>r(t)));f("import",()=>()=>{});f("export",()=>()=>{});f("from",(r,e)=>()=>{});f("as",(r,e)=>()=>{});f("default",r=>i(r));var Ae=new WeakMap,Vt=(r,...e)=>typeof r=="string"?i(s(r)):Ae.get(r)||Ae.set(r,Yt(r,e)).get(r),ye=57344,Yt=(r,e)=>{let t=r.reduce((p,m,u)=>p+(u?String.fromCharCode(ye+u-1):"")+m,""),o=s(t),n=p=>{if(typeof p=="string"&&p.length===1){let m=p.charCodeAt(0)-ye,u;if(m>=0&&m<e.length)return u=e[m],Zt(u)?u:[,u]}return Array.isArray(p)?p.map(n):p};return i(n(o))},Zt=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),qt=Vt;export{ur as access,A as binary,i as compile,c as cur,qt as default,N as err,h as expr,j as group,xt as id,l as idx,C as keyword,H as literal,Lr as loc,I as lookup,Mr as member,fr as nary,k as next,f as operator,pr as operators,P as parens,s as parse,Y as peek,$ as prec,lr as propName,O as seek,d as skip,S as token,_ as unary,T as word};
|
package/justin.min.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var u,l,d=r=>(u=0,l=r,d.enter?.(),r=y(),l[u]?
|
|
1
|
+
var u,l,d=r=>(u=0,l=r,d.enter?.(),r=y(),l[u]?N():r||""),N=(r="Unexpected token",t=u,e=l.slice(0,t).split(`
|
|
2
2
|
`),o=e.pop(),i=l.slice(Math.max(0,t-40),t),p="\u032D",m=(l[t]||" ")+p,f=l.slice(t+1,t+20))=>{throw SyntaxError(`${r} at ${e.length+1}:${o.length+1}
|
|
3
3
|
${l[t-41]!==`
|
|
4
|
-
`,""+i}${m}${f}`)},
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},
|
|
6
|
-
`,"/*":"*/"};var
|
|
7
|
-
`)for(;l.charCodeAt(o)>=
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
4
|
+
`,""+i}${m}${f}`)},sr=(r,t=u)=>(Array.isArray(r)&&(r.loc=t),r),O=(r,t=u,e)=>{for(;e=r(l.charCodeAt(u));)u+=e;return l.slice(t,u)},C=(r=1)=>l[u+=r],M=r=>u=r,y=(r=0,t)=>{let e,o,i;for(t&&d.enter?.(r,t);(e=d.space())&&e!==t&&(i=d.step(o,r,e,y));)o=i;return t&&(e==t?(u++,d.exit?.(r,t)):N("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),o},pr=(r=u)=>{for(;l.charCodeAt(r)<=32;)r++;return l.charCodeAt(r)},Tt=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,mr=(r,t=r.length)=>l.substr(u,t)===r&&!d.id(l.charCodeAt(u+t)),Ut=()=>(C(),y(0,41)),w=[],ir={},I=(r,t=32,e,o=r.charCodeAt(0),i=r.length,p=w[o],m=r.toUpperCase()!==r,f,A)=>(t=ir[r]=!p&&ir[r]||t,w[o]=(h,S,g,E=u)=>(f=g,(g?r==g:(i<2||r.charCodeAt(1)===l.charCodeAt(u+1)&&(i<3||l.substr(u,i)==r))&&(!m||!d.id(l.charCodeAt(u+i)))&&(f=g=r))&&S<t&&(u+=i,(A=e(h))?sr(A,E):(u=E,f=0,!m&&!p&&!h&&N()),A)||p?.(h,S,f))),c=(r,t,e=!1)=>I(r,t,o=>o&&(i=>i&&[r,o,i])(y(t-(e?.5:0)))),k=(r,t,e)=>I(r,t,o=>e?o&&[r,o]:!o&&(o=y(t-.5))&&[r,o]),P=(r,t)=>I(r,200,e=>!e&&[,t]),J=(r,t,e)=>I(r,t,(o,i)=>(i=y(t-(e?.5:0)),o?.[0]!==r&&(o=[r,o||null]),i?.[0]===r?o.push(...i.slice(1)):o.push(i||null),o)),U=(r,t)=>I(r[0],t,e=>!e&&[r,y(0,r.charCodeAt(1))||null]),V=(r,t)=>I(r[0],t,e=>e&&[r,e,y(0,r.charCodeAt(1))||null]),Y=(r,t)=>(d.space(),t=l.charCodeAt(u),d.id(t)&&(t<48||t>57)?O(d.id):y(r)),fr=(r,t)=>I(r,t,e=>e&&(o=>o&&[r,e,o])(Y(t))),D=(r,t,e,o=r.charCodeAt(0),i=r.length,p=w[o],m)=>w[o]=(f,A,h,S=u)=>!f&&(h?r==h:(i<2||l.substr(u,i)==r)&&(h=r))&&A<t&&!d.id(l.charCodeAt(u+i))&&(!d.prop||d.prop(u+i))&&(M(u+i),(m=e())?sr(m,S):M(S),m)||p?.(f,A,h);d.space=r=>{for(;(r=l.charCodeAt(u))<=32;)u++;return r};d.step=(r,t,e,o,i)=>(i=w[e])&&i(r,t)||(r?null:O(d.id)||null);var z={},s=(r,t,e=z[r])=>z[r]=(...o)=>t(...o)||e?.(...o),n=r=>Array.isArray(r)?r[0]==null?(t=>()=>t)(r[1]):z[r[0]]?.(...r.slice(1))??N(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:t=>t?.[r];var G=46,_=48,X=57,ar=69,Br=101,Mr=43,Dr=45,F=95,ur=110,Fr=97,Gr=102,Xr=65,$r=70,lr=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),Z=r=>{let t=lr(O(e=>e===G&&l.charCodeAt(u+1)!==G||e>=_&&e<=X||e===F||((e===ar||e===Br)&&((e=l.charCodeAt(u+1))>=_&&e<=X||e===Mr||e===Dr)?2:0)));return l.charCodeAt(u)===ur?(C(),[,BigInt(t)]):(r=+t)!=r?N():[,r]},Qr={2:r=>r===48||r===49||r===F,8:r=>r>=48&&r<=55||r===F,16:r=>r>=_&&r<=X||r>=Fr&&r<=Gr||r>=Xr&&r<=$r||r===F};d.number=null;w[G]=r=>!r&&l.charCodeAt(u+1)!==G&&Z();for(let r=_;r<=X;r++)w[r]=t=>t?void 0:Z();w[_]=r=>{if(r)return;let t=d.number;if(t){for(let[e,o]of Object.entries(t))if(e[0]==="0"&&l[u+1]?.toLowerCase()===e[1]){C(2);let i=lr(O(Qr[o]));return l.charCodeAt(u)===ur?(C(),[,BigInt("0"+e[1]+i)]):[,parseInt(i,o)]}}return Z()};var Hr=92,cr=34,dr=39,Ar=117,hr=120,jr=123,Kr=125,gr=10,Wr=13,zr={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},yr=r=>r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:-1,Cr=r=>(t,e,o="",i=String.fromCharCode(r))=>{if(t||!d.string?.[i])return;C();let p=()=>{let m=l.charCodeAt(u+1);if(m===gr)return 2;if(m===Wr)return l.charCodeAt(u+2)===gr?3:2;if(m===hr||m===Ar&&l.charCodeAt(u+2)!==jr){let f=m===hr?2:4,A=0,h;for(let S=0;S<f;S++){if((h=yr(l.charCodeAt(u+2+S)))<0)return o+=l[u+1],2;A=A*16+h}return o+=String.fromCharCode(A),2+f}if(m===Ar){let f=0,A=u+3,h;for(;(h=yr(l.charCodeAt(A)))>=0;)f=f*16+h,A++;return A>u+3&&f<=1114111&&l.charCodeAt(A)===Kr?(o+=String.fromCodePoint(f),A-u+1):(o+=l[u+1],2)}return o+=zr[l[u+1]]||l[u+1],2};return O(m=>m-r&&(m!==Hr?(o+=l[u],1):p())),l[u]===i?C():N("Bad string"),[,o]};w[cr]=Cr(cr);w[dr]=Cr(dr);d.string={'"':!0};var Jr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>c(r,Jr,!0));var Vr=30,Yr=40,Zr=140;k("!",Zr);c("||",Vr);c("&&",Yr);var qr=50,xr=60,br=70,Sr=100,rt=140;c("|",qr);c("&",br);c("^",xr);c(">>",Sr);c("<<",Sr);k("~",rt);var $=90;c("<",$);c(">",$);c("<=",$);c(">=",$);var Er=80;c("==",Er);c("!=",Er);var wr=110,q=120,Ir=140;c("+",wr);c("-",wr);c("*",q);c("/",q);c("%",q);k("+",Ir);k("-",Ir);var Q=150;I("++",Q,r=>r?["++",r,null]:["++",y(Q-1)]);I("--",Q,r=>r?["--",r,null]:["--",y(Q-1)]);var tt=5,et=10;J(",",et);J(";",tt,!0);var ot=170;U("()",ot);var x=170;V("[]",x);fr(".",x);V("()",x);var nt=32,it=d.space;d.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};var b;d.space=()=>{b||(b=Object.entries(d.comment).map(([i,p])=>[i,p,i.charCodeAt(0)]));for(var r;r=it();){for(var t=0,e;e=b[t++];)if(r===e[2]&&l.substr(u,e[0].length)===e[0]){var o=u+e[0].length;if(e[1]===`
|
|
7
|
+
`)for(;l.charCodeAt(o)>=nt;)o++;else{for(;l[o]&&l.substr(o,e[1].length)!==e[1];)o++;l[o]&&(o+=e[1].length)}M(o),r=0;break}if(r)return r}return r};var kr=80;c("===",kr);c("!==",kr);var st=30;c("??",st);var pt=130,mt=20;c("**",pt,!0);c("**=",mt,!0);var Nr=90;c("in",Nr);c("of",Nr);var ft=20,ut=100;c(">>>",ut);c(">>>=",ft,!0);var rr=20;c("||=",rr,!0);c("&&=",rr,!0);c("??=",rr,!0);P("true",!0);P("false",!1);P("null",null);D("undefined",200,()=>[]);P("NaN",NaN);P("Infinity",1/0);var tr=20;I("?",tr,(r,t,e)=>r&&(t=y(tr-1))&&O(o=>o===58)&&(e=y(tr-1),["?",r,t,e]));var lt=20;c("=>",lt,!0);var ct=20;k("...",ct);var vr=170;I("?.",vr,(r,t)=>{if(!r)return;let e=d.space();return e===40?(C(),["?.()",r,y(0,41)||null]):e===91?(C(),["?.[]",r,y(0,93)]):(t=Y(vr),t?["?.",r,t]:void 0)});var a=140;k("typeof",a);k("void",a);k("delete",a);D("new",a,()=>mr(".target")?(C(7),["new.target"]):["new",y(a)]);var dt=20,Or=200;d.prop=r=>pr(r)!==58;U("[]",Or);U("{}",Or);c(":",dt-1,!0);var At=170,H=96,ht=36,gt=123,yt=92,Ct={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Rr=()=>{let r=[];for(let t="",e;(e=l.charCodeAt(u))!==H;)e?e===yt?(C(),t+=Ct[l[u]]||l[u],C()):e===ht&&l.charCodeAt(u+1)===gt?(t&&r.push([,t]),t="",C(2),r.push(y(0,125))):(t+=l[u],C(),e=l.charCodeAt(u),e===H&&t&&r.push([,t])):N("Unterminated template");return C(),r},St=r=>r.length<2&&r[0]?.[0]===void 0?r[0]||[,""]:["`",...r],Et=w[H];w[H]=(r,t)=>r&&t<At?d.asi&&d.newline?void 0:(C(),["``",r,...Rr()]):r?Et?.(r,t):(C(),St(Rr()));d.string["'"]=!0;d.number={"0x":16,"0b":2,"0o":8};var Pr=(r,t,e,o)=>typeof r=="string"?i=>t(i,r,i):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o,i)):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i),i)):r[0]==="()"&&r.length===2?Pr(r[1],t):(()=>{throw Error("Invalid assignment target")})(),Lr={"=":(r,t,e)=>r[t]=e,"+=":(r,t,e)=>r[t]+=e,"-=":(r,t,e)=>r[t]-=e,"*=":(r,t,e)=>r[t]*=e,"/=":(r,t,e)=>r[t]/=e,"%=":(r,t,e)=>r[t]%=e,"|=":(r,t,e)=>r[t]|=e,"&=":(r,t,e)=>r[t]&=e,"^=":(r,t,e)=>r[t]^=e,">>=":(r,t,e)=>r[t]>>=e,"<<=":(r,t,e)=>r[t]<<=e};for(let r in Lr)s(r,(t,e)=>(e=n(e),Pr(t,(o,i,p)=>Lr[r](o,i,e(p)))));s("!",r=>(r=n(r),t=>!r(t)));s("||",(r,t)=>(r=n(r),t=n(t),e=>r(e)||t(e)));s("&&",(r,t)=>(r=n(r),t=n(t),e=>r(e)&&t(e)));s("~",r=>(r=n(r),t=>~r(t)));s("|",(r,t)=>(r=n(r),t=n(t),e=>r(e)|t(e)));s("&",(r,t)=>(r=n(r),t=n(t),e=>r(e)&t(e)));s("^",(r,t)=>(r=n(r),t=n(t),e=>r(e)^t(e)));s(">>",(r,t)=>(r=n(r),t=n(t),e=>r(e)>>t(e)));s("<<",(r,t)=>(r=n(r),t=n(t),e=>r(e)<<t(e)));s(">",(r,t)=>(r=n(r),t=n(t),e=>r(e)>t(e)));s("<",(r,t)=>(r=n(r),t=n(t),e=>r(e)<t(e)));s(">=",(r,t)=>(r=n(r),t=n(t),e=>r(e)>=t(e)));s("<=",(r,t)=>(r=n(r),t=n(t),e=>r(e)<=t(e)));s("==",(r,t)=>(r=n(r),t=n(t),e=>r(e)==t(e)));s("!=",(r,t)=>(r=n(r),t=n(t),e=>r(e)!=t(e)));s("+",(r,t)=>t!==void 0?(r=n(r),t=n(t),e=>r(e)+t(e)):(r=n(r),e=>+r(e)));s("-",(r,t)=>t!==void 0?(r=n(r),t=n(t),e=>r(e)-t(e)):(r=n(r),e=>-r(e)));s("*",(r,t)=>(r=n(r),t=n(t),e=>r(e)*t(e)));s("/",(r,t)=>(r=n(r),t=n(t),e=>r(e)/t(e)));s("%",(r,t)=>(r=n(r),t=n(t),e=>r(e)%t(e)));var er=(r,t,e,o)=>typeof r=="string"?i=>t(i,r):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o)):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i))):r[0]==="()"&&r.length===2?er(r[1],t):(()=>{throw Error("Invalid increment target")})();s("++",(r,t)=>er(r,t===null?(e,o)=>e[o]++:(e,o)=>++e[o]));s("--",(r,t)=>er(r,t===null?(e,o)=>e[o]--:(e,o)=>--e[o]));var Tr=(...r)=>(r=r.map(n),t=>{let e;for(let o of r)e=o(t);return e});s(",",Tr);s(";",Tr);var R=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",j=r=>{throw Error(r)};s("[]",(r,t)=>t===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(e=>e==null?(()=>{}):e[0]==="..."?(e=n(e[1]),o=>e(o)):(e=n(e),o=>[e(o)])),e=>r.flatMap(o=>o(e))):(t==null&&j("Missing index"),r=n(r),t=n(t),e=>{let o=t(e);return R(o)?void 0:r(e)[o]}));s(".",(r,t)=>(r=n(r),t=t[0]?t:t[1],R(t)?()=>{}:e=>r(e)[t]));s("()",(r,t)=>{if(t===void 0)return r==null?j("Empty ()"):n(r);let e=i=>i?.[0]===","&&i.slice(1).some(p=>p==null||e(p));e(t)&&j("Empty argument");let o=t?t[0]===","?(t=t.slice(1).map(n),i=>t.map(p=>p(i))):(t=n(t),i=>[t(i)]):()=>[];return or(r,(i,p,m)=>i[p](...o(m)))});var v=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&v(r[1])||r[0]==="{}"),or=(r,t,e,o)=>r==null?j("Empty ()"):r[0]==="()"&&r.length==2?or(r[1],t):typeof r=="string"?i=>t(i,r,i):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o,i)):r[0]==="?."?(e=n(r[1]),o=r[2],i=>{let p=e(i);return p==null?void 0:t(p,o,i)}):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i),i)):r[0]==="?.[]"?(e=n(r[1]),o=n(r[2]),i=>{let p=e(i);return p==null?void 0:t(p,o(i),i)}):(r=n(r),i=>t([r(i)],0,i)),L=or;s("===",(r,t)=>(r=n(r),t=n(t),e=>r(e)===t(e)));s("!==",(r,t)=>(r=n(r),t=n(t),e=>r(e)!==t(e)));s("??",(r,t)=>(r=n(r),t=n(t),e=>r(e)??t(e)));var wt=r=>{throw Error(r)};s("**",(r,t)=>(r=n(r),t=n(t),e=>r(e)**t(e)));s("**=",(r,t)=>(v(r)||wt("Invalid assignment target"),t=n(t),L(r,(e,o,i)=>e[o]**=t(i))));s("in",(r,t)=>(r=n(r),t=n(t),e=>r(e)in t(e)));var It=r=>{throw Error(r)};s(">>>",(r,t)=>(r=n(r),t=n(t),e=>r(e)>>>t(e)));s(">>>=",(r,t)=>(v(r)||It("Invalid assignment target"),t=n(t),L(r,(e,o,i)=>e[o]>>>=t(i))));var kt=r=>r[0]?.[0]===","?r[0].slice(1):r,B=(r,t,e)=>{if(typeof r=="string"){e[r]=t;return}let[o,...i]=r,p=kt(i);if(o==="{}"){let m=[];for(let f of p){if(Array.isArray(f)&&f[0]==="..."){let E={};for(let T in t)m.includes(T)||(E[T]=t[T]);e[f[1]]=E;break}let A,h,S;typeof f=="string"?A=h=f:f[0]==="="?(typeof f[1]=="string"?A=h=f[1]:[,A,h]=f[1],S=f[2]):[,A,h]=f,m.push(A);let g=t[A];g===void 0&&S&&(g=n(S)(e)),B(h,g,e)}}else if(o==="[]"){let m=0;for(let f of p){if(f===null){m++;continue}if(Array.isArray(f)&&f[0]==="..."){e[f[1]]=t.slice(m);break}let A=f,h;Array.isArray(f)&&f[0]==="="&&([,A,h]=f);let S=t[m++];S===void 0&&h&&(S=n(h)(e)),B(A,S,e)}}},nr=(...r)=>(r=r.map(t=>{if(typeof t=="string")return e=>{e[t]=void 0};if(t[0]==="="){let[,e,o]=t,i=n(o);return typeof e=="string"?p=>{p[e]=i(p)}:p=>B(e,i(p),p)}return n(t)}),t=>{for(let e of r)e(t)});s("let",nr);s("const",nr);s("var",nr);var K=r=>{throw Error(r)};s("=",(r,t)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let e=r[1];return t=n(t),typeof e=="string"?o=>{o[e]=t(o)}:o=>B(e,t(o),o)}return v(r)||K("Invalid assignment target"),t=n(t),L(r,(e,o,i)=>e[o]=t(i))});s("||=",(r,t)=>(v(r)||K("Invalid assignment target"),t=n(t),L(r,(e,o,i)=>e[o]||=t(i))));s("&&=",(r,t)=>(v(r)||K("Invalid assignment target"),t=n(t),L(r,(e,o,i)=>e[o]&&=t(i))));s("??=",(r,t)=>(v(r)||K("Invalid assignment target"),t=n(t),L(r,(e,o,i)=>e[o]??=t(i))));s("?",(r,t,e)=>(r=n(r),t=n(t),e=n(e),o=>r(o)?t(o):e(o)));var Nt=[];s("=>",(r,t)=>{r=r?.[0]==="()"?r[1]:r;let e=r?r[0]===","?r.slice(1):[r]:[],o=-1,i=null,p=e[e.length-1];Array.isArray(p)&&p[0]==="..."&&(o=e.length-1,i=p[1],e.length--);let m=t?.[0]==="{}";return t=n(m?["{",t[1]]:t),f=>(...A)=>{let h={};e.forEach((g,E)=>h[g]=A[E]),i&&(h[i]=A.slice(o));let S=new Proxy(h,{get:(g,E)=>E in g?g[E]:f?.[E],set:(g,E,T)=>((E in g?g:f)[E]=T,!0),has:(g,E)=>E in g||(f?E in f:!1)});try{let g=t(S);return m?void 0:g}catch(g){if(g===Nt)return g[0];throw g}}});s("...",r=>(r=n(r),t=>Object.entries(r(t))));s("?.",(r,t)=>(r=n(r),R(t)?()=>{}:e=>r(e)?.[t]));s("?.[]",(r,t)=>(r=n(r),t=n(t),e=>{let o=t(e);return R(o)?void 0:r(e)?.[o]}));s("?.()",(r,t)=>{let e=t?t[0]===","?(t=t.slice(1).map(n),i=>t.map(p=>p(i))):(t=n(t),i=>[t(i)]):()=>[];if(r[0]==="?."){let i=n(r[1]),p=r[2];return R(p)?()=>{}:m=>i(m)?.[p]?.(...e(m))}if(r[0]==="?.[]"){let i=n(r[1]),p=n(r[2]);return m=>{let f=i(m),A=p(m);return R(A)?void 0:f?.[A]?.(...e(m))}}if(r[0]==="."){let i=n(r[1]),p=r[2];return R(p)?()=>{}:m=>i(m)?.[p]?.(...e(m))}if(r[0]==="[]"&&r.length===3){let i=n(r[1]),p=n(r[2]);return m=>{let f=i(m),A=p(m);return R(A)?void 0:f?.[A]?.(...e(m))}}let o=n(r);return i=>o(i)?.(...e(i))});s("typeof",r=>(r=n(r),t=>typeof r(t)));s("void",r=>(r=n(r),t=>(r(t),void 0)));s("delete",r=>{if(r[0]==="."){let t=n(r[1]),e=r[2];return o=>delete t(o)[e]}if(r[0]==="[]"){let t=n(r[1]),e=n(r[2]);return o=>delete t(o)[e(o)]}return()=>!0});s("new",r=>{let t=n(r?.[0]==="()"?r[1]:r),e=r?.[0]==="()"?r[2]:null,o=e?e[0]===","?(i=>p=>i.map(m=>m(p)))(e.slice(1).map(n)):(i=>p=>[i(p)])(n(e)):()=>[];return i=>new(t(i))(...o(i))});var W=Symbol("accessor");s("get",(r,t)=>(t=t?n(t):()=>{},e=>[[W,r,{get:function(){let o=Object.create(e||{});return o.this=this,t(o)}}]]));s("set",(r,t,e)=>(e=e?n(e):()=>{},o=>[[W,r,{set:function(i){let p=Object.create(o||{});p.this=this,p[t]=i,e(p)}}]]));var vt=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);s("{}",(r,t)=>{if(t!==void 0)return;if(!vt(r))return n(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let e=r.map(o=>n(typeof o=="string"?[":",o,o]:o));return o=>{let i={},p={};for(let m of e.flatMap(f=>f(o)))if(m[0]===W){let[,f,A]=m;p[f]={...p[f],...A,configurable:!0,enumerable:!0}}else i[m[0]]=m[1];for(let m in p)Object.defineProperty(i,m,p[m]);return i}});s("{",r=>(r=r?n(r):()=>{},t=>r(Object.create(t))));s(":",(r,t)=>(t=n(t),Array.isArray(r)?(r=n(r),e=>[[r(e),t(e)]]):e=>[[r,t(e)]]));s("`",(...r)=>(r=r.map(n),t=>r.map(e=>e(t)).join("")));s("``",(r,...t)=>{r=n(r);let e=[],o=[];for(let p of t)Array.isArray(p)&&p[0]===void 0?e.push(p[1]):o.push(n(p));let i=Object.assign([...e],{raw:e});return p=>r(p)(i,...o.map(m=>m(p)))});var Ur=new WeakMap,Ot=(r,...t)=>typeof r=="string"?n(d(r)):Ur.get(r)||Ur.set(r,Rt(r,t)).get(r),_r=57344,Rt=(r,t)=>{let e=r.reduce((p,m,f)=>p+(f?String.fromCharCode(_r+f-1):"")+m,""),o=d(e),i=p=>{if(typeof p=="string"&&p.length===1){let m=p.charCodeAt(0)-_r,f;if(m>=0&&m<t.length)return f=t[m],Lt(f)?f:[,f]}return Array.isArray(p)?p.map(i):p};return n(i(o))},Lt=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Pt=Ot;export{V as access,c as binary,n as compile,l as cur,Pt as default,N as err,y as expr,U as group,Tt as id,u as idx,D as keyword,P as literal,sr as loc,w as lookup,fr as member,J as nary,O as next,s as operator,z as operators,Ut as parens,d as parse,pr as peek,ir as prec,Y as propName,M as seek,C as skip,I as token,k as unary,mr as word};
|
package/package.json
CHANGED
package/parse.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
// Pratt parser core + operator registry + compile
|
|
1
|
+
// Pratt parser core + operator registry + compile.
|
|
2
|
+
//
|
|
3
|
+
// Language-agnostic by design: the core (token / lookup / prec / the expr loop)
|
|
4
|
+
// assumes no particular language. The registrars below — binary, unary, nary,
|
|
5
|
+
// literal, group, access, member, keyword — are a shared toolkit of common
|
|
6
|
+
// operator *shapes*; each is parameterized by operator string + precedence, so a
|
|
7
|
+
// dialect composes its grammar from them. Keep language-specific rules in
|
|
8
|
+
// feature/*, not here.
|
|
9
|
+
|
|
2
10
|
// Character codes
|
|
3
11
|
const SPACE = 32;
|
|
4
12
|
|
|
@@ -116,6 +124,16 @@ export let idx, cur,
|
|
|
116
124
|
|
|
117
125
|
access = (op, p) => token(op[0], p, a => (a && [op, a, expr(0, op.charCodeAt(1)) || null])),
|
|
118
126
|
|
|
127
|
+
// propName(p) - parse the right side of a name-access operator. A bare name
|
|
128
|
+
// beats keyword/operator matching, so reserved words read as plain identifiers
|
|
129
|
+
// (a.class). Non-name starts (digit, #, ...) fall back to expr(p), keeping the
|
|
130
|
+
// door open for any dialect-defined token there. Uses the live parse.id.
|
|
131
|
+
propName = (p, c) => (parse.space(), c = cur.charCodeAt(idx), parse.id(c) && (c < 48 || c > 57) ? next(parse.id) : expr(p)),
|
|
132
|
+
|
|
133
|
+
// member(op, p) - binary operator whose right side is a name, not an expression
|
|
134
|
+
// (a.b, a::b, a->b). Same [op, a, b] shape as binary().
|
|
135
|
+
member = (op, p) => token(op, p, a => a && (b => b && [op, a, b])(propName(p))),
|
|
136
|
+
|
|
119
137
|
// keyword(op, prec, fn) - prefix word token with property name support
|
|
120
138
|
// parse.prop set by collection.js to prevent matching {keyword: value}
|
|
121
139
|
keyword = (op, prec, map, c = op.charCodeAt(0), l = op.length, prev = lookup[c], r) =>
|
package/subscript.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export function literal(op: string, val: any): void;
|
|
|
28
28
|
export function nary(op: string, prec: number, right?: boolean): void;
|
|
29
29
|
export function group(op: string, prec: number): void;
|
|
30
30
|
export function access(op: string, prec: number): void;
|
|
31
|
+
export function member(op: string, prec: number): void;
|
|
32
|
+
export function propName(prec: number): AST;
|
|
31
33
|
|
|
32
34
|
// Compile exports
|
|
33
35
|
export const operators: Record<string, Operator>;
|
package/subscript.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var s,p,
|
|
2
|
-
`),o=e.pop(),n=p.slice(Math.max(0,t-40),t),
|
|
1
|
+
var s,p,f=r=>(s=0,p=r,f.enter?.(),r=g(),p[s]?S():r||""),S=(r="Unexpected token",t=s,e=p.slice(0,t).split(`
|
|
2
|
+
`),o=e.pop(),n=p.slice(Math.max(0,t-40),t),l="\u032D",u=(p[t]||" ")+l,d=p.slice(t+1,t+20))=>{throw SyntaxError(`${r} at ${e.length+1}:${o.length+1}
|
|
3
3
|
${p[t-41]!==`
|
|
4
|
-
`,""+n}${
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},
|
|
4
|
+
`,""+n}${u}${d}`)},W=(r,t=s)=>(Array.isArray(r)&&(r.loc=t),r),_=(r,t=s,e)=>{for(;e=r(p.charCodeAt(s));)s+=e;return p.slice(t,s)},w=(r=1)=>p[s+=r],v=r=>s=r,g=(r=0,t)=>{let e,o,n;for(t&&f.enter?.(r,t);(e=f.space())&&e!==t&&(n=f.step(o,r,e,g));)o=n;return t&&(e==t?(s++,f.exit?.(r,t)):S("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),o},vr=(r=s)=>{for(;p.charCodeAt(r)<=32;)r++;return p.charCodeAt(r)},Gr=f.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,Wr=(r,t=r.length)=>p.substr(s,t)===r&&!f.id(p.charCodeAt(s+t)),zr=()=>(w(),g(0,41)),c=[],G={},y=(r,t=32,e,o=r.charCodeAt(0),n=r.length,l=c[o],u=r.toUpperCase()!==r,d,h)=>(t=G[r]=!l&&G[r]||t,c[o]=(C,E,U,H=s)=>(d=U,(U?r==U:(n<2||r.charCodeAt(1)===p.charCodeAt(s+1)&&(n<3||p.substr(s,n)==r))&&(!u||!f.id(p.charCodeAt(s+n)))&&(d=U=r))&&E<t&&(s+=n,(h=e(C))?W(h,H):(s=H,d=0,!u&&!l&&!C&&S()),h)||l?.(C,E,d))),A=(r,t,e=!1)=>y(r,t,o=>o&&(n=>n&&[r,o,n])(g(t-(e?.5:0)))),I=(r,t,e)=>y(r,t,o=>e?o&&[r,o]:!o&&(o=g(t-.5))&&[r,o]),Jr=(r,t)=>y(r,200,e=>!e&&[,t]),F=(r,t,e)=>y(r,t,(o,n)=>(n=g(t-(e?.5:0)),o?.[0]!==r&&(o=[r,o||null]),n?.[0]===r?o.push(...n.slice(1)):o.push(n||null),o)),z=(r,t)=>y(r[0],t,e=>!e&&[r,g(0,r.charCodeAt(1))||null]),$=(r,t)=>y(r[0],t,e=>e&&[r,e,g(0,r.charCodeAt(1))||null]),fr=(r,t)=>(f.space(),t=p.charCodeAt(s),f.id(t)&&(t<48||t>57)?_(f.id):g(r)),J=(r,t)=>y(r,t,e=>e&&(o=>o&&[r,e,o])(fr(t))),Kr=(r,t,e,o=r.charCodeAt(0),n=r.length,l=c[o],u)=>c[o]=(d,h,C,E=s)=>!d&&(C?r==C:(n<2||p.substr(s,n)==r)&&(C=r))&&h<t&&!f.id(p.charCodeAt(s+n))&&(!f.prop||f.prop(s+n))&&(v(s+n),(u=e())?W(u,E):v(E),u)||l?.(d,h,C);f.space=r=>{for(;(r=p.charCodeAt(s))<=32;)s++;return r};f.step=(r,t,e,o,n)=>(n=c[e])&&n(r,t)||(r?null:_(f.id)||null);var N={},m=(r,t,e=N[r])=>N[r]=(...o)=>t(...o)||e?.(...o),i=r=>Array.isArray(r)?r[0]==null?(t=>()=>t)(r[1]):N[r[0]]?.(...r.slice(1))??S(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:t=>t?.[r];var T=46,R=48,k=57,dr=69,Ar=101,hr=43,Cr=45,P=95,K=110,cr=97,gr=102,yr=65,Er=70,V=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),B=r=>{let t=V(_(e=>e===T&&p.charCodeAt(s+1)!==T||e>=R&&e<=k||e===P||((e===dr||e===Ar)&&((e=p.charCodeAt(s+1))>=R&&e<=k||e===hr||e===Cr)?2:0)));return p.charCodeAt(s)===K?(w(),[,BigInt(t)]):(r=+t)!=r?S():[,r]},Sr={2:r=>r===48||r===49||r===P,8:r=>r>=48&&r<=55||r===P,16:r=>r>=R&&r<=k||r>=cr&&r<=gr||r>=yr&&r<=Er||r===P};f.number=null;c[T]=r=>!r&&p.charCodeAt(s+1)!==T&&B();for(let r=R;r<=k;r++)c[r]=t=>t?void 0:B();c[R]=r=>{if(r)return;let t=f.number;if(t){for(let[e,o]of Object.entries(t))if(e[0]==="0"&&p[s+1]?.toLowerCase()===e[1]){w(2);let n=V(_(Sr[o]));return p.charCodeAt(s)===K?(w(),[,BigInt("0"+e[1]+n)]):[,parseInt(n,o)]}}return B()};var wr=92,Y=34,Z=39,q=117,x=120,_r=123,Ir=125,j=10,Rr=13,Ur={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v",0:"\0"},a=r=>r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:-1,b=r=>(t,e,o="",n=String.fromCharCode(r))=>{if(t||!f.string?.[n])return;w();let l=()=>{let u=p.charCodeAt(s+1);if(u===j)return 2;if(u===Rr)return p.charCodeAt(s+2)===j?3:2;if(u===x||u===q&&p.charCodeAt(s+2)!==_r){let d=u===x?2:4,h=0,C;for(let E=0;E<d;E++){if((C=a(p.charCodeAt(s+2+E)))<0)return o+=p[s+1],2;h=h*16+C}return o+=String.fromCharCode(h),2+d}if(u===q){let d=0,h=s+3,C;for(;(C=a(p.charCodeAt(h)))>=0;)d=d*16+C,h++;return h>s+3&&d<=1114111&&p.charCodeAt(h)===Ir?(o+=String.fromCodePoint(d),h-s+1):(o+=p[s+1],2)}return o+=Ur[p[s+1]]||p[s+1],2};return _(u=>u-r&&(u!==wr?(o+=p[s],1):l())),p[s]===n?w():S("Bad string"),[,o]};c[Y]=b(Y);c[Z]=b(Z);f.string={'"':!0};var Pr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>A(r,Pr,!0));var Tr=30,kr=40,Lr=140;I("!",Lr);A("||",Tr);A("&&",kr);var Dr=50,Mr=60,Nr=70,rr=100,Fr=140;A("|",Dr);A("&",Nr);A("^",Mr);A(">>",rr);A("<<",rr);I("~",Fr);var L=90;A("<",L);A(">",L);A("<=",L);A(">=",L);var tr=80;A("==",tr);A("!=",tr);var er=110,X=120,or=140;A("+",er);A("-",er);A("*",X);A("/",X);A("%",X);I("+",or);I("-",or);var D=150;y("++",D,r=>r?["++",r,null]:["++",g(D-1)]);y("--",D,r=>r?["--",r,null]:["--",g(D-1)]);var $r=5,Br=10;F(",",Br);F(";",$r,!0);var Xr=170;z("()",Xr);var O=170;$("[]",O);J(".",O);$("()",O);var ir=(r,t,e,o)=>typeof r=="string"?n=>t(n,r,n):r[0]==="."?(e=i(r[1]),o=r[2],n=>t(e(n),o,n)):r[0]==="[]"&&r.length===3?(e=i(r[1]),o=i(r[2]),n=>t(e(n),o(n),n)):r[0]==="()"&&r.length===2?ir(r[1],t):(()=>{throw Error("Invalid assignment target")})(),nr={"=":(r,t,e)=>r[t]=e,"+=":(r,t,e)=>r[t]+=e,"-=":(r,t,e)=>r[t]-=e,"*=":(r,t,e)=>r[t]*=e,"/=":(r,t,e)=>r[t]/=e,"%=":(r,t,e)=>r[t]%=e,"|=":(r,t,e)=>r[t]|=e,"&=":(r,t,e)=>r[t]&=e,"^=":(r,t,e)=>r[t]^=e,">>=":(r,t,e)=>r[t]>>=e,"<<=":(r,t,e)=>r[t]<<=e};for(let r in nr)m(r,(t,e)=>(e=i(e),ir(t,(o,n,l)=>nr[r](o,n,e(l)))));m("!",r=>(r=i(r),t=>!r(t)));m("||",(r,t)=>(r=i(r),t=i(t),e=>r(e)||t(e)));m("&&",(r,t)=>(r=i(r),t=i(t),e=>r(e)&&t(e)));m("~",r=>(r=i(r),t=>~r(t)));m("|",(r,t)=>(r=i(r),t=i(t),e=>r(e)|t(e)));m("&",(r,t)=>(r=i(r),t=i(t),e=>r(e)&t(e)));m("^",(r,t)=>(r=i(r),t=i(t),e=>r(e)^t(e)));m(">>",(r,t)=>(r=i(r),t=i(t),e=>r(e)>>t(e)));m("<<",(r,t)=>(r=i(r),t=i(t),e=>r(e)<<t(e)));m(">",(r,t)=>(r=i(r),t=i(t),e=>r(e)>t(e)));m("<",(r,t)=>(r=i(r),t=i(t),e=>r(e)<t(e)));m(">=",(r,t)=>(r=i(r),t=i(t),e=>r(e)>=t(e)));m("<=",(r,t)=>(r=i(r),t=i(t),e=>r(e)<=t(e)));m("==",(r,t)=>(r=i(r),t=i(t),e=>r(e)==t(e)));m("!=",(r,t)=>(r=i(r),t=i(t),e=>r(e)!=t(e)));m("+",(r,t)=>t!==void 0?(r=i(r),t=i(t),e=>r(e)+t(e)):(r=i(r),e=>+r(e)));m("-",(r,t)=>t!==void 0?(r=i(r),t=i(t),e=>r(e)-t(e)):(r=i(r),e=>-r(e)));m("*",(r,t)=>(r=i(r),t=i(t),e=>r(e)*t(e)));m("/",(r,t)=>(r=i(r),t=i(t),e=>r(e)/t(e)));m("%",(r,t)=>(r=i(r),t=i(t),e=>r(e)%t(e)));var Q=(r,t,e,o)=>typeof r=="string"?n=>t(n,r):r[0]==="."?(e=i(r[1]),o=r[2],n=>t(e(n),o)):r[0]==="[]"&&r.length===3?(e=i(r[1]),o=i(r[2]),n=>t(e(n),o(n))):r[0]==="()"&&r.length===2?Q(r[1],t):(()=>{throw Error("Invalid increment target")})();m("++",(r,t)=>Q(r,t===null?(e,o)=>e[o]++:(e,o)=>++e[o]));m("--",(r,t)=>Q(r,t===null?(e,o)=>e[o]--:(e,o)=>--e[o]));var sr=(...r)=>(r=r.map(i),t=>{let e;for(let o of r)e=o(t);return e});m(",",sr);m(";",sr);var pr=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",M=r=>{throw Error(r)};m("[]",(r,t)=>t===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(e=>e==null?(()=>{}):e[0]==="..."?(e=i(e[1]),o=>e(o)):(e=i(e),o=>[e(o)])),e=>r.flatMap(o=>o(e))):(t==null&&M("Missing index"),r=i(r),t=i(t),e=>{let o=t(e);return pr(o)?void 0:r(e)[o]}));m(".",(r,t)=>(r=i(r),t=t[0]?t:t[1],pr(t)?()=>{}:e=>r(e)[t]));m("()",(r,t)=>{if(t===void 0)return r==null?M("Empty ()"):i(r);let e=n=>n?.[0]===","&&n.slice(1).some(l=>l==null||e(l));e(t)&&M("Empty argument");let o=t?t[0]===","?(t=t.slice(1).map(i),n=>t.map(l=>l(n))):(t=i(t),n=>[t(n)]):()=>[];return mr(r,(n,l,u)=>n[l](...o(u)))});var mr=(r,t,e,o)=>r==null?M("Empty ()"):r[0]==="()"&&r.length==2?mr(r[1],t):typeof r=="string"?n=>t(n,r,n):r[0]==="."?(e=i(r[1]),o=r[2],n=>t(e(n),o,n)):r[0]==="?."?(e=i(r[1]),o=r[2],n=>{let l=e(n);return l==null?void 0:t(l,o,n)}):r[0]==="[]"&&r.length===3?(e=i(r[1]),o=i(r[2]),n=>t(e(n),o(n),n)):r[0]==="?.[]"?(e=i(r[1]),o=i(r[2]),n=>{let l=e(n);return l==null?void 0:t(l,o(n),n)}):(r=i(r),n=>t([r(n)],0,n));var lr=new WeakMap,Or=(r,...t)=>typeof r=="string"?i(f(r)):lr.get(r)||lr.set(r,Qr(r,t)).get(r),ur=57344,Qr=(r,t)=>{let e=r.reduce((l,u,d)=>l+(d?String.fromCharCode(ur+d-1):"")+u,""),o=f(e),n=l=>{if(typeof l=="string"&&l.length===1){let u=l.charCodeAt(0)-ur,d;if(u>=0&&u<t.length)return d=t[u],Hr(d)?d:[,d]}return Array.isArray(l)?l.map(n):l};return i(n(o))},Hr=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Wt=Or;export{$ as access,A as binary,i as compile,p as cur,Wt as default,S as err,g as expr,z as group,Gr as id,s as idx,Kr as keyword,Jr as literal,W as loc,c as lookup,J as member,F as nary,_ as next,m as operator,N as operators,zr as parens,f as parse,vr as peek,G as prec,fr as propName,v as seek,w as skip,y as token,I as unary,Wr as word};
|