site-panzai/node_modules/es-module-lexer/dist/lexer.js

2 lines
44 KiB
JavaScript
Raw Normal View History

2026-11-13 13:57:04 +01:00
/* es-module-lexer 3.0.4 */
const A=!1;const Q=1===new Uint8Array(new Uint16Array([1]).buffer)[0],B="undefined"!=typeof Buffer,E=/\r\n?/g;function C(A,Q,B){if(B<1||Q+B>A.length)throw new SyntaxError;let E=0;const C=Q+B;for(let B=Q;B<C;B++){const Q=A.charCodeAt(B),C=32|Q,g=Q>=48&&Q<=57?Q-48:C>=97&&C<=102?C-87:-1;if(-1===g)throw new SyntaxError;E=16*E+g}return E}export function parse(R,H="@"){w||k();const o=R.length+1,L=(w.__heap_base.value||w.__heap_base)+4*o+16-w.memory.buffer.byteLength;L>0&&w.memory.grow(Math.ceil(L/65536));const G=w.sa(o-1);if(R.length>=64&&B)Buffer.from(w.memory.buffer,G,2*(o-1)).write(R,"utf16le");else{const A=w.memory.buffer;(null==D?void 0:D.buffer)!==A&&(D=new Uint16Array(A,G)),(Q?I:g)(R,D)}if(!w.parse())throw Object.assign(new Error(`Parse error ${H}:${R.slice(0,w.e()).split("\n").length}:${w.e()-R.lastIndexOf("\n",w.e()-1)}`),{idx:w.e()});const N=[],M=[];for(;w.ri();){const A=w.is(),Q=w.ie(),B=w.it(),E=15&B,C=w.ai(),g=w.id(),I=w.ss(),D=w.se(),H=w.ip();let k,o=!1;if(1&H?k=i(-1===g?A:A+1,-1===g?Q:Q-1,A,!!(2&H)):-1!==g&&"`"===R[A]&&(k=U(A,Q),o=void 0!==k),3===E)N.push({type:"import-meta",specifier:null,typeOnly:!1,start:A,end:Q,importStart:I,importEnd:D});else if(-1!==g){const w=5===E?"source":7===E?"defer":null;N.push({type:"dynamic",specifier:k,glob:o,phase:w,start:A,end:Q,importStart:I,importEnd:D,dynamicStart:g,attributes:null,attributesStart:C,probablyTypeOnly:!!(16&B)})}else{let g=null;if(-1!==C){for(g=[],w.rsa();w.ra();){const A=w.aks(),Q=w.ake(),B=w.avs(),E=w.ave();g.push([Y(A,Q),Y(B,E)])}0===g.length&&(g=null)}const R=4===E?"source":6===E?"defer":null;N.push({type:8===E?"reexport-star":"static",specifier:k,phase:R,start:A,end:Q,importStart:I,importEnd:D,attributes:g,attributesStart:C,typeOnly:!!(16&B)})}}let s=w.re();const J=0===s?void 0:new DataView(w.memory.buffer);for(;0!==s;){A;const Q=J.getUint32(s,!0)-G>>>1,B=J.getUint32(s+4,!0)-G>>>1,E=J.getUint32(s+8,!0),C=0===E?-1:E-G>>>1,g=J.getUint32(s+12,!0),I=0===g?-1:g-G>>>1,D=J.getUint32(s+16,!0)-G>>>1,R=J.getUint32(s+20,!0),H=J.getUint8(s+24),k=J.getUint8(s+25),o=!!(4&k);if(3===H)M.push({type:"reexport-all",from:N[R].specifier,importIndex:R,start:Q,end:B,exportStart:D,typeOnly:o});else{const A=Y(Q,B);if(1===H){const E=C<0?void 0:Y(C,I);M.push({type:"direct",name:A,localName:E,start:Q,end:B,localStart:C,localEnd:I,exportStart:D,typeOnly:o})}else{const E=3&k,g=0===E?Y(C,I):1===E?"default":null;M.push({type:"reexport",name:A,importName:g,importNameStart:0===E?C:-1,importNameEnd:0===E?I:-1,from:N[R].specifier,importIndex:R,start:Q,end:B,exportStart:D,typeOnly:o})}}s=w.re()}function i(A,Q,B,g=!1){try{return function(A,Q){let B=A.indexOf("\\");if(-1===B)return Q?A.replace(E,"\n"):A;let g=A.slice(0,B),I=Q?g.replace(E,"\n"):g;for(;;){let D=B+1;if(D>=A.length)throw new SyntaxError;const w=A.charCodeAt(D++);switch(w){case 13:10===A.charCodeAt(D)&&D++;break;case 10:case 8232:case 8233:break;case 114:I+="\r";break;case 110:I+="\n";break;case 116:I+="\t";break;case 98:I+="\b";break;case 102:I+="\f";break;case 118:I+="\v";break;case 120:I+=String.fromCharCode(C(A,D,2)),D+=2;break;case 117:{let Q;if(123===A.charCodeAt(D)){const B=A.indexOf("}",++D);if(-1===B)throw new SyntaxError;Q=C(A,D,B-D),D=B+1}else Q=C(A,D,4),D+=4;if(Q>1114111)throw new SyntaxError;Q<=65535?I+=String.fromCharCode(Q):(Q-=65536,I+=String.fromCharCode(55296+(Q>>10),56320+(1023&Q)));break}case 48:{const Q=A.charCodeAt(D);if(Q>=48&&Q<=57)throw new SyntaxError;I+="\0";break}default:if(w>=49&&w<=57)throw new SyntaxError;I+=String.fromCharCode(w)}const R=A.indexOf("\\",D);if(-1===R)return g=A.slice(D),I+(Q?g.replace(E,"\n"):g);g=A.slice(D,R),I+=Q?g.replace(E,"\n"):g,B=R}}(R.slice(A,Q),g)}catch(A){throw Object.assign(new Error(`Parse error ${H}:${R.slice(0,B).split("\n").length}:${B-R.lastIndexOf("\n",B-1)}`),{idx:B})}}function Y(A,Q){const B=R.charCodeAt(A);return 34===B||39===B?i(A+1,Q-1,A):R.slice(A,Q)}function U(A,Q){if(w.rts(),!w.rt())return;let B="",E=A+1,C=A+1,g=w.te();for(;C<Q;){const A=R.charCodeAt(C);if(96===A)break;92!==A?42!==A?36===A&&123===R.charCodeAt(C+1)&&C+2<=g?(B+=R.slice(E,C)+"*",C=E=g,g=w.rt()?w.t