@tslite/parser 1.4.1 → 1.5.1

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/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
- 'use strict';var ast=require('@tslite/ast');var ne=class extends ast.TSLiteError{constructor(s,a,u,k,f){super("lex-error",`${s} (${a.line}:${a.column})`,{position:a,index:u,loc:k,end:f});this.position=a;this.index=u;this.loc=k;this.end=f;this.name="LexError";}},De=new Set(["const","if","else","return","async","await","true","false","null","typeof","let","var","function","class","new","for","while","do","this","throw","try","catch","finally","switch","case","break","continue","default","void","delete","instanceof","in","yield","import","export","extends","super","debugger","with","enum","interface"]),pt=["...","===","!==","=>","?.","??=","&&=","||=","**=","??","==","!=","<=",">=","&&","||","|","&","++","--","+=","-=","*=","/=","%=","**","<<","+","-","*","/","%","<",">","!","?",":",".",",",";","=","^","~","(",")","[","]","{","}"],de=r=>r>="a"&&r<="z"||r>="A"&&r<="Z"||r==="_"||r==="$",fe=r=>de(r)||r>="0"&&r<="9",te=r=>r>="0"&&r<="9",je=r=>te(r)||r>="a"&&r<="f"||r>="A"&&r<="F",ct=r=>fe(r)||r==="-",pe=r=>r===`
2
- `||r==="\r"||r==="\u2028"||r==="\u2029",ue=(r,c)=>{let s=c;for(;;){let a=r[s]??"";if(a===" "||a===" "||a==="\f"||a==="\v"||pe(a))s++;else if(a==="/"&&r[s+1]==="/")for(s+=2;s<r.length&&!pe(r[s]??"");)s++;else if(a==="/"&&r[s+1]==="*"){for(s+=2;s<r.length&&!(r[s]==="*"&&r[s+1]==="/");)s++;s+=2;}else return s}},ut=(r,c)=>{if(!de(r[c]??""))return c;let s=c+1;for(;fe(r[s]??"");)s++;return s},Oe=(r,c,s)=>r.startsWith(s,c)&&!fe(r[c+s.length]??""),dt=(r,c)=>{let s=ue(r,c);Oe(r,s,"const")&&(s=ue(r,s+5));let a=ut(r,s);if(a===s)return false;if(s=ue(r,a),Oe(r,s,"extends")){let u=ue(r,s+7),k=r[u]??"";return !(k==="="||k===">"||k==="/")}return r[s]===","?true:r[s]==="="&&r[s+1]!==">"},ft=new Set(["(","[","{",",",";",":","?","=>","...","=","+","-","*","/","%","<","<=",">",">=","==","===","!=","!==","&&","||","??","!","+=","-=","*=","/=","%=","??=","&&=","||=","**="]),yt=new Set(["return","typeof","await","delete","void","in","instanceof","else","case","yield","throw"]);function be(r,c,s){let a=[],u=0,k=1,f=0,o=()=>({line:k,column:f}),h=(E=0)=>r[u+E]??"",M=E=>{let A=o(),U={start:A,end:{line:k,column:f+1}};if(s){s({message:E,position:A,index:u,loc:U,end:u+1});return}throw new ne(E,A,u,U,u+1)},b=()=>{let E=r[u++];return E==="\r"?(r[u]===`
3
- `&&u++,k++,f=0):E===`
4
- `||E==="\u2028"||E==="\u2029"?(k++,f=0):f++,E},p=()=>{for(;;){let E=h();if(E===" "||E===" "||E==="\f"||E==="\v"||pe(E))b();else if(E==="/"&&h(1)==="/"){let A=u,U=o();b(),b();let C=u;for(;u<r.length&&!pe(h());)b();c?.({type:"Line",value:r.slice(C,u),start:A,end:u,loc:{start:U,end:o()}});}else if(E==="/"&&h(1)==="*"){let A=u,U=o();b(),b();let C=u,D=u;for(;;){if(u>=r.length){M("Unterminated block comment"),D=u;break}if(h()==="*"&&h(1)==="/"){D=u,b(),b();break}b();}c?.({type:"Block",value:r.slice(C,D),start:A,end:u,loc:{start:U,end:o()}});}else break}},v=(E,A,U,C)=>{a.push({type:E,value:A,start:U,end:u,loc:{start:C,end:o()}}),W=E==="Punctuator"?ft.has(A):E==="Keyword"?yt.has(A):E==="TemplateHead"||E==="TemplateMiddle";},z=E=>{for(b();u<r.length;){let A=h();if(A===E)return b(),r.slice(d,u);if(pe(A))return M("Unterminated string literal"),r.slice(d,u);if(A==="\\"){if(b(),u>=r.length)return M("Unterminated string literal"),r.slice(d,u);b();continue}b();}return M("Unterminated string literal"),r.slice(d,u)},R=()=>{if(h()==="0"&&(h(1)==="x"||h(1)==="X")){if(b(),b(),!je(h()))return M("Invalid hexadecimal literal");for(;je(h());)b();return}if(h()==="0"&&(h(1)==="b"||h(1)==="B")){if(b(),b(),h()!=="0"&&h()!=="1")return M("Invalid binary literal");for(;h()==="0"||h()==="1";)b();return}if(h()==="0"&&(h(1)==="o"||h(1)==="O")){if(b(),b(),!(h()>="0"&&h()<="7"))return M("Invalid octal literal");for(;h()>="0"&&h()<="7";)b();return}for(;te(h());)b();if(h()===".")for(b();te(h());)b();if(h()==="e"||h()==="E"){if(b(),(h()==="+"||h()==="-")&&b(),!te(h()))return M("Invalid exponent");for(;te(h());)b();}},X=()=>{let E=u;for(;u<r.length;){let A=h();if(A==="`"){let U=r.slice(E,u);return b(),{raw:U,interp:false}}if(A==="$"&&h(1)==="{"){let U=r.slice(E,u);return b(),b(),{raw:U,interp:true}}if(A==="\\"){if(b(),u>=r.length)break;b();continue}b();}return M("Unterminated template literal"),{raw:r.slice(E,u),interp:false}},d=0,I=0,T=[],W=true,P="js",_=[],q=[];for(;;){if(P==="jsxChildren"){d=u;let C=o();if(u>=r.length){v("EOF","",d,C);break}let D=h();if(D==="<"){h(1)==="/"?(b(),b(),v("Punctuator","</",d,C),P="jsxCloseTag"):(b(),v("Punctuator","<",d,C),_.push("jsxChildren"),P="jsxOpenTag");continue}if(D==="{"){b(),v("Punctuator","{",d,C),q.push({level:I,restore:"jsxChildren"}),P="js";continue}for(;u<r.length&&h()!=="<"&&h()!=="{";)b();v("JSXText",r.slice(d,u),d,C);continue}if(P==="jsxOpenTag"||P==="jsxCloseTag"){p(),d=u;let C=o();if(u>=r.length){v("EOF","",d,C);break}let D=h();if(de(D)){for(b();ct(h());)b();v("Identifier",r.slice(d,u),d,C);continue}if(D==="/"&&h(1)===">"){b(),b(),v("Punctuator","/>",d,C),P=_.pop()??"js";continue}if(D===">"){b(),v("Punctuator",">",d,C),P=P==="jsxCloseTag"?_.pop()??"js":"jsxChildren";continue}if(D==="{"){b(),v("Punctuator","{",d,C),q.push({level:I,restore:P}),P="js";continue}if(D==='"'||D==="'"){v("String",z(D),d,C);continue}if(D==="="||D==="."||D===":"){b(),v("Punctuator",D,d,C);continue}if(D==="<"&&P==="jsxOpenTag"){b(),v("Punctuator","<",d,C),_.push("jsxOpenTag");continue}M(`Unexpected character '${D}' in JSX tag`),b(),v("Unknown",D,d,C);continue}p(),d=u;let E=o();if(u>=r.length){v("EOF","",d,E);break}let A=h();if(de(A)){for(;fe(h());)b();let C=r.slice(d,u);v(De.has(C)?"Keyword":"Identifier",C,d,E);continue}if(te(A)||A==="."&&te(h(1))){R(),v("Number",r.slice(d,u),d,E);continue}if(A==='"'||A==="'"){let C=z(A);v("String",C,d,E);continue}if(A==="`"){b();let{raw:C,interp:D}=X();D?(v("TemplateHead",C,d,E),T.push(I)):v("Template",C,d,E);continue}if(A==="<"&&W&&!dt(r,u+1)){b(),v("Punctuator","<",d,E),_.push("js"),P="jsxOpenTag";continue}if(A==="{"){b(),v("Punctuator","{",d,E),I++;continue}if(A==="}"){if(T.length>0&&I===T[T.length-1]){T.pop(),b();let{raw:C,interp:D}=X();v(D?"TemplateMiddle":"TemplateTail",C,d,E),D&&T.push(I);continue}if(q.length>0&&I===q[q.length-1].level){let{restore:C}=q.pop();b(),v("Punctuator","}",d,E),P=C;continue}b(),v("Punctuator","}",d,E),I--;continue}if(A==="?"&&h(1)==="."&&te(h(2))){b(),v("Punctuator","?",d,E);continue}let U=pt.find(C=>r.startsWith(C,u));if(U){for(let C=0;C<U.length;C++)b();v("Punctuator",U,d,E);continue}M(`Unexpected character '${A}'`),b(),v("Unknown",A,d,E);}return a}var mt=new Set(["leadingComments","trailingComments","innerComments","comments"]),Je=r=>typeof r=="object"&&r!==null&&typeof r.type=="string"&&r.loc!=null&&typeof r.start=="number",Xe=new WeakMap;function ht(r){let c=Xe.get(r);if(c)return c;let s=[];for(let a of Object.keys(r)){if(mt.has(a))continue;let u=r[a];if(Je(u))s.push(u);else if(Array.isArray(u))for(let k of u)Je(k)&&s.push(k);}return s.sort((a,u)=>a.start-u.start),Xe.set(r,s),s}function Tt(r,c){let s=r,a,u;for(;;){let k=ht(s);a=void 0,u=void 0;let f;for(let o of k){if(o.start<=c.start&&c.end<=o.end){f=o;break}if(o.end<=c.start)a=o;else if(c.end<=o.start){u=o;break}}if(!f)break;s=f;}return {enclosing:s,preceding:a,following:u}}var ve=(r,c)=>{(r.leadingComments??(r.leadingComments=[])).push(c);},ye=(r,c)=>{(r.trailingComments??(r.trailingComments=[])).push(c);},Se=(r,c)=>{(r.innerComments??(r.innerComments=[])).push(c);};function gt(r,c){for(let s=c;s<r.length;s++){let a=r[s];if(a!==" "&&a!==" "&&a!=="\r"&&a!==`
5
- `&&a!=="\f")return a}return ""}var bt=new Set([")","]","}",","]);function xe(r,c,s=""){for(let a of c){let{enclosing:u,preceding:k,following:f}=Tt(r,a),o=k==null||k.loc.end.line<a.loc.start.line,h=!o&&(f==null||a.loc.end.line<f.loc.start.line);if(o)f?ve(f,a):k?ye(k,a):Se(u,a);else if(h)k?ye(k,a):f?ve(f,a):Se(u,a);else {let M=bt.has(gt(s,a.end));k&&M?ye(k,a):f?ve(f,a):k?ye(k,a):Se(u,a);}}}var me=(r=[])=>({vars:new Set(r),bounds:new Map,noCond:false,inferSink:null}),se=(r,c)=>{let s=new Set(r.vars),a=new Map(r.bounds);for(let u of c)s.add(u.name),u.bound||u.isConst?a.set(u.name,{bound:u.bound,isConst:u.isConst}):a.delete(u.name);return {vars:s,bounds:a,noCond:r.noCond,inferSink:r.inferSink}},vt=(r,c)=>{let s=r.bounds.get(c);return s&&(s.bound||s.isConst)?{t:"var",name:c,...s.bound?{bound:s.bound}:{},...s.isConst?{isConst:true}:{}}:{t:"var",name:c}},Fe=r=>{let{peek:c,next:s,isP:a,isK:u,expectP:k,fail:f,unescape:o}=r,h=(y,m)=>{let l=r.tokens[r.pos()-1]??m;return Object.assign(y,{start:m.start,end:l.end,loc:{start:m.loc.start,end:l.loc.end}})},M=()=>{let y=r.pos(),m=r.tokens[y],l=r.tokens[y-1];return !!l&&!!m&&m.loc.start.line>l.loc.end.line},b=()=>{let y=0;for(let m=r.pos();m<r.tokens.length;m++){let l=r.tokens[m];if(l.type==="EOF")return false;if(l.type==="Punctuator"){if(["(","[","{","<"].includes(l.value))y++;else if([")","]","}",">"].includes(l.value)&&(y--,y===0)){let S=r.tokens[m+1];return !!S&&S.type==="Punctuator"&&S.value==="=>"}}}return false},p=()=>{let y=r.tokens,m=[],l=0,S=false;for(let w=r.pos();w<y.length;w++){let x=y[w];if(x.type==="EOF")break;if(x.type==="Punctuator"){if(x.value==="<")l++,l===1&&(S=true);else if(x.value===">"){if(l--,l===0)break}else x.value==="("||x.value==="["||x.value==="{"?(l++,S=false):x.value===")"||x.value==="]"||x.value==="}"?(l--,S=false):x.value===","&&l===1?S=true:S=false;continue}if(l===1&&S){if(x.type==="Keyword"&&x.value==="const")continue;if(x.type==="Identifier"){m.push(x.value),S=false;continue}}S=false;}return m},v=y=>{let m=se(y,p().map(S=>({name:S})));k("<");let l=[];for(;!a(">");){let S=u("const");S&&s();let w=c();w.type!=="Identifier"&&f("Expected type parameter name"),s();let x,J;if(u("extends")){s();let L=X(m);x=L.schema,J=L.node;}let $,F;if(a("=")){s();let L=X(m);$=L.schema,F=L.node;}l.push({name:w.value,...x?{bound:x}:{},...J?{boundNode:J}:{},...$?{default:$}:{},...F?{defaultNode:F}:{},...S?{isConst:true}:{}}),a(">")||k(",");}return k(">"),l},z=y=>{k("<");let m=[];for(;!a(">");)m.push(X(y)),a(">")||k(",");return k(">"),m},R=y=>{let m=c();return m.type==="Identifier"&&m.value===y},X=y=>{let m=c(),l=d(y);if(y.noCond||!u("extends")||M())return l;s();let S=[],w=d({...y,noCond:true,inferSink:S});k("?");let x=se(y,S.map(F=>({name:F}))),J=X(x);k(":");let $=X(x);return {node:h({type:"TSConditionalType",checkType:l.node,extendsType:w.node,trueType:J.node,falseType:$.node},m),schema:{t:"conditional",check:l.schema,extends:w.schema,then:J.schema,else:$.schema,...S.length?{infer:S}:{}}}},d=y=>{let m=c();a("|")&&s();let l=I(y);if(!a("|"))return l;let S=[l.node],w=[l.schema];for(;a("|");){s();let x=I(y);S.push(x.node),w.push(x.schema);}return {node:h({type:"TSUnionType",types:S},m),schema:{t:"union",of:w}}},I=y=>{let m=c();a("&")&&s();let l=T(y);if(!a("&"))return l;let S=[l.node],w=[l.schema];for(;a("&");){s();let x=T(y);S.push(x.node),w.push(x.schema);}return {node:h({type:"TSIntersectionType",types:S},m),schema:{t:"intersection",of:w}}},T=y=>{let m=c();if(R("keyof")){s();let l=T(y);return {node:h({type:"TSTypeOperator",operator:"keyof",typeAnnotation:l.node},m),schema:{t:"keyof",of:l.schema}}}if(R("readonly")){s();let l=T(y);return l.schema.t!=="array"&&l.schema.t!=="tuple"&&f("'readonly' only applies to array and tuple types"),{node:h({...l.node,readonly:true},m),schema:{...l.schema,readonly:true}}}if(R("infer")){s();let l=c();l.type!=="Identifier"&&f("Expected 'infer' variable name"),s();let S=y.inferSink;return S?(S.push(l.value),{node:h({type:"TSInferType",name:l.value},m),schema:{t:"var",name:l.value}}):f("'infer' is only allowed in the 'extends' clause of a conditional")}return W(y)},W=y=>{let m=c(),l=_(y);for(;a("[")&&!M();)if(s(),a("]"))s(),l={node:h({type:"TSArrayType",elementType:l.node},m),schema:{t:"array",items:l.schema}};else {let S=X(y);k("]"),l={node:h({type:"TSIndexedAccessType",objectType:l.node,indexType:S.node},m),schema:{t:"index",obj:l.schema,key:S.schema}};}return l},P=(y,m,l)=>({node:h({type:"TSKeywordType",kind:m},y),schema:l}),_=y=>{let m=c();if(u("typeof")){s();let w=c();w.type!=="Identifier"&&f("Expected a name after 'typeof' in type position"),s();let x=[w.value];for(;a(".");){s();let J=c();J.type!=="Identifier"&&J.type!=="Keyword"&&f("Expected a property name after '.' in 'typeof'"),s(),x.push(J.value);}return {node:h({type:"TSTypeQuery",exprName:x},m),schema:{t:"typeQuery",path:x}}}if(a("<")){let w=v(y),x=se(y,w);return A(x,m,w.map(J=>J.name))}if(a("(")){if(b())return A(y,m);s();let w=X(y.noCond?{...y,noCond:false}:y);return k(")"),w}if(a("{"))return C()?D(y):he(y);if(a("["))return U(y);let l=c();if(l.type==="String"){s();let w=o(l.value.slice(1,-1));return {node:h({type:"TSLiteralType",literal:w},m),schema:{t:"literal",value:w}}}if(l.type==="Number"){s();let w=Number(l.value);return {node:h({type:"TSLiteralType",literal:w},m),schema:{t:"literal",value:w}}}if(u("true"))return s(),{node:h({type:"TSLiteralType",literal:true},m),schema:{t:"literal",value:true}};if(u("false"))return s(),{node:h({type:"TSLiteralType",literal:false},m),schema:{t:"literal",value:false}};if(u("null"))return s(),P(m,"null",{t:"null"});if(u("void"))return s(),P(m,"void",{t:"void"});if(l.type==="Identifier"){switch(s(),l.value){case "string":return P(m,"string",{t:"string"});case "number":return P(m,"number",{t:"number"});case "boolean":return P(m,"boolean",{t:"boolean"});case "any":return P(m,"any",{t:"any"});case "unknown":return P(m,"unknown",{t:"unknown"});case "undefined":return P(m,"undefined",{t:"undefined"});case "never":return P(m,"never",{t:"union",of:[]})}let w=a("<")?z(y):[],x=w.map(F=>F.schema),J=w.length?w.map(F=>F.node):void 0,$=h({type:"TSTypeReference",typeName:l.value,...J?{typeArguments:J}:{}},m);return y.vars.has(l.value)&&x.length===0?{node:$,schema:vt(y,l.value)}:l.value==="ReturnType"&&x.length===1?{node:$,schema:{t:"returnType",fn:x[0]}}:l.value==="Parameters"&&x.length===1?{node:$,schema:{t:"parameters",fn:x[0]}}:(r.typeRefs?.push({name:l.value,loc:l.loc,args:x}),{node:$,schema:{t:"apply",name:l.value,args:x}})}r.recordError(`Expected a type but got '${l.value||l.type}'`,l);let S=r.createMissingNode({type:"TSTypeReference",typeName:""},l);return r.typeRefs?.push({name:"",loc:S.loc,args:[]}),{node:S,schema:{t:"unknown"}}},q=y=>{k("(");let m=[];for(;!a(")");){let l=c();l.type!=="Identifier"&&f("Expected parameter name in function type"),s();let S=a("?");S&&s(),k(":");let w=X(y);m.push({node:h({type:"TSTypeParameter",name:l.value,typeAnnotation:w.node,...S?{optional:true}:{}},l),schema:{name:l.value,type:w.schema,...S?{optional:true}:{}}}),a(")")||k(",");}return k(")"),m},E=(y,m)=>{let l=c(),S=r.tokens[r.pos()+1];if(!(l.type==="Identifier"&&S?.type==="Identifier"&&S.value==="is"))return X(y);let x=m.indexOf(l.value);x<0&&f(`Cannot find parameter '${l.value}' for the type predicate`),s(),s();let J=X(y);return {node:h({type:"TSTypePredicate",parameterName:l.value,typeAnnotation:J.node},l),schema:{t:"boolean"},guard:{param:x,type:J.schema}}},A=(y,m,l)=>{let S=q(y);k("=>");let w=E(y,S.map(x=>x.schema.name));return {node:h({type:"TSFunctionType",params:S.map(x=>x.node),returnType:w.node,...l?.length?{typeParams:[...l]}:{}},m),schema:{t:"fn",params:S.map(x=>x.schema),returns:w.schema,...w.guard?{guard:w.guard}:{},...l?.length?{typeParams:l}:{}}}},U=y=>{let m=c();k("[");let l=[],S=[],w=[],x=[],J=()=>{let L=r.tokens[r.pos()],O=r.tokens[r.pos()+1],H=r.tokens[r.pos()+2];if(L?.type==="Identifier"&&O?.type==="Punctuator"&&(O.value===":"||O.value==="?"&&H?.type==="Punctuator"&&H.value===":"))return s(),L.value};for(;!a("]");){if(a("...")){s();let L=J();L!==void 0&&k(":"),x.push(L);let O=X(y);O.schema.t==="array"?(S.push(O.schema.items),l.push(O.node.elementType),w.push("rest")):(S.push(O.schema),l.push(O.node),w.push("variadic"));}else {let L=J(),O=false;L!==void 0&&(a("?")&&(s(),O=true),k(":")),x.push(L);let H=X(y);!O&&a("?")&&(s(),O=true),S.push(H.schema),l.push(H.node),w.push(O?"optional":"req");}a("]")||k(",");}k("]");let $=w.some(L=>L!=="req"),F=x.some(L=>L!==void 0);return {node:h({type:"TSTupleType",elementTypes:l,...$?{flags:w}:{},...F?{labels:x}:{}},m),schema:$?{t:"tuple",elements:S,flags:w}:{t:"tuple",elements:S}}},C=()=>{let y=r.tokens,m=r.pos()+1;return y[m]?.type==="Punctuator"&&(y[m]?.value==="+"||y[m]?.value==="-")&&m++,y[m]?.type==="Identifier"&&y[m]?.value==="readonly"&&m++,y[m]?.type==="Punctuator"&&y[m]?.value==="["&&y[m+1]?.type==="Identifier"&&y[m+2]?.type==="Keyword"&&y[m+2]?.value==="in"},D=y=>{let m=c();k("{"),(a("+")||a("-"))&&s(),R("readonly")&&s(),k("[");let l=c();l.type!=="Identifier"&&f("Expected mapped type key name"),s(),u("in")||f("Expected 'in' in mapped type"),s();let S=X(y);R("as")&&f("Key remapping ('as') in mapped types is not supported"),k("]");let w=false,x=a("+")||a("-")?s().value:null;a("?")&&(s(),w=x!=="-"),k(":");let J=X(se(y,[{name:l.value}]));return (a(";")||a(","))&&s(),k("}"),{node:h({type:"TSMappedType",key:l.value,constraint:S.node,typeAnnotation:J.node,optional:w},m),schema:{t:"mapped",key:l.value,over:S.schema,body:J.schema,optional:w}}},he=y=>{let m=c();k("{");let l=[],S={},w,x=[];for(;!a("}");){let $=c();if(a("(")){let F=q(y);k(":");let L=E(y,F.map(O=>O.schema.name));x.push({t:"fn",params:F.map(O=>O.schema),returns:L.schema,...L.guard?{guard:L.guard}:{}}),l.push(h({type:"TSCallSignatureDeclaration",params:F.map(O=>O.node),returnType:L.node},$));}else if(a("[")){s(),c().type!=="Identifier"&&f("Expected index signature parameter name"),s(),k(":");let F=c();(F.type!=="Identifier"||F.value!=="string"&&F.value!=="number")&&f("Index signature parameter type must be 'string' or 'number'"),s(),k("]"),k(":");let L=X(y);w={key:F.value,value:L.schema},l.push(h({type:"TSIndexSignature",keyType:F.value,typeAnnotation:L.node},$));}else {let F=false;if(R("readonly")){let V=r.tokens[r.pos()+1];V&&(V.type==="Identifier"||V.type==="Keyword"||V.type==="String"||V.type==="Number")&&(s(),F=true);}let L=c(),O;if(L.type==="Identifier"||L.type==="Keyword")s(),O=L.value;else if(L.type==="String")s(),O=o(L.value.slice(1,-1));else if(L.type==="Number")s(),O=L.value;else return f("Expected property name in object type");let H=a("?");H&&s(),k(":");let ae=X(y);S[O]={type:ae.schema,...H?{optional:true}:{}},l.push(h({type:"TSPropertySignature",key:O,typeAnnotation:ae.node,...H?{optional:true}:{},...F?{readonly:true}:{}},$));}if(a(";")||a(","))s();else break}k("}");let J=h({type:"TSTypeLiteral",members:l},m);return x.length>0?Object.keys(S).length>0||w?f("Callable object types (call signatures mixed with members) are not supported"):{node:J,schema:x.length===1?x[0]:{t:"overload",signatures:x}}:{node:J,schema:{t:"object",props:S,...w?{index:w}:{}}}};return {parseType:(y=[])=>X(se(me(),y)),parseReturnType:(y,m)=>E(se(me(),y),m),parseTypeParamList:()=>v(me()),parseTypeInScope:y=>X(se(me(),y))}};var re=class extends ast.TSLiteError{constructor(s,a,u,k,f){super("parse-error",`${s} (${a.line}:${a.column})`,{position:a,index:u,loc:k,end:f});this.position=a;this.index=u;this.loc=k;this.end=f;this.name="ParseError";}},xt=r=>{let c=r;return c!=null&&typeof c.start=="number"&&c.start===c.end&&c.start>=0},Ke=(r,c)=>Object.assign(r,{start:c.start,end:c.start,loc:{start:c.loc.start,end:c.loc.start}}),kt={"??":1,"||":2,"&&":3,"|":4,"^":5,"&":6,"==":7,"===":7,"!=":7,"!==":7,"<":8,"<=":8,">":8,">=":8,in:8,as:8,satisfies:8,"<<":9,">>":9,">>>":9,"+":10,"-":10,"*":11,"/":11,"%":11,"**":12},wt=new Set(["??","||","&&"]),Pt=new Set(["class","debugger","with","enum","interface"]),Nt={enum:'use a union of literals (`type T = "a" | "b"`) \u2014 it is serializable',interface:"use a type alias (`type X = { \u2026 }`)",namespace:"use modules (`import`/`export`)",module:"use modules (`import`/`export`)",declare:"declare the shape via the DI env, or with a `type` alias",abstract:"classes are not part of the language \u2014 model with objects + functions"},Et={namespace:(r,c)=>r.type==="Identifier"&&c.type==="Punctuator"&&c.value==="{",module:(r,c)=>r.type==="Identifier"&&c.type==="Punctuator"&&c.value==="{",declare:r=>r.type==="Keyword"&&["const","let","var","function","class","enum","interface"].includes(r.value)||r.type==="Identifier"&&["type","namespace","module"].includes(r.value),abstract:r=>r.type==="Keyword"&&r.value==="class"},Ct=new Set(["=","+=","-=","*=","/=","%=","**=","??=","&&=","||="]);function ke(r){let c=[],s=[],a=be(r,e=>s.push(e),e=>c.push({code:"lex-error",...e})),u=0,k=[],f=(e=0)=>a[Math.min(u+e,a.length-1)],o=()=>a[u++],h=()=>a[u-1],M=()=>{let e=a[u],n=a[u-1];return !!e&&!!n&&e.loc.start.line>n.loc.end.line},b=()=>f().type==="EOF",p=e=>f().type==="Punctuator"&&f().value===e,v=e=>f().type==="Keyword"&&f().value===e,z=e=>f().type==="Identifier"&&f().value===e,R=(e,n=f())=>{throw X(e,n),new re(e,n.loc.start,n.start,n.loc,n.end)},X=(e,n=f())=>{let t=c[c.length-1];t&&t.index===n.start||c.push({code:"parse-error",message:e,position:n.loc.start,index:n.start,loc:n.loc,end:n.end});},d=e=>(p(e)||R(`Expected '${e}' but got '${f().value||f().type}'`),o()),I=(e,n)=>{let t=h()??n;return Object.assign(e,{start:n.start,end:t.end,loc:{start:n.loc.start,end:t.loc.end}})},T=(e,n,t)=>Object.assign(e,{start:n.start,end:t.end,loc:{start:n.loc.start,end:t.loc.end}}),W=e=>{let n="";for(let t=0;t<e.length;t++){if(e[t]!=="\\"){n+=e[t];continue}let i=e[++t];switch(i){case "n":n+=`
6
- `;break;case "t":n+=" ";break;case "r":n+="\r";break;case "b":n+="\b";break;case "f":n+="\f";break;case "v":n+="\v";break;case "0":n+="\0";break;case "x":n+=String.fromCharCode(parseInt(e.slice(t+1,t+3),16)),t+=2;break;case "u":if(e[t+1]==="{"){let g=e.indexOf("}",t);n+=String.fromCodePoint(parseInt(e.slice(t+2,g),16)),t=g;}else n+=String.fromCharCode(parseInt(e.slice(t+1,t+5),16)),t+=4;break;default:n+=i;}}return n},P=(e=false)=>_(e),_=(e=false)=>{let n=q(e),t=f();if(t.type==="Punctuator"&&Ct.has(t.value)){o();let i=_();return T({type:"AssignmentExpression",operator:t.value,left:n,right:i},n,i)}return n},q=(e=false)=>{let n=A(0,e);if(!p("?"))return n;o();let t=P();d(":");let i=P();return T({type:"ConditionalExpression",test:n,consequent:t,alternate:i},n,i)},E=()=>{let e=f();if(e.type==="Keyword")return e.value==="in"?{op:"in",consume:1}:null;if(e.type==="Identifier")return e.value==="as"?{op:"as",consume:1}:e.value==="satisfies"?{op:"satisfies",consume:1}:null;if(e.type!=="Punctuator")return null;if(e.value===">"){let n=f(1);if(n.type==="Punctuator"&&n.value===">"&&e.end===n.start){let t=f(2);return t.type==="Punctuator"&&t.value===">"&&n.end===t.start?{op:">>>",consume:3}:{op:">>",consume:2}}return {op:">",consume:1}}return {op:e.value,consume:1}},A=(e,n=false)=>{let t=U();for(;;){let i=E();if(!i)break;let{op:g,consume:N}=i;if(g==="in"&&n)break;let j=kt[g];if(!j||j<=e)break;if(g==="satisfies"){if(M())break;R("'satisfies' is not supported in this language \u2014 a type annotation (`const x: T = \u2026`) also checks compatibility, but it declares the type as T, while 'satisfies' keeps the inferred one");}if(g==="as"){if(M())break;o();let K=ce();t=T({type:"TSAsExpression",expression:t,typeAnnotation:K.schema,typeAnnotationNode:K.node},t,h());continue}for(let K=0;K<N;K++)o();let B=A(g==="**"?j-1:j,n);t=T({type:wt.has(g)?"LogicalExpression":"BinaryExpression",operator:g,left:t,right:B},t,B);}return t},U=()=>{let e=f();return e.type==="Punctuator"&&(e.value==="++"||e.value==="--")?(o(),I({type:"UpdateExpression",operator:e.value,prefix:true,argument:U()},e)):v("await")?(o(),I({type:"AwaitExpression",argument:U()},e)):v("typeof")||v("void")||v("delete")||e.type==="Punctuator"&&(e.value==="!"||e.value==="-"||e.value==="+"||e.value==="~")?C(e):he()},C=e=>{o();let n=U();return p("**")&&R(`An unary expression with the '${e.value}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.`),I({type:"UnaryExpression",operator:e.value,prefix:true,argument:n},e)},D=()=>{let e=u,n=c.length,t=()=>(u=e,c.length=n,void 0);try{if(o(),p(">"))return t();let i=[];for(;i.push(ce().schema),!!p(",");)o();return p(">")?(o(),p("(")?i:t()):t()}catch{return t()}},he=()=>{let e=_e(),n=false;for(;;)if((f().type==="Template"||f().type==="TemplateHead")&&R("Tagged templates are not supported in this language"),p("?."))if(o(),n=true,p("(")){let{args:t,close:i}=y();e=T({type:"CallExpression",callee:e,arguments:t,optional:true},e,i);}else if(p("[")){o();let t=P(),i=d("]");e=T({type:"MemberExpression",object:e,property:t,computed:true,optional:true},e,i);}else {let t=f();t.type!=="Identifier"&&t.type!=="Keyword"&&R("Expected property name after '?.'"),o();let i=I({type:"Identifier",name:t.value},t);e=T({type:"MemberExpression",object:e,property:i,computed:false,optional:true},e,i);}else if(p(".")){o();let t=f(),i;t.type==="Identifier"||t.type==="Keyword"?(o(),i=I({type:"Identifier",name:t.value},t)):(X("Expected property name"),i=Ke({type:"Identifier",name:""},t)),e=T({type:"MemberExpression",object:e,property:i,computed:false,optional:false},e,i);}else if(p("[")){o();let t=P(),i=d("]");e=T({type:"MemberExpression",object:e,property:t,computed:true,optional:false},e,i);}else if(p("(")){let{args:t,close:i}=y();e=T({type:"CallExpression",callee:e,arguments:t,optional:false},e,i);}else if(p("<")){let t=D();if(!t)break;let{args:i,close:g}=y();e=T({type:"CallExpression",callee:e,arguments:i,optional:false,typeArguments:t},e,g);}else if(p("++")||p("--")){let t=o();e=T({type:"UpdateExpression",operator:t.value,prefix:false,argument:e},e,t);}else break;return n?T({type:"ChainExpression",expression:e},e,e):e},y=()=>{d("(");let e=[];for(;!p(")");)e.push(m()),p(")")||d(",");return {args:e,close:d(")")}},m=()=>{if(p("...")){let e=o(),n=P();return T({type:"SpreadElement",argument:n},e,n)}return P()},l=()=>{let e=f();return e.type!=="Identifier"&&R("Expected identifier"),o(),I({type:"Identifier",name:e.value},e)},S=(e,n=false)=>{let t=p("{")?w(e):p("[")?x(e):l();if(n&&p("?")&&(t.type!=="Identifier"&&R("A binding pattern parameter cannot be optional"),o(),t.optional=true),p(":")){o();let i=ce(e);t.typeAnnotation=i.schema,t.typeAnnotationNode=i.node;}return t},w=e=>{let n=d("{"),t=[];for(;!p("}");){if(p("...")){let g=o(),N=S(e);t.push(T({type:"RestElement",argument:N},g,N));}else {let g=l(),N,j=false;if(p(":")?(o(),N=S(e)):(N={...g},j=true),p("=")){o();let B=P();N=T({type:"AssignmentPattern",left:N,right:B},N,B);}t.push(T({type:"Property",key:g,value:N,kind:"init",shorthand:j,computed:false},g,N));}p("}")||d(",");}let i=d("}");return T({type:"ObjectPattern",properties:t},n,i)},x=e=>{let n=d("["),t=[];for(;!p("]");){if(p(",")){t.push(null),o();continue}if(p("...")){let g=o(),N=S(e);t.push(T({type:"RestElement",argument:N},g,N));}else {let g=S(e);if(p("=")){o();let N=P();g=T({type:"AssignmentPattern",left:g,right:N},g,N);}t.push(g);}p("]")||d(",");}let i=d("]");return T({type:"ArrayPattern",elements:t},n,i)},J=()=>{let e=0;for(let n=u;n<a.length;n++){let t=a[n];if(t.type==="EOF")return false;if(t.type==="Punctuator"){if(t.value==="("||t.value==="["||t.value==="{")e++;else if((t.value===")"||t.value==="]"||t.value==="}")&&(e--,e===0)){let i=a[n+1];return !i||i.type!=="Punctuator"?false:i.value==="=>"?true:i.value===":"?$(n+2):false}}}return false},$=e=>{let n=0;for(let t=e;t<a.length;t++){let i=a[t];if(i.type==="EOF")return false;if(i.type==="Punctuator")if(["(","[","{","<"].includes(i.value))n++;else if([")","]","}",">"].includes(i.value)){if(n===0)return false;n--;}else {if(n===0&&i.value==="=>")return true;if(n===0&&(i.value===";"||i.value===","))return false}}return false},F=(e=[])=>{d("(");let n=[];for(;!p(")");){if(p("...")){let t=o(),i=S(e);n.push(T({type:"RestElement",argument:i},t,i));}else {let t=S(e,true);if(p("=")){t.optional&&R("Parameter cannot have question mark and initializer"),o();let i=P();t=T({type:"AssignmentPattern",left:t,right:i},t,i);}n.push(t);}p(")")||d(",");}return d(")"),n},L=e=>{if(e.type==="Identifier")return e.name;let n=e.left;return e.type==="AssignmentPattern"&&n?.type==="Identifier"?n.name:null},O=(e,n,t=[])=>{let i=p("(")?F(t):[l()],g,N,j;if(p(":")){o();let K=ze(t,i.map(L));g=K.schema,N=K.node,j=K.guard;}d("=>");let B=p("{")?le():P();return I({type:"ArrowFunctionExpression",params:i,body:B,async:e,expression:B.type!=="BlockStatement",generator:false,...g?{returnType:g,returnTypeNode:N}:{},...j?{returnGuard:j}:{},...t.length?{typeParams:t.map(K=>K.name),typeParamNodes:t}:{}},n)},H=()=>{let e=d("["),n=[];for(;!p("]");){if(p(",")){o(),n.push(null);continue}n.push(m()),p("]")||d(",");}return T({type:"ArrayExpression",elements:n},e,d("]"))},ae=()=>{let e=d("{"),n=[];for(;!p("}");){if(p("...")){let t=o(),i=P();n.push(T({type:"SpreadElement",argument:i},t,i));}else {let t=f(),i,g=false;if(p("["))g=true,o(),i=P(),d("]");else if(t.type==="String")o(),i=I({type:"Literal",value:W(t.value.slice(1,-1)),raw:t.value},t);else if(t.type==="Number")o(),i=I({type:"Literal",value:Number(t.value),raw:t.value},t);else if(t.type==="Identifier"||t.type==="Keyword")o(),i=I({type:"Identifier",name:t.value},t);else return R("Invalid property key");if(p(":")){o();let N=P();n.push(T({type:"Property",key:i,value:N,kind:"init",shorthand:false,computed:g},t,N));}else n.push(T({type:"Property",key:i,value:i,kind:"init",shorthand:true,computed:false},t,i));}p("}")||d(",");}return T({type:"ObjectExpression",properties:n},e,d("}"))},V=(e,n)=>({type:"TemplateElement",value:{raw:e,cooked:W(e)},tail:n}),$e=e=>{o();let n=[V(e.value,false)],t=[];for(;;){t.push(P());let i=f();if(i.type==="TemplateMiddle")o(),n.push(V(i.value,false));else if(i.type==="TemplateTail"){o(),n.push(V(i.value,true));break}else R("Expected `}` to close template interpolation");}return I({type:"TemplateLiteral",quasis:n,expressions:t},e)},ie=()=>{let e=f();return e.type!=="Identifier"&&R(`Expected JSX identifier but got '${e.value||e.type}'`),I({type:"JSXIdentifier",name:o().value},e)},we=()=>{let e=ie();if(p(":")){o();let n=ie();return T({type:"JSXNamespacedName",namespace:e,name:n},e,n)}for(;p(".");){o();let n=ie();e=T({type:"JSXMemberExpression",object:e,property:n},e,n);}return e},Q=e=>e.type==="JSXIdentifier"?e.name:e.type==="JSXNamespacedName"?`${Q(e.namespace)}:${Q(e.name)}`:`${Q(e.object)}.${Q(e.property)}`,Me=()=>{let e=f();if(e.type==="String")return o(),I({type:"Literal",value:W(e.value.slice(1,-1)),raw:e.value},e);if(p("{")){let n=o(),t=_(),i=d("}");return T({type:"JSXExpressionContainer",expression:t},n,i)}return p("<")?Te():R(`Invalid JSX attribute value '${e.value||e.type}'`)},Be=()=>{let e=[];for(;!p(">")&&!p("/>")&&!b();){if(p("{")){let i=o();d("...");let g=_(),N=d("}");e.push(T({type:"JSXSpreadAttribute",argument:g},i,N));continue}let n=ie();if(p(":")){o();let i=ie();n=T({type:"JSXNamespacedName",namespace:n,name:i},n,i);}let t=null;p("=")&&(o(),t=Me()),e.push(T({type:"JSXAttribute",name:n,value:t},n,t??n));}return e},Pe=()=>{let e=[];for(;!(p("</")||b());){let n=f();if(n.type==="JSXText")o(),e.push(I({type:"JSXText",value:n.value,raw:n.value},n));else if(p("{")){let t=o();if(p("}")){let i=o(),g=I({type:"JSXEmptyExpression"},t);e.push(T({type:"JSXExpressionContainer",expression:g},t,i));}else if(p("...")){o();let i=_(),g=d("}");e.push(T({type:"JSXSpreadChild",expression:i},t,g));}else {let i=_(),g=d("}");e.push(T({type:"JSXExpressionContainer",expression:i},t,g));}}else p("<")?e.push(Te()):R(`Unexpected token in JSX children '${n.value||n.type}'`);}return e},Te=()=>{let e=d("<");if(p(">")){let ee=o(),oe=T({type:"JSXOpeningFragment"},e,ee),st=Pe(),at=d("</"),Le=d(">"),it=T({type:"JSXClosingFragment"},at,Le);return T({type:"JSXFragment",openingFragment:oe,children:st,closingFragment:it},e,Le)}let n=we(),t=Be();if(p("/>")){let ee=o(),oe=T({type:"JSXOpeningElement",name:n,attributes:t,selfClosing:true},e,ee);return T({type:"JSXElement",openingElement:oe,children:[],closingElement:null},e,ee)}let i=d(">"),g=T({type:"JSXOpeningElement",name:n,attributes:t,selfClosing:false},e,i),N=Pe(),j=d("</"),B=f(),K=we();Q(K)!==Q(n)&&R(`JSX closing tag </${Q(K)}> does not match opening <${Q(n)}>`,B);let G=d(">"),Y=T({type:"JSXClosingElement",name:K},j,G);return T({type:"JSXElement",openingElement:g,children:N,closingElement:Y},e,G)},_e=()=>{let e=f();if(v("async")){let n=f(1);if(n.value==="("||n.type==="Identifier")return o(),O(true,e);if(n.value==="<"){o();let t=Ne(e,true);if(t)return t}return R("Unexpected 'async'")}if(p("(")&&J()||e.type==="Identifier"&&f(1).type==="Punctuator"&&f(1).value==="=>")return O(false,e);if(e.type==="Number")return o(),I({type:"Literal",value:Number(e.value),raw:e.value},e);if(e.type==="String")return o(),I({type:"Literal",value:W(e.value.slice(1,-1)),raw:e.value},e);if(e.type==="Template")return o(),I({type:"TemplateLiteral",expressions:[],quasis:[V(e.value,true)]},e);if(e.type==="TemplateHead")return $e(e);if(e.type==="Keyword")return e.value==="true"?(o(),I({type:"Literal",value:true,raw:"true"},e)):e.value==="false"?(o(),I({type:"Literal",value:false,raw:"false"},e)):e.value==="null"?(o(),I({type:"Literal",value:null,raw:"null"},e)):e.value==="new"?R("'new' is not supported \u2014 the language has no constructors (FP / portable IR). Use a factory function provided via DI (e.g. `now()` instead of `new Date()`)."):e.value==="function"?R("Anonymous functions are not supported \u2014 use an arrow function"):R(`'${e.value}' is not supported in this language`);if(e.type==="Identifier")return o(),I({type:"Identifier",name:e.value},e);if(p("(")){o();let n=P();return d(")"),n}return p("[")?H():p("{")?ae():p("<")?Ne(e)??Te():R(`Unexpected token '${e.value||e.type}'`)},Ne=(e,n=false)=>{let t=u,i=c.length,g=()=>(u=t,c.length=i,void 0);try{let N=Ee();return !N.length||!p("(")?g():O(n,e,N)}catch{return g()}},{parseType:ce,parseReturnType:ze,parseTypeParamList:Ee,parseTypeInScope:We}=Fe({tokens:a,pos:()=>u,peek:f,next:o,isP:p,isK:v,expectP:d,fail:R,recordError:X,createMissingNode:Ke,unescape:W,typeRefs:k}),Ce=()=>{let e=o(),n=l(),t=[],i=[];p("<")&&(i=Ee(),t=i.map(j=>j.name)),d("=");let g=We(i),N=T({type:"TSTypeAliasDeclaration",id:n,typeParameters:t,...i.length?{typeParamNodes:i}:{},typeAnnotation:g.schema,typeNode:g.node},e,h());return p(";")&&o(),N},Z=()=>{let e=f();if(e.type==="Identifier"&&e.value==="type"&&f(1).type==="Identifier"&&f(2).type==="Punctuator"&&(f(2).value==="="||f(2).value==="<"))return Ce();if(v("const")||v("let")||v("var")){let g=Ie();return p(";")&&o(),g}if(v("if"))return et();if(v("for"))return Ve();if(v("while"))return Ze();if(v("do"))return Ye();if(v("break")||v("continue"))return Qe();if(v("return"))return tt();if(v("throw"))return nt();if(v("try"))return rt();if(v("switch"))return ot();if(v("import"))return He();if(v("export"))return Ge();if(p("{"))return le();if((v("function")||v("async")&&f(1).type==="Keyword"&&f(1).value==="function")&&R("Function declarations are not supported \u2014 use 'const fn = () => \u2026'"),p(";"))return o(),I({type:"EmptyStatement"},e);if(e.type==="Keyword"&&Pt.has(e.value)||e.type==="Identifier"&&Et[e.value]?.(f(1),f(2))===true){let g=Nt[e.value];R(`'${e.value}' is not supported in this language`+(g?` \u2014 ${g}`:""));}let t=P(),i=p(";")?o():h();return T({type:"ExpressionStatement",expression:t},t,i)},Ie=()=>{let e=o(),n=e.value,t=()=>{let g=S([]),N=null;return p("=")?(o(),N=P()):n==="const"&&X("'const' declarations must be initialized"),T({type:"VariableDeclarator",id:g,init:N},g,N??g)},i=[t()];for(;p(",");)o(),i.push(t());return T({type:"VariableDeclaration",kind:n,declarations:i},e,i[i.length-1])},qe=()=>{let e=f();return e.type!=="String"&&R("Expected module specifier string"),o(),I({type:"Literal",value:W(e.value.slice(1,-1)),raw:e.value},e)},He=()=>{let e=o(),n=[],t;if(z("type")){let g=f(1);(g.type==="Punctuator"&&(g.value==="{"||g.value==="*")||g.type==="Identifier"&&g.value!=="from")&&(o(),t="type");}if(f().type!=="String"){if(f().type==="Identifier"){let g=l();n.push(T({type:"ImportDefaultSpecifier",local:g},g,g)),p(",")&&o();}if(p("*")){let g=o();z("as")||R("Expected 'as' after '*' in import"),o();let N=l();n.push(T({type:"ImportNamespaceSpecifier",local:N},g,N));}else if(p("{")){for(o();!p("}")&&!b();){let g;z("type")&&f(1).type==="Identifier"&&f(1).value!=="as"&&(o(),g="type");let N=l(),j=N;if(z("as")&&(o(),j=l()),n.push(T({type:"ImportSpecifier",imported:N,local:j,...g?{importKind:g}:{}},N,j)),p(","))o();else break}d("}");}z("from")||R("Expected 'from' in import declaration"),o();}let i=qe();return p(";")&&o(),I({type:"ImportDeclaration",specifiers:n,source:i,...t?{importKind:t}:{}},e)},Ge=()=>{let e=o();if(z("type")&&f(1).type==="Identifier"){let n=Ce();return I({type:"ExportNamedDeclaration",declaration:n,specifiers:[],source:null},e)}if(v("default")){o();let n=P();return p(";")&&o(),I({type:"ExportDefaultDeclaration",declaration:n},e)}if(v("const")||v("let")||v("var")){let n=Ie();return p(";")&&o(),I({type:"ExportNamedDeclaration",declaration:n,specifiers:[],source:null},e)}if(p("{")){o();let n=[];for(;!p("}")&&!b();){let t=l(),i=t;if(z("as")&&(o(),i=l()),n.push(T({type:"ExportSpecifier",local:t,exported:i},t,i)),p(","))o();else break}return d("}"),p(";")&&o(),I({type:"ExportNamedDeclaration",declaration:null,specifiers:n,source:null},e)}return R("Expected 'const', 'type', '{', or 'default' after 'export'")},Re=()=>f().type==="Identifier"&&f().value==="of",ge=()=>v("in"),Ve=()=>{let e=o();d("(");let n=null,t=null;if(!p(";"))if(v("const")||v("let")||v("var")){let j=o(),B=()=>{let G=l();if(p(":")){o();let Y=ce();G.typeAnnotation=Y.schema,G.typeAnnotationNode=Y.node;}return G},K=B();if(Re()||ge()){let G=T({type:"VariableDeclarator",id:K,init:null},K,K);t=T({type:"VariableDeclaration",kind:j.value,declarations:[G]},j,K);}else {let G=ee=>{let oe=null;return p("=")?(o(),oe=P(true)):j.value==="const"&&R("'const' declarations must be initialized"),T({type:"VariableDeclarator",id:ee,init:oe},ee,oe??ee)},Y=[G(K)];for(;p(",");)o(),Y.push(G(B()));n=T({type:"VariableDeclaration",kind:j.value,declarations:Y},j,Y[Y.length-1]);}}else {let j=P(true);Re()||ge()?t=j:n=j;}if(t){let j=ge();o();let B=P();d(")");let K=Z();return T(j?{type:"ForInStatement",left:t,right:B,body:K}:{type:"ForOfStatement",left:t,right:B,body:K,await:false},e,K)}d(";");let i=p(";")?null:P();d(";");let g=p(")")?null:P();d(")");let N=Z();return T({type:"ForStatement",init:n,test:i,update:g,body:N},e,N)},Ye=()=>{let e=o(),n=Z();v("while")||R("Expected 'while' after the 'do' body"),o(),d("(");let t=P(),i=d(")");return p(";")&&o(),T({type:"DoWhileStatement",body:n,test:t},e,i)},Qe=()=>{let e=o(),n=e.value==="break"?"BreakStatement":"ContinueStatement",t=p(";")?o():h();return T({type:n,label:null},e,t)},Ze=()=>{let e=o();d("(");let n=P();d(")");let t=Z();return T({type:"WhileStatement",test:n,body:t},e,t)},et=()=>{let e=o();d("(");let n=P();d(")");let t=Z(),i=null;return v("else")&&(o(),i=Z()),T({type:"IfStatement",test:n,consequent:t,alternate:i},e,i??t)},tt=()=>{let e=o(),n=null;!p(";")&&!p("}")&&!b()&&(n=P());let t=p(";")?o():h();return T({type:"ReturnStatement",argument:n},e,t)},nt=()=>{let e=o(),n=P(),t=p(";")?o():h();return T({type:"ThrowStatement",argument:n},e,t)},rt=()=>{let e=o(),n=le(),t=null,i=null;if(v("catch")){let g=o(),N=null;p("(")&&(o(),N=l(),d(")"));let j=le();t=T({type:"CatchClause",param:N,body:j},g,j);}return v("finally")&&(o(),i=le()),!t&&!i&&R("'try' requires a 'catch' or 'finally' clause"),T({type:"TryStatement",block:n,handler:t,finalizer:i},e,i??t??n)},ot=()=>{let e=o();d("(");let n=P();d(")"),d("{");let t=[];for(;!p("}")&&!b();){let g=f(),N=null;v("case")?(o(),N=P()):v("default")?o():R("Expected 'case' or 'default' in switch"),d(":");let j=[];for(;!p("}")&&!v("case")&&!v("default")&&!b();)j.push(Z());t.push(T({type:"SwitchCase",test:N,consequent:j},g,h()??g));}let i=d("}");return T({type:"SwitchStatement",discriminant:n,cases:t},e,i)},le=()=>{let e=d("{"),n=Ae(()=>p("}"));return T({type:"BlockStatement",body:n},e,d("}"))},Ae=e=>{let n=[];for(;!e()&&!b();){if(f().type==="Unknown"){o();continue}try{n.push(Z());}catch(t){if(!(t instanceof re))throw t;b()||o();}}return n};return {parseExpr:P,parseProgram:()=>{let e=f(),n=Ae(()=>false);return T({type:"Program",sourceType:"module",body:n,...k.length?{typeRefs:k}:{},...s.length?{comments:s}:{},...c.length?{parseDiagnostics:c}:{}},e,h()??e)},eof:b,fail:R,recordError:X,diagnostics:c}}function Ue(r){let c=ke(r),s=c.parseProgram(),a=s.comments;return a?.length&&xe(s,a,r),{ast:s,diagnostics:c.diagnostics}}function It(r){let{ast:c,diagnostics:s}=Ue(r),a=s[0];if(a){let u=a.code==="lex-error"?ne:re;throw new u(a.message,a.position,a.index,a.loc,a.end)}return c}function Rt(r){let c=ke(r),s=c.parseExpr();c.eof()||c.fail("Unexpected token after expression");let a=c.diagnostics[0];if(a){let u=a.code==="lex-error"?ne:re;throw new u(a.message,a.position,a.index,a.loc,a.end)}return s}function At(r){let c=ke(r),s;try{s=c.parseExpr(),c.eof()||c.recordError("Unexpected token after expression");}catch(a){if(!(a instanceof re)&&!(a instanceof ne))throw a}return {ast:s,diagnostics:c.diagnostics}}exports.KEYWORDS=De;exports.LexError=ne;exports.ParseError=re;exports.attachComments=xe;exports.nodeIsMissing=xt;exports.parse=It;exports.parseExpression=Rt;exports.parseExpressionTolerant=At;exports.parseTolerant=Ue;exports.tokenize=be;
1
+ 'use strict';var ast=require('@tslite/ast');var re=class extends ast.TSLiteError{constructor(a,i,f,v,S){super("lex-error",`${a} (${i.line}:${i.column})`,{position:i,index:f,loc:v,end:S});this.position=i;this.index=f;this.loc=v;this.end=S;this.name="LexError";}},Ke=new Set(["const","if","else","return","async","await","true","false","null","typeof","let","var","function","class","new","for","while","do","this","throw","try","catch","finally","switch","case","break","continue","default","void","delete","instanceof","in","yield","import","export","extends","super","debugger","with","enum","interface"]),vt=["...","===","!==","=>","?.","??=","&&=","||=","**=","??","==","!=","<=",">=","&&","||","|","&","++","--","+=","-=","*=","/=","%=","**","<<","+","-","*","/","%","<",">","!","?",":",".",",",";","=","^","~","(",")","[","]","{","}"],he=r=>r>="a"&&r<="z"||r>="A"&&r<="Z"||r==="_"||r==="$",Te=r=>he(r)||r>="0"&&r<="9",ne=r=>r>="0"&&r<="9",Fe=r=>ne(r)||r>="a"&&r<="f"||r>="A"&&r<="F",St=r=>Te(r)||r==="-",ue=r=>r===`
2
+ `||r==="\r"||r==="\u2028"||r==="\u2029",me=(r,u)=>{let a=u;for(;;){let i=r[a]??"";if(i===" "||i===" "||i==="\f"||i==="\v"||ue(i))a++;else if(i==="/"&&r[a+1]==="/")for(a+=2;a<r.length&&!ue(r[a]??"");)a++;else if(i==="/"&&r[a+1]==="*"){for(a+=2;a<r.length&&!(r[a]==="*"&&r[a+1]==="/");)a++;a+=2;}else return a}},kt=(r,u)=>{if(!he(r[u]??""))return u;let a=u+1;for(;Te(r[a]??"");)a++;return a},Xe=(r,u,a)=>r.startsWith(a,u)&&!Te(r[u+a.length]??""),wt=(r,u)=>{let a=me(r,u);Xe(r,a,"const")&&(a=me(r,a+5));let i=kt(r,a);if(i===a)return false;if(a=me(r,i),Xe(r,a,"extends")){let f=me(r,a+7),v=r[f]??"";return !(v==="="||v===">"||v==="/")}return r[a]===","?true:r[a]==="="&&r[a+1]!==">"},Pt=new Set(["(","[","{",",",";",":","?","=>","...","=","+","-","*","/","%","<","<=",">",">=","==","===","!=","!==","&&","||","??","!","+=","-=","*=","/=","%=","??=","&&=","||=","**="]),Nt=new Set(["return","typeof","await","delete","void","in","instanceof","else","case","yield","throw"]);function Et(r,u,a){return ke(r,u,a).scan()}function ke(r,u,a){let i=[],f=0,v=1,S=0,j=()=>({line:v,column:S}),h=(g=0)=>r[f+g]??"",_=g=>{let p=j(),d={start:p,end:{line:v,column:S+1}};if(a){a({message:g,position:p,index:f,loc:d,end:f+1});return}throw new re(g,p,f,d,f+1)},k=()=>{let g=r[f++];return g==="\r"?(r[f]===`
3
+ `&&f++,v++,S=0):g===`
4
+ `||g==="\u2028"||g==="\u2029"?(v++,S=0):S++,g},se=()=>{for(;;){let g=h();if(g===" "||g===" "||g==="\f"||g==="\v"||ue(g))k();else if(g==="/"&&h(1)==="/"){let p=f,d=j();k(),k();let o=f;for(;f<r.length&&!ue(h());)k();u?.({type:"Line",value:r.slice(o,f),start:p,end:f,loc:{start:d,end:j()}});}else if(g==="/"&&h(1)==="*"){let p=f,d=j();k(),k();let o=f,m=f;for(;;){if(f>=r.length){_("Unterminated block comment"),m=f;break}if(h()==="*"&&h(1)==="/"){m=f,k(),k();break}k();}u?.({type:"Block",value:r.slice(o,m),start:p,end:f,loc:{start:d,end:j()}});}else break}},A=(g,p,d,o)=>{i.push({type:g,value:p,start:d,end:f,loc:{start:o,end:j()}}),E=g==="Punctuator"?Pt.has(p):g==="Keyword"?Nt.has(p):g==="TemplateHead"||g==="TemplateMiddle";},P=g=>{for(k();f<r.length;){let p=h();if(p===g)return k(),r.slice(N,f);if(ue(p))return _("Unterminated string literal"),r.slice(N,f);if(p==="\\"){if(k(),f>=r.length)return _("Unterminated string literal"),r.slice(N,f);k();continue}k();}return _("Unterminated string literal"),r.slice(N,f)},l=()=>{if(h()==="0"&&(h(1)==="x"||h(1)==="X")){if(k(),k(),!Fe(h()))return _("Invalid hexadecimal literal");for(;Fe(h());)k();return}if(h()==="0"&&(h(1)==="b"||h(1)==="B")){if(k(),k(),h()!=="0"&&h()!=="1")return _("Invalid binary literal");for(;h()==="0"||h()==="1";)k();return}if(h()==="0"&&(h(1)==="o"||h(1)==="O")){if(k(),k(),!(h()>="0"&&h()<="7"))return _("Invalid octal literal");for(;h()>="0"&&h()<="7";)k();return}for(;ne(h());)k();if(h()===".")for(k();ne(h());)k();if(h()==="e"||h()==="E"){if(k(),(h()==="+"||h()==="-")&&k(),!ne(h()))return _("Invalid exponent");for(;ne(h());)k();}},K=()=>{let g=f;for(;f<r.length;){let p=h();if(p==="`"){let d=r.slice(g,f);return k(),{raw:d,interp:false}}if(p==="$"&&h(1)==="{"){let d=r.slice(g,f);return k(),k(),{raw:d,interp:true}}if(p==="\\"){if(k(),f>=r.length)break;k();continue}k();}return _("Unterminated template literal"),{raw:r.slice(g,f),interp:false}},N=0,M=0,c=[],E=true,F="js",C=[],V=[],w=new Map,D=-1,T=()=>({i:f,line:v,col:S,mode:F,braceDepth:M,tmplStack:[...c],jsxParent:[...C],jsxExpr:V.map(g=>({...g}))}),G=g=>{f=g.i,v=g.line,S=g.col,F=g.mode,M=g.braceDepth,c=[...g.tmplStack],C=[...g.jsxParent],V=g.jsxExpr.map(p=>({...p}));},J=()=>(i=[],Y(),i),Y=()=>{for(;;){if(F==="jsxChildren"){N=f;let o=j();if(f>=r.length){A("EOF","",N,o);break}let m=h();if(m==="<"){h(1)==="/"?(k(),k(),A("Punctuator","</",N,o),F="jsxCloseTag"):(k(),A("Punctuator","<",N,o),C.push("jsxChildren"),F="jsxOpenTag");continue}if(m==="{"){k(),A("Punctuator","{",N,o),V.push({level:M,restore:"jsxChildren"}),F="js";continue}for(;f<r.length&&h()!=="<"&&h()!=="{";)k();A("JSXText",r.slice(N,f),N,o);continue}if(F==="jsxOpenTag"||F==="jsxCloseTag"){se(),N=f;let o=j();if(f>=r.length){A("EOF","",N,o);break}let m=h();if(he(m)){for(k();St(h());)k();A("Identifier",r.slice(N,f),N,o);continue}if(m==="/"&&h(1)===">"){k(),k(),A("Punctuator","/>",N,o),F=C.pop()??"js";continue}if(m===">"){k(),A("Punctuator",">",N,o),F=F==="jsxCloseTag"?C.pop()??"js":"jsxChildren";continue}if(m==="{"){k(),A("Punctuator","{",N,o),V.push({level:M,restore:F}),F="js";continue}if(m==='"'||m==="'"){A("String",P(m),N,o);continue}if(m==="="||m==="."||m===":"){k(),A("Punctuator",m,N,o);continue}if(m==="<"&&F==="jsxOpenTag"){k(),A("Punctuator","<",N,o),C.push("jsxOpenTag");continue}_(`Unexpected character '${m}' in JSX tag`),k(),A("Unknown",m,N,o);continue}se(),N=f;let g=j();if(f>=r.length){A("EOF","",N,g);break}let p=h();if(he(p)){for(;Te(h());)k();let o=r.slice(N,f);A(Ke.has(o)?"Keyword":"Identifier",o,N,g);continue}if(ne(p)||p==="."&&ne(h(1))){l(),A("Number",r.slice(N,f),N,g);continue}if(p==='"'||p==="'"){let o=P(p);A("String",o,N,g);continue}if(p==="`"){k();let{raw:o,interp:m}=K();m?(A("TemplateHead",o,N,g),c.push(M)):A("Template",o,N,g);continue}if(p==="<"&&f===D){D=-1,k(),A("Punctuator","<",N,g);continue}if(p==="<"&&E&&!wt(r,f+1)){w.set(f,T()),k(),A("Punctuator","<",N,g),C.push("js"),F="jsxOpenTag";continue}if(p==="{"){k(),A("Punctuator","{",N,g),M++;continue}if(p==="}"){if(c.length>0&&M===c[c.length-1]){c.pop(),k();let{raw:o,interp:m}=K();A(m?"TemplateMiddle":"TemplateTail",o,N,g),m&&c.push(M);continue}if(V.length>0&&M===V[V.length-1].level){let{restore:o}=V.pop();k(),A("Punctuator","}",N,g),F=o;continue}k(),A("Punctuator","}",N,g),M--;continue}if(p==="?"&&h(1)==="."&&ne(h(2))){k(),A("Punctuator","?",N,g);continue}let d=vt.find(o=>r.startsWith(o,f));if(d){for(let o=0;o<d.length;o++)k();A("Punctuator",d,N,g);continue}_(`Unexpected character '${p}'`),k(),A("Unknown",p,N,g);}};return {scan:J,opensJsx:g=>w.has(g),rescanLessThan:g=>{let p=w.get(g);return p?(G(p),D=g,J()):null}}}var It=new Set(["leadingComments","trailingComments","innerComments","comments"]),Me=r=>typeof r=="object"&&r!==null&&typeof r.type=="string"&&r.loc!=null&&typeof r.start=="number",$e=new WeakMap;function Ct(r){let u=$e.get(r);if(u)return u;let a=[];for(let i of Object.keys(r)){if(It.has(i))continue;let f=r[i];if(Me(f))a.push(f);else if(Array.isArray(f))for(let v of f)Me(v)&&a.push(v);}return a.sort((i,f)=>i.start-f.start),$e.set(r,a),a}function Lt(r,u){let a=r,i,f;for(;;){let v=Ct(a);i=void 0,f=void 0;let S;for(let j of v){if(j.start<=u.start&&u.end<=j.end){S=j;break}if(j.end<=u.start)i=j;else if(u.end<=j.start){f=j;break}}if(!S)break;a=S;}return {enclosing:a,preceding:i,following:f}}var we=(r,u)=>{(r.leadingComments??(r.leadingComments=[])).push(u);},ge=(r,u)=>{(r.trailingComments??(r.trailingComments=[])).push(u);},Pe=(r,u)=>{(r.innerComments??(r.innerComments=[])).push(u);};function Rt(r,u){for(let a=u;a<r.length;a++){let i=r[a];if(i!==" "&&i!==" "&&i!=="\r"&&i!==`
5
+ `&&i!=="\f")return i}return ""}var jt=new Set([")","]","}",","]);function Ne(r,u,a=""){for(let i of u){let{enclosing:f,preceding:v,following:S}=Lt(r,i),j=v==null||v.loc.end.line<i.loc.start.line,h=!j&&(S==null||i.loc.end.line<S.loc.start.line);if(j)S?we(S,i):v?ge(v,i):Pe(f,i);else if(h)v?ge(v,i):S?we(S,i):Pe(f,i);else {let _=jt.has(Rt(a,i.end));v&&_?ge(v,i):S?we(S,i):v?ge(v,i):Pe(f,i);}}}var At=Object.prototype.hasOwnProperty,be=(r,u)=>At.call(r,u)?r[u]:void 0;function Ue(r,u,a){u==="__proto__"?Object.defineProperty(r,u,{value:a,enumerable:true,writable:true,configurable:true}):r[u]=a;}var Ot=(r=[])=>({vars:new Set(r),bounds:new Map,noCond:false,inferSink:null}),le=(r,u)=>{let a=new Set(r.vars),i=new Map(r.bounds);for(let f of u)a.add(f.name),f.bound?i.set(f.name,{bound:f.bound}):i.delete(f.name);return {vars:a,bounds:i,noCond:r.noCond,inferSink:r.inferSink}},Ee=r=>({t:"var",name:r.name,...r.bound?{bound:r.bound}:{},...r.default?{default:r.default}:{}}),Dt=(r,u)=>{let a=r.bounds.get(u)?.bound;return a?{t:"var",name:u,bound:a}:{t:"var",name:u}},Be=r=>{let{peek:u,next:a,isP:i,isK:f,expectP:v,fail:S,unescape:j}=r,h=(p,d)=>{let o=r.tokens[r.pos()-1]??d;return Object.assign(p,{start:d.start,end:o.end,loc:{start:d.loc.start,end:o.loc.end}})},_=()=>{let p=r.pos(),d=r.tokens[p],o=r.tokens[p-1];return !!o&&!!d&&d.loc.start.line>o.loc.end.line},k=()=>{let p=x=>r.tokens[r.pos()+x],d=(x,...b)=>x?.type==="Punctuator"&&b.includes(x.value),o=p(1);if(d(o,")","..."))return true;if(o?.type!=="Identifier")return false;let m=p(2);return d(m,":",",","?","=")?true:d(m,")")&&d(p(3),"=>")},se=()=>{let p=r.tokens,d=[],o=0,m=false;for(let x=r.pos();x<p.length;x++){let b=p[x];if(b.type==="EOF")break;if(b.type==="Punctuator"){if(b.value==="<")o++,o===1&&(m=true);else if(b.value===">"){if(o--,o===0)break}else b.value==="("||b.value==="["||b.value==="{"?(o++,m=false):b.value===")"||b.value==="]"||b.value==="}"?(o--,m=false):b.value===","&&o===1?m=true:m=false;continue}if(o===1&&m){if(b.type==="Keyword"&&b.value==="const")continue;if(b.type==="Identifier"){d.push(b.value),m=false;continue}}m=false;}return d},A=p=>{let d=le(p,se().map(m=>({name:m})));v("<");let o=[];for(;!i(">");){let m=u();f("const")&&S("'const' type parameters are not supported in this language; a constraint keeps the literal: '<T extends string>'");let x=u();x.type!=="Identifier"&&S("Expected type parameter name"),a();let b,X;if(f("extends")){a();let R=K(d);b=R.schema,X=R.node;}let $,I;if(i("=")){a();let R=K(d);$=R.schema,I=R.node;}o.push(h({type:"TSTypeParameter",name:x.value,...b?{bound:b}:{},...X?{boundNode:X}:{},...$?{default:$}:{},...I?{defaultNode:I}:{}},m)),i(">")||v(",");}return v(">"),o},P=p=>{r.splitShiftLeft(),v("<");let d=[];for(;!i(">");)d.push(K(p)),i(">")||v(",");return v(">"),d},l=p=>{let d=u();return d.type==="Identifier"&&d.value===p},K=p=>{let d=u(),o=N(p);if(p.noCond||!f("extends")||_())return o;a();let m=[],x=N({...p,noCond:true,inferSink:m});v("?");let b=le(p,m.map(I=>({name:I}))),X=K(b);v(":");let $=K(b);return {node:h({type:"TSConditionalType",checkType:o.node,extendsType:x.node,trueType:X.node,falseType:$.node},d),schema:{t:"conditional",check:o.schema,extends:x.schema,then:X.schema,else:$.schema,...m.length?{infer:m.map(I=>Ee({name:I}))}:{}}}},N=p=>{let d=u();i("|")&&a();let o=M(p);if(!i("|"))return o;let m=[o.node],x=[o.schema];for(;i("|");){a();let b=M(p);m.push(b.node),x.push(b.schema);}return {node:h({type:"TSUnionType",types:m},d),schema:{t:"union",of:x}}},M=p=>{let d=u();i("&")&&a();let o=c(p);if(!i("&"))return o;let m=[o.node],x=[o.schema];for(;i("&");){a();let b=c(p);m.push(b.node),x.push(b.schema);}return {node:h({type:"TSIntersectionType",types:m},d),schema:{t:"intersection",of:x}}},c=p=>{let d=u();if(l("keyof")){a();let o=c(p);return {node:h({type:"TSTypeOperator",operator:"keyof",typeAnnotation:o.node},d),schema:{t:"keyof",of:o.schema}}}if(l("readonly")){a();let o=c(p);return o.schema.t!=="array"&&o.schema.t!=="tuple"&&S("'readonly' only applies to array and tuple types"),{node:h({...o.node,readonly:true},d),schema:{...o.schema,readonly:true}}}if(l("infer")){a();let o=u();o.type!=="Identifier"&&S("Expected 'infer' variable name"),a();let m=p.inferSink;return m?(m.push(o.value),{node:h({type:"TSInferType",name:o.value},d),schema:{t:"var",name:o.value}}):S("'infer' is only allowed in the 'extends' clause of a conditional")}return E(p)},E=p=>{let d=u(),o=C(p);for(;i("[")&&!_();)if(a(),i("]"))a(),o={node:h({type:"TSArrayType",elementType:o.node},d),schema:{t:"array",items:o.schema}};else {let m=K(p);v("]"),o={node:h({type:"TSIndexedAccessType",objectType:o.node,indexType:m.node},d),schema:{t:"index",obj:o.schema,key:m.schema}};}return o},F=(p,d,o)=>({node:h({type:"TSKeywordType",kind:d},p),schema:o}),C=p=>{let d=u();if(f("typeof")){a();let x=u();x.type!=="Identifier"&&S("Expected a name after 'typeof' in type position"),a();let b=[x.value];for(;i(".");){a();let X=u();X.type!=="Identifier"&&X.type!=="Keyword"&&S("Expected a property name after '.' in 'typeof'"),a(),b.push(X.value);}return {node:h({type:"TSTypeQuery",exprName:b},d),schema:{t:"typeQuery",path:b}}}if(i("<")){r.rescanTypeLessThan();let x=A(p),b=le(p,x);return D(b,d,x)}if(i("(")){if(k())return D(p,d);a();let x=K(p.noCond?{...p,noCond:false}:p);return v(")"),x}if(i("{"))return G()?J(p):Y(p);if(i("["))return T(p);let o=u();if(o.type==="String"){a();let x=j(o.value.slice(1,-1));return {node:h({type:"TSLiteralType",literal:x},d),schema:{t:"literal",value:x}}}if(o.type==="Number"){a();let x=Number(o.value);return {node:h({type:"TSLiteralType",literal:x},d),schema:{t:"literal",value:x}}}if(f("true"))return a(),{node:h({type:"TSLiteralType",literal:true},d),schema:{t:"literal",value:true}};if(f("false"))return a(),{node:h({type:"TSLiteralType",literal:false},d),schema:{t:"literal",value:false}};if(f("null"))return a(),F(d,"null",{t:"null"});if(f("void"))return a(),F(d,"void",{t:"void"});if(o.type==="Identifier"){switch(a(),o.value){case "string":return F(d,"string",{t:"string"});case "number":return F(d,"number",{t:"number"});case "boolean":return F(d,"boolean",{t:"boolean"});case "any":return F(d,"any",{t:"any"});case "unknown":return F(d,"unknown",{t:"unknown"});case "undefined":return F(d,"undefined",{t:"undefined"});case "never":return F(d,"never",{t:"union",of:[]});case "object":return F(d,"object",{t:"nonPrimitive"})}let x=i("<")||i("<<")?P(p):[],b=x.map(I=>I.schema),X=x.length?x.map(I=>I.node):void 0,$=h({type:"TSTypeReference",typeName:o.value,...X?{typeArguments:X}:{}},d);return p.vars.has(o.value)&&b.length===0?{node:$,schema:Dt(p,o.value)}:o.value==="ReturnType"&&b.length===1?{node:$,schema:{t:"returnType",fn:b[0]}}:o.value==="Parameters"&&b.length===1?{node:$,schema:{t:"parameters",fn:b[0]}}:(r.typeRefs?.push({name:o.value,loc:o.loc,args:b}),{node:$,schema:{t:"apply",name:o.value,args:b}})}r.recordError(`Expected a type but got '${o.value||o.type}'`,o);let m=r.createMissingNode({type:"TSTypeReference",typeName:""},o);return r.typeRefs?.push({name:"",loc:m.loc,args:[]}),{node:m,schema:{t:"unknown"}}},V=p=>{v("(");let d=[];for(;!i(")");){let o=u(),m=i("...");m&&a();let x=u();x.type!=="Identifier"&&S("Expected parameter name in function type"),a();let b=!m&&i("?");b&&a(),v(":");let X=K(p),$=h({type:"Identifier",name:x.value,typeAnnotationNode:X.node,...b?{optional:true}:{}},x);d.push({node:m?h({type:"RestElement",argument:$},o):$,schema:{name:x.value,type:X.schema,...b?{optional:true}:{},...m?{variadic:true}:{}}}),m&&!i(")")&&S("A rest parameter must be last in a parameter list"),i(")")||v(",");}return v(")"),d},w=(p,d)=>{let o=u(),m=r.tokens[r.pos()+1];if(!(o.type==="Identifier"&&m?.type==="Identifier"&&m.value==="is"))return K(p);let b=d.indexOf(o.value);b<0&&S(`Cannot find parameter '${o.value}' for the type predicate`),a(),a();let X=K(p);return {node:h({type:"TSTypePredicate",parameterName:o.value,typeAnnotation:X.node},o),schema:{t:"boolean"},guard:{param:b,type:X.schema}}},D=(p,d,o)=>{let m=V(p);v("=>");let x=w(p,m.map(b=>b.schema.name));return {node:h({type:"TSFunctionType",params:m.map(b=>b.node),returnType:x.node,...o?.length?{typeParameters:[...o]}:{}},d),schema:{t:"fn",params:m.map(b=>b.schema),returns:x.schema,...x.guard?{guard:x.guard}:{},...o?.length?{typeParams:o.map(Ee)}:{}}}},T=p=>{let d=u();v("[");let o=[],m=[],x=[],b=[],X=()=>{let R=r.tokens[r.pos()],U=r.tokens[r.pos()+1],z=r.tokens[r.pos()+2];if(R?.type==="Identifier"&&U?.type==="Punctuator"&&(U.value===":"||U.value==="?"&&z?.type==="Punctuator"&&z.value===":"))return a(),R.value};for(;!i("]");){if(x[x.length-1]==="rest"&&S("A rest element must be last in a tuple type"),i("...")){a();let R=X();R!==void 0&&v(":"),b.push(R);let U=K(p);U.schema.t!=="array"&&S("A rest element type must be written as an array type ('...T[]')"),m.push(U.schema.items),o.push(U.node.elementType),x.push("rest");}else {let R=X(),U=false;R!==void 0&&(i("?")&&(a(),U=true),v(":")),b.push(R);let z=K(p);!U&&i("?")&&(a(),U=true),m.push(z.schema),o.push(z.node),x.push(U?"optional":"req");}i("]")||v(",");}v("]");let $=x.some(R=>R!=="req"),I=b.some(R=>R!==void 0);return {node:h({type:"TSTupleType",elementTypes:o,...$?{flags:x}:{},...I?{labels:b}:{}},d),schema:$?{t:"tuple",elements:m,flags:x}:{t:"tuple",elements:m}}},G=()=>{let p=r.tokens,d=r.pos()+1;return p[d]?.type==="Punctuator"&&(p[d]?.value==="+"||p[d]?.value==="-")&&d++,p[d]?.type==="Identifier"&&p[d]?.value==="readonly"&&d++,p[d]?.type==="Punctuator"&&p[d]?.value==="["&&p[d+1]?.type==="Identifier"&&p[d+2]?.type==="Keyword"&&p[d+2]?.value==="in"},J=p=>{let d=u();v("{"),(i("+")||i("-"))&&a(),l("readonly")&&a(),v("[");let o=u();o.type!=="Identifier"&&S("Expected mapped type key name"),a(),f("in")||S("Expected 'in' in mapped type"),a();let m=K(p);l("as")&&S("Key remapping ('as') in mapped types is not supported"),v("]");let x=false,b=i("+")||i("-")?a().value:null;i("?")&&(a(),x=b!=="-"),v(":");let X=K(le(p,[{name:o.value}]));return (i(";")||i(","))&&a(),v("}"),{node:h({type:"TSMappedType",key:o.value,constraint:m.node,typeAnnotation:X.node,optional:x},d),schema:{t:"mapped",key:o.value,over:m.schema,body:X.schema,optional:x}}},Y=p=>{let d=u();v("{");let o=[],m={},x,b=[];for(;!i("}");){let $=u();if(i("(")||i("<")){i("<")&&r.rescanTypeLessThan();let I=i("<")?A(p):[],R=I.length?le(p,I):p,U=V(R);v(":");let z=w(R,U.map(q=>q.schema.name));b.push({t:"fn",params:U.map(q=>q.schema),returns:z.schema,...z.guard?{guard:z.guard}:{},...I.length?{typeParams:I.map(Ee)}:{}}),o.push(h({type:"TSCallSignatureDeclaration",params:U.map(q=>q.node),returnType:z.node,...I.length?{typeParameters:I}:{}},$));}else if(i("[")){a(),u().type!=="Identifier"&&S("Expected index signature parameter name"),a(),v(":");let I=u();(I.type!=="Identifier"||I.value!=="string"&&I.value!=="number")&&S("Index signature parameter type must be 'string' or 'number'"),a(),v("]"),v(":");let R=K(p);x={key:I.value,value:R.schema},o.push(h({type:"TSIndexSignature",keyType:I.value,typeAnnotation:R.node},$));}else {let I=false;if(l("readonly")){let ae=r.tokens[r.pos()+1];ae&&(ae.type==="Identifier"||ae.type==="Keyword"||ae.type==="String"||ae.type==="Number")&&(a(),I=true);}let R=u(),U;if(R.type==="Identifier"||R.type==="Keyword")a(),U=R.value;else if(R.type==="String")a(),U=j(R.value.slice(1,-1));else if(R.type==="Number")a(),U=R.value;else return S("Expected property name in object type");let z=i("?");z&&a(),v(":");let q=K(p);Ue(m,U,{type:q.schema,...z?{optional:true}:{}}),o.push(h({type:"TSPropertySignature",key:U,typeAnnotation:q.node,...z?{optional:true}:{},...I?{readonly:true}:{}},$));}if(i(";")||i(","))a();else break}v("}");let X=h({type:"TSTypeLiteral",members:o},d);return b.length>0?Object.keys(m).length>0||x?S("Callable object types (call signatures mixed with members) are not supported"):{node:X,schema:b.length===1?b[0]:{t:"overload",signatures:b}}:{node:X,schema:{t:"object",props:m,...x?{index:x}:{}}}},g=Ot();return {parseType:()=>K(g),parseReturnType:p=>w(g,p),parseTypeParamList:()=>A(g),parseTypeInScope:p=>K(le(g,p)),withTypeParams:(p,d)=>{let o=g;g=le(o,p);try{return d()}finally{g=o;}}}};var oe=class extends ast.TSLiteError{constructor(a,i,f,v,S){super("parse-error",`${a} (${i.line}:${i.column})`,{position:i,index:f,loc:v,end:S});this.position=i;this.index=f;this.loc=v;this.end=S;this.name="ParseError";}},Ft=r=>{let u=r;return u!=null&&typeof u.start=="number"&&u.start===u.end&&u.start>=0},_e=(r,u)=>Object.assign(r,{start:u.start,end:u.start,loc:{start:u.loc.start,end:u.loc.start}}),Xt={"??":1,"||":2,"&&":3,"|":4,"^":5,"&":6,"==":7,"===":7,"!=":7,"!==":7,"<":8,"<=":8,">":8,">=":8,in:8,as:8,satisfies:8,"<<":9,">>":9,">>>":9,"+":10,"-":10,"*":11,"/":11,"%":11,"**":12},Kt=new Set(["??","||","&&"]),Mt=new Set(["class","debugger","with","enum","interface"]),$t={enum:'use a union of literals (`type T = "a" | "b"`) \u2014 it is serializable',interface:"use a type alias (`type X = { \u2026 }`)",namespace:"use modules (`import`/`export`)",module:"use modules (`import`/`export`)",declare:"declare the shape via the DI env, or with a `type` alias",abstract:"classes are not part of the language \u2014 model with objects + functions"},Ut={namespace:(r,u)=>r.type==="Identifier"&&u.type==="Punctuator"&&u.value==="{",module:(r,u)=>r.type==="Identifier"&&u.type==="Punctuator"&&u.value==="{",declare:r=>r.type==="Keyword"&&["const","let","var","function","class","enum","interface"].includes(r.value)||r.type==="Identifier"&&["type","namespace","module"].includes(r.value),abstract:r=>r.type==="Keyword"&&r.value==="class"},Bt=new Set(["=","+=","-=","*=","/=","%=","**=","??=","&&=","||="]);function Ie(r){let u=[],a=[],i=null,f=e=>`${e.index}:${e.message}`,v=ke(r,e=>{i?.comments.has(e.start)||a.push(e);},e=>{i?.lex.has(f(e))||u.push({code:"lex-error",...e});}),S=v.scan(),j=0,h=[],_=e=>{for(;h.length>e;)h.pop()();},k=(e=j)=>{let t=S[e];if(t?.type!=="Punctuator"||t.value!=="<"||!v.opensJsx(t.start))return;let n=S.slice(e),s=a.length;i={comments:new Set(a.map(L=>L.start)),lex:new Set(u.filter(L=>L.code==="lex-error").map(f))};let y;try{y=v.rescanLessThan(t.start);}finally{i=null;}S.splice(e,S.length-e,...y),h.push(()=>{S.splice(e,S.length-e,...n),a.length=s;});},se=()=>{let e=S[j];if(e?.type!=="Punctuator"||e.value!=="<<")return;let t={line:e.loc.start.line,column:e.loc.start.column+1},n=j;S.splice(n,1,{...e,value:"<",end:e.start+1,loc:{start:e.loc.start,end:t}},{...e,value:"<",start:e.start+1,loc:{start:t,end:e.loc.end}}),h.push(()=>S.splice(n,2,e));},A=[],P=(e=0)=>S[Math.min(j+e,S.length-1)],l=()=>S[j++],K=()=>S[j-1],N=()=>{let e=S[j],t=S[j-1];return !!e&&!!t&&e.loc.start.line>t.loc.end.line},M=()=>P().type==="EOF",c=e=>P().type==="Punctuator"&&P().value===e,E=e=>P().type==="Keyword"&&P().value===e,F=e=>P().type==="Identifier"&&P().value===e,C=(e,t=P())=>{throw V(e,t),new oe(e,t.loc.start,t.start,t.loc,t.end)},V=(e,t=P())=>{let n=u[u.length-1];n&&n.index===t.start||u.push({code:"parse-error",message:e,position:t.loc.start,index:t.start,loc:t.loc,end:t.end});},w=e=>(c(e)||C(`Expected '${e}' but got '${P().value||P().type}'`),l()),D=(e,t)=>{let n=K()??t;return Object.assign(e,{start:t.start,end:n.end,loc:{start:t.loc.start,end:n.loc.end}})},T=(e,t,n)=>Object.assign(e,{start:t.start,end:n.end,loc:{start:t.loc.start,end:n.loc.end}}),G=e=>{let t="";for(let n=0;n<e.length;n++){if(e[n]!=="\\"){t+=e[n];continue}let s=e[++n];switch(s){case "n":t+=`
6
+ `;break;case "t":t+=" ";break;case "r":t+="\r";break;case "b":t+="\b";break;case "f":t+="\f";break;case "v":t+="\v";break;case "0":t+="\0";break;case "x":t+=String.fromCharCode(parseInt(e.slice(n+1,n+3),16)),n+=2;break;case "u":if(e[n+1]==="{"){let y=e.indexOf("}",n);t+=String.fromCodePoint(parseInt(e.slice(n+2,y),16)),n=y;}else t+=String.fromCharCode(parseInt(e.slice(n+1,n+5),16)),n+=4;break;default:t+=s;}}return t},J=(e=false)=>Y(e),Y=(e=false)=>{let t=g(e),n=P();if(n.type==="Punctuator"&&Bt.has(n.value)){l();let s=Y();return T({type:"AssignmentExpression",operator:n.value,left:t,right:s},t,s)}return t},g=(e=false)=>{let t=d(0,e);if(!c("?"))return t;l();let n=J();w(":");let s=J();return T({type:"ConditionalExpression",test:t,consequent:n,alternate:s},t,s)},p=()=>{let e=P();if(e.type==="Keyword")return e.value==="in"?{op:"in",consume:1}:null;if(e.type==="Identifier")return e.value==="as"?{op:"as",consume:1}:e.value==="satisfies"?{op:"satisfies",consume:1}:null;if(e.type!=="Punctuator")return null;if(e.value===">"){let t=P(1);if(t.type==="Punctuator"&&t.value===">"&&e.end===t.start){let n=P(2);return n.type==="Punctuator"&&n.value===">"&&t.end===n.start?{op:">>>",consume:3}:{op:">>",consume:2}}return {op:">",consume:1}}return {op:e.value,consume:1}},d=(e,t=false)=>{let n=o();for(;;){let s=p();if(!s)break;let{op:y,consume:L}=s;if(y==="in"&&t)break;let O=be(Xt,y);if(!O||O<=e)break;if(y==="satisfies"){if(N())break;C("'satisfies' is not supported in this language \u2014 a type annotation (`const x: T = \u2026`) also checks compatibility, but it declares the type as T, while 'satisfies' keeps the inferred one");}if(y==="as"){if(N())break;l();let B=ye();n=T({type:"TSAsExpression",expression:n,typeAnnotation:B.schema,typeAnnotationNode:B.node},n,K());continue}for(let B=0;B<L;B++)l();let W=d(y==="**"?O-1:O,t);n=T({type:Kt.has(y)?"LogicalExpression":"BinaryExpression",operator:y,left:n,right:W},n,W);}return n},o=()=>{let e=P();return e.type==="Punctuator"&&(e.value==="++"||e.value==="--")?(l(),D({type:"UpdateExpression",operator:e.value,prefix:true,argument:o()},e)):E("await")?(l(),D({type:"AwaitExpression",argument:o()},e)):E("typeof")||E("void")||E("delete")||e.type==="Punctuator"&&(e.value==="!"||e.value==="-"||e.value==="+"||e.value==="~")?m(e):b()},m=e=>{l();let t=o();return c("**")&&C(`An unary expression with the '${e.value}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.`),D({type:"UnaryExpression",operator:e.value,prefix:true,argument:t},e)},x=()=>{let e=j,t=h.length,n=u.length,s=()=>(_(t),j=e,u.length=n,void 0);try{if(se(),l(),c(">"))return s();let y=[];for(;y.push(ye().schema),!!c(",");)l();return c(">")?(l(),c("(")?y:s()):s()}catch{return s()}},b=()=>{let e=tt(),t=false;for(;;)if((P().type==="Template"||P().type==="TemplateHead")&&C("Tagged templates are not supported in this language"),c("?."))if(l(),t=true,c("(")){let{args:n,close:s}=X();e=T({type:"CallExpression",callee:e,arguments:n,optional:true},e,s);}else if(c("[")){l();let n=J(),s=w("]");e=T({type:"MemberExpression",object:e,property:n,computed:true,optional:true},e,s);}else {let n=P();n.type!=="Identifier"&&n.type!=="Keyword"&&C("Expected property name after '?.'"),l();let s=D({type:"Identifier",name:n.value},n);e=T({type:"MemberExpression",object:e,property:s,computed:false,optional:true},e,s);}else if(c(".")){l();let n=P(),s;n.type==="Identifier"||n.type==="Keyword"?(l(),s=D({type:"Identifier",name:n.value},n)):(V("Expected property name"),s=_e({type:"Identifier",name:""},n)),e=T({type:"MemberExpression",object:e,property:s,computed:false,optional:false},e,s);}else if(c("[")){l();let n=J(),s=w("]");e=T({type:"MemberExpression",object:e,property:n,computed:true,optional:false},e,s);}else if(c("(")){let{args:n,close:s}=X();e=T({type:"CallExpression",callee:e,arguments:n,optional:false},e,s);}else if(c("<")||c("<<")){let n=x();if(!n)break;let{args:s,close:y}=X();e=T({type:"CallExpression",callee:e,arguments:s,optional:false,typeArguments:n},e,y);}else if(c("++")||c("--")){let n=l();e=T({type:"UpdateExpression",operator:n.value,prefix:false,argument:e},e,n);}else break;return t?T({type:"ChainExpression",expression:e},e,e):e},X=()=>{w("(");let e=[];for(;!c(")");)e.push($()),c(")")||w(",");return {args:e,close:w(")")}},$=()=>{if(c("...")){let e=l(),t=J();return T({type:"SpreadElement",argument:t},e,t)}return J()},I=()=>{let e=P();return e.type!=="Identifier"&&C("Expected identifier"),l(),D({type:"Identifier",name:e.value},e)},R=(e=false)=>{let t=c("{")?U():c("[")?z():I();if(e&&c("?")&&(t.type!=="Identifier"&&C("A binding pattern parameter cannot be optional"),l(),t.optional=true),c(":")){l();let n=ye();t.typeAnnotation=n.schema,t.typeAnnotationNode=n.node;}return t},U=()=>{let e=w("{"),t=[];for(;!c("}");){if(c("...")){let s=l(),y=R();t.push(T({type:"RestElement",argument:y},s,y));}else {let s=I(),y,L=false;if(c(":")?(l(),y=R()):(y={...s},L=true),c("=")){l();let O=J();y=T({type:"AssignmentPattern",left:y,right:O},y,O);}t.push(T({type:"Property",key:s,value:y,kind:"init",shorthand:L,computed:false},s,y));}c("}")||w(",");}let n=w("}");return T({type:"ObjectPattern",properties:t},e,n)},z=()=>{let e=w("["),t=[];for(;!c("]");){if(c(",")){t.push(null),l();continue}if(c("...")){let s=l(),y=R();t.push(T({type:"RestElement",argument:y},s,y));}else {let s=R();if(c("=")){l();let y=J();s=T({type:"AssignmentPattern",left:s,right:y},s,y);}t.push(s);}c("]")||w(",");}let n=w("]");return T({type:"ArrayPattern",elements:t},e,n)},q=()=>{let e=h.length,t=ae();return t||_(e),t},ae=()=>{let e=0,t="name";for(let n=j;n<S.length;n++){let s=S[n];if(s.type==="EOF")return false;if(s.type==="Punctuator"){if(s.value==="<"&&t==="type"){k(n);continue}if(e===1&&s.value===":"&&t==="name"?t="type":e===1&&s.value==="="?t="default":e===1&&s.value===","&&(t="name"),s.value==="("||s.value==="["||s.value==="{")e++;else if((s.value===")"||s.value==="]"||s.value==="}")&&(e--,e===0)){let y=S[n+1];return !y||y.type!=="Punctuator"?false:y.value==="=>"?true:y.value===":"?ze(n+2):false}}}return false},ze=e=>{let t=0;for(let n=e;n<S.length;n++){let s=S[n];if(s.type==="EOF")return false;if(s.type==="Punctuator")if(s.value==="<"&&k(n),["(","[","{","<"].includes(s.value))t++;else if([")","]","}",">"].includes(s.value)){if(t===0)return false;t--;}else {if(t===0&&s.value==="=>")return true;if(t===0&&(s.value===";"||s.value===","))return false}}return false},We=()=>{w("(");let e=[];for(;!c(")");){if(c("...")){let t=l(),n=R();e.push(T({type:"RestElement",argument:n},t,n));}else {let t=R(true);if(c("=")){t.optional&&C("Parameter cannot have question mark and initializer"),l();let n=J();t=T({type:"AssignmentPattern",left:t,right:n},t,n);}e.push(t);}c(")")||w(",");}return w(")"),e},qe=e=>{if(e.type==="Identifier")return e.name;let t=e.left;return e.type==="AssignmentPattern"&&t?.type==="Identifier"?t.name:null},de=(e,t,n=[])=>ot(n,()=>He(e,t,n)),He=(e,t,n)=>{let s=c("(")?We():[I()],y,L,O;if(c(":")){l();let B=nt(s.map(qe));y=B.schema,L=B.node,O=B.guard;}w("=>");let W=c("{")?ce():J();return D({type:"ArrowFunctionExpression",params:s,body:W,async:e,expression:W.type!=="BlockStatement",generator:false,...y?{returnType:y,returnTypeNode:L}:{},...O?{returnGuard:O}:{},...n.length?{typeParameters:[...n]}:{}},t)},Ge=()=>{let e=w("["),t=[];for(;!c("]");){if(c(",")){l(),t.push(null);continue}t.push($()),c("]")||w(",");}return T({type:"ArrayExpression",elements:t},e,w("]"))},Ye=()=>{let e=w("{"),t=[];for(;!c("}");){if(c("...")){let n=l(),s=J();t.push(T({type:"SpreadElement",argument:s},n,s));}else {let n=P(),s,y=false;if(c("["))y=true,l(),s=J(),w("]");else if(n.type==="String")l(),s=D({type:"Literal",value:G(n.value.slice(1,-1)),raw:n.value},n);else if(n.type==="Number")l(),s=D({type:"Literal",value:Number(n.value),raw:n.value},n);else if(n.type==="Identifier"||n.type==="Keyword")l(),s=D({type:"Identifier",name:n.value},n);else return C("Invalid property key");if(c(":")){l();let L=J();t.push(T({type:"Property",key:s,value:L,kind:"init",shorthand:false,computed:y},n,L));}else t.push(T({type:"Property",key:s,value:s,kind:"init",shorthand:true,computed:false},n,s));}c("}")||w(",");}return T({type:"ObjectExpression",properties:t},e,w("}"))},fe=(e,t)=>({type:"TemplateElement",value:{raw:e,cooked:G(e)},tail:t}),Qe=e=>{l();let t=[fe(e.value,false)],n=[];for(;;){n.push(J());let s=P();if(s.type==="TemplateMiddle")l(),t.push(fe(s.value,false));else if(s.type==="TemplateTail"){l(),t.push(fe(s.value,true));break}else C("Expected `}` to close template interpolation");}return D({type:"TemplateLiteral",quasis:t,expressions:n},e)},pe=()=>{let e=P();return e.type!=="Identifier"&&C(`Expected JSX identifier but got '${e.value||e.type}'`),D({type:"JSXIdentifier",name:l().value},e)},Ce=()=>{let e=pe();if(c(":")){l();let t=pe();return T({type:"JSXNamespacedName",namespace:e,name:t},e,t)}for(;c(".");){l();let t=pe();e=T({type:"JSXMemberExpression",object:e,property:t},e,t);}return e},Z=e=>e.type==="JSXIdentifier"?e.name:e.type==="JSXNamespacedName"?`${Z(e.namespace)}:${Z(e.name)}`:`${Z(e.object)}.${Z(e.property)}`,Ze=()=>{let e=P();if(e.type==="String")return l(),D({type:"Literal",value:G(e.value.slice(1,-1)),raw:e.value},e);if(c("{")){let t=l(),n=Y(),s=w("}");return T({type:"JSXExpressionContainer",expression:n},t,s)}return c("<")?xe():C(`Invalid JSX attribute value '${e.value||e.type}'`)},et=()=>{let e=[];for(;!c(">")&&!c("/>")&&!M();){if(c("{")){let s=l();w("...");let y=Y(),L=w("}");e.push(T({type:"JSXSpreadAttribute",argument:y},s,L));continue}let t=pe();if(c(":")){l();let s=pe();t=T({type:"JSXNamespacedName",namespace:t,name:s},t,s);}let n=null;c("=")&&(l(),n=Ze()),e.push(T({type:"JSXAttribute",name:t,value:n},t,n??t));}return e},Le=()=>{let e=[];for(;!(c("</")||M());){let t=P();if(t.type==="JSXText")l(),e.push(D({type:"JSXText",value:t.value,raw:t.value},t));else if(c("{")){let n=l();if(c("}")){let s=l(),y=D({type:"JSXEmptyExpression"},n);e.push(T({type:"JSXExpressionContainer",expression:y},n,s));}else if(c("...")){l();let s=Y(),y=w("}");e.push(T({type:"JSXSpreadChild",expression:s},n,y));}else {let s=Y(),y=w("}");e.push(T({type:"JSXExpressionContainer",expression:s},n,y));}}else c("<")?e.push(xe()):C(`Unexpected token in JSX children '${t.value||t.type}'`);}return e},xe=()=>{let e=w("<");if(c(">")){let te=l(),ie=T({type:"JSXOpeningFragment"},e,te),Tt=Le(),gt=w("</"),Je=w(">"),bt=T({type:"JSXClosingFragment"},gt,Je);return T({type:"JSXFragment",openingFragment:ie,children:Tt,closingFragment:bt},e,Je)}let t=Ce(),n=et();if(c("/>")){let te=l(),ie=T({type:"JSXOpeningElement",name:t,attributes:n,selfClosing:true},e,te);return T({type:"JSXElement",openingElement:ie,children:[],closingElement:null},e,te)}let s=w(">"),y=T({type:"JSXOpeningElement",name:t,attributes:n,selfClosing:false},e,s),L=Le(),O=w("</"),W=P(),B=Ce();Z(B)!==Z(t)&&C(`JSX closing tag </${Z(B)}> does not match opening <${Z(t)}>`,W);let H=w(">"),Q=T({type:"JSXClosingElement",name:B},O,H);return T({type:"JSXElement",openingElement:y,children:L,closingElement:Q},e,H)},tt=()=>{let e=P();if(E("async")){let t=P(1);if(t.value==="("||t.type==="Identifier")return l(),de(true,e);if(t.value==="<"){l();let n=Re(e,true);if(n)return n}return C("Unexpected 'async'")}if(c("(")&&q()||e.type==="Identifier"&&P(1).type==="Punctuator"&&P(1).value==="=>")return de(false,e);if(e.type==="Number")return l(),D({type:"Literal",value:Number(e.value),raw:e.value},e);if(e.type==="String")return l(),D({type:"Literal",value:G(e.value.slice(1,-1)),raw:e.value},e);if(e.type==="Template")return l(),D({type:"TemplateLiteral",expressions:[],quasis:[fe(e.value,true)]},e);if(e.type==="TemplateHead")return Qe(e);if(e.type==="Keyword")return e.value==="true"?(l(),D({type:"Literal",value:true,raw:"true"},e)):e.value==="false"?(l(),D({type:"Literal",value:false,raw:"false"},e)):e.value==="null"?(l(),D({type:"Literal",value:null,raw:"null"},e)):e.value==="new"?C("'new' is not supported \u2014 the language has no constructors (FP / portable IR). Use a factory function provided via DI (e.g. `now()` instead of `new Date()`)."):e.value==="function"?C("Anonymous functions are not supported \u2014 use an arrow function"):C(`'${e.value}' is not supported in this language`);if(e.type==="Identifier")return l(),D({type:"Identifier",name:e.value},e);if(c("(")){l();let t=J();return w(")"),t}return c("[")?Ge():c("{")?Ye():c("<")?Re(e)??xe():C(`Unexpected token '${e.value||e.type}'`)},Re=(e,t=false)=>{let n=j,s=h.length,y=u.length,L=()=>(_(s),j=n,u.length=y,void 0),O=P(1);O.type==="Keyword"&&O.value==="const"&&ve();try{let W=ve();return !W.length||!c("(")?L():de(t,e,W)}catch{return L()}},{parseType:ye,parseReturnType:nt,parseTypeParamList:ve,parseTypeInScope:rt,withTypeParams:ot}=Be({rescanTypeLessThan:k,splitShiftLeft:se,tokens:S,pos:()=>j,peek:P,next:l,isP:c,isK:E,expectP:w,fail:C,recordError:V,createMissingNode:_e,unescape:G,typeRefs:A}),je=()=>{let e=l(),t=I(),n=[];c("<")&&(n=ve()),w("=");let s=rt(n),y=T({type:"TSTypeAliasDeclaration",id:t,...n.length?{typeParameters:[...n]}:{},typeAnnotation:s.schema,typeNode:s.node},e,K());return c(";")&&l(),y},ee=()=>{let e=P();if(e.type==="Identifier"&&e.value==="type"&&P(1).type==="Identifier"&&P(2).type==="Punctuator"&&(P(2).value==="="||P(2).value==="<"))return je();if(E("const")||E("let")||E("var")){let y=Ae();return c(";")&&l(),y}if(E("if"))return dt();if(E("for"))return lt();if(E("while"))return ut();if(E("do"))return pt();if(E("break")||E("continue"))return ct();if(E("return"))return ft();if(E("throw"))return yt();if(E("try"))return mt();if(E("switch"))return ht();if(E("import"))return at();if(E("export"))return it();if(c("{"))return ce();if((E("function")||E("async")&&P(1).type==="Keyword"&&P(1).value==="function")&&C("Function declarations are not supported \u2014 use 'const fn = () => \u2026'"),c(";"))return l(),D({type:"EmptyStatement"},e);if(e.type==="Keyword"&&Mt.has(e.value)||e.type==="Identifier"&&be(Ut,e.value)?.(P(1),P(2))===true){let y=be($t,e.value);C(`'${e.value}' is not supported in this language`+(y?` \u2014 ${y}`:""));}let n=J(),s=c(";")?l():K();return T({type:"ExpressionStatement",expression:n},n,s)},Ae=()=>{let e=l(),t=e.value,n=()=>{let y=R(),L=null;return c("=")?(l(),L=J()):t==="const"&&V("'const' declarations must be initialized"),T({type:"VariableDeclarator",id:y,init:L},y,L??y)},s=[n()];for(;c(",");)l(),s.push(n());return T({type:"VariableDeclaration",kind:t,declarations:s},e,s[s.length-1])},st=()=>{let e=P();return e.type!=="String"&&C("Expected module specifier string"),l(),D({type:"Literal",value:G(e.value.slice(1,-1)),raw:e.value},e)},at=()=>{let e=l(),t=[],n;if(F("type")){let y=P(1);(y.type==="Punctuator"&&(y.value==="{"||y.value==="*")||y.type==="Identifier"&&y.value!=="from")&&(l(),n="type");}if(P().type!=="String"){if(P().type==="Identifier"){let y=I();t.push(T({type:"ImportDefaultSpecifier",local:y},y,y)),c(",")&&l();}if(c("*")){let y=l();F("as")||C("Expected 'as' after '*' in import"),l();let L=I();t.push(T({type:"ImportNamespaceSpecifier",local:L},y,L));}else if(c("{")){for(l();!c("}")&&!M();){let y;F("type")&&P(1).type==="Identifier"&&P(1).value!=="as"&&(l(),y="type");let L=I(),O=L;if(F("as")&&(l(),O=I()),t.push(T({type:"ImportSpecifier",imported:L,local:O,...y?{importKind:y}:{}},L,O)),c(","))l();else break}w("}");}F("from")||C("Expected 'from' in import declaration"),l();}let s=st();return c(";")&&l(),D({type:"ImportDeclaration",specifiers:t,source:s,...n?{importKind:n}:{}},e)},it=()=>{let e=l();if(F("type")&&P(1).type==="Identifier"){let t=je();return D({type:"ExportNamedDeclaration",declaration:t,specifiers:[],source:null},e)}if(E("default")){l();let t=J();return c(";")&&l(),D({type:"ExportDefaultDeclaration",declaration:t},e)}if(E("const")||E("let")||E("var")){let t=Ae();return c(";")&&l(),D({type:"ExportNamedDeclaration",declaration:t,specifiers:[],source:null},e)}if(c("{")){l();let t=[];for(;!c("}")&&!M();){let n=I(),s=n;if(F("as")&&(l(),s=I()),t.push(T({type:"ExportSpecifier",local:n,exported:s},n,s)),c(","))l();else break}return w("}"),c(";")&&l(),D({type:"ExportNamedDeclaration",declaration:null,specifiers:t,source:null},e)}return C("Expected 'const', 'type', '{', or 'default' after 'export'")},Oe=()=>P().type==="Identifier"&&P().value==="of",Se=()=>E("in"),lt=()=>{let e=l();w("(");let t=null,n=null;if(!c(";"))if(E("const")||E("let")||E("var")){let O=l(),W=()=>{let H=I();if(c(":")){l();let Q=ye();H.typeAnnotation=Q.schema,H.typeAnnotationNode=Q.node;}return H},B=W();if(Oe()||Se()){let H=T({type:"VariableDeclarator",id:B,init:null},B,B);n=T({type:"VariableDeclaration",kind:O.value,declarations:[H]},O,B);}else {let H=te=>{let ie=null;return c("=")?(l(),ie=J(true)):O.value==="const"&&C("'const' declarations must be initialized"),T({type:"VariableDeclarator",id:te,init:ie},te,ie??te)},Q=[H(B)];for(;c(",");)l(),Q.push(H(W()));t=T({type:"VariableDeclaration",kind:O.value,declarations:Q},O,Q[Q.length-1]);}}else {let O=J(true);Oe()||Se()?n=O:t=O;}if(n){let O=Se();l();let W=J();w(")");let B=ee();return T(O?{type:"ForInStatement",left:n,right:W,body:B}:{type:"ForOfStatement",left:n,right:W,body:B,await:false},e,B)}w(";");let s=c(";")?null:J();w(";");let y=c(")")?null:J();w(")");let L=ee();return T({type:"ForStatement",init:t,test:s,update:y,body:L},e,L)},pt=()=>{let e=l(),t=ee();E("while")||C("Expected 'while' after the 'do' body"),l(),w("(");let n=J(),s=w(")");return c(";")&&l(),T({type:"DoWhileStatement",body:t,test:n},e,s)},ct=()=>{let e=l(),t=e.value==="break"?"BreakStatement":"ContinueStatement",n=c(";")?l():K();return T({type:t,label:null},e,n)},ut=()=>{let e=l();w("(");let t=J();w(")");let n=ee();return T({type:"WhileStatement",test:t,body:n},e,n)},dt=()=>{let e=l();w("(");let t=J();w(")");let n=ee(),s=null;return E("else")&&(l(),s=ee()),T({type:"IfStatement",test:t,consequent:n,alternate:s},e,s??n)},ft=()=>{let e=l(),t=null;!c(";")&&!c("}")&&!M()&&(t=J());let n=c(";")?l():K();return T({type:"ReturnStatement",argument:t},e,n)},yt=()=>{let e=l(),t=J(),n=c(";")?l():K();return T({type:"ThrowStatement",argument:t},e,n)},mt=()=>{let e=l(),t=ce(),n=null,s=null;if(E("catch")){let y=l(),L=null;c("(")&&(l(),L=I(),w(")"));let O=ce();n=T({type:"CatchClause",param:L,body:O},y,O);}return E("finally")&&(l(),s=ce()),!n&&!s&&C("'try' requires a 'catch' or 'finally' clause"),T({type:"TryStatement",block:t,handler:n,finalizer:s},e,s??n??t)},ht=()=>{let e=l();w("(");let t=J();w(")"),w("{");let n=[];for(;!c("}")&&!M();){let y=P(),L=null;E("case")?(l(),L=J()):E("default")?l():C("Expected 'case' or 'default' in switch"),w(":");let O=[];for(;!c("}")&&!E("case")&&!E("default")&&!M();)O.push(ee());n.push(T({type:"SwitchCase",test:L,consequent:O},y,K()??y));}let s=w("}");return T({type:"SwitchStatement",discriminant:t,cases:n},e,s)},ce=()=>{let e=w("{"),t=De(()=>c("}"));return T({type:"BlockStatement",body:t},e,w("}"))},De=e=>{let t=[];for(;!e()&&!M();){if(P().type==="Unknown"){l();continue}try{t.push(ee());}catch(n){if(!(n instanceof oe))throw n;M()||l();}}return t};return {parseExpr:J,parseProgram:()=>{let e=P(),t=De(()=>false);return a.sort((n,s)=>n.start-s.start),T({type:"Program",sourceType:"module",body:t,...A.length?{typeRefs:A}:{},...a.length?{comments:a}:{},...u.length?{parseDiagnostics:u}:{}},e,K()??e)},eof:M,fail:C,recordError:V,diagnostics:u}}function Ve(r){let u=Ie(r),a=u.parseProgram(),i=a.comments;return i?.length&&Ne(a,i,r),{ast:a,diagnostics:u.diagnostics}}function _t(r){let{ast:u,diagnostics:a}=Ve(r),i=a[0];if(i){let f=i.code==="lex-error"?re:oe;throw new f(i.message,i.position,i.index,i.loc,i.end)}return u}function Vt(r){let u=Ie(r),a=u.parseExpr();u.eof()||u.fail("Unexpected token after expression");let i=u.diagnostics[0];if(i){let f=i.code==="lex-error"?re:oe;throw new f(i.message,i.position,i.index,i.loc,i.end)}return a}function zt(r){let u=Ie(r),a;try{a=u.parseExpr(),u.eof()||u.recordError("Unexpected token after expression");}catch(i){if(!(i instanceof oe)&&!(i instanceof re))throw i}return {ast:a,diagnostics:u.diagnostics}}exports.KEYWORDS=Ke;exports.LexError=re;exports.ParseError=oe;exports.attachComments=Ne;exports.nodeIsMissing=Ft;exports.parse=_t;exports.parseExpression=Vt;exports.parseExpressionTolerant=zt;exports.parseTolerant=Ve;exports.tokenize=Et;
package/dist/index.d.cts CHANGED
@@ -25,8 +25,9 @@ interface Token {
25
25
  /**
26
26
  * Um comentário coletado. É TRIVIA — o parser não o vê como `Token` (não muda a
27
27
  * gramática); vai por um canal LATERAL (`onComment`), no modelo do acorn. O
28
- * `value` é o texto SEM os delimitadores (ESTree): `// foo` → `" foo"`;
29
- * `/* foo *​/` → `" foo "`. Carrega `start`/`end`/`loc` como os nós do parser.
28
+ * `value` é o texto SEM os delimitadores (ESTree): `// foo` → `" foo"`, e o bloco com
29
+ * ` foo ` entre os delimitadores → `" foo "`. Carrega `start`/`end`/`loc` como os nós do
30
+ * parser.
30
31
  */
31
32
  interface CommentToken {
32
33
  readonly type: "Line" | "Block";
package/dist/index.d.ts CHANGED
@@ -25,8 +25,9 @@ interface Token {
25
25
  /**
26
26
  * Um comentário coletado. É TRIVIA — o parser não o vê como `Token` (não muda a
27
27
  * gramática); vai por um canal LATERAL (`onComment`), no modelo do acorn. O
28
- * `value` é o texto SEM os delimitadores (ESTree): `// foo` → `" foo"`;
29
- * `/* foo *​/` → `" foo "`. Carrega `start`/`end`/`loc` como os nós do parser.
28
+ * `value` é o texto SEM os delimitadores (ESTree): `// foo` → `" foo"`, e o bloco com
29
+ * ` foo ` entre os delimitadores → `" foo "`. Carrega `start`/`end`/`loc` como os nós do
30
+ * parser.
30
31
  */
31
32
  interface CommentToken {
32
33
  readonly type: "Line" | "Block";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import {TSLiteError}from'@tslite/ast';var ne=class extends TSLiteError{constructor(s,a,u,k,f){super("lex-error",`${s} (${a.line}:${a.column})`,{position:a,index:u,loc:k,end:f});this.position=a;this.index=u;this.loc=k;this.end=f;this.name="LexError";}},De=new Set(["const","if","else","return","async","await","true","false","null","typeof","let","var","function","class","new","for","while","do","this","throw","try","catch","finally","switch","case","break","continue","default","void","delete","instanceof","in","yield","import","export","extends","super","debugger","with","enum","interface"]),pt=["...","===","!==","=>","?.","??=","&&=","||=","**=","??","==","!=","<=",">=","&&","||","|","&","++","--","+=","-=","*=","/=","%=","**","<<","+","-","*","/","%","<",">","!","?",":",".",",",";","=","^","~","(",")","[","]","{","}"],de=r=>r>="a"&&r<="z"||r>="A"&&r<="Z"||r==="_"||r==="$",fe=r=>de(r)||r>="0"&&r<="9",te=r=>r>="0"&&r<="9",je=r=>te(r)||r>="a"&&r<="f"||r>="A"&&r<="F",ct=r=>fe(r)||r==="-",pe=r=>r===`
2
- `||r==="\r"||r==="\u2028"||r==="\u2029",ue=(r,c)=>{let s=c;for(;;){let a=r[s]??"";if(a===" "||a===" "||a==="\f"||a==="\v"||pe(a))s++;else if(a==="/"&&r[s+1]==="/")for(s+=2;s<r.length&&!pe(r[s]??"");)s++;else if(a==="/"&&r[s+1]==="*"){for(s+=2;s<r.length&&!(r[s]==="*"&&r[s+1]==="/");)s++;s+=2;}else return s}},ut=(r,c)=>{if(!de(r[c]??""))return c;let s=c+1;for(;fe(r[s]??"");)s++;return s},Oe=(r,c,s)=>r.startsWith(s,c)&&!fe(r[c+s.length]??""),dt=(r,c)=>{let s=ue(r,c);Oe(r,s,"const")&&(s=ue(r,s+5));let a=ut(r,s);if(a===s)return false;if(s=ue(r,a),Oe(r,s,"extends")){let u=ue(r,s+7),k=r[u]??"";return !(k==="="||k===">"||k==="/")}return r[s]===","?true:r[s]==="="&&r[s+1]!==">"},ft=new Set(["(","[","{",",",";",":","?","=>","...","=","+","-","*","/","%","<","<=",">",">=","==","===","!=","!==","&&","||","??","!","+=","-=","*=","/=","%=","??=","&&=","||=","**="]),yt=new Set(["return","typeof","await","delete","void","in","instanceof","else","case","yield","throw"]);function be(r,c,s){let a=[],u=0,k=1,f=0,o=()=>({line:k,column:f}),h=(E=0)=>r[u+E]??"",M=E=>{let A=o(),U={start:A,end:{line:k,column:f+1}};if(s){s({message:E,position:A,index:u,loc:U,end:u+1});return}throw new ne(E,A,u,U,u+1)},b=()=>{let E=r[u++];return E==="\r"?(r[u]===`
3
- `&&u++,k++,f=0):E===`
4
- `||E==="\u2028"||E==="\u2029"?(k++,f=0):f++,E},p=()=>{for(;;){let E=h();if(E===" "||E===" "||E==="\f"||E==="\v"||pe(E))b();else if(E==="/"&&h(1)==="/"){let A=u,U=o();b(),b();let C=u;for(;u<r.length&&!pe(h());)b();c?.({type:"Line",value:r.slice(C,u),start:A,end:u,loc:{start:U,end:o()}});}else if(E==="/"&&h(1)==="*"){let A=u,U=o();b(),b();let C=u,D=u;for(;;){if(u>=r.length){M("Unterminated block comment"),D=u;break}if(h()==="*"&&h(1)==="/"){D=u,b(),b();break}b();}c?.({type:"Block",value:r.slice(C,D),start:A,end:u,loc:{start:U,end:o()}});}else break}},v=(E,A,U,C)=>{a.push({type:E,value:A,start:U,end:u,loc:{start:C,end:o()}}),W=E==="Punctuator"?ft.has(A):E==="Keyword"?yt.has(A):E==="TemplateHead"||E==="TemplateMiddle";},z=E=>{for(b();u<r.length;){let A=h();if(A===E)return b(),r.slice(d,u);if(pe(A))return M("Unterminated string literal"),r.slice(d,u);if(A==="\\"){if(b(),u>=r.length)return M("Unterminated string literal"),r.slice(d,u);b();continue}b();}return M("Unterminated string literal"),r.slice(d,u)},R=()=>{if(h()==="0"&&(h(1)==="x"||h(1)==="X")){if(b(),b(),!je(h()))return M("Invalid hexadecimal literal");for(;je(h());)b();return}if(h()==="0"&&(h(1)==="b"||h(1)==="B")){if(b(),b(),h()!=="0"&&h()!=="1")return M("Invalid binary literal");for(;h()==="0"||h()==="1";)b();return}if(h()==="0"&&(h(1)==="o"||h(1)==="O")){if(b(),b(),!(h()>="0"&&h()<="7"))return M("Invalid octal literal");for(;h()>="0"&&h()<="7";)b();return}for(;te(h());)b();if(h()===".")for(b();te(h());)b();if(h()==="e"||h()==="E"){if(b(),(h()==="+"||h()==="-")&&b(),!te(h()))return M("Invalid exponent");for(;te(h());)b();}},X=()=>{let E=u;for(;u<r.length;){let A=h();if(A==="`"){let U=r.slice(E,u);return b(),{raw:U,interp:false}}if(A==="$"&&h(1)==="{"){let U=r.slice(E,u);return b(),b(),{raw:U,interp:true}}if(A==="\\"){if(b(),u>=r.length)break;b();continue}b();}return M("Unterminated template literal"),{raw:r.slice(E,u),interp:false}},d=0,I=0,T=[],W=true,P="js",_=[],q=[];for(;;){if(P==="jsxChildren"){d=u;let C=o();if(u>=r.length){v("EOF","",d,C);break}let D=h();if(D==="<"){h(1)==="/"?(b(),b(),v("Punctuator","</",d,C),P="jsxCloseTag"):(b(),v("Punctuator","<",d,C),_.push("jsxChildren"),P="jsxOpenTag");continue}if(D==="{"){b(),v("Punctuator","{",d,C),q.push({level:I,restore:"jsxChildren"}),P="js";continue}for(;u<r.length&&h()!=="<"&&h()!=="{";)b();v("JSXText",r.slice(d,u),d,C);continue}if(P==="jsxOpenTag"||P==="jsxCloseTag"){p(),d=u;let C=o();if(u>=r.length){v("EOF","",d,C);break}let D=h();if(de(D)){for(b();ct(h());)b();v("Identifier",r.slice(d,u),d,C);continue}if(D==="/"&&h(1)===">"){b(),b(),v("Punctuator","/>",d,C),P=_.pop()??"js";continue}if(D===">"){b(),v("Punctuator",">",d,C),P=P==="jsxCloseTag"?_.pop()??"js":"jsxChildren";continue}if(D==="{"){b(),v("Punctuator","{",d,C),q.push({level:I,restore:P}),P="js";continue}if(D==='"'||D==="'"){v("String",z(D),d,C);continue}if(D==="="||D==="."||D===":"){b(),v("Punctuator",D,d,C);continue}if(D==="<"&&P==="jsxOpenTag"){b(),v("Punctuator","<",d,C),_.push("jsxOpenTag");continue}M(`Unexpected character '${D}' in JSX tag`),b(),v("Unknown",D,d,C);continue}p(),d=u;let E=o();if(u>=r.length){v("EOF","",d,E);break}let A=h();if(de(A)){for(;fe(h());)b();let C=r.slice(d,u);v(De.has(C)?"Keyword":"Identifier",C,d,E);continue}if(te(A)||A==="."&&te(h(1))){R(),v("Number",r.slice(d,u),d,E);continue}if(A==='"'||A==="'"){let C=z(A);v("String",C,d,E);continue}if(A==="`"){b();let{raw:C,interp:D}=X();D?(v("TemplateHead",C,d,E),T.push(I)):v("Template",C,d,E);continue}if(A==="<"&&W&&!dt(r,u+1)){b(),v("Punctuator","<",d,E),_.push("js"),P="jsxOpenTag";continue}if(A==="{"){b(),v("Punctuator","{",d,E),I++;continue}if(A==="}"){if(T.length>0&&I===T[T.length-1]){T.pop(),b();let{raw:C,interp:D}=X();v(D?"TemplateMiddle":"TemplateTail",C,d,E),D&&T.push(I);continue}if(q.length>0&&I===q[q.length-1].level){let{restore:C}=q.pop();b(),v("Punctuator","}",d,E),P=C;continue}b(),v("Punctuator","}",d,E),I--;continue}if(A==="?"&&h(1)==="."&&te(h(2))){b(),v("Punctuator","?",d,E);continue}let U=pt.find(C=>r.startsWith(C,u));if(U){for(let C=0;C<U.length;C++)b();v("Punctuator",U,d,E);continue}M(`Unexpected character '${A}'`),b(),v("Unknown",A,d,E);}return a}var mt=new Set(["leadingComments","trailingComments","innerComments","comments"]),Je=r=>typeof r=="object"&&r!==null&&typeof r.type=="string"&&r.loc!=null&&typeof r.start=="number",Xe=new WeakMap;function ht(r){let c=Xe.get(r);if(c)return c;let s=[];for(let a of Object.keys(r)){if(mt.has(a))continue;let u=r[a];if(Je(u))s.push(u);else if(Array.isArray(u))for(let k of u)Je(k)&&s.push(k);}return s.sort((a,u)=>a.start-u.start),Xe.set(r,s),s}function Tt(r,c){let s=r,a,u;for(;;){let k=ht(s);a=void 0,u=void 0;let f;for(let o of k){if(o.start<=c.start&&c.end<=o.end){f=o;break}if(o.end<=c.start)a=o;else if(c.end<=o.start){u=o;break}}if(!f)break;s=f;}return {enclosing:s,preceding:a,following:u}}var ve=(r,c)=>{(r.leadingComments??(r.leadingComments=[])).push(c);},ye=(r,c)=>{(r.trailingComments??(r.trailingComments=[])).push(c);},Se=(r,c)=>{(r.innerComments??(r.innerComments=[])).push(c);};function gt(r,c){for(let s=c;s<r.length;s++){let a=r[s];if(a!==" "&&a!==" "&&a!=="\r"&&a!==`
5
- `&&a!=="\f")return a}return ""}var bt=new Set([")","]","}",","]);function xe(r,c,s=""){for(let a of c){let{enclosing:u,preceding:k,following:f}=Tt(r,a),o=k==null||k.loc.end.line<a.loc.start.line,h=!o&&(f==null||a.loc.end.line<f.loc.start.line);if(o)f?ve(f,a):k?ye(k,a):Se(u,a);else if(h)k?ye(k,a):f?ve(f,a):Se(u,a);else {let M=bt.has(gt(s,a.end));k&&M?ye(k,a):f?ve(f,a):k?ye(k,a):Se(u,a);}}}var me=(r=[])=>({vars:new Set(r),bounds:new Map,noCond:false,inferSink:null}),se=(r,c)=>{let s=new Set(r.vars),a=new Map(r.bounds);for(let u of c)s.add(u.name),u.bound||u.isConst?a.set(u.name,{bound:u.bound,isConst:u.isConst}):a.delete(u.name);return {vars:s,bounds:a,noCond:r.noCond,inferSink:r.inferSink}},vt=(r,c)=>{let s=r.bounds.get(c);return s&&(s.bound||s.isConst)?{t:"var",name:c,...s.bound?{bound:s.bound}:{},...s.isConst?{isConst:true}:{}}:{t:"var",name:c}},Fe=r=>{let{peek:c,next:s,isP:a,isK:u,expectP:k,fail:f,unescape:o}=r,h=(y,m)=>{let l=r.tokens[r.pos()-1]??m;return Object.assign(y,{start:m.start,end:l.end,loc:{start:m.loc.start,end:l.loc.end}})},M=()=>{let y=r.pos(),m=r.tokens[y],l=r.tokens[y-1];return !!l&&!!m&&m.loc.start.line>l.loc.end.line},b=()=>{let y=0;for(let m=r.pos();m<r.tokens.length;m++){let l=r.tokens[m];if(l.type==="EOF")return false;if(l.type==="Punctuator"){if(["(","[","{","<"].includes(l.value))y++;else if([")","]","}",">"].includes(l.value)&&(y--,y===0)){let S=r.tokens[m+1];return !!S&&S.type==="Punctuator"&&S.value==="=>"}}}return false},p=()=>{let y=r.tokens,m=[],l=0,S=false;for(let w=r.pos();w<y.length;w++){let x=y[w];if(x.type==="EOF")break;if(x.type==="Punctuator"){if(x.value==="<")l++,l===1&&(S=true);else if(x.value===">"){if(l--,l===0)break}else x.value==="("||x.value==="["||x.value==="{"?(l++,S=false):x.value===")"||x.value==="]"||x.value==="}"?(l--,S=false):x.value===","&&l===1?S=true:S=false;continue}if(l===1&&S){if(x.type==="Keyword"&&x.value==="const")continue;if(x.type==="Identifier"){m.push(x.value),S=false;continue}}S=false;}return m},v=y=>{let m=se(y,p().map(S=>({name:S})));k("<");let l=[];for(;!a(">");){let S=u("const");S&&s();let w=c();w.type!=="Identifier"&&f("Expected type parameter name"),s();let x,J;if(u("extends")){s();let L=X(m);x=L.schema,J=L.node;}let $,F;if(a("=")){s();let L=X(m);$=L.schema,F=L.node;}l.push({name:w.value,...x?{bound:x}:{},...J?{boundNode:J}:{},...$?{default:$}:{},...F?{defaultNode:F}:{},...S?{isConst:true}:{}}),a(">")||k(",");}return k(">"),l},z=y=>{k("<");let m=[];for(;!a(">");)m.push(X(y)),a(">")||k(",");return k(">"),m},R=y=>{let m=c();return m.type==="Identifier"&&m.value===y},X=y=>{let m=c(),l=d(y);if(y.noCond||!u("extends")||M())return l;s();let S=[],w=d({...y,noCond:true,inferSink:S});k("?");let x=se(y,S.map(F=>({name:F}))),J=X(x);k(":");let $=X(x);return {node:h({type:"TSConditionalType",checkType:l.node,extendsType:w.node,trueType:J.node,falseType:$.node},m),schema:{t:"conditional",check:l.schema,extends:w.schema,then:J.schema,else:$.schema,...S.length?{infer:S}:{}}}},d=y=>{let m=c();a("|")&&s();let l=I(y);if(!a("|"))return l;let S=[l.node],w=[l.schema];for(;a("|");){s();let x=I(y);S.push(x.node),w.push(x.schema);}return {node:h({type:"TSUnionType",types:S},m),schema:{t:"union",of:w}}},I=y=>{let m=c();a("&")&&s();let l=T(y);if(!a("&"))return l;let S=[l.node],w=[l.schema];for(;a("&");){s();let x=T(y);S.push(x.node),w.push(x.schema);}return {node:h({type:"TSIntersectionType",types:S},m),schema:{t:"intersection",of:w}}},T=y=>{let m=c();if(R("keyof")){s();let l=T(y);return {node:h({type:"TSTypeOperator",operator:"keyof",typeAnnotation:l.node},m),schema:{t:"keyof",of:l.schema}}}if(R("readonly")){s();let l=T(y);return l.schema.t!=="array"&&l.schema.t!=="tuple"&&f("'readonly' only applies to array and tuple types"),{node:h({...l.node,readonly:true},m),schema:{...l.schema,readonly:true}}}if(R("infer")){s();let l=c();l.type!=="Identifier"&&f("Expected 'infer' variable name"),s();let S=y.inferSink;return S?(S.push(l.value),{node:h({type:"TSInferType",name:l.value},m),schema:{t:"var",name:l.value}}):f("'infer' is only allowed in the 'extends' clause of a conditional")}return W(y)},W=y=>{let m=c(),l=_(y);for(;a("[")&&!M();)if(s(),a("]"))s(),l={node:h({type:"TSArrayType",elementType:l.node},m),schema:{t:"array",items:l.schema}};else {let S=X(y);k("]"),l={node:h({type:"TSIndexedAccessType",objectType:l.node,indexType:S.node},m),schema:{t:"index",obj:l.schema,key:S.schema}};}return l},P=(y,m,l)=>({node:h({type:"TSKeywordType",kind:m},y),schema:l}),_=y=>{let m=c();if(u("typeof")){s();let w=c();w.type!=="Identifier"&&f("Expected a name after 'typeof' in type position"),s();let x=[w.value];for(;a(".");){s();let J=c();J.type!=="Identifier"&&J.type!=="Keyword"&&f("Expected a property name after '.' in 'typeof'"),s(),x.push(J.value);}return {node:h({type:"TSTypeQuery",exprName:x},m),schema:{t:"typeQuery",path:x}}}if(a("<")){let w=v(y),x=se(y,w);return A(x,m,w.map(J=>J.name))}if(a("(")){if(b())return A(y,m);s();let w=X(y.noCond?{...y,noCond:false}:y);return k(")"),w}if(a("{"))return C()?D(y):he(y);if(a("["))return U(y);let l=c();if(l.type==="String"){s();let w=o(l.value.slice(1,-1));return {node:h({type:"TSLiteralType",literal:w},m),schema:{t:"literal",value:w}}}if(l.type==="Number"){s();let w=Number(l.value);return {node:h({type:"TSLiteralType",literal:w},m),schema:{t:"literal",value:w}}}if(u("true"))return s(),{node:h({type:"TSLiteralType",literal:true},m),schema:{t:"literal",value:true}};if(u("false"))return s(),{node:h({type:"TSLiteralType",literal:false},m),schema:{t:"literal",value:false}};if(u("null"))return s(),P(m,"null",{t:"null"});if(u("void"))return s(),P(m,"void",{t:"void"});if(l.type==="Identifier"){switch(s(),l.value){case "string":return P(m,"string",{t:"string"});case "number":return P(m,"number",{t:"number"});case "boolean":return P(m,"boolean",{t:"boolean"});case "any":return P(m,"any",{t:"any"});case "unknown":return P(m,"unknown",{t:"unknown"});case "undefined":return P(m,"undefined",{t:"undefined"});case "never":return P(m,"never",{t:"union",of:[]})}let w=a("<")?z(y):[],x=w.map(F=>F.schema),J=w.length?w.map(F=>F.node):void 0,$=h({type:"TSTypeReference",typeName:l.value,...J?{typeArguments:J}:{}},m);return y.vars.has(l.value)&&x.length===0?{node:$,schema:vt(y,l.value)}:l.value==="ReturnType"&&x.length===1?{node:$,schema:{t:"returnType",fn:x[0]}}:l.value==="Parameters"&&x.length===1?{node:$,schema:{t:"parameters",fn:x[0]}}:(r.typeRefs?.push({name:l.value,loc:l.loc,args:x}),{node:$,schema:{t:"apply",name:l.value,args:x}})}r.recordError(`Expected a type but got '${l.value||l.type}'`,l);let S=r.createMissingNode({type:"TSTypeReference",typeName:""},l);return r.typeRefs?.push({name:"",loc:S.loc,args:[]}),{node:S,schema:{t:"unknown"}}},q=y=>{k("(");let m=[];for(;!a(")");){let l=c();l.type!=="Identifier"&&f("Expected parameter name in function type"),s();let S=a("?");S&&s(),k(":");let w=X(y);m.push({node:h({type:"TSTypeParameter",name:l.value,typeAnnotation:w.node,...S?{optional:true}:{}},l),schema:{name:l.value,type:w.schema,...S?{optional:true}:{}}}),a(")")||k(",");}return k(")"),m},E=(y,m)=>{let l=c(),S=r.tokens[r.pos()+1];if(!(l.type==="Identifier"&&S?.type==="Identifier"&&S.value==="is"))return X(y);let x=m.indexOf(l.value);x<0&&f(`Cannot find parameter '${l.value}' for the type predicate`),s(),s();let J=X(y);return {node:h({type:"TSTypePredicate",parameterName:l.value,typeAnnotation:J.node},l),schema:{t:"boolean"},guard:{param:x,type:J.schema}}},A=(y,m,l)=>{let S=q(y);k("=>");let w=E(y,S.map(x=>x.schema.name));return {node:h({type:"TSFunctionType",params:S.map(x=>x.node),returnType:w.node,...l?.length?{typeParams:[...l]}:{}},m),schema:{t:"fn",params:S.map(x=>x.schema),returns:w.schema,...w.guard?{guard:w.guard}:{},...l?.length?{typeParams:l}:{}}}},U=y=>{let m=c();k("[");let l=[],S=[],w=[],x=[],J=()=>{let L=r.tokens[r.pos()],O=r.tokens[r.pos()+1],H=r.tokens[r.pos()+2];if(L?.type==="Identifier"&&O?.type==="Punctuator"&&(O.value===":"||O.value==="?"&&H?.type==="Punctuator"&&H.value===":"))return s(),L.value};for(;!a("]");){if(a("...")){s();let L=J();L!==void 0&&k(":"),x.push(L);let O=X(y);O.schema.t==="array"?(S.push(O.schema.items),l.push(O.node.elementType),w.push("rest")):(S.push(O.schema),l.push(O.node),w.push("variadic"));}else {let L=J(),O=false;L!==void 0&&(a("?")&&(s(),O=true),k(":")),x.push(L);let H=X(y);!O&&a("?")&&(s(),O=true),S.push(H.schema),l.push(H.node),w.push(O?"optional":"req");}a("]")||k(",");}k("]");let $=w.some(L=>L!=="req"),F=x.some(L=>L!==void 0);return {node:h({type:"TSTupleType",elementTypes:l,...$?{flags:w}:{},...F?{labels:x}:{}},m),schema:$?{t:"tuple",elements:S,flags:w}:{t:"tuple",elements:S}}},C=()=>{let y=r.tokens,m=r.pos()+1;return y[m]?.type==="Punctuator"&&(y[m]?.value==="+"||y[m]?.value==="-")&&m++,y[m]?.type==="Identifier"&&y[m]?.value==="readonly"&&m++,y[m]?.type==="Punctuator"&&y[m]?.value==="["&&y[m+1]?.type==="Identifier"&&y[m+2]?.type==="Keyword"&&y[m+2]?.value==="in"},D=y=>{let m=c();k("{"),(a("+")||a("-"))&&s(),R("readonly")&&s(),k("[");let l=c();l.type!=="Identifier"&&f("Expected mapped type key name"),s(),u("in")||f("Expected 'in' in mapped type"),s();let S=X(y);R("as")&&f("Key remapping ('as') in mapped types is not supported"),k("]");let w=false,x=a("+")||a("-")?s().value:null;a("?")&&(s(),w=x!=="-"),k(":");let J=X(se(y,[{name:l.value}]));return (a(";")||a(","))&&s(),k("}"),{node:h({type:"TSMappedType",key:l.value,constraint:S.node,typeAnnotation:J.node,optional:w},m),schema:{t:"mapped",key:l.value,over:S.schema,body:J.schema,optional:w}}},he=y=>{let m=c();k("{");let l=[],S={},w,x=[];for(;!a("}");){let $=c();if(a("(")){let F=q(y);k(":");let L=E(y,F.map(O=>O.schema.name));x.push({t:"fn",params:F.map(O=>O.schema),returns:L.schema,...L.guard?{guard:L.guard}:{}}),l.push(h({type:"TSCallSignatureDeclaration",params:F.map(O=>O.node),returnType:L.node},$));}else if(a("[")){s(),c().type!=="Identifier"&&f("Expected index signature parameter name"),s(),k(":");let F=c();(F.type!=="Identifier"||F.value!=="string"&&F.value!=="number")&&f("Index signature parameter type must be 'string' or 'number'"),s(),k("]"),k(":");let L=X(y);w={key:F.value,value:L.schema},l.push(h({type:"TSIndexSignature",keyType:F.value,typeAnnotation:L.node},$));}else {let F=false;if(R("readonly")){let V=r.tokens[r.pos()+1];V&&(V.type==="Identifier"||V.type==="Keyword"||V.type==="String"||V.type==="Number")&&(s(),F=true);}let L=c(),O;if(L.type==="Identifier"||L.type==="Keyword")s(),O=L.value;else if(L.type==="String")s(),O=o(L.value.slice(1,-1));else if(L.type==="Number")s(),O=L.value;else return f("Expected property name in object type");let H=a("?");H&&s(),k(":");let ae=X(y);S[O]={type:ae.schema,...H?{optional:true}:{}},l.push(h({type:"TSPropertySignature",key:O,typeAnnotation:ae.node,...H?{optional:true}:{},...F?{readonly:true}:{}},$));}if(a(";")||a(","))s();else break}k("}");let J=h({type:"TSTypeLiteral",members:l},m);return x.length>0?Object.keys(S).length>0||w?f("Callable object types (call signatures mixed with members) are not supported"):{node:J,schema:x.length===1?x[0]:{t:"overload",signatures:x}}:{node:J,schema:{t:"object",props:S,...w?{index:w}:{}}}};return {parseType:(y=[])=>X(se(me(),y)),parseReturnType:(y,m)=>E(se(me(),y),m),parseTypeParamList:()=>v(me()),parseTypeInScope:y=>X(se(me(),y))}};var re=class extends TSLiteError{constructor(s,a,u,k,f){super("parse-error",`${s} (${a.line}:${a.column})`,{position:a,index:u,loc:k,end:f});this.position=a;this.index=u;this.loc=k;this.end=f;this.name="ParseError";}},xt=r=>{let c=r;return c!=null&&typeof c.start=="number"&&c.start===c.end&&c.start>=0},Ke=(r,c)=>Object.assign(r,{start:c.start,end:c.start,loc:{start:c.loc.start,end:c.loc.start}}),kt={"??":1,"||":2,"&&":3,"|":4,"^":5,"&":6,"==":7,"===":7,"!=":7,"!==":7,"<":8,"<=":8,">":8,">=":8,in:8,as:8,satisfies:8,"<<":9,">>":9,">>>":9,"+":10,"-":10,"*":11,"/":11,"%":11,"**":12},wt=new Set(["??","||","&&"]),Pt=new Set(["class","debugger","with","enum","interface"]),Nt={enum:'use a union of literals (`type T = "a" | "b"`) \u2014 it is serializable',interface:"use a type alias (`type X = { \u2026 }`)",namespace:"use modules (`import`/`export`)",module:"use modules (`import`/`export`)",declare:"declare the shape via the DI env, or with a `type` alias",abstract:"classes are not part of the language \u2014 model with objects + functions"},Et={namespace:(r,c)=>r.type==="Identifier"&&c.type==="Punctuator"&&c.value==="{",module:(r,c)=>r.type==="Identifier"&&c.type==="Punctuator"&&c.value==="{",declare:r=>r.type==="Keyword"&&["const","let","var","function","class","enum","interface"].includes(r.value)||r.type==="Identifier"&&["type","namespace","module"].includes(r.value),abstract:r=>r.type==="Keyword"&&r.value==="class"},Ct=new Set(["=","+=","-=","*=","/=","%=","**=","??=","&&=","||="]);function ke(r){let c=[],s=[],a=be(r,e=>s.push(e),e=>c.push({code:"lex-error",...e})),u=0,k=[],f=(e=0)=>a[Math.min(u+e,a.length-1)],o=()=>a[u++],h=()=>a[u-1],M=()=>{let e=a[u],n=a[u-1];return !!e&&!!n&&e.loc.start.line>n.loc.end.line},b=()=>f().type==="EOF",p=e=>f().type==="Punctuator"&&f().value===e,v=e=>f().type==="Keyword"&&f().value===e,z=e=>f().type==="Identifier"&&f().value===e,R=(e,n=f())=>{throw X(e,n),new re(e,n.loc.start,n.start,n.loc,n.end)},X=(e,n=f())=>{let t=c[c.length-1];t&&t.index===n.start||c.push({code:"parse-error",message:e,position:n.loc.start,index:n.start,loc:n.loc,end:n.end});},d=e=>(p(e)||R(`Expected '${e}' but got '${f().value||f().type}'`),o()),I=(e,n)=>{let t=h()??n;return Object.assign(e,{start:n.start,end:t.end,loc:{start:n.loc.start,end:t.loc.end}})},T=(e,n,t)=>Object.assign(e,{start:n.start,end:t.end,loc:{start:n.loc.start,end:t.loc.end}}),W=e=>{let n="";for(let t=0;t<e.length;t++){if(e[t]!=="\\"){n+=e[t];continue}let i=e[++t];switch(i){case "n":n+=`
6
- `;break;case "t":n+=" ";break;case "r":n+="\r";break;case "b":n+="\b";break;case "f":n+="\f";break;case "v":n+="\v";break;case "0":n+="\0";break;case "x":n+=String.fromCharCode(parseInt(e.slice(t+1,t+3),16)),t+=2;break;case "u":if(e[t+1]==="{"){let g=e.indexOf("}",t);n+=String.fromCodePoint(parseInt(e.slice(t+2,g),16)),t=g;}else n+=String.fromCharCode(parseInt(e.slice(t+1,t+5),16)),t+=4;break;default:n+=i;}}return n},P=(e=false)=>_(e),_=(e=false)=>{let n=q(e),t=f();if(t.type==="Punctuator"&&Ct.has(t.value)){o();let i=_();return T({type:"AssignmentExpression",operator:t.value,left:n,right:i},n,i)}return n},q=(e=false)=>{let n=A(0,e);if(!p("?"))return n;o();let t=P();d(":");let i=P();return T({type:"ConditionalExpression",test:n,consequent:t,alternate:i},n,i)},E=()=>{let e=f();if(e.type==="Keyword")return e.value==="in"?{op:"in",consume:1}:null;if(e.type==="Identifier")return e.value==="as"?{op:"as",consume:1}:e.value==="satisfies"?{op:"satisfies",consume:1}:null;if(e.type!=="Punctuator")return null;if(e.value===">"){let n=f(1);if(n.type==="Punctuator"&&n.value===">"&&e.end===n.start){let t=f(2);return t.type==="Punctuator"&&t.value===">"&&n.end===t.start?{op:">>>",consume:3}:{op:">>",consume:2}}return {op:">",consume:1}}return {op:e.value,consume:1}},A=(e,n=false)=>{let t=U();for(;;){let i=E();if(!i)break;let{op:g,consume:N}=i;if(g==="in"&&n)break;let j=kt[g];if(!j||j<=e)break;if(g==="satisfies"){if(M())break;R("'satisfies' is not supported in this language \u2014 a type annotation (`const x: T = \u2026`) also checks compatibility, but it declares the type as T, while 'satisfies' keeps the inferred one");}if(g==="as"){if(M())break;o();let K=ce();t=T({type:"TSAsExpression",expression:t,typeAnnotation:K.schema,typeAnnotationNode:K.node},t,h());continue}for(let K=0;K<N;K++)o();let B=A(g==="**"?j-1:j,n);t=T({type:wt.has(g)?"LogicalExpression":"BinaryExpression",operator:g,left:t,right:B},t,B);}return t},U=()=>{let e=f();return e.type==="Punctuator"&&(e.value==="++"||e.value==="--")?(o(),I({type:"UpdateExpression",operator:e.value,prefix:true,argument:U()},e)):v("await")?(o(),I({type:"AwaitExpression",argument:U()},e)):v("typeof")||v("void")||v("delete")||e.type==="Punctuator"&&(e.value==="!"||e.value==="-"||e.value==="+"||e.value==="~")?C(e):he()},C=e=>{o();let n=U();return p("**")&&R(`An unary expression with the '${e.value}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.`),I({type:"UnaryExpression",operator:e.value,prefix:true,argument:n},e)},D=()=>{let e=u,n=c.length,t=()=>(u=e,c.length=n,void 0);try{if(o(),p(">"))return t();let i=[];for(;i.push(ce().schema),!!p(",");)o();return p(">")?(o(),p("(")?i:t()):t()}catch{return t()}},he=()=>{let e=_e(),n=false;for(;;)if((f().type==="Template"||f().type==="TemplateHead")&&R("Tagged templates are not supported in this language"),p("?."))if(o(),n=true,p("(")){let{args:t,close:i}=y();e=T({type:"CallExpression",callee:e,arguments:t,optional:true},e,i);}else if(p("[")){o();let t=P(),i=d("]");e=T({type:"MemberExpression",object:e,property:t,computed:true,optional:true},e,i);}else {let t=f();t.type!=="Identifier"&&t.type!=="Keyword"&&R("Expected property name after '?.'"),o();let i=I({type:"Identifier",name:t.value},t);e=T({type:"MemberExpression",object:e,property:i,computed:false,optional:true},e,i);}else if(p(".")){o();let t=f(),i;t.type==="Identifier"||t.type==="Keyword"?(o(),i=I({type:"Identifier",name:t.value},t)):(X("Expected property name"),i=Ke({type:"Identifier",name:""},t)),e=T({type:"MemberExpression",object:e,property:i,computed:false,optional:false},e,i);}else if(p("[")){o();let t=P(),i=d("]");e=T({type:"MemberExpression",object:e,property:t,computed:true,optional:false},e,i);}else if(p("(")){let{args:t,close:i}=y();e=T({type:"CallExpression",callee:e,arguments:t,optional:false},e,i);}else if(p("<")){let t=D();if(!t)break;let{args:i,close:g}=y();e=T({type:"CallExpression",callee:e,arguments:i,optional:false,typeArguments:t},e,g);}else if(p("++")||p("--")){let t=o();e=T({type:"UpdateExpression",operator:t.value,prefix:false,argument:e},e,t);}else break;return n?T({type:"ChainExpression",expression:e},e,e):e},y=()=>{d("(");let e=[];for(;!p(")");)e.push(m()),p(")")||d(",");return {args:e,close:d(")")}},m=()=>{if(p("...")){let e=o(),n=P();return T({type:"SpreadElement",argument:n},e,n)}return P()},l=()=>{let e=f();return e.type!=="Identifier"&&R("Expected identifier"),o(),I({type:"Identifier",name:e.value},e)},S=(e,n=false)=>{let t=p("{")?w(e):p("[")?x(e):l();if(n&&p("?")&&(t.type!=="Identifier"&&R("A binding pattern parameter cannot be optional"),o(),t.optional=true),p(":")){o();let i=ce(e);t.typeAnnotation=i.schema,t.typeAnnotationNode=i.node;}return t},w=e=>{let n=d("{"),t=[];for(;!p("}");){if(p("...")){let g=o(),N=S(e);t.push(T({type:"RestElement",argument:N},g,N));}else {let g=l(),N,j=false;if(p(":")?(o(),N=S(e)):(N={...g},j=true),p("=")){o();let B=P();N=T({type:"AssignmentPattern",left:N,right:B},N,B);}t.push(T({type:"Property",key:g,value:N,kind:"init",shorthand:j,computed:false},g,N));}p("}")||d(",");}let i=d("}");return T({type:"ObjectPattern",properties:t},n,i)},x=e=>{let n=d("["),t=[];for(;!p("]");){if(p(",")){t.push(null),o();continue}if(p("...")){let g=o(),N=S(e);t.push(T({type:"RestElement",argument:N},g,N));}else {let g=S(e);if(p("=")){o();let N=P();g=T({type:"AssignmentPattern",left:g,right:N},g,N);}t.push(g);}p("]")||d(",");}let i=d("]");return T({type:"ArrayPattern",elements:t},n,i)},J=()=>{let e=0;for(let n=u;n<a.length;n++){let t=a[n];if(t.type==="EOF")return false;if(t.type==="Punctuator"){if(t.value==="("||t.value==="["||t.value==="{")e++;else if((t.value===")"||t.value==="]"||t.value==="}")&&(e--,e===0)){let i=a[n+1];return !i||i.type!=="Punctuator"?false:i.value==="=>"?true:i.value===":"?$(n+2):false}}}return false},$=e=>{let n=0;for(let t=e;t<a.length;t++){let i=a[t];if(i.type==="EOF")return false;if(i.type==="Punctuator")if(["(","[","{","<"].includes(i.value))n++;else if([")","]","}",">"].includes(i.value)){if(n===0)return false;n--;}else {if(n===0&&i.value==="=>")return true;if(n===0&&(i.value===";"||i.value===","))return false}}return false},F=(e=[])=>{d("(");let n=[];for(;!p(")");){if(p("...")){let t=o(),i=S(e);n.push(T({type:"RestElement",argument:i},t,i));}else {let t=S(e,true);if(p("=")){t.optional&&R("Parameter cannot have question mark and initializer"),o();let i=P();t=T({type:"AssignmentPattern",left:t,right:i},t,i);}n.push(t);}p(")")||d(",");}return d(")"),n},L=e=>{if(e.type==="Identifier")return e.name;let n=e.left;return e.type==="AssignmentPattern"&&n?.type==="Identifier"?n.name:null},O=(e,n,t=[])=>{let i=p("(")?F(t):[l()],g,N,j;if(p(":")){o();let K=ze(t,i.map(L));g=K.schema,N=K.node,j=K.guard;}d("=>");let B=p("{")?le():P();return I({type:"ArrowFunctionExpression",params:i,body:B,async:e,expression:B.type!=="BlockStatement",generator:false,...g?{returnType:g,returnTypeNode:N}:{},...j?{returnGuard:j}:{},...t.length?{typeParams:t.map(K=>K.name),typeParamNodes:t}:{}},n)},H=()=>{let e=d("["),n=[];for(;!p("]");){if(p(",")){o(),n.push(null);continue}n.push(m()),p("]")||d(",");}return T({type:"ArrayExpression",elements:n},e,d("]"))},ae=()=>{let e=d("{"),n=[];for(;!p("}");){if(p("...")){let t=o(),i=P();n.push(T({type:"SpreadElement",argument:i},t,i));}else {let t=f(),i,g=false;if(p("["))g=true,o(),i=P(),d("]");else if(t.type==="String")o(),i=I({type:"Literal",value:W(t.value.slice(1,-1)),raw:t.value},t);else if(t.type==="Number")o(),i=I({type:"Literal",value:Number(t.value),raw:t.value},t);else if(t.type==="Identifier"||t.type==="Keyword")o(),i=I({type:"Identifier",name:t.value},t);else return R("Invalid property key");if(p(":")){o();let N=P();n.push(T({type:"Property",key:i,value:N,kind:"init",shorthand:false,computed:g},t,N));}else n.push(T({type:"Property",key:i,value:i,kind:"init",shorthand:true,computed:false},t,i));}p("}")||d(",");}return T({type:"ObjectExpression",properties:n},e,d("}"))},V=(e,n)=>({type:"TemplateElement",value:{raw:e,cooked:W(e)},tail:n}),$e=e=>{o();let n=[V(e.value,false)],t=[];for(;;){t.push(P());let i=f();if(i.type==="TemplateMiddle")o(),n.push(V(i.value,false));else if(i.type==="TemplateTail"){o(),n.push(V(i.value,true));break}else R("Expected `}` to close template interpolation");}return I({type:"TemplateLiteral",quasis:n,expressions:t},e)},ie=()=>{let e=f();return e.type!=="Identifier"&&R(`Expected JSX identifier but got '${e.value||e.type}'`),I({type:"JSXIdentifier",name:o().value},e)},we=()=>{let e=ie();if(p(":")){o();let n=ie();return T({type:"JSXNamespacedName",namespace:e,name:n},e,n)}for(;p(".");){o();let n=ie();e=T({type:"JSXMemberExpression",object:e,property:n},e,n);}return e},Q=e=>e.type==="JSXIdentifier"?e.name:e.type==="JSXNamespacedName"?`${Q(e.namespace)}:${Q(e.name)}`:`${Q(e.object)}.${Q(e.property)}`,Me=()=>{let e=f();if(e.type==="String")return o(),I({type:"Literal",value:W(e.value.slice(1,-1)),raw:e.value},e);if(p("{")){let n=o(),t=_(),i=d("}");return T({type:"JSXExpressionContainer",expression:t},n,i)}return p("<")?Te():R(`Invalid JSX attribute value '${e.value||e.type}'`)},Be=()=>{let e=[];for(;!p(">")&&!p("/>")&&!b();){if(p("{")){let i=o();d("...");let g=_(),N=d("}");e.push(T({type:"JSXSpreadAttribute",argument:g},i,N));continue}let n=ie();if(p(":")){o();let i=ie();n=T({type:"JSXNamespacedName",namespace:n,name:i},n,i);}let t=null;p("=")&&(o(),t=Me()),e.push(T({type:"JSXAttribute",name:n,value:t},n,t??n));}return e},Pe=()=>{let e=[];for(;!(p("</")||b());){let n=f();if(n.type==="JSXText")o(),e.push(I({type:"JSXText",value:n.value,raw:n.value},n));else if(p("{")){let t=o();if(p("}")){let i=o(),g=I({type:"JSXEmptyExpression"},t);e.push(T({type:"JSXExpressionContainer",expression:g},t,i));}else if(p("...")){o();let i=_(),g=d("}");e.push(T({type:"JSXSpreadChild",expression:i},t,g));}else {let i=_(),g=d("}");e.push(T({type:"JSXExpressionContainer",expression:i},t,g));}}else p("<")?e.push(Te()):R(`Unexpected token in JSX children '${n.value||n.type}'`);}return e},Te=()=>{let e=d("<");if(p(">")){let ee=o(),oe=T({type:"JSXOpeningFragment"},e,ee),st=Pe(),at=d("</"),Le=d(">"),it=T({type:"JSXClosingFragment"},at,Le);return T({type:"JSXFragment",openingFragment:oe,children:st,closingFragment:it},e,Le)}let n=we(),t=Be();if(p("/>")){let ee=o(),oe=T({type:"JSXOpeningElement",name:n,attributes:t,selfClosing:true},e,ee);return T({type:"JSXElement",openingElement:oe,children:[],closingElement:null},e,ee)}let i=d(">"),g=T({type:"JSXOpeningElement",name:n,attributes:t,selfClosing:false},e,i),N=Pe(),j=d("</"),B=f(),K=we();Q(K)!==Q(n)&&R(`JSX closing tag </${Q(K)}> does not match opening <${Q(n)}>`,B);let G=d(">"),Y=T({type:"JSXClosingElement",name:K},j,G);return T({type:"JSXElement",openingElement:g,children:N,closingElement:Y},e,G)},_e=()=>{let e=f();if(v("async")){let n=f(1);if(n.value==="("||n.type==="Identifier")return o(),O(true,e);if(n.value==="<"){o();let t=Ne(e,true);if(t)return t}return R("Unexpected 'async'")}if(p("(")&&J()||e.type==="Identifier"&&f(1).type==="Punctuator"&&f(1).value==="=>")return O(false,e);if(e.type==="Number")return o(),I({type:"Literal",value:Number(e.value),raw:e.value},e);if(e.type==="String")return o(),I({type:"Literal",value:W(e.value.slice(1,-1)),raw:e.value},e);if(e.type==="Template")return o(),I({type:"TemplateLiteral",expressions:[],quasis:[V(e.value,true)]},e);if(e.type==="TemplateHead")return $e(e);if(e.type==="Keyword")return e.value==="true"?(o(),I({type:"Literal",value:true,raw:"true"},e)):e.value==="false"?(o(),I({type:"Literal",value:false,raw:"false"},e)):e.value==="null"?(o(),I({type:"Literal",value:null,raw:"null"},e)):e.value==="new"?R("'new' is not supported \u2014 the language has no constructors (FP / portable IR). Use a factory function provided via DI (e.g. `now()` instead of `new Date()`)."):e.value==="function"?R("Anonymous functions are not supported \u2014 use an arrow function"):R(`'${e.value}' is not supported in this language`);if(e.type==="Identifier")return o(),I({type:"Identifier",name:e.value},e);if(p("(")){o();let n=P();return d(")"),n}return p("[")?H():p("{")?ae():p("<")?Ne(e)??Te():R(`Unexpected token '${e.value||e.type}'`)},Ne=(e,n=false)=>{let t=u,i=c.length,g=()=>(u=t,c.length=i,void 0);try{let N=Ee();return !N.length||!p("(")?g():O(n,e,N)}catch{return g()}},{parseType:ce,parseReturnType:ze,parseTypeParamList:Ee,parseTypeInScope:We}=Fe({tokens:a,pos:()=>u,peek:f,next:o,isP:p,isK:v,expectP:d,fail:R,recordError:X,createMissingNode:Ke,unescape:W,typeRefs:k}),Ce=()=>{let e=o(),n=l(),t=[],i=[];p("<")&&(i=Ee(),t=i.map(j=>j.name)),d("=");let g=We(i),N=T({type:"TSTypeAliasDeclaration",id:n,typeParameters:t,...i.length?{typeParamNodes:i}:{},typeAnnotation:g.schema,typeNode:g.node},e,h());return p(";")&&o(),N},Z=()=>{let e=f();if(e.type==="Identifier"&&e.value==="type"&&f(1).type==="Identifier"&&f(2).type==="Punctuator"&&(f(2).value==="="||f(2).value==="<"))return Ce();if(v("const")||v("let")||v("var")){let g=Ie();return p(";")&&o(),g}if(v("if"))return et();if(v("for"))return Ve();if(v("while"))return Ze();if(v("do"))return Ye();if(v("break")||v("continue"))return Qe();if(v("return"))return tt();if(v("throw"))return nt();if(v("try"))return rt();if(v("switch"))return ot();if(v("import"))return He();if(v("export"))return Ge();if(p("{"))return le();if((v("function")||v("async")&&f(1).type==="Keyword"&&f(1).value==="function")&&R("Function declarations are not supported \u2014 use 'const fn = () => \u2026'"),p(";"))return o(),I({type:"EmptyStatement"},e);if(e.type==="Keyword"&&Pt.has(e.value)||e.type==="Identifier"&&Et[e.value]?.(f(1),f(2))===true){let g=Nt[e.value];R(`'${e.value}' is not supported in this language`+(g?` \u2014 ${g}`:""));}let t=P(),i=p(";")?o():h();return T({type:"ExpressionStatement",expression:t},t,i)},Ie=()=>{let e=o(),n=e.value,t=()=>{let g=S([]),N=null;return p("=")?(o(),N=P()):n==="const"&&X("'const' declarations must be initialized"),T({type:"VariableDeclarator",id:g,init:N},g,N??g)},i=[t()];for(;p(",");)o(),i.push(t());return T({type:"VariableDeclaration",kind:n,declarations:i},e,i[i.length-1])},qe=()=>{let e=f();return e.type!=="String"&&R("Expected module specifier string"),o(),I({type:"Literal",value:W(e.value.slice(1,-1)),raw:e.value},e)},He=()=>{let e=o(),n=[],t;if(z("type")){let g=f(1);(g.type==="Punctuator"&&(g.value==="{"||g.value==="*")||g.type==="Identifier"&&g.value!=="from")&&(o(),t="type");}if(f().type!=="String"){if(f().type==="Identifier"){let g=l();n.push(T({type:"ImportDefaultSpecifier",local:g},g,g)),p(",")&&o();}if(p("*")){let g=o();z("as")||R("Expected 'as' after '*' in import"),o();let N=l();n.push(T({type:"ImportNamespaceSpecifier",local:N},g,N));}else if(p("{")){for(o();!p("}")&&!b();){let g;z("type")&&f(1).type==="Identifier"&&f(1).value!=="as"&&(o(),g="type");let N=l(),j=N;if(z("as")&&(o(),j=l()),n.push(T({type:"ImportSpecifier",imported:N,local:j,...g?{importKind:g}:{}},N,j)),p(","))o();else break}d("}");}z("from")||R("Expected 'from' in import declaration"),o();}let i=qe();return p(";")&&o(),I({type:"ImportDeclaration",specifiers:n,source:i,...t?{importKind:t}:{}},e)},Ge=()=>{let e=o();if(z("type")&&f(1).type==="Identifier"){let n=Ce();return I({type:"ExportNamedDeclaration",declaration:n,specifiers:[],source:null},e)}if(v("default")){o();let n=P();return p(";")&&o(),I({type:"ExportDefaultDeclaration",declaration:n},e)}if(v("const")||v("let")||v("var")){let n=Ie();return p(";")&&o(),I({type:"ExportNamedDeclaration",declaration:n,specifiers:[],source:null},e)}if(p("{")){o();let n=[];for(;!p("}")&&!b();){let t=l(),i=t;if(z("as")&&(o(),i=l()),n.push(T({type:"ExportSpecifier",local:t,exported:i},t,i)),p(","))o();else break}return d("}"),p(";")&&o(),I({type:"ExportNamedDeclaration",declaration:null,specifiers:n,source:null},e)}return R("Expected 'const', 'type', '{', or 'default' after 'export'")},Re=()=>f().type==="Identifier"&&f().value==="of",ge=()=>v("in"),Ve=()=>{let e=o();d("(");let n=null,t=null;if(!p(";"))if(v("const")||v("let")||v("var")){let j=o(),B=()=>{let G=l();if(p(":")){o();let Y=ce();G.typeAnnotation=Y.schema,G.typeAnnotationNode=Y.node;}return G},K=B();if(Re()||ge()){let G=T({type:"VariableDeclarator",id:K,init:null},K,K);t=T({type:"VariableDeclaration",kind:j.value,declarations:[G]},j,K);}else {let G=ee=>{let oe=null;return p("=")?(o(),oe=P(true)):j.value==="const"&&R("'const' declarations must be initialized"),T({type:"VariableDeclarator",id:ee,init:oe},ee,oe??ee)},Y=[G(K)];for(;p(",");)o(),Y.push(G(B()));n=T({type:"VariableDeclaration",kind:j.value,declarations:Y},j,Y[Y.length-1]);}}else {let j=P(true);Re()||ge()?t=j:n=j;}if(t){let j=ge();o();let B=P();d(")");let K=Z();return T(j?{type:"ForInStatement",left:t,right:B,body:K}:{type:"ForOfStatement",left:t,right:B,body:K,await:false},e,K)}d(";");let i=p(";")?null:P();d(";");let g=p(")")?null:P();d(")");let N=Z();return T({type:"ForStatement",init:n,test:i,update:g,body:N},e,N)},Ye=()=>{let e=o(),n=Z();v("while")||R("Expected 'while' after the 'do' body"),o(),d("(");let t=P(),i=d(")");return p(";")&&o(),T({type:"DoWhileStatement",body:n,test:t},e,i)},Qe=()=>{let e=o(),n=e.value==="break"?"BreakStatement":"ContinueStatement",t=p(";")?o():h();return T({type:n,label:null},e,t)},Ze=()=>{let e=o();d("(");let n=P();d(")");let t=Z();return T({type:"WhileStatement",test:n,body:t},e,t)},et=()=>{let e=o();d("(");let n=P();d(")");let t=Z(),i=null;return v("else")&&(o(),i=Z()),T({type:"IfStatement",test:n,consequent:t,alternate:i},e,i??t)},tt=()=>{let e=o(),n=null;!p(";")&&!p("}")&&!b()&&(n=P());let t=p(";")?o():h();return T({type:"ReturnStatement",argument:n},e,t)},nt=()=>{let e=o(),n=P(),t=p(";")?o():h();return T({type:"ThrowStatement",argument:n},e,t)},rt=()=>{let e=o(),n=le(),t=null,i=null;if(v("catch")){let g=o(),N=null;p("(")&&(o(),N=l(),d(")"));let j=le();t=T({type:"CatchClause",param:N,body:j},g,j);}return v("finally")&&(o(),i=le()),!t&&!i&&R("'try' requires a 'catch' or 'finally' clause"),T({type:"TryStatement",block:n,handler:t,finalizer:i},e,i??t??n)},ot=()=>{let e=o();d("(");let n=P();d(")"),d("{");let t=[];for(;!p("}")&&!b();){let g=f(),N=null;v("case")?(o(),N=P()):v("default")?o():R("Expected 'case' or 'default' in switch"),d(":");let j=[];for(;!p("}")&&!v("case")&&!v("default")&&!b();)j.push(Z());t.push(T({type:"SwitchCase",test:N,consequent:j},g,h()??g));}let i=d("}");return T({type:"SwitchStatement",discriminant:n,cases:t},e,i)},le=()=>{let e=d("{"),n=Ae(()=>p("}"));return T({type:"BlockStatement",body:n},e,d("}"))},Ae=e=>{let n=[];for(;!e()&&!b();){if(f().type==="Unknown"){o();continue}try{n.push(Z());}catch(t){if(!(t instanceof re))throw t;b()||o();}}return n};return {parseExpr:P,parseProgram:()=>{let e=f(),n=Ae(()=>false);return T({type:"Program",sourceType:"module",body:n,...k.length?{typeRefs:k}:{},...s.length?{comments:s}:{},...c.length?{parseDiagnostics:c}:{}},e,h()??e)},eof:b,fail:R,recordError:X,diagnostics:c}}function Ue(r){let c=ke(r),s=c.parseProgram(),a=s.comments;return a?.length&&xe(s,a,r),{ast:s,diagnostics:c.diagnostics}}function It(r){let{ast:c,diagnostics:s}=Ue(r),a=s[0];if(a){let u=a.code==="lex-error"?ne:re;throw new u(a.message,a.position,a.index,a.loc,a.end)}return c}function Rt(r){let c=ke(r),s=c.parseExpr();c.eof()||c.fail("Unexpected token after expression");let a=c.diagnostics[0];if(a){let u=a.code==="lex-error"?ne:re;throw new u(a.message,a.position,a.index,a.loc,a.end)}return s}function At(r){let c=ke(r),s;try{s=c.parseExpr(),c.eof()||c.recordError("Unexpected token after expression");}catch(a){if(!(a instanceof re)&&!(a instanceof ne))throw a}return {ast:s,diagnostics:c.diagnostics}}export{De as KEYWORDS,ne as LexError,re as ParseError,xe as attachComments,xt as nodeIsMissing,It as parse,Rt as parseExpression,At as parseExpressionTolerant,Ue as parseTolerant,be as tokenize};
1
+ import {TSLiteError}from'@tslite/ast';var re=class extends TSLiteError{constructor(a,i,f,v,S){super("lex-error",`${a} (${i.line}:${i.column})`,{position:i,index:f,loc:v,end:S});this.position=i;this.index=f;this.loc=v;this.end=S;this.name="LexError";}},Ke=new Set(["const","if","else","return","async","await","true","false","null","typeof","let","var","function","class","new","for","while","do","this","throw","try","catch","finally","switch","case","break","continue","default","void","delete","instanceof","in","yield","import","export","extends","super","debugger","with","enum","interface"]),vt=["...","===","!==","=>","?.","??=","&&=","||=","**=","??","==","!=","<=",">=","&&","||","|","&","++","--","+=","-=","*=","/=","%=","**","<<","+","-","*","/","%","<",">","!","?",":",".",",",";","=","^","~","(",")","[","]","{","}"],he=r=>r>="a"&&r<="z"||r>="A"&&r<="Z"||r==="_"||r==="$",Te=r=>he(r)||r>="0"&&r<="9",ne=r=>r>="0"&&r<="9",Fe=r=>ne(r)||r>="a"&&r<="f"||r>="A"&&r<="F",St=r=>Te(r)||r==="-",ue=r=>r===`
2
+ `||r==="\r"||r==="\u2028"||r==="\u2029",me=(r,u)=>{let a=u;for(;;){let i=r[a]??"";if(i===" "||i===" "||i==="\f"||i==="\v"||ue(i))a++;else if(i==="/"&&r[a+1]==="/")for(a+=2;a<r.length&&!ue(r[a]??"");)a++;else if(i==="/"&&r[a+1]==="*"){for(a+=2;a<r.length&&!(r[a]==="*"&&r[a+1]==="/");)a++;a+=2;}else return a}},kt=(r,u)=>{if(!he(r[u]??""))return u;let a=u+1;for(;Te(r[a]??"");)a++;return a},Xe=(r,u,a)=>r.startsWith(a,u)&&!Te(r[u+a.length]??""),wt=(r,u)=>{let a=me(r,u);Xe(r,a,"const")&&(a=me(r,a+5));let i=kt(r,a);if(i===a)return false;if(a=me(r,i),Xe(r,a,"extends")){let f=me(r,a+7),v=r[f]??"";return !(v==="="||v===">"||v==="/")}return r[a]===","?true:r[a]==="="&&r[a+1]!==">"},Pt=new Set(["(","[","{",",",";",":","?","=>","...","=","+","-","*","/","%","<","<=",">",">=","==","===","!=","!==","&&","||","??","!","+=","-=","*=","/=","%=","??=","&&=","||=","**="]),Nt=new Set(["return","typeof","await","delete","void","in","instanceof","else","case","yield","throw"]);function Et(r,u,a){return ke(r,u,a).scan()}function ke(r,u,a){let i=[],f=0,v=1,S=0,j=()=>({line:v,column:S}),h=(g=0)=>r[f+g]??"",_=g=>{let p=j(),d={start:p,end:{line:v,column:S+1}};if(a){a({message:g,position:p,index:f,loc:d,end:f+1});return}throw new re(g,p,f,d,f+1)},k=()=>{let g=r[f++];return g==="\r"?(r[f]===`
3
+ `&&f++,v++,S=0):g===`
4
+ `||g==="\u2028"||g==="\u2029"?(v++,S=0):S++,g},se=()=>{for(;;){let g=h();if(g===" "||g===" "||g==="\f"||g==="\v"||ue(g))k();else if(g==="/"&&h(1)==="/"){let p=f,d=j();k(),k();let o=f;for(;f<r.length&&!ue(h());)k();u?.({type:"Line",value:r.slice(o,f),start:p,end:f,loc:{start:d,end:j()}});}else if(g==="/"&&h(1)==="*"){let p=f,d=j();k(),k();let o=f,m=f;for(;;){if(f>=r.length){_("Unterminated block comment"),m=f;break}if(h()==="*"&&h(1)==="/"){m=f,k(),k();break}k();}u?.({type:"Block",value:r.slice(o,m),start:p,end:f,loc:{start:d,end:j()}});}else break}},A=(g,p,d,o)=>{i.push({type:g,value:p,start:d,end:f,loc:{start:o,end:j()}}),E=g==="Punctuator"?Pt.has(p):g==="Keyword"?Nt.has(p):g==="TemplateHead"||g==="TemplateMiddle";},P=g=>{for(k();f<r.length;){let p=h();if(p===g)return k(),r.slice(N,f);if(ue(p))return _("Unterminated string literal"),r.slice(N,f);if(p==="\\"){if(k(),f>=r.length)return _("Unterminated string literal"),r.slice(N,f);k();continue}k();}return _("Unterminated string literal"),r.slice(N,f)},l=()=>{if(h()==="0"&&(h(1)==="x"||h(1)==="X")){if(k(),k(),!Fe(h()))return _("Invalid hexadecimal literal");for(;Fe(h());)k();return}if(h()==="0"&&(h(1)==="b"||h(1)==="B")){if(k(),k(),h()!=="0"&&h()!=="1")return _("Invalid binary literal");for(;h()==="0"||h()==="1";)k();return}if(h()==="0"&&(h(1)==="o"||h(1)==="O")){if(k(),k(),!(h()>="0"&&h()<="7"))return _("Invalid octal literal");for(;h()>="0"&&h()<="7";)k();return}for(;ne(h());)k();if(h()===".")for(k();ne(h());)k();if(h()==="e"||h()==="E"){if(k(),(h()==="+"||h()==="-")&&k(),!ne(h()))return _("Invalid exponent");for(;ne(h());)k();}},K=()=>{let g=f;for(;f<r.length;){let p=h();if(p==="`"){let d=r.slice(g,f);return k(),{raw:d,interp:false}}if(p==="$"&&h(1)==="{"){let d=r.slice(g,f);return k(),k(),{raw:d,interp:true}}if(p==="\\"){if(k(),f>=r.length)break;k();continue}k();}return _("Unterminated template literal"),{raw:r.slice(g,f),interp:false}},N=0,M=0,c=[],E=true,F="js",C=[],V=[],w=new Map,D=-1,T=()=>({i:f,line:v,col:S,mode:F,braceDepth:M,tmplStack:[...c],jsxParent:[...C],jsxExpr:V.map(g=>({...g}))}),G=g=>{f=g.i,v=g.line,S=g.col,F=g.mode,M=g.braceDepth,c=[...g.tmplStack],C=[...g.jsxParent],V=g.jsxExpr.map(p=>({...p}));},J=()=>(i=[],Y(),i),Y=()=>{for(;;){if(F==="jsxChildren"){N=f;let o=j();if(f>=r.length){A("EOF","",N,o);break}let m=h();if(m==="<"){h(1)==="/"?(k(),k(),A("Punctuator","</",N,o),F="jsxCloseTag"):(k(),A("Punctuator","<",N,o),C.push("jsxChildren"),F="jsxOpenTag");continue}if(m==="{"){k(),A("Punctuator","{",N,o),V.push({level:M,restore:"jsxChildren"}),F="js";continue}for(;f<r.length&&h()!=="<"&&h()!=="{";)k();A("JSXText",r.slice(N,f),N,o);continue}if(F==="jsxOpenTag"||F==="jsxCloseTag"){se(),N=f;let o=j();if(f>=r.length){A("EOF","",N,o);break}let m=h();if(he(m)){for(k();St(h());)k();A("Identifier",r.slice(N,f),N,o);continue}if(m==="/"&&h(1)===">"){k(),k(),A("Punctuator","/>",N,o),F=C.pop()??"js";continue}if(m===">"){k(),A("Punctuator",">",N,o),F=F==="jsxCloseTag"?C.pop()??"js":"jsxChildren";continue}if(m==="{"){k(),A("Punctuator","{",N,o),V.push({level:M,restore:F}),F="js";continue}if(m==='"'||m==="'"){A("String",P(m),N,o);continue}if(m==="="||m==="."||m===":"){k(),A("Punctuator",m,N,o);continue}if(m==="<"&&F==="jsxOpenTag"){k(),A("Punctuator","<",N,o),C.push("jsxOpenTag");continue}_(`Unexpected character '${m}' in JSX tag`),k(),A("Unknown",m,N,o);continue}se(),N=f;let g=j();if(f>=r.length){A("EOF","",N,g);break}let p=h();if(he(p)){for(;Te(h());)k();let o=r.slice(N,f);A(Ke.has(o)?"Keyword":"Identifier",o,N,g);continue}if(ne(p)||p==="."&&ne(h(1))){l(),A("Number",r.slice(N,f),N,g);continue}if(p==='"'||p==="'"){let o=P(p);A("String",o,N,g);continue}if(p==="`"){k();let{raw:o,interp:m}=K();m?(A("TemplateHead",o,N,g),c.push(M)):A("Template",o,N,g);continue}if(p==="<"&&f===D){D=-1,k(),A("Punctuator","<",N,g);continue}if(p==="<"&&E&&!wt(r,f+1)){w.set(f,T()),k(),A("Punctuator","<",N,g),C.push("js"),F="jsxOpenTag";continue}if(p==="{"){k(),A("Punctuator","{",N,g),M++;continue}if(p==="}"){if(c.length>0&&M===c[c.length-1]){c.pop(),k();let{raw:o,interp:m}=K();A(m?"TemplateMiddle":"TemplateTail",o,N,g),m&&c.push(M);continue}if(V.length>0&&M===V[V.length-1].level){let{restore:o}=V.pop();k(),A("Punctuator","}",N,g),F=o;continue}k(),A("Punctuator","}",N,g),M--;continue}if(p==="?"&&h(1)==="."&&ne(h(2))){k(),A("Punctuator","?",N,g);continue}let d=vt.find(o=>r.startsWith(o,f));if(d){for(let o=0;o<d.length;o++)k();A("Punctuator",d,N,g);continue}_(`Unexpected character '${p}'`),k(),A("Unknown",p,N,g);}};return {scan:J,opensJsx:g=>w.has(g),rescanLessThan:g=>{let p=w.get(g);return p?(G(p),D=g,J()):null}}}var It=new Set(["leadingComments","trailingComments","innerComments","comments"]),Me=r=>typeof r=="object"&&r!==null&&typeof r.type=="string"&&r.loc!=null&&typeof r.start=="number",$e=new WeakMap;function Ct(r){let u=$e.get(r);if(u)return u;let a=[];for(let i of Object.keys(r)){if(It.has(i))continue;let f=r[i];if(Me(f))a.push(f);else if(Array.isArray(f))for(let v of f)Me(v)&&a.push(v);}return a.sort((i,f)=>i.start-f.start),$e.set(r,a),a}function Lt(r,u){let a=r,i,f;for(;;){let v=Ct(a);i=void 0,f=void 0;let S;for(let j of v){if(j.start<=u.start&&u.end<=j.end){S=j;break}if(j.end<=u.start)i=j;else if(u.end<=j.start){f=j;break}}if(!S)break;a=S;}return {enclosing:a,preceding:i,following:f}}var we=(r,u)=>{(r.leadingComments??(r.leadingComments=[])).push(u);},ge=(r,u)=>{(r.trailingComments??(r.trailingComments=[])).push(u);},Pe=(r,u)=>{(r.innerComments??(r.innerComments=[])).push(u);};function Rt(r,u){for(let a=u;a<r.length;a++){let i=r[a];if(i!==" "&&i!==" "&&i!=="\r"&&i!==`
5
+ `&&i!=="\f")return i}return ""}var jt=new Set([")","]","}",","]);function Ne(r,u,a=""){for(let i of u){let{enclosing:f,preceding:v,following:S}=Lt(r,i),j=v==null||v.loc.end.line<i.loc.start.line,h=!j&&(S==null||i.loc.end.line<S.loc.start.line);if(j)S?we(S,i):v?ge(v,i):Pe(f,i);else if(h)v?ge(v,i):S?we(S,i):Pe(f,i);else {let _=jt.has(Rt(a,i.end));v&&_?ge(v,i):S?we(S,i):v?ge(v,i):Pe(f,i);}}}var At=Object.prototype.hasOwnProperty,be=(r,u)=>At.call(r,u)?r[u]:void 0;function Ue(r,u,a){u==="__proto__"?Object.defineProperty(r,u,{value:a,enumerable:true,writable:true,configurable:true}):r[u]=a;}var Ot=(r=[])=>({vars:new Set(r),bounds:new Map,noCond:false,inferSink:null}),le=(r,u)=>{let a=new Set(r.vars),i=new Map(r.bounds);for(let f of u)a.add(f.name),f.bound?i.set(f.name,{bound:f.bound}):i.delete(f.name);return {vars:a,bounds:i,noCond:r.noCond,inferSink:r.inferSink}},Ee=r=>({t:"var",name:r.name,...r.bound?{bound:r.bound}:{},...r.default?{default:r.default}:{}}),Dt=(r,u)=>{let a=r.bounds.get(u)?.bound;return a?{t:"var",name:u,bound:a}:{t:"var",name:u}},Be=r=>{let{peek:u,next:a,isP:i,isK:f,expectP:v,fail:S,unescape:j}=r,h=(p,d)=>{let o=r.tokens[r.pos()-1]??d;return Object.assign(p,{start:d.start,end:o.end,loc:{start:d.loc.start,end:o.loc.end}})},_=()=>{let p=r.pos(),d=r.tokens[p],o=r.tokens[p-1];return !!o&&!!d&&d.loc.start.line>o.loc.end.line},k=()=>{let p=x=>r.tokens[r.pos()+x],d=(x,...b)=>x?.type==="Punctuator"&&b.includes(x.value),o=p(1);if(d(o,")","..."))return true;if(o?.type!=="Identifier")return false;let m=p(2);return d(m,":",",","?","=")?true:d(m,")")&&d(p(3),"=>")},se=()=>{let p=r.tokens,d=[],o=0,m=false;for(let x=r.pos();x<p.length;x++){let b=p[x];if(b.type==="EOF")break;if(b.type==="Punctuator"){if(b.value==="<")o++,o===1&&(m=true);else if(b.value===">"){if(o--,o===0)break}else b.value==="("||b.value==="["||b.value==="{"?(o++,m=false):b.value===")"||b.value==="]"||b.value==="}"?(o--,m=false):b.value===","&&o===1?m=true:m=false;continue}if(o===1&&m){if(b.type==="Keyword"&&b.value==="const")continue;if(b.type==="Identifier"){d.push(b.value),m=false;continue}}m=false;}return d},A=p=>{let d=le(p,se().map(m=>({name:m})));v("<");let o=[];for(;!i(">");){let m=u();f("const")&&S("'const' type parameters are not supported in this language; a constraint keeps the literal: '<T extends string>'");let x=u();x.type!=="Identifier"&&S("Expected type parameter name"),a();let b,X;if(f("extends")){a();let R=K(d);b=R.schema,X=R.node;}let $,I;if(i("=")){a();let R=K(d);$=R.schema,I=R.node;}o.push(h({type:"TSTypeParameter",name:x.value,...b?{bound:b}:{},...X?{boundNode:X}:{},...$?{default:$}:{},...I?{defaultNode:I}:{}},m)),i(">")||v(",");}return v(">"),o},P=p=>{r.splitShiftLeft(),v("<");let d=[];for(;!i(">");)d.push(K(p)),i(">")||v(",");return v(">"),d},l=p=>{let d=u();return d.type==="Identifier"&&d.value===p},K=p=>{let d=u(),o=N(p);if(p.noCond||!f("extends")||_())return o;a();let m=[],x=N({...p,noCond:true,inferSink:m});v("?");let b=le(p,m.map(I=>({name:I}))),X=K(b);v(":");let $=K(b);return {node:h({type:"TSConditionalType",checkType:o.node,extendsType:x.node,trueType:X.node,falseType:$.node},d),schema:{t:"conditional",check:o.schema,extends:x.schema,then:X.schema,else:$.schema,...m.length?{infer:m.map(I=>Ee({name:I}))}:{}}}},N=p=>{let d=u();i("|")&&a();let o=M(p);if(!i("|"))return o;let m=[o.node],x=[o.schema];for(;i("|");){a();let b=M(p);m.push(b.node),x.push(b.schema);}return {node:h({type:"TSUnionType",types:m},d),schema:{t:"union",of:x}}},M=p=>{let d=u();i("&")&&a();let o=c(p);if(!i("&"))return o;let m=[o.node],x=[o.schema];for(;i("&");){a();let b=c(p);m.push(b.node),x.push(b.schema);}return {node:h({type:"TSIntersectionType",types:m},d),schema:{t:"intersection",of:x}}},c=p=>{let d=u();if(l("keyof")){a();let o=c(p);return {node:h({type:"TSTypeOperator",operator:"keyof",typeAnnotation:o.node},d),schema:{t:"keyof",of:o.schema}}}if(l("readonly")){a();let o=c(p);return o.schema.t!=="array"&&o.schema.t!=="tuple"&&S("'readonly' only applies to array and tuple types"),{node:h({...o.node,readonly:true},d),schema:{...o.schema,readonly:true}}}if(l("infer")){a();let o=u();o.type!=="Identifier"&&S("Expected 'infer' variable name"),a();let m=p.inferSink;return m?(m.push(o.value),{node:h({type:"TSInferType",name:o.value},d),schema:{t:"var",name:o.value}}):S("'infer' is only allowed in the 'extends' clause of a conditional")}return E(p)},E=p=>{let d=u(),o=C(p);for(;i("[")&&!_();)if(a(),i("]"))a(),o={node:h({type:"TSArrayType",elementType:o.node},d),schema:{t:"array",items:o.schema}};else {let m=K(p);v("]"),o={node:h({type:"TSIndexedAccessType",objectType:o.node,indexType:m.node},d),schema:{t:"index",obj:o.schema,key:m.schema}};}return o},F=(p,d,o)=>({node:h({type:"TSKeywordType",kind:d},p),schema:o}),C=p=>{let d=u();if(f("typeof")){a();let x=u();x.type!=="Identifier"&&S("Expected a name after 'typeof' in type position"),a();let b=[x.value];for(;i(".");){a();let X=u();X.type!=="Identifier"&&X.type!=="Keyword"&&S("Expected a property name after '.' in 'typeof'"),a(),b.push(X.value);}return {node:h({type:"TSTypeQuery",exprName:b},d),schema:{t:"typeQuery",path:b}}}if(i("<")){r.rescanTypeLessThan();let x=A(p),b=le(p,x);return D(b,d,x)}if(i("(")){if(k())return D(p,d);a();let x=K(p.noCond?{...p,noCond:false}:p);return v(")"),x}if(i("{"))return G()?J(p):Y(p);if(i("["))return T(p);let o=u();if(o.type==="String"){a();let x=j(o.value.slice(1,-1));return {node:h({type:"TSLiteralType",literal:x},d),schema:{t:"literal",value:x}}}if(o.type==="Number"){a();let x=Number(o.value);return {node:h({type:"TSLiteralType",literal:x},d),schema:{t:"literal",value:x}}}if(f("true"))return a(),{node:h({type:"TSLiteralType",literal:true},d),schema:{t:"literal",value:true}};if(f("false"))return a(),{node:h({type:"TSLiteralType",literal:false},d),schema:{t:"literal",value:false}};if(f("null"))return a(),F(d,"null",{t:"null"});if(f("void"))return a(),F(d,"void",{t:"void"});if(o.type==="Identifier"){switch(a(),o.value){case "string":return F(d,"string",{t:"string"});case "number":return F(d,"number",{t:"number"});case "boolean":return F(d,"boolean",{t:"boolean"});case "any":return F(d,"any",{t:"any"});case "unknown":return F(d,"unknown",{t:"unknown"});case "undefined":return F(d,"undefined",{t:"undefined"});case "never":return F(d,"never",{t:"union",of:[]});case "object":return F(d,"object",{t:"nonPrimitive"})}let x=i("<")||i("<<")?P(p):[],b=x.map(I=>I.schema),X=x.length?x.map(I=>I.node):void 0,$=h({type:"TSTypeReference",typeName:o.value,...X?{typeArguments:X}:{}},d);return p.vars.has(o.value)&&b.length===0?{node:$,schema:Dt(p,o.value)}:o.value==="ReturnType"&&b.length===1?{node:$,schema:{t:"returnType",fn:b[0]}}:o.value==="Parameters"&&b.length===1?{node:$,schema:{t:"parameters",fn:b[0]}}:(r.typeRefs?.push({name:o.value,loc:o.loc,args:b}),{node:$,schema:{t:"apply",name:o.value,args:b}})}r.recordError(`Expected a type but got '${o.value||o.type}'`,o);let m=r.createMissingNode({type:"TSTypeReference",typeName:""},o);return r.typeRefs?.push({name:"",loc:m.loc,args:[]}),{node:m,schema:{t:"unknown"}}},V=p=>{v("(");let d=[];for(;!i(")");){let o=u(),m=i("...");m&&a();let x=u();x.type!=="Identifier"&&S("Expected parameter name in function type"),a();let b=!m&&i("?");b&&a(),v(":");let X=K(p),$=h({type:"Identifier",name:x.value,typeAnnotationNode:X.node,...b?{optional:true}:{}},x);d.push({node:m?h({type:"RestElement",argument:$},o):$,schema:{name:x.value,type:X.schema,...b?{optional:true}:{},...m?{variadic:true}:{}}}),m&&!i(")")&&S("A rest parameter must be last in a parameter list"),i(")")||v(",");}return v(")"),d},w=(p,d)=>{let o=u(),m=r.tokens[r.pos()+1];if(!(o.type==="Identifier"&&m?.type==="Identifier"&&m.value==="is"))return K(p);let b=d.indexOf(o.value);b<0&&S(`Cannot find parameter '${o.value}' for the type predicate`),a(),a();let X=K(p);return {node:h({type:"TSTypePredicate",parameterName:o.value,typeAnnotation:X.node},o),schema:{t:"boolean"},guard:{param:b,type:X.schema}}},D=(p,d,o)=>{let m=V(p);v("=>");let x=w(p,m.map(b=>b.schema.name));return {node:h({type:"TSFunctionType",params:m.map(b=>b.node),returnType:x.node,...o?.length?{typeParameters:[...o]}:{}},d),schema:{t:"fn",params:m.map(b=>b.schema),returns:x.schema,...x.guard?{guard:x.guard}:{},...o?.length?{typeParams:o.map(Ee)}:{}}}},T=p=>{let d=u();v("[");let o=[],m=[],x=[],b=[],X=()=>{let R=r.tokens[r.pos()],U=r.tokens[r.pos()+1],z=r.tokens[r.pos()+2];if(R?.type==="Identifier"&&U?.type==="Punctuator"&&(U.value===":"||U.value==="?"&&z?.type==="Punctuator"&&z.value===":"))return a(),R.value};for(;!i("]");){if(x[x.length-1]==="rest"&&S("A rest element must be last in a tuple type"),i("...")){a();let R=X();R!==void 0&&v(":"),b.push(R);let U=K(p);U.schema.t!=="array"&&S("A rest element type must be written as an array type ('...T[]')"),m.push(U.schema.items),o.push(U.node.elementType),x.push("rest");}else {let R=X(),U=false;R!==void 0&&(i("?")&&(a(),U=true),v(":")),b.push(R);let z=K(p);!U&&i("?")&&(a(),U=true),m.push(z.schema),o.push(z.node),x.push(U?"optional":"req");}i("]")||v(",");}v("]");let $=x.some(R=>R!=="req"),I=b.some(R=>R!==void 0);return {node:h({type:"TSTupleType",elementTypes:o,...$?{flags:x}:{},...I?{labels:b}:{}},d),schema:$?{t:"tuple",elements:m,flags:x}:{t:"tuple",elements:m}}},G=()=>{let p=r.tokens,d=r.pos()+1;return p[d]?.type==="Punctuator"&&(p[d]?.value==="+"||p[d]?.value==="-")&&d++,p[d]?.type==="Identifier"&&p[d]?.value==="readonly"&&d++,p[d]?.type==="Punctuator"&&p[d]?.value==="["&&p[d+1]?.type==="Identifier"&&p[d+2]?.type==="Keyword"&&p[d+2]?.value==="in"},J=p=>{let d=u();v("{"),(i("+")||i("-"))&&a(),l("readonly")&&a(),v("[");let o=u();o.type!=="Identifier"&&S("Expected mapped type key name"),a(),f("in")||S("Expected 'in' in mapped type"),a();let m=K(p);l("as")&&S("Key remapping ('as') in mapped types is not supported"),v("]");let x=false,b=i("+")||i("-")?a().value:null;i("?")&&(a(),x=b!=="-"),v(":");let X=K(le(p,[{name:o.value}]));return (i(";")||i(","))&&a(),v("}"),{node:h({type:"TSMappedType",key:o.value,constraint:m.node,typeAnnotation:X.node,optional:x},d),schema:{t:"mapped",key:o.value,over:m.schema,body:X.schema,optional:x}}},Y=p=>{let d=u();v("{");let o=[],m={},x,b=[];for(;!i("}");){let $=u();if(i("(")||i("<")){i("<")&&r.rescanTypeLessThan();let I=i("<")?A(p):[],R=I.length?le(p,I):p,U=V(R);v(":");let z=w(R,U.map(q=>q.schema.name));b.push({t:"fn",params:U.map(q=>q.schema),returns:z.schema,...z.guard?{guard:z.guard}:{},...I.length?{typeParams:I.map(Ee)}:{}}),o.push(h({type:"TSCallSignatureDeclaration",params:U.map(q=>q.node),returnType:z.node,...I.length?{typeParameters:I}:{}},$));}else if(i("[")){a(),u().type!=="Identifier"&&S("Expected index signature parameter name"),a(),v(":");let I=u();(I.type!=="Identifier"||I.value!=="string"&&I.value!=="number")&&S("Index signature parameter type must be 'string' or 'number'"),a(),v("]"),v(":");let R=K(p);x={key:I.value,value:R.schema},o.push(h({type:"TSIndexSignature",keyType:I.value,typeAnnotation:R.node},$));}else {let I=false;if(l("readonly")){let ae=r.tokens[r.pos()+1];ae&&(ae.type==="Identifier"||ae.type==="Keyword"||ae.type==="String"||ae.type==="Number")&&(a(),I=true);}let R=u(),U;if(R.type==="Identifier"||R.type==="Keyword")a(),U=R.value;else if(R.type==="String")a(),U=j(R.value.slice(1,-1));else if(R.type==="Number")a(),U=R.value;else return S("Expected property name in object type");let z=i("?");z&&a(),v(":");let q=K(p);Ue(m,U,{type:q.schema,...z?{optional:true}:{}}),o.push(h({type:"TSPropertySignature",key:U,typeAnnotation:q.node,...z?{optional:true}:{},...I?{readonly:true}:{}},$));}if(i(";")||i(","))a();else break}v("}");let X=h({type:"TSTypeLiteral",members:o},d);return b.length>0?Object.keys(m).length>0||x?S("Callable object types (call signatures mixed with members) are not supported"):{node:X,schema:b.length===1?b[0]:{t:"overload",signatures:b}}:{node:X,schema:{t:"object",props:m,...x?{index:x}:{}}}},g=Ot();return {parseType:()=>K(g),parseReturnType:p=>w(g,p),parseTypeParamList:()=>A(g),parseTypeInScope:p=>K(le(g,p)),withTypeParams:(p,d)=>{let o=g;g=le(o,p);try{return d()}finally{g=o;}}}};var oe=class extends TSLiteError{constructor(a,i,f,v,S){super("parse-error",`${a} (${i.line}:${i.column})`,{position:i,index:f,loc:v,end:S});this.position=i;this.index=f;this.loc=v;this.end=S;this.name="ParseError";}},Ft=r=>{let u=r;return u!=null&&typeof u.start=="number"&&u.start===u.end&&u.start>=0},_e=(r,u)=>Object.assign(r,{start:u.start,end:u.start,loc:{start:u.loc.start,end:u.loc.start}}),Xt={"??":1,"||":2,"&&":3,"|":4,"^":5,"&":6,"==":7,"===":7,"!=":7,"!==":7,"<":8,"<=":8,">":8,">=":8,in:8,as:8,satisfies:8,"<<":9,">>":9,">>>":9,"+":10,"-":10,"*":11,"/":11,"%":11,"**":12},Kt=new Set(["??","||","&&"]),Mt=new Set(["class","debugger","with","enum","interface"]),$t={enum:'use a union of literals (`type T = "a" | "b"`) \u2014 it is serializable',interface:"use a type alias (`type X = { \u2026 }`)",namespace:"use modules (`import`/`export`)",module:"use modules (`import`/`export`)",declare:"declare the shape via the DI env, or with a `type` alias",abstract:"classes are not part of the language \u2014 model with objects + functions"},Ut={namespace:(r,u)=>r.type==="Identifier"&&u.type==="Punctuator"&&u.value==="{",module:(r,u)=>r.type==="Identifier"&&u.type==="Punctuator"&&u.value==="{",declare:r=>r.type==="Keyword"&&["const","let","var","function","class","enum","interface"].includes(r.value)||r.type==="Identifier"&&["type","namespace","module"].includes(r.value),abstract:r=>r.type==="Keyword"&&r.value==="class"},Bt=new Set(["=","+=","-=","*=","/=","%=","**=","??=","&&=","||="]);function Ie(r){let u=[],a=[],i=null,f=e=>`${e.index}:${e.message}`,v=ke(r,e=>{i?.comments.has(e.start)||a.push(e);},e=>{i?.lex.has(f(e))||u.push({code:"lex-error",...e});}),S=v.scan(),j=0,h=[],_=e=>{for(;h.length>e;)h.pop()();},k=(e=j)=>{let t=S[e];if(t?.type!=="Punctuator"||t.value!=="<"||!v.opensJsx(t.start))return;let n=S.slice(e),s=a.length;i={comments:new Set(a.map(L=>L.start)),lex:new Set(u.filter(L=>L.code==="lex-error").map(f))};let y;try{y=v.rescanLessThan(t.start);}finally{i=null;}S.splice(e,S.length-e,...y),h.push(()=>{S.splice(e,S.length-e,...n),a.length=s;});},se=()=>{let e=S[j];if(e?.type!=="Punctuator"||e.value!=="<<")return;let t={line:e.loc.start.line,column:e.loc.start.column+1},n=j;S.splice(n,1,{...e,value:"<",end:e.start+1,loc:{start:e.loc.start,end:t}},{...e,value:"<",start:e.start+1,loc:{start:t,end:e.loc.end}}),h.push(()=>S.splice(n,2,e));},A=[],P=(e=0)=>S[Math.min(j+e,S.length-1)],l=()=>S[j++],K=()=>S[j-1],N=()=>{let e=S[j],t=S[j-1];return !!e&&!!t&&e.loc.start.line>t.loc.end.line},M=()=>P().type==="EOF",c=e=>P().type==="Punctuator"&&P().value===e,E=e=>P().type==="Keyword"&&P().value===e,F=e=>P().type==="Identifier"&&P().value===e,C=(e,t=P())=>{throw V(e,t),new oe(e,t.loc.start,t.start,t.loc,t.end)},V=(e,t=P())=>{let n=u[u.length-1];n&&n.index===t.start||u.push({code:"parse-error",message:e,position:t.loc.start,index:t.start,loc:t.loc,end:t.end});},w=e=>(c(e)||C(`Expected '${e}' but got '${P().value||P().type}'`),l()),D=(e,t)=>{let n=K()??t;return Object.assign(e,{start:t.start,end:n.end,loc:{start:t.loc.start,end:n.loc.end}})},T=(e,t,n)=>Object.assign(e,{start:t.start,end:n.end,loc:{start:t.loc.start,end:n.loc.end}}),G=e=>{let t="";for(let n=0;n<e.length;n++){if(e[n]!=="\\"){t+=e[n];continue}let s=e[++n];switch(s){case "n":t+=`
6
+ `;break;case "t":t+=" ";break;case "r":t+="\r";break;case "b":t+="\b";break;case "f":t+="\f";break;case "v":t+="\v";break;case "0":t+="\0";break;case "x":t+=String.fromCharCode(parseInt(e.slice(n+1,n+3),16)),n+=2;break;case "u":if(e[n+1]==="{"){let y=e.indexOf("}",n);t+=String.fromCodePoint(parseInt(e.slice(n+2,y),16)),n=y;}else t+=String.fromCharCode(parseInt(e.slice(n+1,n+5),16)),n+=4;break;default:t+=s;}}return t},J=(e=false)=>Y(e),Y=(e=false)=>{let t=g(e),n=P();if(n.type==="Punctuator"&&Bt.has(n.value)){l();let s=Y();return T({type:"AssignmentExpression",operator:n.value,left:t,right:s},t,s)}return t},g=(e=false)=>{let t=d(0,e);if(!c("?"))return t;l();let n=J();w(":");let s=J();return T({type:"ConditionalExpression",test:t,consequent:n,alternate:s},t,s)},p=()=>{let e=P();if(e.type==="Keyword")return e.value==="in"?{op:"in",consume:1}:null;if(e.type==="Identifier")return e.value==="as"?{op:"as",consume:1}:e.value==="satisfies"?{op:"satisfies",consume:1}:null;if(e.type!=="Punctuator")return null;if(e.value===">"){let t=P(1);if(t.type==="Punctuator"&&t.value===">"&&e.end===t.start){let n=P(2);return n.type==="Punctuator"&&n.value===">"&&t.end===n.start?{op:">>>",consume:3}:{op:">>",consume:2}}return {op:">",consume:1}}return {op:e.value,consume:1}},d=(e,t=false)=>{let n=o();for(;;){let s=p();if(!s)break;let{op:y,consume:L}=s;if(y==="in"&&t)break;let O=be(Xt,y);if(!O||O<=e)break;if(y==="satisfies"){if(N())break;C("'satisfies' is not supported in this language \u2014 a type annotation (`const x: T = \u2026`) also checks compatibility, but it declares the type as T, while 'satisfies' keeps the inferred one");}if(y==="as"){if(N())break;l();let B=ye();n=T({type:"TSAsExpression",expression:n,typeAnnotation:B.schema,typeAnnotationNode:B.node},n,K());continue}for(let B=0;B<L;B++)l();let W=d(y==="**"?O-1:O,t);n=T({type:Kt.has(y)?"LogicalExpression":"BinaryExpression",operator:y,left:n,right:W},n,W);}return n},o=()=>{let e=P();return e.type==="Punctuator"&&(e.value==="++"||e.value==="--")?(l(),D({type:"UpdateExpression",operator:e.value,prefix:true,argument:o()},e)):E("await")?(l(),D({type:"AwaitExpression",argument:o()},e)):E("typeof")||E("void")||E("delete")||e.type==="Punctuator"&&(e.value==="!"||e.value==="-"||e.value==="+"||e.value==="~")?m(e):b()},m=e=>{l();let t=o();return c("**")&&C(`An unary expression with the '${e.value}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.`),D({type:"UnaryExpression",operator:e.value,prefix:true,argument:t},e)},x=()=>{let e=j,t=h.length,n=u.length,s=()=>(_(t),j=e,u.length=n,void 0);try{if(se(),l(),c(">"))return s();let y=[];for(;y.push(ye().schema),!!c(",");)l();return c(">")?(l(),c("(")?y:s()):s()}catch{return s()}},b=()=>{let e=tt(),t=false;for(;;)if((P().type==="Template"||P().type==="TemplateHead")&&C("Tagged templates are not supported in this language"),c("?."))if(l(),t=true,c("(")){let{args:n,close:s}=X();e=T({type:"CallExpression",callee:e,arguments:n,optional:true},e,s);}else if(c("[")){l();let n=J(),s=w("]");e=T({type:"MemberExpression",object:e,property:n,computed:true,optional:true},e,s);}else {let n=P();n.type!=="Identifier"&&n.type!=="Keyword"&&C("Expected property name after '?.'"),l();let s=D({type:"Identifier",name:n.value},n);e=T({type:"MemberExpression",object:e,property:s,computed:false,optional:true},e,s);}else if(c(".")){l();let n=P(),s;n.type==="Identifier"||n.type==="Keyword"?(l(),s=D({type:"Identifier",name:n.value},n)):(V("Expected property name"),s=_e({type:"Identifier",name:""},n)),e=T({type:"MemberExpression",object:e,property:s,computed:false,optional:false},e,s);}else if(c("[")){l();let n=J(),s=w("]");e=T({type:"MemberExpression",object:e,property:n,computed:true,optional:false},e,s);}else if(c("(")){let{args:n,close:s}=X();e=T({type:"CallExpression",callee:e,arguments:n,optional:false},e,s);}else if(c("<")||c("<<")){let n=x();if(!n)break;let{args:s,close:y}=X();e=T({type:"CallExpression",callee:e,arguments:s,optional:false,typeArguments:n},e,y);}else if(c("++")||c("--")){let n=l();e=T({type:"UpdateExpression",operator:n.value,prefix:false,argument:e},e,n);}else break;return t?T({type:"ChainExpression",expression:e},e,e):e},X=()=>{w("(");let e=[];for(;!c(")");)e.push($()),c(")")||w(",");return {args:e,close:w(")")}},$=()=>{if(c("...")){let e=l(),t=J();return T({type:"SpreadElement",argument:t},e,t)}return J()},I=()=>{let e=P();return e.type!=="Identifier"&&C("Expected identifier"),l(),D({type:"Identifier",name:e.value},e)},R=(e=false)=>{let t=c("{")?U():c("[")?z():I();if(e&&c("?")&&(t.type!=="Identifier"&&C("A binding pattern parameter cannot be optional"),l(),t.optional=true),c(":")){l();let n=ye();t.typeAnnotation=n.schema,t.typeAnnotationNode=n.node;}return t},U=()=>{let e=w("{"),t=[];for(;!c("}");){if(c("...")){let s=l(),y=R();t.push(T({type:"RestElement",argument:y},s,y));}else {let s=I(),y,L=false;if(c(":")?(l(),y=R()):(y={...s},L=true),c("=")){l();let O=J();y=T({type:"AssignmentPattern",left:y,right:O},y,O);}t.push(T({type:"Property",key:s,value:y,kind:"init",shorthand:L,computed:false},s,y));}c("}")||w(",");}let n=w("}");return T({type:"ObjectPattern",properties:t},e,n)},z=()=>{let e=w("["),t=[];for(;!c("]");){if(c(",")){t.push(null),l();continue}if(c("...")){let s=l(),y=R();t.push(T({type:"RestElement",argument:y},s,y));}else {let s=R();if(c("=")){l();let y=J();s=T({type:"AssignmentPattern",left:s,right:y},s,y);}t.push(s);}c("]")||w(",");}let n=w("]");return T({type:"ArrayPattern",elements:t},e,n)},q=()=>{let e=h.length,t=ae();return t||_(e),t},ae=()=>{let e=0,t="name";for(let n=j;n<S.length;n++){let s=S[n];if(s.type==="EOF")return false;if(s.type==="Punctuator"){if(s.value==="<"&&t==="type"){k(n);continue}if(e===1&&s.value===":"&&t==="name"?t="type":e===1&&s.value==="="?t="default":e===1&&s.value===","&&(t="name"),s.value==="("||s.value==="["||s.value==="{")e++;else if((s.value===")"||s.value==="]"||s.value==="}")&&(e--,e===0)){let y=S[n+1];return !y||y.type!=="Punctuator"?false:y.value==="=>"?true:y.value===":"?ze(n+2):false}}}return false},ze=e=>{let t=0;for(let n=e;n<S.length;n++){let s=S[n];if(s.type==="EOF")return false;if(s.type==="Punctuator")if(s.value==="<"&&k(n),["(","[","{","<"].includes(s.value))t++;else if([")","]","}",">"].includes(s.value)){if(t===0)return false;t--;}else {if(t===0&&s.value==="=>")return true;if(t===0&&(s.value===";"||s.value===","))return false}}return false},We=()=>{w("(");let e=[];for(;!c(")");){if(c("...")){let t=l(),n=R();e.push(T({type:"RestElement",argument:n},t,n));}else {let t=R(true);if(c("=")){t.optional&&C("Parameter cannot have question mark and initializer"),l();let n=J();t=T({type:"AssignmentPattern",left:t,right:n},t,n);}e.push(t);}c(")")||w(",");}return w(")"),e},qe=e=>{if(e.type==="Identifier")return e.name;let t=e.left;return e.type==="AssignmentPattern"&&t?.type==="Identifier"?t.name:null},de=(e,t,n=[])=>ot(n,()=>He(e,t,n)),He=(e,t,n)=>{let s=c("(")?We():[I()],y,L,O;if(c(":")){l();let B=nt(s.map(qe));y=B.schema,L=B.node,O=B.guard;}w("=>");let W=c("{")?ce():J();return D({type:"ArrowFunctionExpression",params:s,body:W,async:e,expression:W.type!=="BlockStatement",generator:false,...y?{returnType:y,returnTypeNode:L}:{},...O?{returnGuard:O}:{},...n.length?{typeParameters:[...n]}:{}},t)},Ge=()=>{let e=w("["),t=[];for(;!c("]");){if(c(",")){l(),t.push(null);continue}t.push($()),c("]")||w(",");}return T({type:"ArrayExpression",elements:t},e,w("]"))},Ye=()=>{let e=w("{"),t=[];for(;!c("}");){if(c("...")){let n=l(),s=J();t.push(T({type:"SpreadElement",argument:s},n,s));}else {let n=P(),s,y=false;if(c("["))y=true,l(),s=J(),w("]");else if(n.type==="String")l(),s=D({type:"Literal",value:G(n.value.slice(1,-1)),raw:n.value},n);else if(n.type==="Number")l(),s=D({type:"Literal",value:Number(n.value),raw:n.value},n);else if(n.type==="Identifier"||n.type==="Keyword")l(),s=D({type:"Identifier",name:n.value},n);else return C("Invalid property key");if(c(":")){l();let L=J();t.push(T({type:"Property",key:s,value:L,kind:"init",shorthand:false,computed:y},n,L));}else t.push(T({type:"Property",key:s,value:s,kind:"init",shorthand:true,computed:false},n,s));}c("}")||w(",");}return T({type:"ObjectExpression",properties:t},e,w("}"))},fe=(e,t)=>({type:"TemplateElement",value:{raw:e,cooked:G(e)},tail:t}),Qe=e=>{l();let t=[fe(e.value,false)],n=[];for(;;){n.push(J());let s=P();if(s.type==="TemplateMiddle")l(),t.push(fe(s.value,false));else if(s.type==="TemplateTail"){l(),t.push(fe(s.value,true));break}else C("Expected `}` to close template interpolation");}return D({type:"TemplateLiteral",quasis:t,expressions:n},e)},pe=()=>{let e=P();return e.type!=="Identifier"&&C(`Expected JSX identifier but got '${e.value||e.type}'`),D({type:"JSXIdentifier",name:l().value},e)},Ce=()=>{let e=pe();if(c(":")){l();let t=pe();return T({type:"JSXNamespacedName",namespace:e,name:t},e,t)}for(;c(".");){l();let t=pe();e=T({type:"JSXMemberExpression",object:e,property:t},e,t);}return e},Z=e=>e.type==="JSXIdentifier"?e.name:e.type==="JSXNamespacedName"?`${Z(e.namespace)}:${Z(e.name)}`:`${Z(e.object)}.${Z(e.property)}`,Ze=()=>{let e=P();if(e.type==="String")return l(),D({type:"Literal",value:G(e.value.slice(1,-1)),raw:e.value},e);if(c("{")){let t=l(),n=Y(),s=w("}");return T({type:"JSXExpressionContainer",expression:n},t,s)}return c("<")?xe():C(`Invalid JSX attribute value '${e.value||e.type}'`)},et=()=>{let e=[];for(;!c(">")&&!c("/>")&&!M();){if(c("{")){let s=l();w("...");let y=Y(),L=w("}");e.push(T({type:"JSXSpreadAttribute",argument:y},s,L));continue}let t=pe();if(c(":")){l();let s=pe();t=T({type:"JSXNamespacedName",namespace:t,name:s},t,s);}let n=null;c("=")&&(l(),n=Ze()),e.push(T({type:"JSXAttribute",name:t,value:n},t,n??t));}return e},Le=()=>{let e=[];for(;!(c("</")||M());){let t=P();if(t.type==="JSXText")l(),e.push(D({type:"JSXText",value:t.value,raw:t.value},t));else if(c("{")){let n=l();if(c("}")){let s=l(),y=D({type:"JSXEmptyExpression"},n);e.push(T({type:"JSXExpressionContainer",expression:y},n,s));}else if(c("...")){l();let s=Y(),y=w("}");e.push(T({type:"JSXSpreadChild",expression:s},n,y));}else {let s=Y(),y=w("}");e.push(T({type:"JSXExpressionContainer",expression:s},n,y));}}else c("<")?e.push(xe()):C(`Unexpected token in JSX children '${t.value||t.type}'`);}return e},xe=()=>{let e=w("<");if(c(">")){let te=l(),ie=T({type:"JSXOpeningFragment"},e,te),Tt=Le(),gt=w("</"),Je=w(">"),bt=T({type:"JSXClosingFragment"},gt,Je);return T({type:"JSXFragment",openingFragment:ie,children:Tt,closingFragment:bt},e,Je)}let t=Ce(),n=et();if(c("/>")){let te=l(),ie=T({type:"JSXOpeningElement",name:t,attributes:n,selfClosing:true},e,te);return T({type:"JSXElement",openingElement:ie,children:[],closingElement:null},e,te)}let s=w(">"),y=T({type:"JSXOpeningElement",name:t,attributes:n,selfClosing:false},e,s),L=Le(),O=w("</"),W=P(),B=Ce();Z(B)!==Z(t)&&C(`JSX closing tag </${Z(B)}> does not match opening <${Z(t)}>`,W);let H=w(">"),Q=T({type:"JSXClosingElement",name:B},O,H);return T({type:"JSXElement",openingElement:y,children:L,closingElement:Q},e,H)},tt=()=>{let e=P();if(E("async")){let t=P(1);if(t.value==="("||t.type==="Identifier")return l(),de(true,e);if(t.value==="<"){l();let n=Re(e,true);if(n)return n}return C("Unexpected 'async'")}if(c("(")&&q()||e.type==="Identifier"&&P(1).type==="Punctuator"&&P(1).value==="=>")return de(false,e);if(e.type==="Number")return l(),D({type:"Literal",value:Number(e.value),raw:e.value},e);if(e.type==="String")return l(),D({type:"Literal",value:G(e.value.slice(1,-1)),raw:e.value},e);if(e.type==="Template")return l(),D({type:"TemplateLiteral",expressions:[],quasis:[fe(e.value,true)]},e);if(e.type==="TemplateHead")return Qe(e);if(e.type==="Keyword")return e.value==="true"?(l(),D({type:"Literal",value:true,raw:"true"},e)):e.value==="false"?(l(),D({type:"Literal",value:false,raw:"false"},e)):e.value==="null"?(l(),D({type:"Literal",value:null,raw:"null"},e)):e.value==="new"?C("'new' is not supported \u2014 the language has no constructors (FP / portable IR). Use a factory function provided via DI (e.g. `now()` instead of `new Date()`)."):e.value==="function"?C("Anonymous functions are not supported \u2014 use an arrow function"):C(`'${e.value}' is not supported in this language`);if(e.type==="Identifier")return l(),D({type:"Identifier",name:e.value},e);if(c("(")){l();let t=J();return w(")"),t}return c("[")?Ge():c("{")?Ye():c("<")?Re(e)??xe():C(`Unexpected token '${e.value||e.type}'`)},Re=(e,t=false)=>{let n=j,s=h.length,y=u.length,L=()=>(_(s),j=n,u.length=y,void 0),O=P(1);O.type==="Keyword"&&O.value==="const"&&ve();try{let W=ve();return !W.length||!c("(")?L():de(t,e,W)}catch{return L()}},{parseType:ye,parseReturnType:nt,parseTypeParamList:ve,parseTypeInScope:rt,withTypeParams:ot}=Be({rescanTypeLessThan:k,splitShiftLeft:se,tokens:S,pos:()=>j,peek:P,next:l,isP:c,isK:E,expectP:w,fail:C,recordError:V,createMissingNode:_e,unescape:G,typeRefs:A}),je=()=>{let e=l(),t=I(),n=[];c("<")&&(n=ve()),w("=");let s=rt(n),y=T({type:"TSTypeAliasDeclaration",id:t,...n.length?{typeParameters:[...n]}:{},typeAnnotation:s.schema,typeNode:s.node},e,K());return c(";")&&l(),y},ee=()=>{let e=P();if(e.type==="Identifier"&&e.value==="type"&&P(1).type==="Identifier"&&P(2).type==="Punctuator"&&(P(2).value==="="||P(2).value==="<"))return je();if(E("const")||E("let")||E("var")){let y=Ae();return c(";")&&l(),y}if(E("if"))return dt();if(E("for"))return lt();if(E("while"))return ut();if(E("do"))return pt();if(E("break")||E("continue"))return ct();if(E("return"))return ft();if(E("throw"))return yt();if(E("try"))return mt();if(E("switch"))return ht();if(E("import"))return at();if(E("export"))return it();if(c("{"))return ce();if((E("function")||E("async")&&P(1).type==="Keyword"&&P(1).value==="function")&&C("Function declarations are not supported \u2014 use 'const fn = () => \u2026'"),c(";"))return l(),D({type:"EmptyStatement"},e);if(e.type==="Keyword"&&Mt.has(e.value)||e.type==="Identifier"&&be(Ut,e.value)?.(P(1),P(2))===true){let y=be($t,e.value);C(`'${e.value}' is not supported in this language`+(y?` \u2014 ${y}`:""));}let n=J(),s=c(";")?l():K();return T({type:"ExpressionStatement",expression:n},n,s)},Ae=()=>{let e=l(),t=e.value,n=()=>{let y=R(),L=null;return c("=")?(l(),L=J()):t==="const"&&V("'const' declarations must be initialized"),T({type:"VariableDeclarator",id:y,init:L},y,L??y)},s=[n()];for(;c(",");)l(),s.push(n());return T({type:"VariableDeclaration",kind:t,declarations:s},e,s[s.length-1])},st=()=>{let e=P();return e.type!=="String"&&C("Expected module specifier string"),l(),D({type:"Literal",value:G(e.value.slice(1,-1)),raw:e.value},e)},at=()=>{let e=l(),t=[],n;if(F("type")){let y=P(1);(y.type==="Punctuator"&&(y.value==="{"||y.value==="*")||y.type==="Identifier"&&y.value!=="from")&&(l(),n="type");}if(P().type!=="String"){if(P().type==="Identifier"){let y=I();t.push(T({type:"ImportDefaultSpecifier",local:y},y,y)),c(",")&&l();}if(c("*")){let y=l();F("as")||C("Expected 'as' after '*' in import"),l();let L=I();t.push(T({type:"ImportNamespaceSpecifier",local:L},y,L));}else if(c("{")){for(l();!c("}")&&!M();){let y;F("type")&&P(1).type==="Identifier"&&P(1).value!=="as"&&(l(),y="type");let L=I(),O=L;if(F("as")&&(l(),O=I()),t.push(T({type:"ImportSpecifier",imported:L,local:O,...y?{importKind:y}:{}},L,O)),c(","))l();else break}w("}");}F("from")||C("Expected 'from' in import declaration"),l();}let s=st();return c(";")&&l(),D({type:"ImportDeclaration",specifiers:t,source:s,...n?{importKind:n}:{}},e)},it=()=>{let e=l();if(F("type")&&P(1).type==="Identifier"){let t=je();return D({type:"ExportNamedDeclaration",declaration:t,specifiers:[],source:null},e)}if(E("default")){l();let t=J();return c(";")&&l(),D({type:"ExportDefaultDeclaration",declaration:t},e)}if(E("const")||E("let")||E("var")){let t=Ae();return c(";")&&l(),D({type:"ExportNamedDeclaration",declaration:t,specifiers:[],source:null},e)}if(c("{")){l();let t=[];for(;!c("}")&&!M();){let n=I(),s=n;if(F("as")&&(l(),s=I()),t.push(T({type:"ExportSpecifier",local:n,exported:s},n,s)),c(","))l();else break}return w("}"),c(";")&&l(),D({type:"ExportNamedDeclaration",declaration:null,specifiers:t,source:null},e)}return C("Expected 'const', 'type', '{', or 'default' after 'export'")},Oe=()=>P().type==="Identifier"&&P().value==="of",Se=()=>E("in"),lt=()=>{let e=l();w("(");let t=null,n=null;if(!c(";"))if(E("const")||E("let")||E("var")){let O=l(),W=()=>{let H=I();if(c(":")){l();let Q=ye();H.typeAnnotation=Q.schema,H.typeAnnotationNode=Q.node;}return H},B=W();if(Oe()||Se()){let H=T({type:"VariableDeclarator",id:B,init:null},B,B);n=T({type:"VariableDeclaration",kind:O.value,declarations:[H]},O,B);}else {let H=te=>{let ie=null;return c("=")?(l(),ie=J(true)):O.value==="const"&&C("'const' declarations must be initialized"),T({type:"VariableDeclarator",id:te,init:ie},te,ie??te)},Q=[H(B)];for(;c(",");)l(),Q.push(H(W()));t=T({type:"VariableDeclaration",kind:O.value,declarations:Q},O,Q[Q.length-1]);}}else {let O=J(true);Oe()||Se()?n=O:t=O;}if(n){let O=Se();l();let W=J();w(")");let B=ee();return T(O?{type:"ForInStatement",left:n,right:W,body:B}:{type:"ForOfStatement",left:n,right:W,body:B,await:false},e,B)}w(";");let s=c(";")?null:J();w(";");let y=c(")")?null:J();w(")");let L=ee();return T({type:"ForStatement",init:t,test:s,update:y,body:L},e,L)},pt=()=>{let e=l(),t=ee();E("while")||C("Expected 'while' after the 'do' body"),l(),w("(");let n=J(),s=w(")");return c(";")&&l(),T({type:"DoWhileStatement",body:t,test:n},e,s)},ct=()=>{let e=l(),t=e.value==="break"?"BreakStatement":"ContinueStatement",n=c(";")?l():K();return T({type:t,label:null},e,n)},ut=()=>{let e=l();w("(");let t=J();w(")");let n=ee();return T({type:"WhileStatement",test:t,body:n},e,n)},dt=()=>{let e=l();w("(");let t=J();w(")");let n=ee(),s=null;return E("else")&&(l(),s=ee()),T({type:"IfStatement",test:t,consequent:n,alternate:s},e,s??n)},ft=()=>{let e=l(),t=null;!c(";")&&!c("}")&&!M()&&(t=J());let n=c(";")?l():K();return T({type:"ReturnStatement",argument:t},e,n)},yt=()=>{let e=l(),t=J(),n=c(";")?l():K();return T({type:"ThrowStatement",argument:t},e,n)},mt=()=>{let e=l(),t=ce(),n=null,s=null;if(E("catch")){let y=l(),L=null;c("(")&&(l(),L=I(),w(")"));let O=ce();n=T({type:"CatchClause",param:L,body:O},y,O);}return E("finally")&&(l(),s=ce()),!n&&!s&&C("'try' requires a 'catch' or 'finally' clause"),T({type:"TryStatement",block:t,handler:n,finalizer:s},e,s??n??t)},ht=()=>{let e=l();w("(");let t=J();w(")"),w("{");let n=[];for(;!c("}")&&!M();){let y=P(),L=null;E("case")?(l(),L=J()):E("default")?l():C("Expected 'case' or 'default' in switch"),w(":");let O=[];for(;!c("}")&&!E("case")&&!E("default")&&!M();)O.push(ee());n.push(T({type:"SwitchCase",test:L,consequent:O},y,K()??y));}let s=w("}");return T({type:"SwitchStatement",discriminant:t,cases:n},e,s)},ce=()=>{let e=w("{"),t=De(()=>c("}"));return T({type:"BlockStatement",body:t},e,w("}"))},De=e=>{let t=[];for(;!e()&&!M();){if(P().type==="Unknown"){l();continue}try{t.push(ee());}catch(n){if(!(n instanceof oe))throw n;M()||l();}}return t};return {parseExpr:J,parseProgram:()=>{let e=P(),t=De(()=>false);return a.sort((n,s)=>n.start-s.start),T({type:"Program",sourceType:"module",body:t,...A.length?{typeRefs:A}:{},...a.length?{comments:a}:{},...u.length?{parseDiagnostics:u}:{}},e,K()??e)},eof:M,fail:C,recordError:V,diagnostics:u}}function Ve(r){let u=Ie(r),a=u.parseProgram(),i=a.comments;return i?.length&&Ne(a,i,r),{ast:a,diagnostics:u.diagnostics}}function _t(r){let{ast:u,diagnostics:a}=Ve(r),i=a[0];if(i){let f=i.code==="lex-error"?re:oe;throw new f(i.message,i.position,i.index,i.loc,i.end)}return u}function Vt(r){let u=Ie(r),a=u.parseExpr();u.eof()||u.fail("Unexpected token after expression");let i=u.diagnostics[0];if(i){let f=i.code==="lex-error"?re:oe;throw new f(i.message,i.position,i.index,i.loc,i.end)}return a}function zt(r){let u=Ie(r),a;try{a=u.parseExpr(),u.eof()||u.recordError("Unexpected token after expression");}catch(i){if(!(i instanceof oe)&&!(i instanceof re))throw i}return {ast:a,diagnostics:u.diagnostics}}export{Ke as KEYWORDS,re as LexError,oe as ParseError,Ne as attachComments,Ft as nodeIsMissing,_t as parse,Vt as parseExpression,zt as parseExpressionTolerant,Ve as parseTolerant,Et as tokenize};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tslite/parser",
3
- "version": "1.4.1",
3
+ "version": "1.5.1",
4
4
  "description": "TSLite parser — tokenizer + Pratt parser for the TSLite language (JS subset + pipe) into ESTree",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -40,13 +40,13 @@
40
40
  "access": "public"
41
41
  },
42
42
  "dependencies": {
43
- "@tslite/ast": "1.0.0"
43
+ "@tslite/ast": "1.1.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@tslite/codegen": "1.0.0",
47
- "@tslite/capability": "1.0.0",
48
- "@tslite/checker": "1.0.0",
49
- "@tslite/interpret": "1.0.0"
46
+ "@tslite/capability": "1.1.0",
47
+ "@tslite/interpret": "1.1.0",
48
+ "@tslite/codegen": "1.1.0",
49
+ "@tslite/checker": "1.4.0"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsup",