subscript 10.0.1 → 10.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/feature/block.js +1 -4
- package/jessie.min.js +4 -4
- package/package.json +1 -1
- package/util/stringify.js +2 -5
package/feature/block.js
CHANGED
|
@@ -35,7 +35,4 @@ export const block = () =>
|
|
|
35
35
|
|
|
36
36
|
// body() - parse { body } or single statement
|
|
37
37
|
export const body = () =>
|
|
38
|
-
space() !== OBRACE ? expr(STATEMENT + .5) : (skip(),
|
|
39
|
-
|
|
40
|
-
// Compile
|
|
41
|
-
operator('block', body => body === undefined ? () => {} : (body = compile(body), ctx => body(ctx)));
|
|
38
|
+
space() !== OBRACE ? expr(STATEMENT + .5) : (skip(), expr(STATEMENT - .5, CBRACE) || null);
|
package/jessie.min.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var u,c,m=r=>(u=0,c=r,m.newline=!1,r=A(),c[u]?I():r||""),I=(r="Unexpected token",e=u,t=c.slice(0,e).split(`
|
|
2
2
|
`),o=t.pop(),n=c.slice(Math.max(0,e-40),e),s="\u032D",f=(c[e]||"\u2205")+s,l=c.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
|
|
3
3
|
${(c[e-41]!==`
|
|
4
|
-
`?"...":"")+n}${f}${l}`)},V=(r,e=u)=>(Array.isArray(r)&&(r.loc=e),r),k=(r,e=u,t)=>{for(;t=r(c.charCodeAt(u));)u+=t;return c.slice(e,u)},g=(r=1)=>c[u+=r],G=r=>u=r,A=(r=0,e)=>{let t,o,n,s,f=m.reserved,l;for(e&&m.asi&&(m.newline=!1),m.reserved=0;(t=m.space())&&(l=m.newline,1)&&t!==e&&(n=((s=w[t])&&s(o,r))??(m.asi&&o&&l&&(n=m.asi(o,r,A)))??(!o&&!m.reserved&&k(m.id)));)o=n,m.reserved=0;return m.reserved=f,e&&(t==e?u++:I("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Ir=r=>(e,t,o="")=>{if(!(e||!m.string?.[String.fromCharCode(r)]))return g(),k(n=>n-r&&(n===fe?(o+=le[c[u+1]]||c[u+1],2):(o+=c[u],1))),c[u]===String.fromCharCode(r)?g():I("Bad string"),[,o]};w[vr]=Ir(vr);w[Tr]=Ir(Tr);m.string={'"':!0};var ue=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>d(r,ue,!0));var Rr=(r,e,t,o)=>typeof r=="string"?n=>e(n,r,n):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o,n)):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n),n)):r[0]==="()"&&r.length===2?Rr(r[1],e):(()=>{throw Error("Invalid assignment target")})(),Nr={"=":(r,e,t)=>r[e]=t,"+=":(r,e,t)=>r[e]+=t,"-=":(r,e,t)=>r[e]-=t,"*=":(r,e,t)=>r[e]*=t,"/=":(r,e,t)=>r[e]/=t,"%=":(r,e,t)=>r[e]%=t,"|=":(r,e,t)=>r[e]|=t,"&=":(r,e,t)=>r[e]&=t,"^=":(r,e,t)=>r[e]^=t,">>=":(r,e,t)=>r[e]>>=t,"<<=":(r,e,t)=>r[e]<<=t};for(let r in Nr)p(r,(e,t)=>(t=i(t),Rr(e,(o,n,s)=>Nr[r](o,n,t(s)))));var me=30,ce=40,_r=140;d("!",_r);v("!",_r);d("||",me);d("&&",ce);p("!",r=>(r=i(r),e=>!r(e)));p("||",(r,e)=>(r=i(r),e=i(e),t=>r(t)||e(t)));p("&&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&&e(t)));var de=50,Ae=60,
|
|
4
|
+
`?"...":"")+n}${f}${l}`)},V=(r,e=u)=>(Array.isArray(r)&&(r.loc=e),r),k=(r,e=u,t)=>{for(;t=r(c.charCodeAt(u));)u+=t;return c.slice(e,u)},g=(r=1)=>c[u+=r],G=r=>u=r,A=(r=0,e)=>{let t,o,n,s,f=m.reserved,l;for(e&&m.asi&&(m.newline=!1),m.reserved=0;(t=m.space())&&(l=m.newline,1)&&t!==e&&(n=((s=w[t])&&s(o,r))??(m.asi&&o&&l&&(n=m.asi(o,r,A)))??(!o&&!m.reserved&&k(m.id)));)o=n,m.reserved=0;return m.reserved=f,e&&(t==e?u++:I("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},y=m.space=(r,e=u)=>{for(;(r=c.charCodeAt(u))<=32;)m.asi&&r===10&&(m.newline=!0),u++;return r},mt=m.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,X=(r,e=r.length)=>c.substr(u,e)===r&&!m.id(c.charCodeAt(u+e)),N=()=>(g(),A(0,41)),w=[],S=(r,e=32,t,o=r.charCodeAt(0),n=r.length,s=w[o],f=r.toUpperCase()!==r,l,h)=>w[o]=(E,T,F,C=u)=>(l=F,(F?r==F:(n<2||r.charCodeAt(1)===c.charCodeAt(u+1)&&(n<3||c.substr(u,n)==r))&&(!f||!m.id(c.charCodeAt(u+n)))&&(l=F=r))&&T<e&&(u+=n,(h=t(E))?V(h,C):(u=C,l=0,f&&h!==!1&&(m.reserved=1),!f&&!s&&I()),h)||s?.(E,T,l)),d=(r,e,t=!1)=>S(r,e,(o,n)=>o&&(n=A(e-(t?.5:0)))&&[r,o,n]),v=(r,e,t)=>S(r,e,o=>t?o&&[r,o]:!o&&(o=A(e-.5))&&[r,o]),P=(r,e)=>S(r,200,t=>!t&&[,e]),sr=(r,e,t)=>{S(r,e,(o,n)=>(n=A(e-(t?.5:0)),o?.[0]!==r&&(o=[r,o||null]),n?.[0]===r?o.push(...n.slice(1)):o.push(n||null),o))},H=(r,e)=>S(r[0],e,t=>!t&&[r,A(0,r.charCodeAt(1))||null]),pr=(r,e)=>S(r[0],e,t=>t&&[r,t,A(0,r.charCodeAt(1))||null]),ir={},p=(r,e,t=ir[r])=>ir[r]=(...o)=>e(...o)||t?.(...o),i=r=>Array.isArray(r)?r[0]===void 0?(e=>()=>e)(r[1]):ir[r[0]]?.(...r.slice(1))??I(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var Y=46,j=48,Z=57,br=69,re=101,ee=43,te=45,oe=97,ne=102,ie=65,se=70,fr=r=>[,(r=+k(e=>e===Y&&c.charCodeAt(u+1)!==Y||e>=j&&e<=Z||((e===br||e===re)&&((e=c.charCodeAt(u+1))>=j&&e<=Z||e===ee||e===te)?2:0)))!=r?I():r],pe={2:r=>r===48||r===49,8:r=>r>=48&&r<=55,16:r=>r>=j&&r<=Z||r>=oe&&r<=ne||r>=ie&&r<=se};m.number=null;w[Y]=r=>!r&&c.charCodeAt(u+1)!==Y&&fr();for(let r=j;r<=Z;r++)w[r]=e=>e?void 0:fr();w[j]=r=>{if(r)return;let e=m.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&c[u+1]?.toLowerCase()===t[1])return g(2),[,parseInt(k(pe[o]),o)]}return fr()};var fe=92,vr=34,Tr=39,le={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Ir=r=>(e,t,o="")=>{if(!(e||!m.string?.[String.fromCharCode(r)]))return g(),k(n=>n-r&&(n===fe?(o+=le[c[u+1]]||c[u+1],2):(o+=c[u],1))),c[u]===String.fromCharCode(r)?g():I("Bad string"),[,o]};w[vr]=Ir(vr);w[Tr]=Ir(Tr);m.string={'"':!0};var ue=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>d(r,ue,!0));var Rr=(r,e,t,o)=>typeof r=="string"?n=>e(n,r,n):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o,n)):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n),n)):r[0]==="()"&&r.length===2?Rr(r[1],e):(()=>{throw Error("Invalid assignment target")})(),Nr={"=":(r,e,t)=>r[e]=t,"+=":(r,e,t)=>r[e]+=t,"-=":(r,e,t)=>r[e]-=t,"*=":(r,e,t)=>r[e]*=t,"/=":(r,e,t)=>r[e]/=t,"%=":(r,e,t)=>r[e]%=t,"|=":(r,e,t)=>r[e]|=t,"&=":(r,e,t)=>r[e]&=t,"^=":(r,e,t)=>r[e]^=t,">>=":(r,e,t)=>r[e]>>=t,"<<=":(r,e,t)=>r[e]<<=t};for(let r in Nr)p(r,(e,t)=>(t=i(t),Rr(e,(o,n,s)=>Nr[r](o,n,t(s)))));var me=30,ce=40,_r=140;d("!",_r);v("!",_r);d("||",me);d("&&",ce);p("!",r=>(r=i(r),e=>!r(e)));p("||",(r,e)=>(r=i(r),e=i(e),t=>r(t)||e(t)));p("&&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&&e(t)));var de=50,Ae=60,ye=70,Or=100,he=140;d("|",de);d("&",ye);d("^",Ae);d(">>",Or);d("<<",Or);v("~",he);p("~",r=>(r=i(r),e=>~r(e)));p("|",(r,e)=>(r=i(r),e=i(e),t=>r(t)|e(t)));p("&",(r,e)=>(r=i(r),e=i(e),t=>r(t)&e(t)));p("^",(r,e)=>(r=i(r),e=i(e),t=>r(t)^e(t)));p(">>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>e(t)));p("<<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<<e(t)));var q=90;d("<",q);d(">",q);d("<=",q);d(">=",q);p(">",(r,e)=>(r=i(r),e=i(e),t=>r(t)>e(t)));p("<",(r,e)=>(r=i(r),e=i(e),t=>r(t)<e(t)));p(">=",(r,e)=>(r=i(r),e=i(e),t=>r(t)>=e(t)));p("<=",(r,e)=>(r=i(r),e=i(e),t=>r(t)<=e(t)));var Pr=80;d("==",Pr);d("!=",Pr);p("==",(r,e)=>(r=i(r),e=i(e),t=>r(t)==e(t)));p("!=",(r,e)=>(r=i(r),e=i(e),t=>r(t)!=e(t)));var Mr=110,lr=120,Ur=140;d("+",Mr);d("-",Mr);d("*",lr);d("/",lr);d("%",lr);v("+",Ur);v("-",Ur);p("+",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)+e(t)):(r=i(r),t=>+r(t)));p("-",(r,e)=>e!==void 0?(r=i(r),e=i(e),t=>r(t)-e(t)):(r=i(r),t=>-r(t)));p("*",(r,e)=>(r=i(r),e=i(e),t=>r(t)*e(t)));p("/",(r,e)=>(r=i(r),e=i(e),t=>r(t)/e(t)));p("%",(r,e)=>(r=i(r),e=i(e),t=>r(t)%e(t)));var x=150;S("++",x,r=>r?["++",r,null]:["++",A(x-1)]);S("--",x,r=>r?["--",r,null]:["--",A(x-1)]);var ur=(r,e,t,o)=>typeof r=="string"?n=>e(n,r):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o)):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n))):r[0]==="()"&&r.length===2?ur(r[1],e):(()=>{throw Error("Invalid increment target")})();p("++",(r,e)=>ur(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));p("--",(r,e)=>ur(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var ge=5,Ee=10,ae=170;H("()",ae);sr(",",Ee);sr(";",ge,!0);var Lr=(...r)=>(r=r.map(i),e=>{let t;for(let o of r)t=o(e);return t});p(",",Lr);p(";",Lr);var M=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",mr=170;pr("[]",mr);d(".",mr);pr("()",mr);var b=r=>{throw Error(r)};p("[]",(r,e)=>e===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(t=>t==null?(()=>{}):t[0]==="..."?(t=i(t[1]),o=>t(o)):(t=i(t),o=>[t(o)])),t=>r.flatMap(o=>o(t))):(e==null&&b("Missing index"),r=i(r),e=i(e),t=>{let o=e(t);return M(o)?void 0:r(t)[o]}));p(".",(r,e)=>(r=i(r),e=e[0]?e:e[1],M(e)?()=>{}:t=>r(t)[e]));p("()",(r,e)=>{if(e===void 0)return r==null?b("Empty ()"):i(r);let t=n=>n?.[0]===","&&n.slice(1).some(s=>s==null||t(s));t(e)&&b("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];return cr(r,(n,s,f)=>n[s](...o(f)))});var O=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&O(r[1])||r[0]==="{}"),cr=(r,e,t,o)=>r==null?b("Empty ()"):r[0]==="()"&&r.length==2?cr(r[1],e):typeof r=="string"?n=>e(n,r,n):r[0]==="."?(t=i(r[1]),o=r[2],n=>e(t(n),o,n)):r[0]==="?."?(t=i(r[1]),o=r[2],n=>{let s=t(n);return s==null?void 0:e(s,o,n)}):r[0]==="[]"&&r.length===3?(t=i(r[1]),o=i(r[2]),n=>e(t(n),o(n),n)):r[0]==="?.[]"?(t=i(r[1]),o=i(r[2]),n=>{let s=t(n);return s==null?void 0:e(s,o(n),n)}):(r=i(r),n=>e([r(n)],0,n)),U=cr;var Fr=new WeakMap,Se=(r,...e)=>typeof r=="string"?i(m(r)):Fr.get(r)||Fr.set(r,Ce(r,e)).get(r),Gr=57344,Ce=(r,e)=>{let t=r.reduce((s,f,l)=>s+(l?String.fromCharCode(Gr+l-1):"")+f,""),o=m(t),n=s=>{if(typeof s=="string"&&s.length===1){let f=s.charCodeAt(0)-Gr,l;if(f>=0&&f<e.length)return l=e[f],we(l)?l:[,l]}return Array.isArray(s)?s.map(n):s};return i(n(o))},we=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Xr=Se;var ke=32,ve=m.space;m.comment??={"//":`
|
|
6
6
|
`,"/*":"*/"};var dr;m.space=()=>{dr||(dr=Object.entries(m.comment).map(([n,s])=>[n,s,n.charCodeAt(0)]));for(var r;r=ve();){for(var e=0,t;t=dr[e++];)if(r===t[2]&&c.substr(u,t[0].length)===t[0]){var o=u+t[0].length;if(t[1]===`
|
|
7
|
-
`)for(;c.charCodeAt(o)>=ke;)o++;else{for(;c[o]&&c.substr(o,t[1].length)!==t[1];)o++;c[o]&&(o+=t[1].length)}G(o),r=0;break}if(r)return r}return r};var Kr=80;d("===",Kr);d("!==",Kr);p("===",(r,e)=>(r=i(r),e=i(e),t=>r(t)===e(t)));p("!==",(r,e)=>(r=i(r),e=i(e),t=>r(t)!==e(t)));var Te=30;d("??",Te);p("??",(r,e)=>(r=i(r),e=i(e),t=>r(t)??e(t)));var Ie=130,Ne=20;d("**",Ie,!0);d("**=",Ne,!0);p("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));var Re=r=>{throw Error(r)};p("**=",(r,e)=>(O(r)||Re("Invalid assignment target"),e=i(e),U(r,(t,o,n)=>t[o]**=e(n))));var Dr=90;d("in",Dr);d("of",Dr);p("in",(r,e)=>(r=i(r),e=i(e),t=>r(t)in e(t)));var _e=20,Oe=100,Pe=r=>{throw Error(r)};d(">>>",Oe);d(">>>=",_e,!0);p(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));p(">>>=",(r,e)=>(O(r)||Pe("Invalid assignment target"),e=i(e),U(r,(t,o,n)=>t[o]>>>=e(n))));var L=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...n]=r;if(o==="{}")for(let s of n){let f,l,
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},jr=()=>{let r=[];for(let e="",t;(t=c.charCodeAt(u))!==or;)t?t===$e?(g(),e+=He[c[u]]||c[u],g()):t===Be&&c.charCodeAt(u+1)===Qe?(e&&r.push([,e]),e="",g(2),r.push(A(0,125))):(e+=c[u],g(),t=c.charCodeAt(u),t===or&&e&&r.push([,e])):I("Unterminated template");return g(),r},je=w[or];w[or]=(r,e)=>r&&e<De?m.asi&&m.newline?void 0:(g(),["``",r,...jr()]):r?je?.(r,e):(g(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(jr()));p("`",(...r)=>(r=r.map(i),e=>r.map(t=>t(e)).join("")));p("``",(r,...e)=>{r=i(r);let t=[],o=[];for(let s of e)Array.isArray(s)&&s[0]===void 0?t.push(s[1]):o.push(i(s));let n=Object.assign([...t],{raw:t});return s=>r(s)(n,...o.map(f=>f(s)))});m.string["'"]=!0;m.number={"0x":16,"0b":2,"0o":8};var
|
|
7
|
+
`)for(;c.charCodeAt(o)>=ke;)o++;else{for(;c[o]&&c.substr(o,t[1].length)!==t[1];)o++;c[o]&&(o+=t[1].length)}G(o),r=0;break}if(r)return r}return r};var Kr=80;d("===",Kr);d("!==",Kr);p("===",(r,e)=>(r=i(r),e=i(e),t=>r(t)===e(t)));p("!==",(r,e)=>(r=i(r),e=i(e),t=>r(t)!==e(t)));var Te=30;d("??",Te);p("??",(r,e)=>(r=i(r),e=i(e),t=>r(t)??e(t)));var Ie=130,Ne=20;d("**",Ie,!0);d("**=",Ne,!0);p("**",(r,e)=>(r=i(r),e=i(e),t=>r(t)**e(t)));var Re=r=>{throw Error(r)};p("**=",(r,e)=>(O(r)||Re("Invalid assignment target"),e=i(e),U(r,(t,o,n)=>t[o]**=e(n))));var Dr=90;d("in",Dr);d("of",Dr);p("in",(r,e)=>(r=i(r),e=i(e),t=>r(t)in e(t)));var _e=20,Oe=100,Pe=r=>{throw Error(r)};d(">>>",Oe);d(">>>=",_e,!0);p(">>>",(r,e)=>(r=i(r),e=i(e),t=>r(t)>>>e(t)));p(">>>=",(r,e)=>(O(r)||Pe("Invalid assignment target"),e=i(e),U(r,(t,o,n)=>t[o]>>>=e(n))));var L=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...n]=r;if(o==="{}")for(let s of n){let f,l,h;s[0]==="="?[,[,f,l],h]=s:[,f,l]=s;let E=e[f];E===void 0&&h&&(E=i(h)(t)),L(l,E,t)}else if(o==="[]"){let s=0;for(let f of n){if(f===null){s++;continue}if(Array.isArray(f)&&f[0]==="..."){t[f[1]]=e.slice(s);break}let l=f,h;Array.isArray(f)&&f[0]==="="&&([,l,h]=f);let E=e[s++];E===void 0&&h&&(E=i(h)(t)),L(l,E,t)}}};var Ar=20,rr=r=>{throw Error(r)};d("||=",Ar,!0);d("&&=",Ar,!0);d("??=",Ar,!0);p("=",(r,e)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let t=r[1];return e=i(e),typeof t=="string"?o=>{o[t]=e(o)}:o=>L(t,e(o),o)}return O(r)||rr("Invalid assignment target"),e=i(e),U(r,(t,o,n)=>t[o]=e(n))});p("||=",(r,e)=>(O(r)||rr("Invalid assignment target"),e=i(e),U(r,(t,o,n)=>t[o]||=e(n))));p("&&=",(r,e)=>(O(r)||rr("Invalid assignment target"),e=i(e),U(r,(t,o,n)=>t[o]&&=e(n))));p("??=",(r,e)=>(O(r)||rr("Invalid assignment target"),e=i(e),U(r,(t,o,n)=>t[o]??=e(n))));P("true",!0);P("false",!1);P("null",null);P("undefined",void 0);P("NaN",NaN);P("Infinity",1/0);var yr=20;S("?",yr,(r,e,t)=>r&&(e=A(yr-1))&&k(o=>o===58)&&(t=A(yr-1),["?",r,e,t]));p("?",(r,e,t)=>(r=i(r),e=i(e),t=i(t),o=>r(o)?e(o):t(o)));var Me=20;d("=>",Me,!0);p("=>",(r,e)=>{r=r[0]==="()"?r[1]:r,r=r?r[0]===","?r.slice(1):[r]:[];let t=-1,o=null;return r.length&&Array.isArray(r[r.length-1])&&r[r.length-1][0]==="..."&&(t=r.length-1,o=r[t][1],r=r.slice(0,-1)),e=i(e[0]==="{}"?e[1]:e),(n=null)=>(n=Object.create(n),(...s)=>(r.forEach((f,l)=>n[f]=s[l]),o&&(n[o]=s.slice(t)),e(n)))});var Ue=140;v("...",Ue);p("...",r=>(r=i(r),e=>Object.entries(r(e))));var Br=170;S("?.",Br,(r,e)=>{if(!r)return;let t=y();return t===40?(g(),["?.()",r,A(0,41)||null]):t===91?(g(),["?.[]",r,A(0,93)]):(e=A(Br),e?["?.",r,e]:void 0)});p("?.",(r,e)=>(r=i(r),M(e)?()=>{}:t=>r(t)?.[e]));p("?.[]",(r,e)=>(r=i(r),e=i(e),t=>{let o=e(t);return M(o)?void 0:r(t)?.[o]}));p("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(i),n=>e.map(s=>s(n))):(e=i(e),n=>[e(n)]):()=>[];if(r[0]==="?."){let n=i(r[1]),s=r[2];return M(s)?()=>{}:f=>n(f)?.[s]?.(...t(f))}if(r[0]==="?.[]"){let n=i(r[1]),s=i(r[2]);return f=>{let l=n(f),h=s(f);return M(h)?void 0:l?.[h]?.(...t(f))}}if(r[0]==="."){let n=i(r[1]),s=r[2];return M(s)?()=>{}:f=>n(f)?.[s]?.(...t(f))}if(r[0]==="[]"&&r.length===3){let n=i(r[1]),s=i(r[2]);return f=>{let l=n(f),h=s(f);return M(h)?void 0:l?.[h]?.(...t(f))}}let o=i(r);return n=>o(n)?.(...t(n))});var er=140;v("typeof",er);v("void",er);v("delete",er);v("new",er);p("typeof",r=>(r=i(r),e=>typeof r(e)));p("void",r=>(r=i(r),e=>(r(e),void 0)));p("delete",r=>{if(r[0]==="."){let e=i(r[1]),t=r[2];return o=>delete e(o)[t]}if(r[0]==="[]"){let e=i(r[1]),t=i(r[2]);return o=>delete e(o)[t(o)]}return()=>!0});p("new",r=>{let e=i(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,o=t?t[0]===","?(n=>s=>n.map(f=>f(s)))(t.slice(1).map(i)):(n=>s=>[n(s)])(i(t)):()=>[];return n=>new(e(n))(...o(n))});var tr=Symbol("accessor"),Qr=20,Le=40,Fe=41,Ge=123,Xe=125,$r=r=>e=>{if(e)return;y();let t=k(m.id);if(!t||(y(),c.charCodeAt(u)!==Le))return!1;g();let o=A(0,Fe);return y(),c.charCodeAt(u)!==Ge?!1:(g(),[r,t,o,A(0,Xe)])};S("get",Qr-1,$r("get"));S("set",Qr-1,$r("set"));p("get",(r,e)=>(e=e?i(e):()=>{},t=>[[tr,r,{get:function(){let o=Object.create(t||{});return o.this=this,e(o)}}]]));p("set",(r,e,t)=>(t=t?i(t):()=>{},o=>[[tr,r,{set:function(n){let s=Object.create(o||{});s.this=this,s[e]=n,t(s)}}]]));var Ke=20,Hr=200;H("[]",Hr);H("{}",Hr);d(":",Ke-1,!0);p("{}",(r,e)=>{if(e!==void 0)return;r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(o=>i(typeof o=="string"?[":",o,o]:o));return o=>{let n={},s={};for(let f of t.flatMap(l=>l(o)))if(f[0]===tr){let[,l,h]=f;s[l]={...s[l],...h,configurable:!0,enumerable:!0}}else n[f[0]]=f[1];for(let f in s)Object.defineProperty(n,f,s[f]);return n}});p(":",(r,e)=>(e=i(e),Array.isArray(r)?(r=i(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));var De=170,or=96,Be=36,Qe=123,$e=92,He={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},jr=()=>{let r=[];for(let e="",t;(t=c.charCodeAt(u))!==or;)t?t===$e?(g(),e+=He[c[u]]||c[u],g()):t===Be&&c.charCodeAt(u+1)===Qe?(e&&r.push([,e]),e="",g(2),r.push(A(0,125))):(e+=c[u],g(),t=c.charCodeAt(u),t===or&&e&&r.push([,e])):I("Unterminated template");return g(),r},je=w[or];w[or]=(r,e)=>r&&e<De?m.asi&&m.newline?void 0:(g(),["``",r,...jr()]):r?je?.(r,e):(g(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(jr()));p("`",(...r)=>(r=r.map(i),e=>r.map(t=>t(e)).join("")));p("``",(r,...e)=>{r=i(r);let t=[],o=[];for(let s of e)Array.isArray(s)&&s[0]===void 0?t.push(s[1]):o.push(i(s));let n=Object.assign([...t],{raw:t});return s=>r(s)(n,...o.map(f=>f(s)))});m.string["'"]=!0;m.number={"0x":16,"0b":2,"0o":8};var hr=5,Wr=123,zr=125,a=(r,e,t,o=r.charCodeAt(0),n=r.length,s=w[o],f)=>w[o]=(l,h,E,T=u)=>!l&&(E?r==E:(n<2||c.substr(u,n)==r)&&(E=r))&&h<e&&!m.id(c.charCodeAt(u+n))&&(G(u+n),(f=t())?V(f,T):(G(T),!s&&I()),f)||s?.(l,h,E),gr=(r,e,t,o=r.charCodeAt(0),n=r.length,s=w[o],f)=>w[o]=(l,h,E,T=u)=>l&&(E?r==E:(n<2||c.substr(u,n)==r)&&(E=r))&&h<e&&!m.id(c.charCodeAt(u+n))&&(G(u+n),V(f=t(l),T),f)||s?.(l,h,E),_=()=>(y()===Wr||I("Expected {"),g(),A(hr-.5,zr)||null),K=()=>y()!==Wr?A(hr+.5):(g(),A(hr-.5,zr)||null);var Er=5,We=10,ze=20,Jr=r=>{let e=A(We-1);return e?.[0]==="in"||e?.[0]==="of"?[e[0],[r,e[1]],e[2]]:e?.[0]===","?[r,...e.slice(1)]:[r,e]};S("let",Er+1,r=>!r&&Jr("let"));S("const",Er+1,r=>!r&&Jr("const"));a("var",Er,()=>(y(),["var",A(ze)]));var Vr=(...r)=>(r=r.map(e=>{if(typeof e=="string")return t=>{t[e]=void 0};if(e[0]==="="){let[,t,o]=e,n=i(o);return typeof t=="string"?s=>{s[t]=n(s)}:s=>L(t,n(s),s)}return i(e)}),e=>{for(let t of r)t(e)});p("let",Vr);p("const",Vr);p("var",r=>typeof r=="string"?e=>{e[r]=void 0}:()=>{});var D=Symbol("break"),W=Symbol("continue"),B=Symbol("return");var Je=200;a("function",Je,()=>{y();let r=k(m.id);return r&&y(),["function",r,N()||null,_()]});p("function",(r,e,t)=>{t=t?i(t):()=>{};let o=e?e[0]===","?e.slice(1):[e]:[],n=null,s=-1,f=o[o.length-1];return Array.isArray(f)&&f[0]==="..."&&(s=o.length-1,n=f[1],o.length--),l=>{let h=(...E)=>{let T={};o.forEach((C,R)=>T[C]=E[R]),n&&(T[n]=E.slice(s));let F=new Proxy(T,{get:(C,R)=>R in C?C[R]:l[R],set:(C,R,xr)=>((R in C?C:l)[R]=xr,!0),has:(C,R)=>R in C||R in l});try{return t(F)}catch(C){if(C?.type===B)return C.value;throw C}};return r&&(l[r]=h),h}});var nr=140,ar=20;v("await",nr);a("yield",nr,()=>(y(),c[u]==="*"?(g(),y(),["yield*",A(ar)]):["yield",A(ar)]));a("async",nr,()=>{if(y(),X("function"))return["async",A(nr)];let r=A(ar-.5);return r&&["async",r]});p("async",r=>{let e=i(r);return t=>{let o=e(t);return async function(...n){return o(...n)}}});p("await",r=>(r=i(r),async e=>await r(e)));p("yield",r=>(r=r?i(r):null,e=>{throw{__yield__:r?r(e):void 0}}));p("yield*",r=>(r=i(r),e=>{throw{__yield_all__:r(e)}}));var Sr=200,Ve=140,Ye=90,Ze=Symbol("static");P("super",Symbol.for("super"));v("static",Ve);d("instanceof",Ye);S("#",Sr,r=>{if(r)return;let e=k(m.id);return e?"#"+e:void 0});a("class",Sr,()=>{y();let r=k(m.id)||null;if(r==="extends")r=null;else if(y(),!X("extends"))return["class",r,null,_()];return y(),["class",r,A(Sr),_()]});var qe=r=>{throw Error(r)};p("instanceof",(r,e)=>(r=i(r),e=i(e),t=>r(t)instanceof e(t)));p("class",(r,e,t)=>(e=e?i(e):null,t=t?i(t):null,o=>{let n=e?e(o):Object,s=function(...f){if(!(this instanceof s))return qe("Class constructor must be called with new");let l=e?Reflect.construct(n,f,s):this;return s.prototype.__constructor__&&s.prototype.__constructor__.apply(l,f),l};if(Object.setPrototypeOf(s.prototype,n.prototype),Object.setPrototypeOf(s,n),t){let f=Object.create(o);f.super=n;let l=t(f),h=Array.isArray(l)&&typeof l[0]?.[0]=="string"?l:[];for(let[E,T]of h)E==="constructor"?s.prototype.__constructor__=T:s.prototype[E]=T}return r&&(o[r]=s),s}));p("static",r=>(r=i(r),e=>[[Ze,r(e)]]));var xe=140,Cr=47,be=92,rt=r=>r===be?2:r&&r!==Cr,et=r=>r===103||r===105||r===109||r===115||r===117||r===121;S("/",xe,r=>{if(r)return;let e=c.charCodeAt(u);if(e===Cr||e===42||e===43||e===63||e===61)return;let t=k(rt);c.charCodeAt(u)===Cr||I("Unterminated regex"),g();try{return[,new RegExp(t,k(et))]}catch(o){I("Invalid regex: "+o.message)}});var tt=5,ot=59,nt=()=>{let r=u;return y()===ot&&g(),y(),X("else")?(g(4),!0):(G(r),!1)};a("if",tt+1,()=>{y();let r=["if",N(),K()];return nt()&&r.push(K()),r});p("if",(r,e,t)=>(r=i(r),e=i(e),t=t!==void 0?i(t):null,o=>r(o)?e(o):t?.(o)));var z=(r,e)=>{try{return{v:r(e)}}catch(t){if(t?.type===D)return{b:1};if(t?.type===W)return{c:1};if(t?.type===B)return{r:1,v:t.value};throw t}},Q=5,it=125,st=59;a("while",Q+1,()=>(y(),["while",N(),K()]));a("do",Q+1,()=>(r=>(y(),g(5),y(),["do",r,N()]))(K()));a("for",Q+1,()=>(y(),X("await")?(g(5),y(),["for await",N(),K()]):["for",N(),K()]));a("break",Q+1,()=>["break"]);a("continue",Q+1,()=>["continue"]);a("return",Q+1,()=>{m.asi&&(m.newline=!1),y();let r=c.charCodeAt(u);return!r||r===it||r===st||m.newline?["return"]:["return",A(Q)]});p("while",(r,e)=>(r=i(r),e=i(e),t=>{let o,n;for(;r(t)&&!(o=z(e,t)).b;){if(o.r)return o.v;o.c||(n=o.v)}return n}));p("do",(r,e)=>(r=i(r),e=i(e),t=>{let o,n;do{if((o=z(r,t)).b)break;if(o.r)return o.v;o.c||(n=o.v)}while(e(t));return n}));p("for",(r,e)=>{if(Array.isArray(r)&&r[0]===";"){let[,t,o,n]=r;return t=t?i(t):null,o=o?i(o):()=>!0,n=n?i(n):null,e=i(e),s=>{let f,l;for(t?.(s);o(s)&&!(f=z(e,s)).b;n?.(s)){if(f.r)return f.v;f.c||(l=f.v)}return l}}if(Array.isArray(r)&&(r[0]==="in"||r[0]==="of")){let[t,o,n]=r;if(Array.isArray(o)&&(o[0]==="let"||o[0]==="const"||o[0]==="var")&&(o=o[1]),t==="in")return ft(o,n,e);if(t==="of")return pt(o,n,e)}});var pt=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let s,f,l=o?null:n[r];for(let h of e(n)){if(o?L(r,h,n):n[r]=h,(s=z(t,n)).b)break;if(s.r)return s.v;s.c||(f=s.v)}return o||(n[r]=l),f}},ft=(r,e,t)=>{e=i(e),t=i(t);let o=Array.isArray(r);return n=>{let s,f,l=o?null:n[r];for(let h in e(n)){if(o?L(r,h,n):n[r]=h,(s=z(t,n)).b)break;if(s.r)return s.v;s.c||(f=s.v)}return o||(n[r]=l),f}};p("break",()=>()=>{throw{type:D}});p("continue",()=>()=>{throw{type:W}});p("return",r=>(r=r!==void 0?i(r):null,e=>{throw{type:B,value:r?.(e)}}));var J=5;a("try",J+1,()=>["try",_()]);gr("catch",J+1,r=>(y(),["catch",r,N(),_()]));gr("finally",J+1,r=>["finally",r,_()]);a("throw",J+1,()=>{if(m.asi&&(m.newline=!1),y(),m.newline)throw SyntaxError("Unexpected newline after throw");return["throw",A(J)]});p("try",r=>(r=r?i(r):null,e=>r?.(e)));p("catch",(r,e,t)=>{let o=r?.[1]?i(r[1]):null;return t=t?i(t):null,n=>{let s;try{s=o?.(n)}catch(f){if(f?.type===D||f?.type===W||f?.type===B)throw f;if(e!==null&&t){let l=e in n,h=n[e];n[e]=f;try{s=t(n)}finally{l?n[e]=h:delete n[e]}}else if(e===null)throw f}return s}});p("finally",(r,e)=>(r=r?i(r):null,e=e?i(e):null,t=>{let o;try{o=r?.(t)}finally{e?.(t)}return o}));p("throw",r=>(r=i(r),e=>{throw r(e)}));var wr=5,lt=20,Yr=58;a("switch",wr+1,()=>(y(),["switch",N(),_()]));a("case",wr+1,()=>(y(),(r=>(y()===Yr&&g(),["case",r]))(A(lt))));a("default",wr+1,()=>(y()===Yr&&g(),["default"]));p("switch",(r,e)=>{if(r=i(r),!e)return s=>r(s);let t=[],o=e[0]===";"?e.slice(1):[e],n=null;for(let s of o)Array.isArray(s)&&(s[0]==="case"||s[0]==="default")?(n&&t.push(n),n=[s[0]==="case"?i(s[1]):null,[]]):n&&n[1].push(i(s));return n&&t.push(n),s=>{let f=r(s),l=!1,h;for(let[E,T]of t)if(l||E===null||E(s)===f){l=!0;for(let F of T)try{h=F(s)}catch(C){if(C?.type===D)return C.value!==void 0?C.value:h;throw C}}return h}});var kr=5,$=10,Zr=42,ut=w[Zr];w[Zr]=(r,e)=>r?ut?.(r,e):(g(),"*");S("from",$+1,r=>r?r[0]!=="="&&r[0]!==","&&(y(),["from",r,A($+1)]):!1);S("as",$+2,r=>r?(y(),["as",r,A($+2)]):!1);a("import",kr,()=>(y(),["import",A($)]));a("export",kr,()=>(y(),["export",A(kr)]));a("default",$+1,()=>(y(),["default",A($)]));p("import",()=>()=>{});p("export",()=>()=>{});p("from",(r,e)=>()=>{});p("as",(r,e)=>()=>{});p("default",r=>i(r));var qr=5;m.asi=(r,e,t)=>{if(e>=qr)return;let o=t(qr-.5);if(o)return r?.[0]!==";"?[";",r,o]:(r.push(o),r)};export{pr as access,d as binary,i as compile,c as cur,Xr as default,I as err,A as expr,H as group,mt as id,u as idx,P as literal,V as loc,w as lookup,sr as nary,k as next,p as operator,ir as operators,N as parens,m as parse,G as seek,g as skip,y as space,S as token,v as unary,X as word};
|
package/package.json
CHANGED
package/util/stringify.js
CHANGED
|
@@ -67,8 +67,6 @@ export const codegen = node => {
|
|
|
67
67
|
|
|
68
68
|
// --- Statement generators (need structure) ---
|
|
69
69
|
|
|
70
|
-
generator('block', body => body === undefined ? '{}' : '{ ' + codegen(body) + ' }');
|
|
71
|
-
|
|
72
70
|
// Variables: ['let', decl] or ['let', decl1, decl2, ...]
|
|
73
71
|
const varGen = kw => (...args) => kw + ' ' + args.map(codegen).join(', ');
|
|
74
72
|
generator('let', varGen('let'));
|
|
@@ -76,7 +74,7 @@ generator('const', varGen('const'));
|
|
|
76
74
|
generator('var', varGen('var'));
|
|
77
75
|
|
|
78
76
|
// Control flow
|
|
79
|
-
const wrap = s =>
|
|
77
|
+
const wrap = s => '{ ' + (s ? codegen(s) : '') + ' }';
|
|
80
78
|
generator('if', (cond, then, els) => 'if (' + codegen(cond) + ') ' + wrap(then) + (els ? ' else ' + wrap(els) : ''));
|
|
81
79
|
generator('while', (cond, body) => 'while (' + codegen(cond) + ') ' + wrap(body));
|
|
82
80
|
generator('do', (body, cond) => 'do ' + wrap(body) + ' while (' + codegen(cond) + ')');
|
|
@@ -101,8 +99,7 @@ generator('finally', (expr, body) => codegen(expr) + ' finally { ' + codegen(bod
|
|
|
101
99
|
// Functions
|
|
102
100
|
generator('function', (name, params, body) => {
|
|
103
101
|
const args = !params ? '' : params[0] === ',' ? params.slice(1).map(codegen).join(', ') : codegen(params);
|
|
104
|
-
|
|
105
|
-
return 'function' + (name ? ' ' + name : '') + '(' + args + ') ' + b;
|
|
102
|
+
return 'function' + (name ? ' ' + name : '') + '(' + args + ') ' + wrap(body);
|
|
106
103
|
});
|
|
107
104
|
|
|
108
105
|
generator('=>', (params, body) => {
|