just-bash 2.12.4 → 2.12.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/banned-patterns-test.d.ts +0 -7
- package/dist/bin/chunks/{awk2-RGDNV4HO.js → awk2-EB5SCHVW.js} +1 -1
- package/dist/bin/{shell/chunks/chmod-4O2C4V42.js → chunks/chmod-N5CQATDW.js} +1 -1
- package/dist/bin/{shell/chunks/chunk-WO4B7WUT.js → chunks/chunk-5MUD3WB2.js} +1 -1
- package/dist/bin/chunks/chunk-7ADG3DNO.js +8 -0
- package/dist/bin/{shell/chunks/chunk-Q4WHWGOT.js → chunks/chunk-BBRVF6XE.js} +1 -1
- package/dist/bin/chunks/chunk-DHFZMFUW.js +36 -0
- package/dist/bin/chunks/{chunk-LHN3LRVT.js → chunk-IRCLOW32.js} +20 -20
- package/dist/bin/chunks/chunk-JX6YLHDX.js +2 -0
- package/dist/bin/chunks/chunk-MY5PY2PL.js +2 -0
- package/dist/bin/chunks/chunk-NTKUVXEL.js +5 -0
- package/dist/bin/chunks/{chunk-OKL2SPHK.js → chunk-O5B6WWQQ.js} +39 -39
- package/dist/bin/chunks/{chunk-DGFDVZ4N.js → chunk-OLN6BSO3.js} +1 -1
- package/dist/bin/chunks/chunk-OQV5J23L.js +7 -0
- package/dist/bin/chunks/chunk-PIBXJ3VX.js +13 -0
- package/dist/bin/chunks/chunk-PLKGKTIS.js +6 -0
- package/dist/bin/{shell/chunks/chunk-J4WYAO5Q.js → chunks/chunk-QTII62YM.js} +13 -13
- package/dist/bin/chunks/chunk-QZNF3Y3J.js +2 -0
- package/dist/bin/chunks/chunk-R2LDP472.js +8 -0
- package/dist/bin/chunks/chunk-ROMKUVHI.js +10 -0
- package/dist/bin/chunks/chunk-STOAUD75.js +11 -0
- package/dist/bin/chunks/chunk-SXB55JOI.js +2 -0
- package/dist/bin/chunks/chunk-VCKKRS7V.js +12 -0
- package/dist/bin/chunks/{chunk-SY2WM5RM.js → chunk-VIYJJTN2.js} +5 -5
- package/dist/bin/{shell/chunks/chunk-GA6KXSOC.js → chunks/chunk-YFPDB4PH.js} +1 -1
- package/dist/bin/chunks/chunk-YMMJLYIX.js +2 -0
- package/dist/bin/chunks/chunk-YTIURC67.js +2 -0
- package/dist/bin/chunks/chunk-YWZOGBFE.js +9 -0
- package/dist/bin/chunks/chunk-YX7OOTPO.js +9 -0
- package/dist/bin/chunks/chunk-ZJGIBTWD.js +2 -0
- package/dist/bin/chunks/{chunk-Q3FNZYGG.js → chunk-ZNPXCE5B.js} +99 -99
- package/dist/bin/chunks/chunk-ZSVBYEY4.js +6 -0
- package/dist/bin/chunks/curl-3GMIPMCI.js +26 -0
- package/dist/bin/{shell/chunks/expansion-TCB3WZP5.js → chunks/expansion-JBCP2CHQ.js} +1 -1
- package/dist/bin/chunks/find-MTLF23HX.js +2 -0
- package/dist/bin/chunks/flag-coverage-7GOZYXJT.js +2 -0
- package/dist/bin/{shell/chunks/grep-F3GT2VPG.js → chunks/grep-OZJTRD4D.js} +1 -1
- package/dist/bin/chunks/jq-P457LMHU.js +2 -0
- package/dist/bin/chunks/{ln-BEOFQJNP.js → ln-VAOSD4HK.js} +1 -1
- package/dist/bin/chunks/mkdir-CH7JGW4N.js +2 -0
- package/dist/bin/chunks/python3-45TMCI4M.js +17 -0
- package/dist/bin/chunks/{readlink-YNOUXNUY.js → readlink-BD5VFOC5.js} +1 -1
- package/dist/bin/chunks/rm-GWYJO4W7.js +2 -0
- package/dist/bin/chunks/sed-UV2LTNVK.js +2 -0
- package/dist/bin/chunks/sleep-3WHM7JMW.js +2 -0
- package/dist/bin/chunks/{sqlite3-SJHZFBT2.js → sqlite3-B3P3OMPI.js} +1 -1
- package/dist/bin/chunks/stat-XS2LXYS2.js +2 -0
- package/dist/bin/chunks/tar-SO3XDDIW.js +2 -0
- package/dist/bin/chunks/time-GZSHCM77.js +2 -0
- package/dist/bin/chunks/timeout-BYB3L2JA.js +2 -0
- package/dist/bin/chunks/worker.js +229 -20
- package/dist/bin/chunks/xan-FZB7FHX3.js +2 -0
- package/dist/bin/chunks/yq-H7D2U3HS.js +2 -0
- package/dist/bin/just-bash.js +183 -183
- package/dist/bin/shell/chunks/{awk2-RGDNV4HO.js → awk2-EB5SCHVW.js} +1 -1
- package/dist/bin/{chunks/chmod-4O2C4V42.js → shell/chunks/chmod-N5CQATDW.js} +1 -1
- package/dist/bin/{chunks/chunk-WO4B7WUT.js → shell/chunks/chunk-5MUD3WB2.js} +1 -1
- package/dist/bin/shell/chunks/chunk-7ADG3DNO.js +8 -0
- package/dist/bin/{chunks/chunk-Q4WHWGOT.js → shell/chunks/chunk-BBRVF6XE.js} +1 -1
- package/dist/bin/shell/chunks/chunk-D64U2VGQ.js +2 -0
- package/dist/bin/shell/chunks/chunk-DHFZMFUW.js +36 -0
- package/dist/bin/shell/chunks/{chunk-LHN3LRVT.js → chunk-IRCLOW32.js} +20 -20
- package/dist/bin/shell/chunks/chunk-JX6YLHDX.js +2 -0
- package/dist/bin/shell/chunks/chunk-NTKUVXEL.js +5 -0
- package/dist/bin/shell/chunks/{chunk-OKL2SPHK.js → chunk-O5B6WWQQ.js} +39 -39
- package/dist/bin/shell/chunks/{chunk-DGFDVZ4N.js → chunk-OLN6BSO3.js} +1 -1
- package/dist/bin/shell/chunks/chunk-OQV5J23L.js +7 -0
- package/dist/bin/shell/chunks/chunk-PIBXJ3VX.js +13 -0
- package/dist/bin/shell/chunks/chunk-PLKGKTIS.js +6 -0
- package/dist/bin/{chunks/chunk-J4WYAO5Q.js → shell/chunks/chunk-QTII62YM.js} +13 -13
- package/dist/bin/shell/chunks/chunk-QZNF3Y3J.js +2 -0
- package/dist/bin/shell/chunks/chunk-R2LDP472.js +8 -0
- package/dist/bin/shell/chunks/chunk-ROMKUVHI.js +10 -0
- package/dist/bin/shell/chunks/chunk-STOAUD75.js +11 -0
- package/dist/bin/shell/chunks/chunk-SXB55JOI.js +2 -0
- package/dist/bin/shell/chunks/chunk-VCKKRS7V.js +12 -0
- package/dist/bin/shell/chunks/{chunk-SY2WM5RM.js → chunk-VIYJJTN2.js} +5 -5
- package/dist/bin/{chunks/chunk-GA6KXSOC.js → shell/chunks/chunk-YFPDB4PH.js} +1 -1
- package/dist/bin/shell/chunks/chunk-YMMJLYIX.js +2 -0
- package/dist/bin/shell/chunks/chunk-YTIURC67.js +2 -0
- package/dist/bin/shell/chunks/chunk-YWZOGBFE.js +9 -0
- package/dist/bin/shell/chunks/chunk-YX7OOTPO.js +9 -0
- package/dist/bin/shell/chunks/chunk-ZJGIBTWD.js +2 -0
- package/dist/bin/shell/chunks/{chunk-Q3FNZYGG.js → chunk-ZNPXCE5B.js} +99 -99
- package/dist/bin/shell/chunks/chunk-ZSVBYEY4.js +6 -0
- package/dist/bin/shell/chunks/curl-3GMIPMCI.js +26 -0
- package/dist/bin/{chunks/expansion-TCB3WZP5.js → shell/chunks/expansion-JBCP2CHQ.js} +1 -1
- package/dist/bin/shell/chunks/find-MTLF23HX.js +2 -0
- package/dist/bin/shell/chunks/flag-coverage-7GOZYXJT.js +2 -0
- package/dist/bin/{chunks/grep-F3GT2VPG.js → shell/chunks/grep-OZJTRD4D.js} +1 -1
- package/dist/bin/shell/chunks/jq-P457LMHU.js +2 -0
- package/dist/bin/shell/chunks/{ln-BEOFQJNP.js → ln-VAOSD4HK.js} +1 -1
- package/dist/bin/shell/chunks/mkdir-CH7JGW4N.js +2 -0
- package/dist/bin/shell/chunks/python3-IV3DBMHM.js +17 -0
- package/dist/bin/shell/chunks/{readlink-YNOUXNUY.js → readlink-BD5VFOC5.js} +1 -1
- package/dist/bin/shell/chunks/rm-GWYJO4W7.js +2 -0
- package/dist/bin/shell/chunks/sed-UV2LTNVK.js +2 -0
- package/dist/bin/shell/chunks/sleep-3WHM7JMW.js +2 -0
- package/dist/bin/shell/chunks/{sqlite3-SJHZFBT2.js → sqlite3-B3P3OMPI.js} +1 -1
- package/dist/bin/shell/chunks/stat-XS2LXYS2.js +2 -0
- package/dist/bin/shell/chunks/tar-SO3XDDIW.js +2 -0
- package/dist/bin/shell/chunks/time-GZSHCM77.js +2 -0
- package/dist/bin/shell/chunks/timeout-BYB3L2JA.js +2 -0
- package/dist/bin/shell/chunks/xan-FZB7FHX3.js +2 -0
- package/dist/bin/shell/chunks/yq-H7D2U3HS.js +2 -0
- package/dist/bin/shell/shell.js +187 -187
- package/dist/bundle/browser.js +632 -635
- package/dist/bundle/chunks/{awk2-XLDR2J4Q.js → awk2-VPBKDCSO.js} +1 -1
- package/dist/bundle/chunks/{chmod-MIKE3OIT.js → chmod-SYMGL4JA.js} +1 -1
- package/dist/bundle/chunks/chunk-3ZUFRYJ4.js +1 -0
- package/dist/bundle/chunks/chunk-4GTNDTRF.js +7 -0
- package/dist/bundle/chunks/{chunk-N4QLRJ32.js → chunk-4YPFHVJJ.js} +1 -1
- package/dist/bundle/chunks/chunk-5QVNJEHU.js +8 -0
- package/dist/bundle/chunks/chunk-64CW2LGZ.js +6 -0
- package/dist/bundle/chunks/chunk-6HBBXB3L.js +11 -0
- package/dist/bundle/chunks/chunk-72EQZSVH.js +4 -0
- package/dist/bundle/chunks/chunk-7YDOWJ75.js +1 -0
- package/dist/bundle/chunks/chunk-AUD37QB3.js +35 -0
- package/dist/bundle/chunks/{chunk-NTP6TTH5.js → chunk-BED5HSP2.js} +13 -13
- package/dist/bundle/chunks/{chunk-K5BTXJQC.js → chunk-C7ZTXK5C.js} +99 -99
- package/dist/bundle/chunks/chunk-D2FZX7A2.js +10 -0
- package/dist/bundle/chunks/chunk-DZZS6SJP.js +1 -0
- package/dist/bundle/chunks/{chunk-KAZYKNBG.js → chunk-EX62JIX3.js} +5 -5
- package/dist/bundle/chunks/chunk-FGALERPA.js +8 -0
- package/dist/bundle/chunks/chunk-HJWBQKYG.js +5 -0
- package/dist/bundle/chunks/chunk-IP7G3BNA.js +7 -0
- package/dist/bundle/chunks/chunk-J642UCRS.js +1 -0
- package/dist/bundle/chunks/chunk-KZ7BI7TV.js +5 -0
- package/dist/bundle/chunks/chunk-RH6GWZAJ.js +1 -0
- package/dist/bundle/chunks/{chunk-4VCAQZKQ.js → chunk-TRD56HID.js} +39 -39
- package/dist/bundle/chunks/chunk-U5FWK6IA.js +12 -0
- package/dist/bundle/chunks/{chunk-H4QOE4W3.js → chunk-VBF2GWEM.js} +20 -20
- package/dist/bundle/chunks/{chunk-2OHMPZNZ.js → chunk-VSWTMNI3.js} +1 -1
- package/dist/bundle/chunks/chunk-X2AJGDEF.js +1 -0
- package/dist/bundle/chunks/{chunk-T2EHE3CV.js → chunk-X36DXRVC.js} +1 -1
- package/dist/bundle/chunks/chunk-X3CVFNQZ.js +9 -0
- package/dist/bundle/chunks/chunk-XHM67O4N.js +1 -0
- package/dist/bundle/chunks/{chunk-CYTBPLPE.js → chunk-YS3AZT3J.js} +1 -1
- package/dist/bundle/chunks/curl-KM2ZAUR6.js +25 -0
- package/dist/bundle/chunks/{expansion-HJ6B4DDG.js → expansion-XG7G47TX.js} +1 -1
- package/dist/bundle/chunks/find-DOIVMX6X.js +1 -0
- package/dist/bundle/chunks/flag-coverage-NT32EG6Q.js +1 -0
- package/dist/bundle/chunks/{grep-LXKUQUAE.js → grep-3AIAIJVR.js} +1 -1
- package/dist/bundle/chunks/jq-NLRWI2Q6.js +1 -0
- package/dist/bundle/chunks/{ln-RI2SJGXU.js → ln-UJ6YJVBK.js} +1 -1
- package/dist/bundle/chunks/mkdir-F6XHPXZC.js +1 -0
- package/dist/bundle/chunks/python3-G2ZUJAQL.js +16 -0
- package/dist/bundle/chunks/{readlink-IEQO24KU.js → readlink-MI4GCHJF.js} +1 -1
- package/dist/bundle/chunks/rm-FYNVTQIU.js +1 -0
- package/dist/bundle/chunks/sed-2BILOGNL.js +1 -0
- package/dist/bundle/chunks/sleep-IUBP5GMH.js +1 -0
- package/dist/bundle/chunks/{sqlite3-CTI4ZW7L.js → sqlite3-VEDNWJL6.js} +1 -1
- package/dist/bundle/chunks/stat-BT5A227F.js +1 -0
- package/dist/bundle/chunks/tar-LKO7DKAK.js +1 -0
- package/dist/bundle/chunks/time-XL42Z4U5.js +1 -0
- package/dist/bundle/chunks/timeout-TL4Q5YKZ.js +1 -0
- package/dist/bundle/chunks/worker.js +229 -20
- package/dist/bundle/chunks/xan-KSDYKKEK.js +1 -0
- package/dist/bundle/chunks/yq-HIQ4WMDY.js +1 -0
- package/dist/bundle/index.cjs +857 -860
- package/dist/bundle/index.js +246 -246
- package/dist/commands/duration.d.ts +5 -0
- package/dist/commands/format-mode.d.ts +4 -0
- package/dist/commands/python3/worker.d.ts +1 -0
- package/dist/commands/query-engine/safe-object.d.ts +13 -0
- package/dist/commands/sed/types.d.ts +0 -4
- package/dist/commands/sqlite3/worker.d.ts +1 -0
- package/dist/commands/tar/archive.d.ts +18 -4
- package/dist/fs/in-memory-fs/in-memory-fs.d.ts +0 -3
- package/dist/fs/mountable-fs/mountable-fs.d.ts +0 -4
- package/dist/fs/overlay-fs/overlay-fs.d.ts +6 -7
- package/dist/fs/path-utils.d.ts +46 -0
- package/dist/fs/read-write-fs/read-write-fs.d.ts +0 -4
- package/dist/fs/real-fs-utils.d.ts +17 -11
- package/dist/timers.d.ts +0 -3
- package/package.json +3 -2
- package/dist/bin/chunks/chunk-253LRF5J.js +0 -11
- package/dist/bin/chunks/chunk-4C4F4EKM.js +0 -2
- package/dist/bin/chunks/chunk-55QIFSKH.js +0 -36
- package/dist/bin/chunks/chunk-5VFN7VVJ.js +0 -9
- package/dist/bin/chunks/chunk-6MF2IYQX.js +0 -10
- package/dist/bin/chunks/chunk-D2GFNFUN.js +0 -7
- package/dist/bin/chunks/chunk-EO5AH4U7.js +0 -5
- package/dist/bin/chunks/chunk-GIFF636B.js +0 -2
- package/dist/bin/chunks/chunk-KWLLB7S3.js +0 -7
- package/dist/bin/chunks/chunk-NDP6L74Z.js +0 -10
- package/dist/bin/chunks/chunk-PWZZGTFL.js +0 -13
- package/dist/bin/chunks/chunk-UYBH3FNE.js +0 -2
- package/dist/bin/chunks/chunk-V5YFCVCZ.js +0 -12
- package/dist/bin/chunks/chunk-V7VIJQD6.js +0 -6
- package/dist/bin/chunks/chunk-WMYKQURM.js +0 -2
- package/dist/bin/chunks/chunk-XAL6VWGA.js +0 -9
- package/dist/bin/chunks/chunk-YYQ22ZRL.js +0 -8
- package/dist/bin/chunks/curl-RWQO3SBN.js +0 -26
- package/dist/bin/chunks/find-4YAO7JQS.js +0 -2
- package/dist/bin/chunks/flag-coverage-K6IBGWAC.js +0 -2
- package/dist/bin/chunks/jq-VBB2XIZS.js +0 -2
- package/dist/bin/chunks/mkdir-6OKMS3KO.js +0 -2
- package/dist/bin/chunks/python3-JX5PXXTX.js +0 -17
- package/dist/bin/chunks/rm-5QIBTLJG.js +0 -2
- package/dist/bin/chunks/sed-BYFYBR4A.js +0 -2
- package/dist/bin/chunks/sleep-E3K6M6BN.js +0 -2
- package/dist/bin/chunks/stat-XH7E4E2C.js +0 -2
- package/dist/bin/chunks/tar-W5GBTEDZ.js +0 -2
- package/dist/bin/chunks/time-AWAKKRSE.js +0 -2
- package/dist/bin/chunks/timeout-OLS72AZG.js +0 -2
- package/dist/bin/chunks/xan-BJ66NSYT.js +0 -2
- package/dist/bin/chunks/yq-GPYVGU2N.js +0 -2
- package/dist/bin/shell/chunks/chunk-253LRF5J.js +0 -11
- package/dist/bin/shell/chunks/chunk-4C4F4EKM.js +0 -2
- package/dist/bin/shell/chunks/chunk-55QIFSKH.js +0 -36
- package/dist/bin/shell/chunks/chunk-5VFN7VVJ.js +0 -9
- package/dist/bin/shell/chunks/chunk-6MF2IYQX.js +0 -10
- package/dist/bin/shell/chunks/chunk-D2GFNFUN.js +0 -7
- package/dist/bin/shell/chunks/chunk-EO5AH4U7.js +0 -5
- package/dist/bin/shell/chunks/chunk-GIFF636B.js +0 -2
- package/dist/bin/shell/chunks/chunk-KWLLB7S3.js +0 -7
- package/dist/bin/shell/chunks/chunk-NDP6L74Z.js +0 -10
- package/dist/bin/shell/chunks/chunk-PWZZGTFL.js +0 -13
- package/dist/bin/shell/chunks/chunk-UYBH3FNE.js +0 -2
- package/dist/bin/shell/chunks/chunk-V5YFCVCZ.js +0 -12
- package/dist/bin/shell/chunks/chunk-V7VIJQD6.js +0 -6
- package/dist/bin/shell/chunks/chunk-WMYKQURM.js +0 -2
- package/dist/bin/shell/chunks/chunk-XAL6VWGA.js +0 -9
- package/dist/bin/shell/chunks/chunk-YYQ22ZRL.js +0 -8
- package/dist/bin/shell/chunks/curl-RWQO3SBN.js +0 -26
- package/dist/bin/shell/chunks/find-4YAO7JQS.js +0 -2
- package/dist/bin/shell/chunks/flag-coverage-K6IBGWAC.js +0 -2
- package/dist/bin/shell/chunks/jq-VBB2XIZS.js +0 -2
- package/dist/bin/shell/chunks/mkdir-6OKMS3KO.js +0 -2
- package/dist/bin/shell/chunks/python3-JX5PXXTX.js +0 -17
- package/dist/bin/shell/chunks/rm-5QIBTLJG.js +0 -2
- package/dist/bin/shell/chunks/sed-BYFYBR4A.js +0 -2
- package/dist/bin/shell/chunks/sleep-E3K6M6BN.js +0 -2
- package/dist/bin/shell/chunks/stat-XH7E4E2C.js +0 -2
- package/dist/bin/shell/chunks/tar-W5GBTEDZ.js +0 -2
- package/dist/bin/shell/chunks/time-AWAKKRSE.js +0 -2
- package/dist/bin/shell/chunks/timeout-OLS72AZG.js +0 -2
- package/dist/bin/shell/chunks/xan-BJ66NSYT.js +0 -2
- package/dist/bin/shell/chunks/yq-GPYVGU2N.js +0 -2
- package/dist/bundle/chunks/chunk-27LMNKBP.js +0 -7
- package/dist/bundle/chunks/chunk-3RCXHB4E.js +0 -4
- package/dist/bundle/chunks/chunk-7MKBHGLS.js +0 -1
- package/dist/bundle/chunks/chunk-DOTBQEPN.js +0 -5
- package/dist/bundle/chunks/chunk-GENDESYN.js +0 -1
- package/dist/bundle/chunks/chunk-GZ2N3SXD.js +0 -8
- package/dist/bundle/chunks/chunk-IJXFPKNC.js +0 -1
- package/dist/bundle/chunks/chunk-IKZ5LEGB.js +0 -6
- package/dist/bundle/chunks/chunk-OFJTSXN6.js +0 -8
- package/dist/bundle/chunks/chunk-QUME7R6S.js +0 -9
- package/dist/bundle/chunks/chunk-TBAWQWQB.js +0 -12
- package/dist/bundle/chunks/chunk-VYV3YE2F.js +0 -35
- package/dist/bundle/chunks/chunk-W42IGK5R.js +0 -11
- package/dist/bundle/chunks/chunk-WAN3B6E3.js +0 -9
- package/dist/bundle/chunks/chunk-XZ3MZS57.js +0 -6
- package/dist/bundle/chunks/chunk-YCABLDKV.js +0 -10
- package/dist/bundle/chunks/chunk-ZK6J6F7O.js +0 -1
- package/dist/bundle/chunks/curl-6L7YZUIH.js +0 -25
- package/dist/bundle/chunks/find-DQFMWHAC.js +0 -1
- package/dist/bundle/chunks/flag-coverage-VGF5NAZP.js +0 -1
- package/dist/bundle/chunks/jq-JQXAVWNT.js +0 -1
- package/dist/bundle/chunks/mkdir-QWGXDWUS.js +0 -1
- package/dist/bundle/chunks/python3-TSPOVUHX.js +0 -16
- package/dist/bundle/chunks/rm-KPTLPKPH.js +0 -1
- package/dist/bundle/chunks/sed-CJFW7UYO.js +0 -1
- package/dist/bundle/chunks/sleep-TFDNFOXK.js +0 -1
- package/dist/bundle/chunks/stat-74KBZFAX.js +0 -1
- package/dist/bundle/chunks/tar-Y6LP5EBC.js +0 -1
- package/dist/bundle/chunks/time-WBKSMCJ6.js +0 -1
- package/dist/bundle/chunks/timeout-O7WSXY5H.js +0 -1
- package/dist/bundle/chunks/xan-VMLUNIDS.js +0 -1
- package/dist/bundle/chunks/yq-QXIYE3MW.js +0 -1
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as O}from"./chunk-SE4C7FJY.js";import{e as j,f as K,g as C,h as re,i as
|
|
3
|
-
`){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var
|
|
4
|
-
`;break;case"t":s+=" ";break;case"r":s+="\r";break;case"\\":s+="\\";break;case"'":s+="'";break;default:s+=a}r+=2}else s+=e[r],r++;e[r]==="'"&&r++;let n=Number.parseInt(s,10);return{expr:{type:"ArithNumber",value:Number.isNaN(n)?0:n},pos:r}}function Dt(e,t){if(e.slice(t,t+2)!=='$"')return null;let r=t+2,s="";for(;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?(s+=e[r+1],r+=2):(s+=e[r],r++);e[r]==='"'&&r++;let n=Number.parseInt(s,10);return{expr:{type:"ArithNumber",value:Number.isNaN(n)?0:n},pos:r}}function Nr(e){let t="",r=0;for(;r<e.length;)if(e[r]==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?(t+=e[r+1],r+=2):(t+=e[r],r++);r<e.length&&r++}else t+=e[r],r++;return t}function M(e,t){let r=Nr(t),{expr:s,pos:n}=Z(e,r,0),a=$(r,n);if(a<r.length){let i=t.slice(a).trim();if(i)return{type:"ArithmeticExpression",originalText:t,expression:{type:"ArithSyntaxError",errorToken:i,message:`${i}: syntax error: invalid arithmetic operator (error token is "${i}")`}}}return{type:"ArithmeticExpression",expression:s,originalText:t}}function F(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function z(e,t){return $(e,t)>=e.length}function Z(e,t,r){return kr(e,t,r)}function kr(e,t,r){let{expr:s,pos:n}=ye(e,t,r);for(n=$(t,n);t[n]===",";){if(n++,z(t,n))return F(",",n);let{expr:i,pos:l}=ye(e,t,n);s={type:"ArithBinary",operator:",",left:s,right:i},n=$(t,l)}return{expr:s,pos:n}}function ye(e,t,r){let{expr:s,pos:n}=Pr(e,t,r);if(n=$(t,n),t[n]==="?"){n++;let{expr:a,pos:i}=Z(e,t,n);if(n=$(t,i),t[n]===":"){n++;let{expr:l,pos:o}=Z(e,t,n);return{expr:{type:"ArithTernary",condition:s,consequent:a,alternate:l},pos:o}}}return{expr:s,pos:n}}function Pr(e,t,r){let{expr:s,pos:n}=xt(e,t,r);for(;n=$(t,n),t.slice(n,n+2)==="||";){if(n+=2,z(t,n))return F("||",n);let{expr:i,pos:l}=xt(e,t,n);s={type:"ArithBinary",operator:"||",left:s,right:i},n=l}return{expr:s,pos:n}}function xt(e,t,r){let{expr:s,pos:n}=_t(e,t,r);for(;n=$(t,n),t.slice(n,n+2)==="&&";){if(n+=2,z(t,n))return F("&&",n);let{expr:i,pos:l}=_t(e,t,n);s={type:"ArithBinary",operator:"&&",left:s,right:i},n=l}return{expr:s,pos:n}}function _t(e,t,r){let{expr:s,pos:n}=$t(e,t,r);for(;n=$(t,n),t[n]==="|"&&t[n+1]!=="|";){if(n++,z(t,n))return F("|",n);let{expr:i,pos:l}=$t(e,t,n);s={type:"ArithBinary",operator:"|",left:s,right:i},n=l}return{expr:s,pos:n}}function $t(e,t,r){let{expr:s,pos:n}=Ct(e,t,r);for(;n=$(t,n),t[n]==="^";){if(n++,z(t,n))return F("^",n);let{expr:i,pos:l}=Ct(e,t,n);s={type:"ArithBinary",operator:"^",left:s,right:i},n=l}return{expr:s,pos:n}}function Ct(e,t,r){let{expr:s,pos:n}=Ot(e,t,r);for(;n=$(t,n),t[n]==="&"&&t[n+1]!=="&";){if(n++,z(t,n))return F("&",n);let{expr:i,pos:l}=Ot(e,t,n);s={type:"ArithBinary",operator:"&",left:s,right:i},n=l}return{expr:s,pos:n}}function Ot(e,t,r){let{expr:s,pos:n}=Lt(e,t,r);for(;n=$(t,n),t.slice(n,n+2)==="=="||t.slice(n,n+2)==="!=";){let a=t.slice(n,n+2);if(n+=2,z(t,n))return F(a,n);let{expr:i,pos:l}=Lt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Lt(e,t,r){let{expr:s,pos:n}=Fe(e,t,r);for(;;)if(n=$(t,n),t.slice(n,n+2)==="<="||t.slice(n,n+2)===">="){let a=t.slice(n,n+2);if(n+=2,z(t,n))return F(a,n);let{expr:i,pos:l}=Fe(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else if(t[n]==="<"||t[n]===">"){let a=t[n];if(n++,z(t,n))return F(a,n);let{expr:i,pos:l}=Fe(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else break;return{expr:s,pos:n}}function Fe(e,t,r){let{expr:s,pos:n}=Wt(e,t,r);for(;n=$(t,n),t.slice(n,n+2)==="<<"||t.slice(n,n+2)===">>";){let a=t.slice(n,n+2);if(n+=2,z(t,n))return F(a,n);let{expr:i,pos:l}=Wt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Wt(e,t,r){let{expr:s,pos:n}=Tt(e,t,r);for(;n=$(t,n),(t[n]==="+"||t[n]==="-")&&t[n+1]!==t[n];){let a=t[n];if(n++,z(t,n))return F(a,n);let{expr:i,pos:l}=Tt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Tt(e,t,r){let{expr:s,pos:n}=Re(e,t,r);for(;;)if(n=$(t,n),t[n]==="*"&&t[n+1]!=="*"){if(n++,z(t,n))return F("*",n);let{expr:i,pos:l}=Re(e,t,n);s={type:"ArithBinary",operator:"*",left:s,right:i},n=l}else if(t[n]==="/"||t[n]==="%"){let a=t[n];if(n++,z(t,n))return F(a,n);let{expr:i,pos:l}=Re(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else break;return{expr:s,pos:n}}function Re(e,t,r){let{expr:s,pos:n}=ze(e,t,r),a=$(t,n);if(t.slice(a,a+2)==="**"){if(a+=2,z(t,a))return F("**",a);let{expr:l,pos:o}=Re(e,t,a);return{expr:{type:"ArithBinary",operator:"**",left:s,right:l},pos:o}}return{expr:s,pos:n}}function ze(e,t,r){let s=$(t,r);if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let n=t.slice(s,s+2);s+=2;let{expr:a,pos:i}=ze(e,t,s);return{expr:{type:"ArithUnary",operator:n,operand:a,prefix:!0},pos:i}}if(t[s]==="+"||t[s]==="-"||t[s]==="!"||t[s]==="~"){let n=t[s];s++;let{expr:a,pos:i}=ze(e,t,s);return{expr:{type:"ArithUnary",operator:n,operand:a,prefix:!0},pos:i}}return Ir(e,t,s)}function Rr(e,t){let r=e[t];return r==="$"||r==="`"}function Ir(e,t,r){let{expr:s,pos:n}=Mt(e,t,r,!1),a=[s];for(;Rr(t,n);){let{expr:l,pos:o}=Mt(e,t,n,!0);a.push(l),n=o}a.length>1&&(s={type:"ArithConcat",parts:a});let i;if(t[n]==="["&&s.type==="ArithConcat"){n++;let{expr:l,pos:o}=Z(e,t,n);i=l,n=o,t[n]==="]"&&n++}if(i&&s.type==="ArithConcat"&&(s={type:"ArithDynamicElement",nameExpr:s,subscript:i},i=void 0),n=$(t,n),s.type==="ArithConcat"||s.type==="ArithVariable"||s.type==="ArithDynamicElement"){for(let l of Pe)if(t.slice(n,n+l.length)===l&&t.slice(n,n+l.length+1)!=="=="){n+=l.length;let{expr:o,pos:c}=ye(e,t,n);return s.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:l,target:s.nameExpr,subscript:s.subscript,value:o},pos:c}:s.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:l,target:s,value:o},pos:c}:{expr:{type:"ArithAssignment",operator:l,variable:s.name,value:o},pos:c}}}if(t.slice(n,n+2)==="++"||t.slice(n,n+2)==="--"){let l=t.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:l,operand:s,prefix:!1},pos:n}}return{expr:s,pos:n}}function Mt(e,t,r,s=!1){let n=$(t,r),a=It(Z,e,t,n);if(a)return a;let i=vt(t,n);if(i)return i;let l=Dt(t,n);if(l)return l;if(t.slice(n,n+2)==="$("&&t[n+2]!=="("){n+=2;let c=1,u=n;for(;n<t.length&&c>0;)t[n]==="("?c++:t[n]===")"&&c--,c>0&&n++;let f=t.slice(u,n);return n++,{expr:{type:"ArithCommandSubst",command:f},pos:n}}if(t[n]==="`"){n++;let c=n;for(;n<t.length&&t[n]!=="`";)n++;let u=t.slice(c,n);return t[n]==="`"&&n++,{expr:{type:"ArithCommandSubst",command:u},pos:n}}if(t[n]==="("){n++;let{expr:c,pos:u}=Z(e,t,n);return n=$(t,u),t[n]===")"&&n++,{expr:{type:"ArithGroup",expression:c},pos:n}}if(t[n]==="'"){n++;let c="";for(;n<t.length&&t[n]!=="'";)c+=t[n],n++;t[n]==="'"&&n++;let u=Number.parseInt(c,10);return{expr:{type:"ArithSingleQuote",content:c,value:Number.isNaN(u)?0:u},pos:n}}if(t[n]==='"'){n++;let c="";for(;n<t.length&&t[n]!=='"';)t[n]==="\\"&&n+1<t.length?(c+=t[n+1],n+=2):(c+=t[n],n++);t[n]==='"'&&n++;let u=c.trim();if(!u)return{expr:{type:"ArithNumber",value:0},pos:n};let{expr:f}=Z(e,u,0);return{expr:f,pos:n}}if(/[0-9]/.test(t[n])){let c="",u=!1,f=!1;for(;n<t.length;){let d=t[n];if(u)if(/[0-9a-zA-Z@_]/.test(d))c+=d,n++;else break;else if(d==="#")u=!0,c+=d,n++;else if(c==="0"&&(d==="x"||d==="X")&&n+1<t.length&&/[0-9a-fA-F]/.test(t[n+1]))f=!0,c+=d,n++;else if(f&&/[0-9a-fA-F]/.test(d))c+=d,n++;else if(!f&&/[0-9]/.test(d))c+=d,n++;else break}if(n<t.length&&/[a-zA-Z_]/.test(t[n])){let d=c;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)d+=t[n],n++;return{expr:{type:"ArithSyntaxError",errorToken:d,message:`${d}: value too great for base (error token is "${d}")`},pos:n}}if(t[n]==="."&&/[0-9]/.test(t[n+1]))throw new C(`${c}.${t[n+1]}...: syntax error: invalid arithmetic operator`);if(t[n]==="["){let d=t.slice(n).trim();return{expr:{type:"ArithNumberSubscript",number:c,errorToken:d},pos:t.length}}return{expr:{type:"ArithNumber",value:ge(c)},pos:n}}if(t[n]==="$"&&t[n+1]==="{"){let c=n+2,u=1,f=c;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;let h=t.slice(c,f),d=f+1;if(t[d]==="#"){let m=d+1;for(;m<t.length&&/[0-9a-zA-Z@_]/.test(t[m]);)m++;let g=t.slice(d+1,m);return{expr:{type:"ArithDynamicBase",baseExpr:h,value:g},pos:m}}if(/[0-9]/.test(t[d])||t[d]==="x"||t[d]==="X"){let m=d;if(t[d]==="x"||t[d]==="X")for(m++;m<t.length&&/[0-9a-fA-F]/.test(t[m]);)m++;else for(;m<t.length&&/[0-9]/.test(t[m]);)m++;let g=t.slice(d,m);return{expr:{type:"ArithDynamicNumber",prefix:h,suffix:g},pos:m}}return n=d,{expr:{type:"ArithBracedExpansion",content:h},pos:n}}if(t[n]==="$"&&n+1<t.length&&/[0-9]/.test(t[n+1])){n++;let c="";for(;n<t.length&&/[0-9]/.test(t[n]);)c+=t[n],n++;return{expr:{type:"ArithVariable",name:c,hasDollarPrefix:!0},pos:n}}if(t[n]==="$"&&n+1<t.length&&/[*@#?\-!$]/.test(t[n+1])){let c=t[n+1];return n+=2,{expr:{type:"ArithSpecialVar",name:c},pos:n}}let o=!1;if(t[n]==="$"&&n+1<t.length&&/[a-zA-Z_]/.test(t[n+1])&&(o=!0,n++),n<t.length&&/[a-zA-Z_]/.test(t[n])){let c="";for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)c+=t[n],n++;if(t[n]==="["&&!s){n++;let u;if(t[n]==="'"||t[n]==='"'){let h=t[n];for(n++,u="";n<t.length&&t[n]!==h;)u+=t[n],n++;t[n]===h&&n++,n=$(t,n),t[n]==="]"&&n++}let f;if(u===void 0){let{expr:h,pos:d}=Z(e,t,n);f=h,n=d,t[n]==="]"&&n++}if(n=$(t,n),t[n]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:c,index:f},pos:n};if(!s){for(let h of Pe)if(t.slice(n,n+h.length)===h&&t.slice(n,n+h.length+1)!=="=="){n+=h.length;let{expr:d,pos:m}=ye(e,t,n);return{expr:{type:"ArithAssignment",operator:h,variable:c,subscript:f,stringKey:u,value:d},pos:m}}}return{expr:{type:"ArithArrayElement",array:c,index:f,stringKey:u},pos:n}}if(n=$(t,n),!s){for(let u of Pe)if(t.slice(n,n+u.length)===u&&t.slice(n,n+u.length+1)!=="=="){n+=u.length;let{expr:f,pos:h}=ye(e,t,n);return{expr:{type:"ArithAssignment",operator:u,variable:c,value:f},pos:h}}}return{expr:{type:"ArithVariable",name:c,hasDollarPrefix:o},pos:n}}if(t[n]==="#"){let c=n+1;for(;c<t.length&&t[c]!==`
|
|
5
|
-
`;)c++;let u=t.slice(n,c).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:u,message:`${u}: syntax error: invalid arithmetic operator (error token is "${u}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:n}}var w={script(e){return{type:"Script",statements:e}},statement(e,t=[],r=!1,s,n){let a={type:"Statement",pipelines:e,operators:t,background:r};return s&&(a.deferredError=s),n!==void 0&&(a.sourceText=n),a},pipeline(e,t=!1,r=!1,s=!1,n){return{type:"Pipeline",commands:e,negated:t,timed:r,timePosix:s,pipeStderr:n}},simpleCommand(e,t=[],r=[],s=[]){return{type:"SimpleCommand",name:e,args:t,assignments:r,redirections:s}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},assignment(e,t,r=!1,s=null){return{type:"Assignment",name:e,value:t,append:r,array:s}},redirection(e,t,r=null,s){let n={type:"Redirection",fd:r,operator:e,target:t};return s&&(n.fdVariable=s),n},hereDoc(e,t,r=!1,s=!1){return{type:"HereDoc",delimiter:e,content:t,stripTabs:r,quoted:s}},ifNode(e,t=null,r=[]){return{type:"If",clauses:e,elseBody:t,redirections:r}},forNode(e,t,r,s=[]){return{type:"For",variable:e,words:t,body:r,redirections:s}},whileNode(e,t,r=[]){return{type:"While",condition:e,body:t,redirections:r}},untilNode(e,t,r=[]){return{type:"Until",condition:e,body:t,redirections:r}},caseNode(e,t,r=[]){return{type:"Case",word:e,items:t,redirections:r}},caseItem(e,t,r=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:r}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,r=[],s){return{type:"FunctionDef",name:e,body:t,redirections:r,sourceFile:s}},conditionalCommand(e,t=[],r){return{type:"ConditionalCommand",expression:e,redirections:t,line:r}},arithmeticCommand(e,t=[],r){return{type:"ArithmeticCommand",expression:e,redirections:t,line:r}}};var p;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(p||(p={}));var pe=class extends Error{line;column;constructor(t,r,s){super(`line ${r}: ${t}`),this.line=r,this.column=s,this.name="LexerError"}},
|
|
6
|
-
`||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var
|
|
2
|
+
import{a as O}from"./chunk-SE4C7FJY.js";import{e as j,f as K,g as C,h as re,i as Pe,j as It,k as L}from"./chunk-6KZRLMG3.js";function $(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
|
|
3
|
+
`){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var Re=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function ge(e){if(e.includes("#")){let[r,s]=e.split("#"),n=Number.parseInt(r,10);if(n<2||n>64)return Number.NaN;if(n<=36){let i=Number.parseInt(s,n);return i>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:i}let a=0;for(let i of s){let l;if(/[0-9]/.test(i))l=i.charCodeAt(0)-48;else if(/[a-z]/.test(i))l=i.charCodeAt(0)-97+10;else if(/[A-Z]/.test(i))l=i.charCodeAt(0)-65+36;else if(i==="@")l=62;else if(i==="_")l=63;else return Number.NaN;if(l>=n)return Number.NaN;if(a=a*n+l,a>Number.MAX_SAFE_INTEGER)return Number.MAX_SAFE_INTEGER}return a}if(e.startsWith("0x")||e.startsWith("0X")){let r=Number.parseInt(e.slice(2),16);return r>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:r}if(e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)){if(/[89]/.test(e))return Number.NaN;let r=Number.parseInt(e,8);return r>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:r}let t=Number.parseInt(e,10);return t>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:t}function vt(e,t,r,s){if(r.slice(s,s+3)!=="$((")return null;let n=s+3,a=1,i=n;for(;n<r.length-1&&a>0;)r[n]==="("&&r[n+1]==="("?(a++,n+=2):r[n]===")"&&r[n+1]===")"?(a--,a>0&&(n+=2)):n++;let l=r.slice(i,n),{expr:o}=e(t,l,0);return n+=2,{expr:{type:"ArithNested",expression:o},pos:n}}function Dt(e,t){if(e.slice(t,t+2)!=="$'")return null;let r=t+2,s="";for(;r<e.length&&e[r]!=="'";)if(e[r]==="\\"&&r+1<e.length){let a=e[r+1];switch(a){case"n":s+=`
|
|
4
|
+
`;break;case"t":s+=" ";break;case"r":s+="\r";break;case"\\":s+="\\";break;case"'":s+="'";break;default:s+=a}r+=2}else s+=e[r],r++;e[r]==="'"&&r++;let n=Number.parseInt(s,10);return{expr:{type:"ArithNumber",value:Number.isNaN(n)?0:n},pos:r}}function xt(e,t){if(e.slice(t,t+2)!=='$"')return null;let r=t+2,s="";for(;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?(s+=e[r+1],r+=2):(s+=e[r],r++);e[r]==='"'&&r++;let n=Number.parseInt(s,10);return{expr:{type:"ArithNumber",value:Number.isNaN(n)?0:n},pos:r}}function kr(e){let t="",r=0;for(;r<e.length;)if(e[r]==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?(t+=e[r+1],r+=2):(t+=e[r],r++);r<e.length&&r++}else t+=e[r],r++;return t}function M(e,t){let r=kr(t),{expr:s,pos:n}=Z(e,r,0),a=$(r,n);if(a<r.length){let i=t.slice(a).trim();if(i)return{type:"ArithmeticExpression",originalText:t,expression:{type:"ArithSyntaxError",errorToken:i,message:`${i}: syntax error: invalid arithmetic operator (error token is "${i}")`}}}return{type:"ArithmeticExpression",expression:s,originalText:t}}function F(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function z(e,t){return $(e,t)>=e.length}function Z(e,t,r){return Pr(e,t,r)}function Pr(e,t,r){let{expr:s,pos:n}=ye(e,t,r);for(n=$(t,n);t[n]===",";){if(n++,z(t,n))return F(",",n);let{expr:i,pos:l}=ye(e,t,n);s={type:"ArithBinary",operator:",",left:s,right:i},n=$(t,l)}return{expr:s,pos:n}}function ye(e,t,r){let{expr:s,pos:n}=Rr(e,t,r);if(n=$(t,n),t[n]==="?"){n++;let{expr:a,pos:i}=Z(e,t,n);if(n=$(t,i),t[n]===":"){n++;let{expr:l,pos:o}=Z(e,t,n);return{expr:{type:"ArithTernary",condition:s,consequent:a,alternate:l},pos:o}}}return{expr:s,pos:n}}function Rr(e,t,r){let{expr:s,pos:n}=_t(e,t,r);for(;n=$(t,n),t.slice(n,n+2)==="||";){if(n+=2,z(t,n))return F("||",n);let{expr:i,pos:l}=_t(e,t,n);s={type:"ArithBinary",operator:"||",left:s,right:i},n=l}return{expr:s,pos:n}}function _t(e,t,r){let{expr:s,pos:n}=$t(e,t,r);for(;n=$(t,n),t.slice(n,n+2)==="&&";){if(n+=2,z(t,n))return F("&&",n);let{expr:i,pos:l}=$t(e,t,n);s={type:"ArithBinary",operator:"&&",left:s,right:i},n=l}return{expr:s,pos:n}}function $t(e,t,r){let{expr:s,pos:n}=Ct(e,t,r);for(;n=$(t,n),t[n]==="|"&&t[n+1]!=="|";){if(n++,z(t,n))return F("|",n);let{expr:i,pos:l}=Ct(e,t,n);s={type:"ArithBinary",operator:"|",left:s,right:i},n=l}return{expr:s,pos:n}}function Ct(e,t,r){let{expr:s,pos:n}=Ot(e,t,r);for(;n=$(t,n),t[n]==="^";){if(n++,z(t,n))return F("^",n);let{expr:i,pos:l}=Ot(e,t,n);s={type:"ArithBinary",operator:"^",left:s,right:i},n=l}return{expr:s,pos:n}}function Ot(e,t,r){let{expr:s,pos:n}=Lt(e,t,r);for(;n=$(t,n),t[n]==="&"&&t[n+1]!=="&";){if(n++,z(t,n))return F("&",n);let{expr:i,pos:l}=Lt(e,t,n);s={type:"ArithBinary",operator:"&",left:s,right:i},n=l}return{expr:s,pos:n}}function Lt(e,t,r){let{expr:s,pos:n}=Wt(e,t,r);for(;n=$(t,n),t.slice(n,n+2)==="=="||t.slice(n,n+2)==="!=";){let a=t.slice(n,n+2);if(n+=2,z(t,n))return F(a,n);let{expr:i,pos:l}=Wt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Wt(e,t,r){let{expr:s,pos:n}=ze(e,t,r);for(;;)if(n=$(t,n),t.slice(n,n+2)==="<="||t.slice(n,n+2)===">="){let a=t.slice(n,n+2);if(n+=2,z(t,n))return F(a,n);let{expr:i,pos:l}=ze(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else if(t[n]==="<"||t[n]===">"){let a=t[n];if(n++,z(t,n))return F(a,n);let{expr:i,pos:l}=ze(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else break;return{expr:s,pos:n}}function ze(e,t,r){let{expr:s,pos:n}=Tt(e,t,r);for(;n=$(t,n),t.slice(n,n+2)==="<<"||t.slice(n,n+2)===">>";){let a=t.slice(n,n+2);if(n+=2,z(t,n))return F(a,n);let{expr:i,pos:l}=Tt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Tt(e,t,r){let{expr:s,pos:n}=Mt(e,t,r);for(;n=$(t,n),(t[n]==="+"||t[n]==="-")&&t[n+1]!==t[n];){let a=t[n];if(n++,z(t,n))return F(a,n);let{expr:i,pos:l}=Mt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Mt(e,t,r){let{expr:s,pos:n}=Ie(e,t,r);for(;;)if(n=$(t,n),t[n]==="*"&&t[n+1]!=="*"){if(n++,z(t,n))return F("*",n);let{expr:i,pos:l}=Ie(e,t,n);s={type:"ArithBinary",operator:"*",left:s,right:i},n=l}else if(t[n]==="/"||t[n]==="%"){let a=t[n];if(n++,z(t,n))return F(a,n);let{expr:i,pos:l}=Ie(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else break;return{expr:s,pos:n}}function Ie(e,t,r){let{expr:s,pos:n}=Ge(e,t,r),a=$(t,n);if(t.slice(a,a+2)==="**"){if(a+=2,z(t,a))return F("**",a);let{expr:l,pos:o}=Ie(e,t,a);return{expr:{type:"ArithBinary",operator:"**",left:s,right:l},pos:o}}return{expr:s,pos:n}}function Ge(e,t,r){let s=$(t,r);if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let n=t.slice(s,s+2);s+=2;let{expr:a,pos:i}=Ge(e,t,s);return{expr:{type:"ArithUnary",operator:n,operand:a,prefix:!0},pos:i}}if(t[s]==="+"||t[s]==="-"||t[s]==="!"||t[s]==="~"){let n=t[s];s++;let{expr:a,pos:i}=Ge(e,t,s);return{expr:{type:"ArithUnary",operator:n,operand:a,prefix:!0},pos:i}}return vr(e,t,s)}function Ir(e,t){let r=e[t];return r==="$"||r==="`"}function vr(e,t,r){let{expr:s,pos:n}=Vt(e,t,r,!1),a=[s];for(;Ir(t,n);){let{expr:l,pos:o}=Vt(e,t,n,!0);a.push(l),n=o}a.length>1&&(s={type:"ArithConcat",parts:a});let i;if(t[n]==="["&&s.type==="ArithConcat"){n++;let{expr:l,pos:o}=Z(e,t,n);i=l,n=o,t[n]==="]"&&n++}if(i&&s.type==="ArithConcat"&&(s={type:"ArithDynamicElement",nameExpr:s,subscript:i},i=void 0),n=$(t,n),s.type==="ArithConcat"||s.type==="ArithVariable"||s.type==="ArithDynamicElement"){for(let l of Re)if(t.slice(n,n+l.length)===l&&t.slice(n,n+l.length+1)!=="=="){n+=l.length;let{expr:o,pos:c}=ye(e,t,n);return s.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:l,target:s.nameExpr,subscript:s.subscript,value:o},pos:c}:s.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:l,target:s,value:o},pos:c}:{expr:{type:"ArithAssignment",operator:l,variable:s.name,value:o},pos:c}}}if(t.slice(n,n+2)==="++"||t.slice(n,n+2)==="--"){let l=t.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:l,operand:s,prefix:!1},pos:n}}return{expr:s,pos:n}}function Vt(e,t,r,s=!1){let n=$(t,r),a=vt(Z,e,t,n);if(a)return a;let i=Dt(t,n);if(i)return i;let l=xt(t,n);if(l)return l;if(t.slice(n,n+2)==="$("&&t[n+2]!=="("){n+=2;let c=1,u=n;for(;n<t.length&&c>0;)t[n]==="("?c++:t[n]===")"&&c--,c>0&&n++;let f=t.slice(u,n);return n++,{expr:{type:"ArithCommandSubst",command:f},pos:n}}if(t[n]==="`"){n++;let c=n;for(;n<t.length&&t[n]!=="`";)n++;let u=t.slice(c,n);return t[n]==="`"&&n++,{expr:{type:"ArithCommandSubst",command:u},pos:n}}if(t[n]==="("){n++;let{expr:c,pos:u}=Z(e,t,n);return n=$(t,u),t[n]===")"&&n++,{expr:{type:"ArithGroup",expression:c},pos:n}}if(t[n]==="'"){n++;let c="";for(;n<t.length&&t[n]!=="'";)c+=t[n],n++;t[n]==="'"&&n++;let u=Number.parseInt(c,10);return{expr:{type:"ArithSingleQuote",content:c,value:Number.isNaN(u)?0:u},pos:n}}if(t[n]==='"'){n++;let c="";for(;n<t.length&&t[n]!=='"';)t[n]==="\\"&&n+1<t.length?(c+=t[n+1],n+=2):(c+=t[n],n++);t[n]==='"'&&n++;let u=c.trim();if(!u)return{expr:{type:"ArithNumber",value:0},pos:n};let{expr:f}=Z(e,u,0);return{expr:f,pos:n}}if(/[0-9]/.test(t[n])){let c="",u=!1,f=!1;for(;n<t.length;){let d=t[n];if(u)if(/[0-9a-zA-Z@_]/.test(d))c+=d,n++;else break;else if(d==="#")u=!0,c+=d,n++;else if(c==="0"&&(d==="x"||d==="X")&&n+1<t.length&&/[0-9a-fA-F]/.test(t[n+1]))f=!0,c+=d,n++;else if(f&&/[0-9a-fA-F]/.test(d))c+=d,n++;else if(!f&&/[0-9]/.test(d))c+=d,n++;else break}if(n<t.length&&/[a-zA-Z_]/.test(t[n])){let d=c;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)d+=t[n],n++;return{expr:{type:"ArithSyntaxError",errorToken:d,message:`${d}: value too great for base (error token is "${d}")`},pos:n}}if(t[n]==="."&&/[0-9]/.test(t[n+1]))throw new C(`${c}.${t[n+1]}...: syntax error: invalid arithmetic operator`);if(t[n]==="["){let d=t.slice(n).trim();return{expr:{type:"ArithNumberSubscript",number:c,errorToken:d},pos:t.length}}return{expr:{type:"ArithNumber",value:ge(c)},pos:n}}if(t[n]==="$"&&t[n+1]==="{"){let c=n+2,u=1,f=c;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;let h=t.slice(c,f),d=f+1;if(t[d]==="#"){let m=d+1;for(;m<t.length&&/[0-9a-zA-Z@_]/.test(t[m]);)m++;let g=t.slice(d+1,m);return{expr:{type:"ArithDynamicBase",baseExpr:h,value:g},pos:m}}if(/[0-9]/.test(t[d])||t[d]==="x"||t[d]==="X"){let m=d;if(t[d]==="x"||t[d]==="X")for(m++;m<t.length&&/[0-9a-fA-F]/.test(t[m]);)m++;else for(;m<t.length&&/[0-9]/.test(t[m]);)m++;let g=t.slice(d,m);return{expr:{type:"ArithDynamicNumber",prefix:h,suffix:g},pos:m}}return n=d,{expr:{type:"ArithBracedExpansion",content:h},pos:n}}if(t[n]==="$"&&n+1<t.length&&/[0-9]/.test(t[n+1])){n++;let c="";for(;n<t.length&&/[0-9]/.test(t[n]);)c+=t[n],n++;return{expr:{type:"ArithVariable",name:c,hasDollarPrefix:!0},pos:n}}if(t[n]==="$"&&n+1<t.length&&/[*@#?\-!$]/.test(t[n+1])){let c=t[n+1];return n+=2,{expr:{type:"ArithSpecialVar",name:c},pos:n}}let o=!1;if(t[n]==="$"&&n+1<t.length&&/[a-zA-Z_]/.test(t[n+1])&&(o=!0,n++),n<t.length&&/[a-zA-Z_]/.test(t[n])){let c="";for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)c+=t[n],n++;if(t[n]==="["&&!s){n++;let u;if(t[n]==="'"||t[n]==='"'){let h=t[n];for(n++,u="";n<t.length&&t[n]!==h;)u+=t[n],n++;t[n]===h&&n++,n=$(t,n),t[n]==="]"&&n++}let f;if(u===void 0){let{expr:h,pos:d}=Z(e,t,n);f=h,n=d,t[n]==="]"&&n++}if(n=$(t,n),t[n]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:c,index:f},pos:n};if(!s){for(let h of Re)if(t.slice(n,n+h.length)===h&&t.slice(n,n+h.length+1)!=="=="){n+=h.length;let{expr:d,pos:m}=ye(e,t,n);return{expr:{type:"ArithAssignment",operator:h,variable:c,subscript:f,stringKey:u,value:d},pos:m}}}return{expr:{type:"ArithArrayElement",array:c,index:f,stringKey:u},pos:n}}if(n=$(t,n),!s){for(let u of Re)if(t.slice(n,n+u.length)===u&&t.slice(n,n+u.length+1)!=="=="){n+=u.length;let{expr:f,pos:h}=ye(e,t,n);return{expr:{type:"ArithAssignment",operator:u,variable:c,value:f},pos:h}}}return{expr:{type:"ArithVariable",name:c,hasDollarPrefix:o},pos:n}}if(t[n]==="#"){let c=n+1;for(;c<t.length&&t[c]!==`
|
|
5
|
+
`;)c++;let u=t.slice(n,c).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:u,message:`${u}: syntax error: invalid arithmetic operator (error token is "${u}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:n}}var w={script(e){return{type:"Script",statements:e}},statement(e,t=[],r=!1,s,n){let a={type:"Statement",pipelines:e,operators:t,background:r};return s&&(a.deferredError=s),n!==void 0&&(a.sourceText=n),a},pipeline(e,t=!1,r=!1,s=!1,n){return{type:"Pipeline",commands:e,negated:t,timed:r,timePosix:s,pipeStderr:n}},simpleCommand(e,t=[],r=[],s=[]){return{type:"SimpleCommand",name:e,args:t,assignments:r,redirections:s}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},assignment(e,t,r=!1,s=null){return{type:"Assignment",name:e,value:t,append:r,array:s}},redirection(e,t,r=null,s){let n={type:"Redirection",fd:r,operator:e,target:t};return s&&(n.fdVariable=s),n},hereDoc(e,t,r=!1,s=!1){return{type:"HereDoc",delimiter:e,content:t,stripTabs:r,quoted:s}},ifNode(e,t=null,r=[]){return{type:"If",clauses:e,elseBody:t,redirections:r}},forNode(e,t,r,s=[]){return{type:"For",variable:e,words:t,body:r,redirections:s}},whileNode(e,t,r=[]){return{type:"While",condition:e,body:t,redirections:r}},untilNode(e,t,r=[]){return{type:"Until",condition:e,body:t,redirections:r}},caseNode(e,t,r=[]){return{type:"Case",word:e,items:t,redirections:r}},caseItem(e,t,r=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:r}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,r=[],s){return{type:"FunctionDef",name:e,body:t,redirections:r,sourceFile:s}},conditionalCommand(e,t=[],r){return{type:"ConditionalCommand",expression:e,redirections:t,line:r}},arithmeticCommand(e,t=[],r){return{type:"ArithmeticCommand",expression:e,redirections:t,line:r}}};var p;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(p||(p={}));var pe=class extends Error{line;column;constructor(t,r,s){super(`line ${r}: ${t}`),this.line=r,this.column=s,this.name="LexerError"}},Bt=new Map([["if",p.IF],["then",p.THEN],["else",p.ELSE],["elif",p.ELIF],["fi",p.FI],["for",p.FOR],["while",p.WHILE],["until",p.UNTIL],["do",p.DO],["done",p.DONE],["case",p.CASE],["esac",p.ESAC],["in",p.IN],["function",p.FUNCTION],["select",p.SELECT],["time",p.TIME],["coproc",p.COPROC]]);function Ft(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return!1;let r=e.slice(t[0].length);if(r===""||r==="+")return!0;if(r[0]==="["){let s=0,n=0;for(;n<r.length;n++)if(r[n]==="[")s++;else if(r[n]==="]"&&(s--,s===0))break;if(s!==0||n>=r.length)return!1;let a=r.slice(n+1);return a===""||a==="+"}return!1}function zt(e){let t=0;for(let r=0;r<e.length;r++){let s=e[r];if(s==="[")t++;else if(s==="]")t--;else{if(t===0&&s==="=")return r;if(t===0&&s==="+"&&e[r+1]==="=")return r+1}}return-1}var Dr=[[";",";","&",p.SEMI_SEMI_AND],["<","<","<",p.TLESS],["&",">",">",p.AND_DGREAT]],xr=[["[","[",p.DBRACK_START],["]","]",p.DBRACK_END],["(","(",p.DPAREN_START],[")",")",p.DPAREN_END],["&","&",p.AND_AND],["|","|",p.OR_OR],[";",";",p.DSEMI],[";","&",p.SEMI_AND],["|","&",p.PIPE_AMP],[">",">",p.DGREAT],["<","&",p.LESSAND],[">","&",p.GREATAND],["<",">",p.LESSGREAT],[">","|",p.CLOBBER],["&",">",p.AND_GREAT]],_r=new Map([["|",p.PIPE],["&",p.AMP],[";",p.SEMICOLON],["(",p.LPAREN],[")",p.RPAREN],["<",p.LESS],[">",p.GREAT]]);function $r(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Gt(e){return e===" "||e===" "||e===`
|
|
6
|
+
`||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var ve=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];dparenDepth=0;maxHeredocSize;constructor(t,r){this.input=t,this.maxHeredocSize=r?.maxHeredocSize??10485760}tokenize(){let r=this.input.length,s=this.tokens,n=this.pendingHeredocs;for(;this.pos<r;){if(n.length>0&&s.length>0&&s[s.length-1].type===p.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=r)break;let a=this.nextToken();a&&s.push(a)}return s.push({type:p.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),s}skipWhitespace(){let t=this.input,r=t.length,s=this.pos,n=this.column,a=this.line;for(;s<r;){let i=t[s];if(i===" "||i===" ")s++,n++;else if(i==="\\"&&t[s+1]===`
|
|
7
7
|
`)s+=2,a++,n=1;else break}this.pos=s,this.column=n,this.line=a}nextToken(){let t=this.input,r=this.pos,s=this.line,n=this.column,a=t[r],i=t[r+1],l=t[r+2];if(a==="#"&&this.dparenDepth===0)return this.readComment(r,s,n);if(a===`
|
|
8
8
|
`)return this.pos=r+1,this.line++,this.column=1,{type:p.NEWLINE,value:`
|
|
9
|
-
`,start:r,end:r+1,line:s,column:n};if(a==="<"&&i==="<"&&l==="-")return this.pos=r+3,this.column=n+3,this.registerHeredocFromLookahead(!0),this.makeToken(p.DLESSDASH,"<<-",r,s,n);for(let[c,u,f,h]of
|
|
10
|
-
`&&h!==";"&&h!=="&"&&h!=="|"&&h!=="("&&h!==")"&&h!=="<"&&h!==">")break}return this.pos=r+2,this.column=n+2,this.makeToken(f,c+u,r,s,n)}if(a==="("&&this.dparenDepth>0)return this.pos=r+1,this.column=n+1,this.dparenDepth++,this.makeToken(p.LPAREN,"(",r,s,n);if(a===")"&&this.dparenDepth>1)return this.pos=r+1,this.column=n+1,this.dparenDepth--,this.makeToken(p.RPAREN,")",r,s,n);let o=
|
|
9
|
+
`,start:r,end:r+1,line:s,column:n};if(a==="<"&&i==="<"&&l==="-")return this.pos=r+3,this.column=n+3,this.registerHeredocFromLookahead(!0),this.makeToken(p.DLESSDASH,"<<-",r,s,n);for(let[c,u,f,h]of Dr)if(a===c&&i===u&&l===f)return this.pos=r+3,this.column=n+3,this.makeToken(h,c+u+f,r,s,n);if(a==="<"&&i==="<")return this.pos=r+2,this.column=n+2,this.registerHeredocFromLookahead(!1),this.makeToken(p.DLESS,"<<",r,s,n);if(a==="("&&i==="(")return this.dparenDepth>0?(this.pos=r+1,this.column=n+1,this.dparenDepth++,this.makeToken(p.LPAREN,"(",r,s,n)):this.looksLikeNestedSubshells(r+2)||this.dparenClosesWithSpacedParens(r+2)?(this.pos=r+1,this.column=n+1,this.makeToken(p.LPAREN,"(",r,s,n)):(this.pos=r+2,this.column=n+2,this.dparenDepth=1,this.makeToken(p.DPAREN_START,"((",r,s,n));if(a===")"&&i===")")return this.dparenDepth===1?(this.pos=r+2,this.column=n+2,this.dparenDepth=0,this.makeToken(p.DPAREN_END,"))",r,s,n)):this.dparenDepth>1?(this.pos=r+1,this.column=n+1,this.dparenDepth--,this.makeToken(p.RPAREN,")",r,s,n)):(this.pos=r+1,this.column=n+1,this.makeToken(p.RPAREN,")",r,s,n));for(let[c,u,f]of xr)if(!(c==="("&&u==="("||c===")"&&u===")")&&!(this.dparenDepth>0&&c===";"&&(f===p.DSEMI||f===p.SEMI_AND||f===p.SEMI_SEMI_AND))&&a===c&&i===u){if(f===p.DBRACK_START||f===p.DBRACK_END){let h=t[r+2];if(h!==void 0&&h!==" "&&h!==" "&&h!==`
|
|
10
|
+
`&&h!==";"&&h!=="&"&&h!=="|"&&h!=="("&&h!==")"&&h!=="<"&&h!==">")break}return this.pos=r+2,this.column=n+2,this.makeToken(f,c+u,r,s,n)}if(a==="("&&this.dparenDepth>0)return this.pos=r+1,this.column=n+1,this.dparenDepth++,this.makeToken(p.LPAREN,"(",r,s,n);if(a===")"&&this.dparenDepth>1)return this.pos=r+1,this.column=n+1,this.dparenDepth--,this.makeToken(p.RPAREN,")",r,s,n);let o=_r.get(a);if(o!==void 0)return this.pos=r+1,this.column=n+1,this.makeToken(o,a,r,s,n);if(a==="{"){let c=this.scanFdVariable(r);return c!==null?(this.pos=c.end,this.column=n+(c.end-r),{type:p.FD_VARIABLE,value:c.varname,start:r,end:c.end,line:s,column:n}):i==="}"?(this.pos=r+2,this.column=n+2,{type:p.WORD,value:"{}",start:r,end:r+2,line:s,column:n,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(r)!==null?this.readWordWithBraceExpansion(r,s,n):this.scanLiteralBraceWord(r)!==null?this.readWordWithBraceExpansion(r,s,n):i!==void 0&&i!==" "&&i!==" "&&i!==`
|
|
11
11
|
`?this.readWord(r,s,n):(this.pos=r+1,this.column=n+1,this.makeToken(p.LBRACE,"{",r,s,n))}return a==="}"?this.isWordCharFollowing(r+1)?this.readWord(r,s,n):(this.pos=r+1,this.column=n+1,this.makeToken(p.RBRACE,"}",r,s,n)):a==="!"?i==="="?(this.pos=r+2,this.column=n+2,this.makeToken(p.WORD,"!=",r,s,n)):(this.pos=r+1,this.column=n+1,this.makeToken(p.BANG,"!",r,s,n)):this.readWord(r,s,n)}looksLikeNestedSubshells(t){let r=this.input,s=r.length,n=t;for(;n<s&&(r[n]===" "||r[n]===" ");)n++;if(n>=s)return!1;let a=r[n];if(a==="(")return this.looksLikeNestedSubshells(n+1);let i=/[a-zA-Z_]/.test(a),l=a==="!"||a==="[";if(!i&&!l)return!1;let o=n;for(;o<s&&/[a-zA-Z0-9_\-.]/.test(r[o]);)o++;if(o===n)return l;let c=o;for(;c<s&&(r[c]===" "||r[c]===" ");)c++;if(c>=s)return!1;let u=r[c];if(u==="="&&r[c+1]!=="="||u===`
|
|
12
12
|
`||o===c&&/[+\-*/%<>&|^!~?:]/.test(u)&&u!=="-"||u===")"&&r[c+1]===")")return!1;if(c>o&&(u==="-"||u==='"'||u==="'"||u==="$"||/[a-zA-Z_/.]/.test(u))){let f=c;for(;f<s&&r[f]!==`
|
|
13
13
|
`;){if(r[f]===")")return!0;f++}return!1}if(u===")"){let f=c+1;for(;f<s&&(r[f]===" "||r[f]===" ");)f++;if(r[f]==="|"&&r[f+1]==="|"||r[f]==="&"&&r[f+1]==="&"||r[f]===";"||r[f]==="|"&&r[f+1]!=="|")return!0}return!1}makeToken(t,r,s,n,a){return{type:t,value:r,start:s,end:this.pos,line:n,column:a}}readComment(t,r,s){let n=this.input,a=n.length,i=this.pos;for(;i<a&&n[i]!==`
|
|
14
14
|
`;)i++;let l=n.slice(t,i);return this.pos=i,this.column=s+(i-t),{type:p.COMMENT,value:l,start:t,end:i,line:r,column:s}}readWord(t,r,s){let n=this.input,a=n.length,i=this.pos,l=i;for(;i<a;){let y=n[i];if(y===" "||y===" "||y===`
|
|
15
15
|
`||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"||y==="'"||y==='"'||y==="\\"||y==="$"||y==="`"||y==="{"||y==="}"||y==="~"||y==="*"||y==="?"||y==="[")break;i++}if(i>l){let y=n[i];if(!(y==="("&&i>l&&"@*+?!".includes(n[i-1]))){if(i>=a||y===" "||y===" "||y===`
|
|
16
|
-
`||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"){let b=n.slice(l,i);this.pos=i,this.column=s+(i-l);let D=
|
|
16
|
+
`||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"){let b=n.slice(l,i);this.pos=i,this.column=s+(i-l);let D=Bt.get(b);if(D!==void 0)return{type:D,value:b,start:t,end:i,line:r,column:s};let Q=zt(b);return Q>0&&Ft(b.slice(0,Q))?{type:p.ASSIGNMENT_WORD,value:b,start:t,end:i,line:r,column:s}:/^[0-9]+$/.test(b)?{type:p.NUMBER,value:b,start:t,end:i,line:r,column:s}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(b)?{type:p.NAME,value:b,start:t,end:i,line:r,column:s,quoted:!1,singleQuoted:!1}:{type:p.WORD,value:b,start:t,end:i,line:r,column:s,quoted:!1,singleQuoted:!1}}}}i=this.pos;let o=this.column,c=this.line,u="",f=!1,h=!1,d=!1,m=!1,g=n[i]==='"'||n[i]==="'",E=!1,A=0;for(;i<a;){let y=n[i];if(!d&&!m){if(y==="("&&u.length>0&&"@*+?!".includes(u[u.length-1])){let b=this.scanExtglobPattern(i);if(b!==null){u+=b.content,i=b.end,o+=b.content.length;continue}}if(y==="["&&A===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)){let b=i+1<a?n[i+1]:"";if(b==="^"||b==="!"){u+=y,i++,o++;continue}A=1,u+=y,i++,o++;continue}}else if(y==="["&&A>0){u.length>0&&u[u.length-1]!=="\\"&&A++,u+=y,i++,o++;continue}else if(y==="]"&&A>0){u.length>0&&u[u.length-1]!=="\\"&&A--,u+=y,i++,o++;continue}if(A>0){if(y===`
|
|
17
17
|
`)break;u+=y,i++,o++;continue}if(y===" "||y===" "||y===`
|
|
18
|
-
`||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">")break}if(y==="$"&&i+1<a&&n[i+1]==="'"&&!d&&!m){for(u+="$'",i+=2,o+=2;i<a&&n[i]!=="'";)n[i]==="\\"&&i+1<a?(u+=n[i]+n[i+1],i+=2,o+=2):(u+=n[i],i++,o++);i<a&&(u+="'",i++,o++);continue}if(y==="$"&&i+1<a&&n[i+1]==='"'&&!d&&!m){i++,o++,m=!0,f=!0,u===""&&(g=!0),i++,o++;continue}if(y==="'"&&!m){if(d)if(d=!1,!g||E)u+=y;else{let b=i+1<a?n[i+1]:"";b&&!
|
|
18
|
+
`||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">")break}if(y==="$"&&i+1<a&&n[i+1]==="'"&&!d&&!m){for(u+="$'",i+=2,o+=2;i<a&&n[i]!=="'";)n[i]==="\\"&&i+1<a?(u+=n[i]+n[i+1],i+=2,o+=2):(u+=n[i],i++,o++);i<a&&(u+="'",i++,o++);continue}if(y==="$"&&i+1<a&&n[i+1]==='"'&&!d&&!m){i++,o++,m=!0,f=!0,u===""&&(g=!0),i++,o++;continue}if(y==="'"&&!m){if(d)if(d=!1,!g||E)u+=y;else{let b=i+1<a?n[i+1]:"";b&&!Gt(b)&&b!=="'"&&(b==='"'?(E=!0,u+=y,h=!1,f=!1):(E=!0,u+=y))}else d=!0,g&&!E?(h=!0,f=!0):u+=y;i++,o++;continue}if(y==='"'&&!d){if(m)if(m=!1,!g||E)u+=y;else{let b=i+1<a?n[i+1]:"";b&&!Gt(b)&&b!=='"'&&(b==="'"?(E=!0,u+=y,h=!1,f=!1):(E=!0,u+=y))}else m=!0,g&&!E?f=!0:u+=y;i++,o++;continue}if(y==="\\"&&!d&&i+1<a){let b=n[i+1];if(b===`
|
|
19
19
|
`){i+=2,c++,o=1;continue}if(m){if(b==='"'||b==="\\"||b==="$"||b==="`"||b===`
|
|
20
20
|
`){if(b===`
|
|
21
|
-
`){i+=2,o=1,c++;continue}u+=y+b,i+=2,o+=2;continue}}else{b==="\\"||b==='"'||b==="'"||b==="`"||b==="*"||b==="?"||b==="["||b==="]"||b==="("||b===")"||b==="$"||b==="-"||b==="."||b==="^"||b==="+"||b==="{"||b==="}"?u+=y+b:u+=b,i+=2,o+=2;continue}}if(y==="$"&&i+1<a&&n[i+1]==="("&&!d){u+=y,i++,o++,u+=n[i],i++,o++;let b=1,D=!1,Q=!1,ie=0,H=!1,B="",
|
|
22
|
-
`?(c++,o=0):o++,i++}B="";continue}else if(_==="#"&&!
|
|
21
|
+
`){i+=2,o=1,c++;continue}u+=y+b,i+=2,o+=2;continue}}else{b==="\\"||b==='"'||b==="'"||b==="`"||b==="*"||b==="?"||b==="["||b==="]"||b==="("||b===")"||b==="$"||b==="-"||b==="."||b==="^"||b==="+"||b==="{"||b==="}"?u+=y+b:u+=b,i+=2,o+=2;continue}}if(y==="$"&&i+1<a&&n[i+1]==="("&&!d){u+=y,i++,o++,u+=n[i],i++,o++;let b=1,D=!1,Q=!1,ie=0,H=!1,B="",Ne=n[i]==="("&&!this.dollarDparenIsSubshell(i);for(;b>0&&i<a;){let _=n[i];if(u+=_,D)_==="'"&&(D=!1);else if(Q)_==="\\"&&i+1<a?(u+=n[i+1],i++,o++):_==='"'&&(Q=!1);else if(_==="'")D=!0,B="";else if(_==='"')Q=!0,B="";else if(_==="\\"&&i+1<a)u+=n[i+1],i++,o++,B="";else if(_==="$"&&i+1<a&&n[i+1]==="{"){i++,o++,u+=n[i],i++,o++;let Be=1,ke=!1,Fe=!1;for(;Be>0&&i<a;){let Y=n[i];if(Y==="\\"&&i+1<a&&!ke){u+=Y,i++,o++,u+=n[i],i++,o++;continue}u+=Y,ke?Y==="'"&&(ke=!1):Fe?Y==='"'&&(Fe=!1):Y==="'"?ke=!0:Y==='"'?Fe=!0:Y==="{"?Be++:Y==="}"&&Be--,Y===`
|
|
22
|
+
`?(c++,o=0):o++,i++}B="";continue}else if(_==="#"&&!Ne&&(B===""||/\s/.test(n[i-1]||""))){for(;i+1<a&&n[i+1]!==`
|
|
23
23
|
`;)i++,o++,u+=n[i];B=""}else/[a-zA-Z_]/.test(_)?B+=_:(B==="case"?(ie++,H=!1):B==="in"&&ie>0?H=!0:B==="esac"&&ie>0&&(ie--,H=!1),B="",_==="("?i>0&&n[i-1]==="$"?b++:H||b++:_===")"?H?H=!1:b--:_===";"&&ie>0&&(i+1<a&&n[i+1]===";"||i+1<a&&n[i+1]==="&")&&(H=!0));_===`
|
|
24
24
|
`&&(c++,o=0,B=""),i++,o++}continue}if(y==="$"&&i+1<a&&n[i+1]==="["&&!d){u+=y,i++,o++,u+=n[i],i++,o++;let b=1;for(;b>0&&i<a;){let D=n[i];u+=D,D==="["?b++:D==="]"?b--:D===`
|
|
25
|
-
`&&(c++,o=0),i++,o++}continue}if(y==="$"&&i+1<a&&n[i+1]==="{"&&!d){u+=y,i++,o++,u+=n[i],i++,o++;let b=1,D=!1,Q=!1,ie=c,H=o,B=c,
|
|
26
|
-
`){i+=2,c++,o=1;continue}if(_==="\\"&&i+1<a&&!D){u+=_,i++,o++,u+=n[i],i++,o++;continue}u+=_,D?_==="'"&&(D=!1):Q?_==='"'&&(Q=!1):_==="'"?(D=!0,ie=c,H=o):_==='"'?(Q=!0,B=c,
|
|
27
|
-
`&&(c++,o=0),i++,o++}if(D)throw new pe("unexpected EOF while looking for matching `''",ie,H);if(Q)throw new pe("unexpected EOF while looking for matching `\"'",B,
|
|
25
|
+
`&&(c++,o=0),i++,o++}continue}if(y==="$"&&i+1<a&&n[i+1]==="{"&&!d){u+=y,i++,o++,u+=n[i],i++,o++;let b=1,D=!1,Q=!1,ie=c,H=o,B=c,Ne=o;for(;b>0&&i<a;){let _=n[i];if(_==="\\"&&i+1<a&&n[i+1]===`
|
|
26
|
+
`){i+=2,c++,o=1;continue}if(_==="\\"&&i+1<a&&!D){u+=_,i++,o++,u+=n[i],i++,o++;continue}u+=_,D?_==="'"&&(D=!1):Q?_==='"'&&(Q=!1):_==="'"?(D=!0,ie=c,H=o):_==='"'?(Q=!0,B=c,Ne=o):_==="{"?b++:_==="}"&&b--,_===`
|
|
27
|
+
`&&(c++,o=0),i++,o++}if(D)throw new pe("unexpected EOF while looking for matching `''",ie,H);if(Q)throw new pe("unexpected EOF while looking for matching `\"'",B,Ne);continue}if(y==="$"&&i+1<a&&!d){let b=n[i+1];if(b==="#"||b==="?"||b==="$"||b==="!"||b==="@"||b==="*"||b==="-"||b>="0"&&b<="9"){u+=y+b,i+=2,o+=2;continue}}if(y==="`"&&!d){for(u+=y,i++,o++;i<a&&n[i]!=="`";){let b=n[i];u+=b,b==="\\"&&i+1<a&&(u+=n[i+1],i++,o++),b===`
|
|
28
28
|
`&&(c++,o=0),i++,o++}i<a&&(u+=n[i],i++,o++);continue}u+=y,i++,y===`
|
|
29
|
-
`?(c++,o=1):o++}if(this.pos=i,this.column=o,this.line=c,E&&g&&(u=n[t]+u,f=!1,h=!1),d||m){let y=d?"'":'"';throw new pe(`unexpected EOF while looking for matching \`${y}'`,r,s)}if(!g&&u.length>=2){if(u[0]==="'"&&u[u.length-1]==="'"){let y=u.slice(1,-1);!y.includes("'")&&!y.includes('"')&&(u=y,f=!0,h=!0)}else if(u[0]==='"'&&u[u.length-1]==='"'){let y=u.slice(1,-1),b=!1;for(let D=0;D<y.length;D++){if(y[D]==='"'){b=!0;break}y[D]==="\\"&&D+1<y.length&&D++}b||(u=y,f=!0,h=!1)}}if(u==="")return{type:p.WORD,value:"",start:t,end:i,line:r,column:s,quoted:f,singleQuoted:h};let S=
|
|
30
|
-
`;)
|
|
31
|
-
`&&(this.pos++,this.line++,this.column=1);break}if(a+=
|
|
29
|
+
`?(c++,o=1):o++}if(this.pos=i,this.column=o,this.line=c,E&&g&&(u=n[t]+u,f=!1,h=!1),d||m){let y=d?"'":'"';throw new pe(`unexpected EOF while looking for matching \`${y}'`,r,s)}if(!g&&u.length>=2){if(u[0]==="'"&&u[u.length-1]==="'"){let y=u.slice(1,-1);!y.includes("'")&&!y.includes('"')&&(u=y,f=!0,h=!0)}else if(u[0]==='"'&&u[u.length-1]==='"'){let y=u.slice(1,-1),b=!1;for(let D=0;D<y.length;D++){if(y[D]==='"'){b=!0;break}y[D]==="\\"&&D+1<y.length&&D++}b||(u=y,f=!0,h=!1)}}if(u==="")return{type:p.WORD,value:"",start:t,end:i,line:r,column:s,quoted:f,singleQuoted:h};let S=Bt.get(u);if(!f&&S!==void 0)return{type:S,value:u,start:t,end:i,line:r,column:s};if(!g){let y=zt(u);if(y>0&&Ft(u.slice(0,y)))return{type:p.ASSIGNMENT_WORD,value:u,start:t,end:i,line:r,column:s,quoted:f,singleQuoted:h}}return/^[0-9]+$/.test(u)?{type:p.NUMBER,value:u,start:t,end:i,line:r,column:s}:$r(u)?{type:p.NAME,value:u,start:t,end:i,line:r,column:s,quoted:f,singleQuoted:h}:{type:p.WORD,value:u,start:t,end:i,line:r,column:s,quoted:f,singleQuoted:h}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let r=this.pos,s=this.line,n=this.column,a="";for(;this.pos<this.input.length;){let i="";for(;this.pos<this.input.length&&this.input[this.pos]!==`
|
|
30
|
+
`;)i+=this.input[this.pos],this.pos++,this.column++;if((t.stripTabs?i.replace(/^\t+/,""):i)===t.delimiter){this.pos<this.input.length&&this.input[this.pos]===`
|
|
31
|
+
`&&(this.pos++,this.line++,this.column=1);break}if(a+=i,a.length>this.maxHeredocSize)throw new pe(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,s,n);this.pos<this.input.length&&this.input[this.pos]===`
|
|
32
32
|
`&&(a+=`
|
|
33
33
|
`,this.pos++,this.line++,this.column=1)}this.tokens.push({type:p.HEREDOC_CONTENT,value:a,start:r,end:this.pos,line:s,column:n})}}addPendingHeredoc(t,r,s){this.pendingHeredocs.push({delimiter:t,stripTabs:r,quoted:s})}registerHeredocFromLookahead(t){let r=this.pos,s=this.column;for(;this.pos<this.input.length&&(this.input[this.pos]===" "||this.input[this.pos]===" ");)this.pos++,this.column++;let n="",a=!1;for(;this.pos<this.input.length;){let i=this.input[this.pos];if(/[\s;<>&|()]/.test(i))break;if(i==="'"||i==='"'){a=!0;let l=i;for(this.pos++,this.column++;this.pos<this.input.length&&this.input[this.pos]!==l;)n+=this.input[this.pos],this.pos++,this.column++;this.pos<this.input.length&&this.input[this.pos]===l&&(this.pos++,this.column++)}else i==="\\"?(a=!0,this.pos++,this.column++,this.pos<this.input.length&&(n+=this.input[this.pos],this.pos++,this.column++)):(n+=i,this.pos++,this.column++)}this.pos=r,this.column=s,n&&this.pendingHeredocs.push({delimiter:n,stripTabs:t,quoted:a})}isWordCharFollowing(t){if(t>=this.input.length)return!1;let r=this.input[t];return!(r===" "||r===" "||r===`
|
|
34
34
|
`||r===";"||r==="&"||r==="|"||r==="("||r===")"||r==="<"||r===">")}readWordWithBraceExpansion(t,r,s){let n=this.input,a=n.length,i=t,l=s;for(;i<a;){let c=n[i];if(c===" "||c===" "||c===`
|
|
@@ -40,35 +40,35 @@ import{a as O}from"./chunk-SE4C7FJY.js";import{e as j,f as K,g as C,h as re,i as
|
|
|
40
40
|
`&&(o=!0),n++;continue}if(c==="'"){i=!0,n++;continue}if(c==='"'){l=!0,n++;continue}if(c==="\\"){n+=2;continue}if(c===`
|
|
41
41
|
`&&(o=!0),c==="("){a++,n++;continue}if(c===")"){if(a--,a===1){let u=n+1;if(u<s&&r[u]===")")return!1;let f=u,h=!1;for(;f<s&&(r[f]===" "||r[f]===" "||r[f]===`
|
|
42
42
|
`);)h=!0,f++;if(h&&f<s&&r[f]===")"||o)return!0}if(a===0)return!1;n++;continue}n++}return!1}dparenClosesWithSpacedParens(t){let r=this.input,s=r.length,n=t,a=2,i=!1,l=!1;for(;n<s&&a>0;){let o=r[n];if(i){o==="'"&&(i=!1),n++;continue}if(l){if(o==="\\"){n+=2;continue}o==='"'&&(l=!1),n++;continue}if(o==="'"){i=!0,n++;continue}if(o==='"'){l=!0,n++;continue}if(o==="\\"){n+=2;continue}if(o==="("){a++,n++;continue}if(o===")"){if(a--,a===1){let c=n+1;if(c<s&&r[c]===")")return!1;let u=c,f=!1;for(;u<s&&(r[u]===" "||r[u]===" "||r[u]===`
|
|
43
|
-
`);)f=!0,u++;if(f&&u<s&&r[u]===")")return!0}if(a===0)return!1;n++;continue}if(a===1&&(o==="|"&&n+1<s&&r[n+1]==="|"||o==="&"&&n+1<s&&r[n+1]==="&"||o==="|"&&n+1<s&&r[n+1]!=="|"))return!0;n++}return!1}};var
|
|
44
|
-
`,n+=2;break;case"t":s+=" ",n+=2;break;case"r":s+="\r",n+=2;break;case"\\":s+="\\",n+=2;break;case"'":s+="'",n+=2;break;case'"':s+='"',n+=2;break;case"a":s+="\x07",n+=2;break;case"b":s+="\b",n+=2;break;case"e":case"E":s+="\x1B",n+=2;break;case"f":s+="\f",n+=2;break;case"v":s+="\v",n+=2;break;case"x":{let l=[],o=n;for(;o+1<t.length&&t[o]==="\\"&&t[o+1]==="x";){let c=t.slice(o+2,o+4),u=parseInt(c,16);if(!Number.isNaN(u)&&c.length>0)l.push(u),o+=2+c.length;else break}l.length>0?(s+=$r(l),n=o):(s+="\\x",n+=2);break}case"u":{let l=t.slice(n+2,n+6),o=parseInt(l,16);Number.isNaN(o)?(s+="\\u",n+=2):(s+=String.fromCharCode(o),n+=6);break}case"c":{if(n+2<t.length){let o=t[n+2].charCodeAt(0)&31;s+=String.fromCharCode(o),n+=3}else s+="\\c",n+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let l="",o=n+1;for(;o<t.length&&o<n+4&&/[0-7]/.test(t[o]);)l+=t[o],o++;let c=parseInt(l,8);s+=String.fromCharCode(c),n=o;break}default:s+=a,n++}else s+=a,n++}return n<t.length&&t[n]==="'"&&n++,{part:w.literal(s),endIndex:n}}function He(e,t){let r=t.trim();return r===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:M(e,r)}function Ht(e){let t=[],r="",s=0;for(let n=0;n<e.length;n++){let a=e[n];a==="{"?(s++,r+=a):a==="}"?(s--,r+=a):a===","&&s===0?(t.push(r),r=""):r+=a}return t.push(r),t}function Yt(e,t,r,s){let n=Ue(e,t,r,"{","}");if(n===-1)return null;let a=t.slice(r+1,n),i=a.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(i)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(i[1],10),end:Number.parseInt(i[2],10),step:i[3]?Number.parseInt(i[3],10):void 0,startStr:i[1],endStr:i[2]}]},endIndex:n+1};let l=a.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return l?{part:{type:"BraceExpansion",items:[{type:"Range",start:l[1],end:l[2],step:l[3]?Number.parseInt(l[3],10):void 0}]},endIndex:n+1}:a.includes(",")&&s?{part:{type:"BraceExpansion",items:Ht(a).map(u=>({type:"Word",word:w.word(s(e,u,!1,!1,!1))}))},endIndex:n+1}:a.includes(",")?{part:{type:"BraceExpansion",items:Ht(a).map(u=>({type:"Word",word:w.word([w.literal(u)])}))},endIndex:n+1}:null}function je(e,t){let r="";for(let s of t.parts)switch(s.type){case"Literal":r+=s.value;break;case"SingleQuoted":r+=`'${s.value}'`;break;case"Escaped":r+=s.value;break;case"DoubleQuoted":r+='"';for(let n of s.parts)n.type==="Literal"||n.type==="Escaped"?r+=n.value:n.type==="ParameterExpansion"&&(r+=`\${${n.parameter}}`);r+='"';break;case"ParameterExpansion":r+=`\${${s.parameter}}`;break;case"Glob":r+=s.pattern;break;case"TildeExpansion":r+="~",s.user&&(r+=s.user);break;case"BraceExpansion":{r+="{";let n=[];for(let a of s.items)if(a.type==="Range"){let i=a.startStr??String(a.start),l=a.endStr??String(a.end);a.step!==void 0?n.push(`${i}..${l}..${a.step}`):n.push(`${i}..${l}`)}else n.push(je(e,a.word));n.length===1&&s.items[0].type==="Range"?r+=n[0]:r+=n.join(","),r+="}";break}default:r+=s.type}return r}function en(e,t){return{[p.LESS]:"<",[p.GREAT]:">",[p.DGREAT]:">>",[p.LESSAND]:"<&",[p.GREATAND]:">&",[p.LESSGREAT]:"<>",[p.CLOBBER]:">|",[p.TLESS]:"<<<",[p.AND_GREAT]:"&>",[p.AND_DGREAT]:"&>>",[p.DLESS]:"<",[p.DLESSDASH]:"<"}[t]||">"}function ve(e){let t=e.current(),r=t.type;if(r===p.NUMBER){let s=e.peek(1);return t.end!==s.start?!1:Zt.has(s.type)}if(r===p.FD_VARIABLE){let s=e.peek(1);return Ut.has(s.type)}return Qt.has(r)}function De(e){let t=null,r;e.check(p.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(p.FD_VARIABLE)&&(r=e.advance().value);let s=e.advance(),n=en(e,s.type);if(s.type===p.DLESS||s.type===p.DLESSDASH)return Or(e,n,t,s.type===p.DLESSDASH);e.isWord()||e.error("Expected redirection target");let a=e.parseWord();return w.redirection(n,a,t,r)}function Or(e,t,r,s){e.isWord()||e.error("Expected here-document delimiter");let n=e.advance(),a=n.value,i=n.quoted||!1;(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1));let l=w.redirection(s?"<<-":"<<",w.hereDoc(a,w.word([]),s,i),r);return e.addPendingHeredoc(l,a,s,i),l}function nn(e){let t=e.current().line,r=[],s=null,n=[],a=[];for(;e.check(p.ASSIGNMENT_WORD)||ve(e);)e.checkIterationLimit(),e.check(p.ASSIGNMENT_WORD)?r.push(Lr(e)):a.push(De(e));if(e.isWord())s=e.parseWord();else if(r.length>0&&(e.check(p.DBRACK_START)||e.check(p.DPAREN_START))){let l=e.advance();s=w.word([w.literal(l.value)])}for(;(!e.isStatementEnd()||e.check(p.RBRACE))&&!e.check(p.PIPE,p.PIPE_AMP);)if(e.checkIterationLimit(),ve(e))a.push(De(e));else if(e.check(p.RBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(p.LBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(p.DBRACK_END)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.isWord())n.push(e.parseWord());else if(e.check(p.ASSIGNMENT_WORD)){let l=e.advance(),o=l.value,c=o.endsWith("="),u=o.endsWith("=(");if((c||u)&&(u||e.check(p.LPAREN))){let f=u?o.slice(0,-2):o.slice(0,-1);u||e.expect(p.LPAREN);let h=Ke(e);e.expect(p.RPAREN);let d=h.map(g=>je(e,g)),m=`${f}=(${d.join(" ")})`;n.push(e.parseWordFromString(m,!1,!1))}else n.push(e.parseWordFromString(o,l.quoted,l.singleQuoted))}else if(e.check(p.LPAREN))e.error("syntax error near unexpected token `('");else break;let i=w.simpleCommand(s,n,r,a);return i.line=t,i}function Lr(e){let t=e.expect(p.ASSIGNMENT_WORD),r=t.value,s=r.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);s||e.error(`Invalid assignment: ${r}`);let n=s[0],a,i=n.length;if(r[i]==="["){let f=0,h=i+1;for(;i<r.length;i++)if(r[i]==="[")f++;else if(r[i]==="]"&&(f--,f===0))break;f!==0&&e.error(`Invalid assignment: ${r}`),a=r.slice(h,i),i++}let l=r[i]==="+";l&&i++,r[i]!=="="&&e.error(`Invalid assignment: ${r}`),i++;let o=r.slice(i);if(o==="("){let f=Ke(e);e.expect(p.RPAREN);let h=a!==void 0?`${n}[${a}]`:n;return w.assignment(h,null,l,f)}if(o===""&&e.check(p.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let h=Ke(e);e.expect(p.RPAREN);let d=a!==void 0?`${n}[${a}]`:n;return w.assignment(d,null,l,h)}}let c=o?e.parseWordFromString(o,t.quoted,t.singleQuoted,!0):null,u=a!==void 0?`${n}[${a}]`:n;return w.assignment(u,c,l,null)}var Wr=new Set([p.AMP,p.PIPE,p.PIPE_AMP,p.SEMICOLON,p.AND_AND,p.OR_OR,p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND]);function Ke(e){let t=[];for(e.skipNewlines();!e.check(p.RPAREN,p.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):Wr.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function Xe(e,t){e.expect(p.IF);let r=[],s=e.parseCompoundList();e.expect(p.THEN);let n=e.parseCompoundList();if(n.length===0){let l=e.check(p.FI)?"fi":e.check(p.ELSE)?"else":e.check(p.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${l}'`)}for(r.push({condition:s,body:n});e.check(p.ELIF);){e.advance();let l=e.parseCompoundList();e.expect(p.THEN);let o=e.parseCompoundList();if(o.length===0){let c=e.check(p.FI)?"fi":e.check(p.ELSE)?"else":e.check(p.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${c}'`)}r.push({condition:l,body:o})}let a=null;e.check(p.ELSE)&&(e.advance(),a=e.parseCompoundList(),a.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(p.FI);let i=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.ifNode(r,a,i)}function Je(e,t){let r=e.expect(p.FOR);if(e.check(p.DPAREN_START))return Mr(e,t,r.line);e.isWord()||e.error("Expected variable name in for loop");let n=e.advance().value,a=null;if(e.skipNewlines(),e.check(p.IN))for(e.advance(),a=[];!e.check(p.SEMICOLON,p.NEWLINE,p.DO,p.EOF)&&e.isWord();)a.push(e.parseWord());e.check(p.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(p.DO);let i=e.parseCompoundList();e.expect(p.DONE);let l=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.forNode(n,a,i,l)}function Mr(e,t,r){e.expect(p.DPAREN_START);let s=null,n=null,a=null,i=["","",""],l=0,o=0;for(;!e.check(p.DPAREN_END,p.EOF);){let f=e.advance();if(f.type===p.SEMICOLON&&o===0){if(l++,l>2)break}else f.value==="("&&o++,f.value===")"&&o--,i[l]+=f.value}e.expect(p.DPAREN_END),i[0].trim()&&(s=M(e,i[0].trim())),i[1].trim()&&(n=M(e,i[1].trim())),i[2].trim()&&(a=M(e,i[2].trim())),e.skipNewlines(),e.check(p.SEMICOLON)&&e.advance(),e.skipNewlines();let c;e.check(p.LBRACE)?(e.advance(),c=e.parseCompoundList(),e.expect(p.RBRACE)):(e.expect(p.DO),c=e.parseCompoundList(),e.expect(p.DONE));let u=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:s,condition:n,update:a,body:c,redirections:u,line:r}}function Ye(e,t){e.expect(p.WHILE);let r=e.parseCompoundList();e.expect(p.DO);let s=e.parseCompoundList();s.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(p.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.whileNode(r,s,n)}function et(e,t){e.expect(p.UNTIL);let r=e.parseCompoundList();e.expect(p.DO);let s=e.parseCompoundList();s.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(p.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.untilNode(r,s,n)}function tt(e,t){e.expect(p.CASE),e.isWord()||e.error("Expected word after 'case'");let r=e.parseWord();e.skipNewlines(),e.expect(p.IN),e.skipNewlines();let s=[];for(;!e.check(p.ESAC,p.EOF);){e.checkIterationLimit();let a=e.getPos(),i=Vr(e);if(i&&s.push(i),e.skipNewlines(),e.getPos()===a&&!i)break}e.expect(p.ESAC);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.caseNode(r,s,n)}function Vr(e){e.check(p.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(p.PIPE));)e.advance();if(t.length===0)return null;e.expect(p.RPAREN),e.skipNewlines();let r=[];for(;!e.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND,p.ESAC,p.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===p.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(p.LPAREN)&&e.peek(1).type===p.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let n=e.getPos(),a=e.parseStatement();if(a&&r.push(a),e.skipSeparators(!1),e.getPos()===n&&!a)break}let s=";;";return e.check(p.DSEMI)?(e.advance(),s=";;"):e.check(p.SEMI_AND)?(e.advance(),s=";&"):e.check(p.SEMI_SEMI_AND)&&(e.advance(),s=";;&"),w.caseItem(t,r,s)}function nt(e,t){e.expect(p.LPAREN);let r=e.parseCompoundList();e.expect(p.RPAREN);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.subshell(r,s)}function rt(e,t){e.expect(p.LBRACE);let r=e.parseCompoundList();e.expect(p.RBRACE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.group(r,s)}var Br=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],Fr=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function rn(e){return e.isWord()||e.check(p.LBRACE)||e.check(p.RBRACE)||e.check(p.ASSIGNMENT_WORD)}function sn(e){if(e.check(p.BANG)&&e.peek(1).type===p.LPAREN){e.advance(),e.advance();let t=1,r="!(";for(;t>0&&!e.check(p.EOF);)if(e.check(p.LPAREN))t++,r+="(",e.advance();else if(e.check(p.RPAREN))t--,t>0&&(r+=")"),e.advance();else if(e.isWord())r+=e.advance().value;else if(e.check(p.PIPE))r+="|",e.advance();else break;return r+=")",e.parseWordFromString(r,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function it(e){return e.skipNewlines(),zr(e)}function zr(e){let t=an(e);for(e.skipNewlines();e.check(p.OR_OR);){e.advance(),e.skipNewlines();let r=an(e);t={type:"CondOr",left:t,right:r},e.skipNewlines()}return t}function an(e){let t=st(e);for(e.skipNewlines();e.check(p.AND_AND);){e.advance(),e.skipNewlines();let r=st(e);t={type:"CondAnd",left:t,right:r},e.skipNewlines()}return t}function st(e){return e.skipNewlines(),e.check(p.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:st(e)}):Gr(e)}function Gr(e){if(e.check(p.LPAREN)){e.advance();let t=it(e);return e.expect(p.RPAREN),{type:"CondGroup",expression:t}}if(rn(e)){let t=e.current(),r=t.value;if(Br.includes(r)&&!t.quoted){if(e.advance(),e.check(p.DBRACK_END)&&e.error(`Expected operand after ${r}`),rn(e)){let a=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:r,operand:a}}let n=e.current();e.error(`unexpected argument \`${n.value}' to conditional unary operator`)}let s=e.parseWordNoBraceExpansion();if(e.isWord()&&Fr.includes(e.current().value)){let n=e.advance().value,a;return n==="=~"?a=Qr(e):n==="=="||n==="!="?a=sn(e):a=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:n,left:s,right:a}}if(e.check(p.LESS)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:s,right:n}}if(e.check(p.GREAT)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:s,right:n}}if(e.isWord()&&e.current().value==="="){e.advance();let n=sn(e);return{type:"CondBinary",operator:"==",left:s,right:n}}return{type:"CondWord",word:s}}e.error("Expected conditional expression")}function Qr(e){let t=[],r=0,s=-1,n=e.getInput(),a=()=>e.check(p.DBRACK_END)||e.check(p.AND_AND)||e.check(p.OR_OR)||e.check(p.NEWLINE)||e.check(p.EOF);for(;!a();){let i=e.current(),l=s>=0&&i.start>s;if(r===0&&l)break;if(r>0&&l){let o=n.slice(s,i.start);t.push({type:"Literal",value:o})}if(e.isWord()||e.check(p.ASSIGNMENT_WORD)){let o=e.parseWordForRegex();t.push(...o.parts),s=e.peek(-1).end}else if(e.check(p.LPAREN)){let o=e.advance();t.push({type:"Literal",value:"("}),r++,s=o.end}else if(e.check(p.DPAREN_START)){let o=e.advance();t.push({type:"Literal",value:"(("}),r+=2,s=o.end}else if(e.check(p.DPAREN_END))if(r>=2){let o=e.advance();t.push({type:"Literal",value:"))"}),r-=2,s=o.end}else{if(r===1)break;break}else if(e.check(p.RPAREN))if(r>0){let o=e.advance();t.push({type:"Literal",value:")"}),r--,s=o.end}else break;else if(e.check(p.PIPE)){let o=e.advance();t.push({type:"Literal",value:"|"}),s=o.end}else if(e.check(p.SEMICOLON))if(r>0){let o=e.advance();t.push({type:"Literal",value:";"}),s=o.end}else break;else if(r>0&&e.check(p.LESS)){let o=e.advance();t.push({type:"Literal",value:"<"}),s=o.end}else if(r>0&&e.check(p.GREAT)){let o=e.advance();t.push({type:"Literal",value:">"}),s=o.end}else if(r>0&&e.check(p.DGREAT)){let o=e.advance();t.push({type:"Literal",value:">>"}),s=o.end}else if(r>0&&e.check(p.DLESS)){let o=e.advance();t.push({type:"Literal",value:"<<"}),s=o.end}else if(r>0&&e.check(p.LESSAND)){let o=e.advance();t.push({type:"Literal",value:"<&"}),s=o.end}else if(r>0&&e.check(p.GREATAND)){let o=e.advance();t.push({type:"Literal",value:">&"}),s=o.end}else if(r>0&&e.check(p.LESSGREAT)){let o=e.advance();t.push({type:"Literal",value:"<>"}),s=o.end}else if(r>0&&e.check(p.CLOBBER)){let o=e.advance();t.push({type:"Literal",value:">|"}),s=o.end}else if(r>0&&e.check(p.TLESS)){let o=e.advance();t.push({type:"Literal",value:"<<<"}),s=o.end}else if(r>0&&e.check(p.AMP)){let o=e.advance();t.push({type:"Literal",value:"&"}),s=o.end}else if(r>0&&e.check(p.LBRACE)){let o=e.advance();t.push({type:"Literal",value:"{"}),s=o.end}else if(r>0&&e.check(p.RBRACE)){let o=e.advance();t.push({type:"Literal",value:"}"}),s=o.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function Ur(e,t){let r=1,s=t+1;for(;s<e.length&&r>0;){let n=e[s];if(n==="\\"){s+=2;continue}if("@*+?!".includes(n)&&s+1<e.length&&e[s+1]==="("){s++,r++,s++;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function Hr(e,t,r){let s=r+1,n=t[s];if("@*#?$!-0123456789".includes(n))return{part:w.parameterExpansion(n),endIndex:s+1};let a="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)a+=t[s],s++;return{part:w.parameterExpansion(a),endIndex:s}}function jr(e,t,r,s=!1){let n=r+2,a=!1;t[n]==="!"&&(a=!0,n++);let i=!1;t[n]==="#"&&!/[}:#%/^,]/.test(t[n+1]||"}")&&(i=!0,n++);let l="",o=t[n];if(/[@*#?$!-]/.test(o)&&!/[a-zA-Z0-9_]/.test(t[n+1]||""))l=o,n++;else for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)l+=t[n],n++;if(t[n]==="["){let u=Ue(e,t,n,"[","]");if(l+=t.slice(n,u+1),n=u+1,t[n]==="["){let f=1,h=n;for(;h<t.length&&f>0;)t[h]==="{"?f++:t[h]==="}"&&f--,f>0&&h++;let d=t.slice(r+2,h);return{part:w.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:h+1}}}if(l===""&&!a&&!i&&t[n]!=="}"){let u=1,f=n;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;if(u>0)throw new G("unexpected EOF while looking for matching '}'",0,0);let h=t.slice(r+2,f);return{part:w.parameterExpansion("",{type:"BadSubstitution",text:h}),endIndex:f+1}}let c=null;if(a){let u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)if(n<t.length&&t[n]!=="}"&&/[:=\-+?#%/^,@]/.test(t[n])){let f=at(e,t,n,l,s);f.operation?(c={type:"Indirection",innerOp:f.operation},n=f.endIndex):(c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},l="")}else c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},l="";else if(t[n]==="*"||t[n]==="@"&&!/[QPaAEKkuUL]/.test(t[n+1]||"")){let f=t[n];n++,c={type:"VarNamePrefix",prefix:l,star:f==="*"},l=""}else if(n<t.length&&t[n]!=="}"&&/[:=\-+?#%/^,@]/.test(t[n])){let f=at(e,t,n,l,s);f.operation?(c={type:"Indirection",innerOp:f.operation},n=f.endIndex):c={type:"Indirection"}}else c={type:"Indirection"}}else if(i)if(t[n]===":")for(c={type:"LengthSliceError"};n<t.length&&t[n]!=="}";)n++;else t[n]!=="}"&&/[-+=?]/.test(t[n])?e.error(`\${#${l}${t.slice(n,t.indexOf("}",n))}}: bad substitution`):t[n]==="/"?e.error(`\${#${l}${t.slice(n,t.indexOf("}",n))}}: bad substitution`):c={type:"Length"};if(!c&&n<t.length&&t[n]!=="}"){let u=at(e,t,n,l,s);c=u.operation,n=u.endIndex}if(n<t.length&&t[n]!=="}"){let u=t[n];if(!/[:\-+=?#%/^,@[]/.test(u)){let f=n;for(;f<t.length&&t[f]!=="}";)f++;let h=t.slice(r,f+1);e.error(`\${${h.slice(2,-1)}}: bad substitution`)}}for(;n<t.length&&t[n]!=="}";)n++;if(n>=t.length)throw new G("unexpected EOF while looking for matching '}'",0,0);return{part:w.parameterExpansion(l,c),endIndex:n+1}}function at(e,t,r,s,n=!1){let a=r,i=t[a],l=t[a+1]||"";if(i===":"){let o=l;if("-=?+".includes(o)){a+=2;let A=fe(e,t,a),S=t.slice(a,A),y=ae(e,S,!1,!1,!0,!1,n,!1,!1,!0),b=w.word(y.length>0?y:[w.literal("")]);if(o==="-")return{operation:{type:"DefaultValue",word:b,checkEmpty:!0},endIndex:A};if(o==="=")return{operation:{type:"AssignDefault",word:b,checkEmpty:!0},endIndex:A};if(o==="?")return{operation:{type:"ErrorIfUnset",word:b,checkEmpty:!0},endIndex:A};if(o==="+")return{operation:{type:"UseAlternative",word:b,checkEmpty:!0},endIndex:A}}a++;let c=fe(e,t,a),u=t.slice(a,c),f=-1,h=0,d=0;for(let E=0;E<u.length;E++){let A=u[E];if(A==="("||A==="[")h++;else if(A===")"||A==="]")h--;else if(A==="?"&&h===0)d++;else if(A===":"&&h===0)if(d>0)d--;else{f=E;break}}let m=f>=0?u.slice(0,f):u,g=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:He(e,m),length:g!==null?He(e,g):null},endIndex:c}}if("-=?+".includes(i)){a++;let o=fe(e,t,a),c=t.slice(a,o),u=ae(e,c,!1,!1,!0,!1,n,!1,!1,!0),f=w.word(u.length>0?u:[w.literal("")]);if(i==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:o};if(i==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:o};if(i==="?")return{operation:{type:"ErrorIfUnset",word:c?f:null,checkEmpty:!1},endIndex:o};if(i==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:o}}if(i==="#"||i==="%"){let o=l===i,c=i==="#"?"prefix":"suffix";a+=o?2:1;let u=fe(e,t,a),f=t.slice(a,u),h=ae(e,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:w.word(h.length>0?h:[w.literal("")]),side:c,greedy:o},endIndex:u}}if(i==="/"){let o=l==="/";a+=o?2:1;let c=null;t[a]==="#"?(c="start",a++):t[a]==="%"&&(c="end",a++);let u;c!==null&&(t[a]==="/"||t[a]==="}")?u=a:u=Kt(e,t,a);let f=t.slice(a,u),h=ae(e,f,!1,!1,!1),d=w.word(h.length>0?h:[w.literal("")]),m=null,g=u;if(t[u]==="/"){let E=u+1,A=fe(e,t,E),S=t.slice(E,A),y=ae(e,S,!1,!1,!1);m=w.word(y.length>0?y:[w.literal("")]),g=A}return{operation:{type:"PatternReplacement",pattern:d,replacement:m,all:o,anchor:c},endIndex:g}}if(i==="^"||i===","){let o=l===i,c=i==="^"?"upper":"lower";a+=o?2:1;let u=fe(e,t,a),f=t.slice(a,u),h=f?w.word([w.literal(f)]):null;return{operation:{type:"CaseModification",direction:c,all:o,pattern:h},endIndex:u}}return i==="@"&&/[QPaAEKkuUL]/.test(l)?{operation:{type:"Transform",operator:l},endIndex:a+2}:{operation:null,endIndex:a}}function ot(e,t,r,s=!1){let n=r+1;if(n>=t.length)return{part:w.literal("$"),endIndex:n};let a=t[n];if(a==="("&&t[n+1]==="(")return e.isDollarDparenSubshell(t,r)?e.parseCommandSubstitution(t,r):e.parseArithmeticExpansion(t,r);if(a==="["){let i=1,l=n+1;for(;l<t.length&&i>0;)t[l]==="["?i++:t[l]==="]"&&i--,i>0&&l++;if(i===0){let o=t.slice(n+1,l),c=M(e,o);return{part:w.arithmeticExpansion(c),endIndex:l+1}}}return a==="("?e.parseCommandSubstitution(t,r):a==="{"?jr(e,t,r,s):/[a-zA-Z_0-9@*#?$!-]/.test(a)?Hr(e,t,r):{part:w.literal("$"),endIndex:n}}function on(e,t){let r=[],s=0,n="",a=()=>{n&&(r.push(w.literal(n)),n="")};for(;s<t.length;){let i=t[s];if(i==="\\"&&s+1<t.length){let l=t[s+1];if(l==="$"||l==="`"||l==='"'||l==="\\"){n+=l,s+=2;continue}n+=i,s++;continue}if(i==="$"){a();let{part:l,endIndex:o}=ot(e,t,s,!0);l&&r.push(l),s=o;continue}if(i==="`"){a();let{part:l,endIndex:o}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=o;continue}n+=i,s++}return a(),r}function Kr(e,t,r){let s=[],n=r,a="",i=()=>{a&&(s.push(w.literal(a)),a="")};for(;n<t.length&&t[n]!=='"';){let l=t[n];if(l==="\\"&&n+1<t.length){let o=t[n+1];if('"\\$`\n'.includes(o)){a+=o,n+=2;continue}a+=l,n++;continue}if(l==="$"){i();let{part:o,endIndex:c}=ot(e,t,n,!0);o&&s.push(o),n=c;continue}if(l==="`"){i();let{part:o,endIndex:c}=e.parseBacktickSubstitution(t,n,!0);s.push(o),n=c;continue}a+=l,n++}return i(),{part:w.doubleQuoted(s),endIndex:n}}function ae(e,t,r=!1,s=!1,n=!1,a=!1,i=!1,l=!1,o=!1,c=!1){if(s)return[w.singleQuoted(t)];if(r){let m=on(e,t);return[w.doubleQuoted(m)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let m=t.slice(1,-1),g=!1;for(let E=0;E<m.length;E++){if(m[E]==='"'){g=!0;break}m[E]==="\\"&&E+1<m.length&&E++}if(!g){let E=on(e,m);return[w.doubleQuoted(E)]}}let u=[],f=0,h="",d=()=>{h&&(u.push(w.literal(h)),h="")};for(;f<t.length;){let m=t[f];if(m==="\\"&&f+1<t.length){let g=t[f+1];if(o){d(),u.push(w.escaped(g)),f+=2;continue}let E=a?g==="$"||g==="`"||g===`
|
|
43
|
+
`);)f=!0,u++;if(f&&u<s&&r[u]===")")return!0}if(a===0)return!1;n++;continue}if(a===1&&(o==="|"&&n+1<s&&r[n+1]==="|"||o==="&"&&n+1<s&&r[n+1]==="&"||o==="|"&&n+1<s&&r[n+1]!=="|"))return!0;n++}return!1}};var Qe=1e6,Ze=1e5,Qt=1e6,Ue=200,Zt=new Set([p.LESS,p.GREAT,p.DLESS,p.DGREAT,p.LESSAND,p.GREATAND,p.LESSGREAT,p.DLESSDASH,p.CLOBBER,p.TLESS,p.AND_GREAT,p.AND_DGREAT]),Ut=new Set([p.LESS,p.GREAT,p.DLESS,p.DGREAT,p.LESSAND,p.GREATAND,p.LESSGREAT,p.DLESSDASH,p.CLOBBER,p.TLESS]),Ht=new Set([p.LESS,p.GREAT,p.DLESS,p.DGREAT,p.LESSAND,p.GREATAND,p.LESSGREAT,p.DLESSDASH,p.CLOBBER,p.TLESS,p.AND_GREAT,p.AND_DGREAT]),G=class extends Error{line;column;token;constructor(t,r,s,n=void 0){super(`Parse error at ${r}:${s}: ${t}`),this.line=r,this.column=s,this.token=n,this.name="ParseException"}};function Cr(e){let t="",r=0;for(;r<e.length;){let s=e[r];if(s<128){t+=String.fromCharCode(s),r++;continue}if((s&224)===192){if(r+1<e.length&&(e[r+1]&192)===128&&s>=194){let n=(s&31)<<6|e[r+1]&63;t+=String.fromCharCode(n),r+=2;continue}t+=String.fromCharCode(s),r++;continue}if((s&240)===224){if(r+2<e.length&&(e[r+1]&192)===128&&(e[r+2]&192)===128){if(s===224&&e[r+1]<160){t+=String.fromCharCode(s),r++;continue}let n=(s&15)<<12|(e[r+1]&63)<<6|e[r+2]&63;if(n>=55296&&n<=57343){t+=String.fromCharCode(s),r++;continue}t+=String.fromCharCode(n),r+=3;continue}t+=String.fromCharCode(s),r++;continue}if((s&248)===240&&s<=244){if(r+3<e.length&&(e[r+1]&192)===128&&(e[r+2]&192)===128&&(e[r+3]&192)===128){if(s===240&&e[r+1]<144){t+=String.fromCharCode(s),r++;continue}let n=(s&7)<<18|(e[r+1]&63)<<12|(e[r+2]&63)<<6|e[r+3]&63;if(n>1114111){t+=String.fromCharCode(s),r++;continue}t+=String.fromCodePoint(n),r+=4;continue}t+=String.fromCharCode(s),r++;continue}t+=String.fromCharCode(s),r++}return t}function Kt(e,t,r){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_-]/.test(t[s]);)s++;return s}function He(e,t,r,s,n){let a=1,i=r+1;for(;i<t.length&&a>0;)t[i]===s?a++:t[i]===n&&a--,a>0&&i++;return a===0?i:-1}function fe(e,t,r){let s=r,n=1;for(;s<t.length&&n>0;){let a=t[s];if(a==="\\"&&s+1<t.length){s+=2;continue}if(a==="'"){let i=t.indexOf("'",s+1);if(i!==-1){s=i+1;continue}}if(a==='"'){for(s++;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?s+=2:s++;s<t.length&&s++;continue}a==="{"?n++:a==="}"&&n--,n>0&&s++}return s}function Xt(e,t,r){let s=r,n=!1;for(;s<t.length;){let a=t[s];if(a==="/"&&n||a==="}")break;if(a==="'"){let i=t.indexOf("'",s+1);if(i!==-1){s=i+1,n=!0;continue}}if(a==='"'){for(s++;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?s+=2:s++;s<t.length&&s++,n=!0;continue}a==="\\"?(s+=2,n=!0):(s++,n=!0)}return s}function Jt(e,t,r){let s=r,n="";for(;s<t.length;){let a=t[s];if(a==="*"||a==="?")n+=a,s++;else if(a==="["){let i=Or(t,s);i===-1?(n+=a,s++):(n+=t.slice(s,i+1),s=i+1)}else break}return{pattern:n,endIndex:s}}function Or(e,t){let r=t+1;for(r<e.length&&e[r]==="^"&&r++,r<e.length&&e[r]==="]"&&r++;r<e.length;){let s=e[r];if(s==="\\"&&r+1<e.length){let n=e[r+1];if(n==='"'||n==="'")return-1;r+=2;continue}if(s==="]")return r;if(s==='"'||s==="$"||s==="`")return-1;if(s==="'"){let n=e.indexOf("'",r+1);if(n!==-1){r=n+1;continue}}if(s==="["&&r+1<e.length&&e[r+1]===":"){let n=e.indexOf(":]",r+2);if(n!==-1){r=n+2;continue}}if(s==="["&&r+1<e.length&&(e[r+1]==="."||e[r+1]==="=")){let a=`${e[r+1]}]`,i=e.indexOf(a,r+2);if(i!==-1){r=i+2;continue}}r++}return-1}function Yt(e,t,r){let s="",n=r;for(;n<t.length&&t[n]!=="'";){let a=t[n];if(a==="\\"&&n+1<t.length)switch(t[n+1]){case"n":s+=`
|
|
44
|
+
`,n+=2;break;case"t":s+=" ",n+=2;break;case"r":s+="\r",n+=2;break;case"\\":s+="\\",n+=2;break;case"'":s+="'",n+=2;break;case'"':s+='"',n+=2;break;case"a":s+="\x07",n+=2;break;case"b":s+="\b",n+=2;break;case"e":case"E":s+="\x1B",n+=2;break;case"f":s+="\f",n+=2;break;case"v":s+="\v",n+=2;break;case"x":{let l=[],o=n;for(;o+1<t.length&&t[o]==="\\"&&t[o+1]==="x";){let c=t.slice(o+2,o+4),u=parseInt(c,16);if(!Number.isNaN(u)&&c.length>0)l.push(u),o+=2+c.length;else break}l.length>0?(s+=Cr(l),n=o):(s+="\\x",n+=2);break}case"u":{let l=t.slice(n+2,n+6),o=parseInt(l,16);Number.isNaN(o)?(s+="\\u",n+=2):(s+=String.fromCharCode(o),n+=6);break}case"c":{if(n+2<t.length){let o=t[n+2].charCodeAt(0)&31;s+=String.fromCharCode(o),n+=3}else s+="\\c",n+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let l="",o=n+1;for(;o<t.length&&o<n+4&&/[0-7]/.test(t[o]);)l+=t[o],o++;let c=parseInt(l,8);s+=String.fromCharCode(c),n=o;break}default:s+=a,n++}else s+=a,n++}return n<t.length&&t[n]==="'"&&n++,{part:w.literal(s),endIndex:n}}function je(e,t){let r=t.trim();return r===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:M(e,r)}function jt(e){let t=[],r="",s=0;for(let n=0;n<e.length;n++){let a=e[n];a==="{"?(s++,r+=a):a==="}"?(s--,r+=a):a===","&&s===0?(t.push(r),r=""):r+=a}return t.push(r),t}function en(e,t,r,s){let n=He(e,t,r,"{","}");if(n===-1)return null;let a=t.slice(r+1,n),i=a.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(i)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(i[1],10),end:Number.parseInt(i[2],10),step:i[3]?Number.parseInt(i[3],10):void 0,startStr:i[1],endStr:i[2]}]},endIndex:n+1};let l=a.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return l?{part:{type:"BraceExpansion",items:[{type:"Range",start:l[1],end:l[2],step:l[3]?Number.parseInt(l[3],10):void 0}]},endIndex:n+1}:a.includes(",")&&s?{part:{type:"BraceExpansion",items:jt(a).map(u=>({type:"Word",word:w.word(s(e,u,!1,!1,!1))}))},endIndex:n+1}:a.includes(",")?{part:{type:"BraceExpansion",items:jt(a).map(u=>({type:"Word",word:w.word([w.literal(u)])}))},endIndex:n+1}:null}function Ke(e,t){let r="";for(let s of t.parts)switch(s.type){case"Literal":r+=s.value;break;case"SingleQuoted":r+=`'${s.value}'`;break;case"Escaped":r+=s.value;break;case"DoubleQuoted":r+='"';for(let n of s.parts)n.type==="Literal"||n.type==="Escaped"?r+=n.value:n.type==="ParameterExpansion"&&(r+=`\${${n.parameter}}`);r+='"';break;case"ParameterExpansion":r+=`\${${s.parameter}}`;break;case"Glob":r+=s.pattern;break;case"TildeExpansion":r+="~",s.user&&(r+=s.user);break;case"BraceExpansion":{r+="{";let n=[];for(let a of s.items)if(a.type==="Range"){let i=a.startStr??String(a.start),l=a.endStr??String(a.end);a.step!==void 0?n.push(`${i}..${l}..${a.step}`):n.push(`${i}..${l}`)}else n.push(Ke(e,a.word));n.length===1&&s.items[0].type==="Range"?r+=n[0]:r+=n.join(","),r+="}";break}default:r+=s.type}return r}function tn(e,t){return{[p.LESS]:"<",[p.GREAT]:">",[p.DGREAT]:">>",[p.LESSAND]:"<&",[p.GREATAND]:">&",[p.LESSGREAT]:"<>",[p.CLOBBER]:">|",[p.TLESS]:"<<<",[p.AND_GREAT]:"&>",[p.AND_DGREAT]:"&>>",[p.DLESS]:"<",[p.DLESSDASH]:"<"}[t]||">"}function De(e){let t=e.current(),r=t.type;if(r===p.NUMBER){let s=e.peek(1);return t.end!==s.start?!1:Ut.has(s.type)}if(r===p.FD_VARIABLE){let s=e.peek(1);return Ht.has(s.type)}return Zt.has(r)}function xe(e){let t=null,r;e.check(p.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(p.FD_VARIABLE)&&(r=e.advance().value);let s=e.advance(),n=tn(e,s.type);if(s.type===p.DLESS||s.type===p.DLESSDASH)return Lr(e,n,t,s.type===p.DLESSDASH);e.isWord()||e.error("Expected redirection target");let a=e.parseWord();return w.redirection(n,a,t,r)}function Lr(e,t,r,s){e.isWord()||e.error("Expected here-document delimiter");let n=e.advance(),a=n.value,i=n.quoted||!1;(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1));let l=w.redirection(s?"<<-":"<<",w.hereDoc(a,w.word([]),s,i),r);return e.addPendingHeredoc(l,a,s,i),l}function rn(e){let t=e.current().line,r=[],s=null,n=[],a=[];for(;e.check(p.ASSIGNMENT_WORD)||De(e);)e.checkIterationLimit(),e.check(p.ASSIGNMENT_WORD)?r.push(Wr(e)):a.push(xe(e));if(e.isWord())s=e.parseWord();else if(r.length>0&&(e.check(p.DBRACK_START)||e.check(p.DPAREN_START))){let l=e.advance();s=w.word([w.literal(l.value)])}for(;(!e.isStatementEnd()||e.check(p.RBRACE))&&!e.check(p.PIPE,p.PIPE_AMP);)if(e.checkIterationLimit(),De(e))a.push(xe(e));else if(e.check(p.RBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(p.LBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(p.DBRACK_END)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.isWord())n.push(e.parseWord());else if(e.check(p.ASSIGNMENT_WORD)){let l=e.advance(),o=l.value,c=o.endsWith("="),u=o.endsWith("=(");if((c||u)&&(u||e.check(p.LPAREN))){let f=u?o.slice(0,-2):o.slice(0,-1);u||e.expect(p.LPAREN);let h=Xe(e);e.expect(p.RPAREN);let d=h.map(g=>Ke(e,g)),m=`${f}=(${d.join(" ")})`;n.push(e.parseWordFromString(m,!1,!1))}else n.push(e.parseWordFromString(o,l.quoted,l.singleQuoted))}else if(e.check(p.LPAREN))e.error("syntax error near unexpected token `('");else break;let i=w.simpleCommand(s,n,r,a);return i.line=t,i}function Wr(e){let t=e.expect(p.ASSIGNMENT_WORD),r=t.value,s=r.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);s||e.error(`Invalid assignment: ${r}`);let n=s[0],a,i=n.length;if(r[i]==="["){let f=0,h=i+1;for(;i<r.length;i++)if(r[i]==="[")f++;else if(r[i]==="]"&&(f--,f===0))break;f!==0&&e.error(`Invalid assignment: ${r}`),a=r.slice(h,i),i++}let l=r[i]==="+";l&&i++,r[i]!=="="&&e.error(`Invalid assignment: ${r}`),i++;let o=r.slice(i);if(o==="("){let f=Xe(e);e.expect(p.RPAREN);let h=a!==void 0?`${n}[${a}]`:n;return w.assignment(h,null,l,f)}if(o===""&&e.check(p.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let h=Xe(e);e.expect(p.RPAREN);let d=a!==void 0?`${n}[${a}]`:n;return w.assignment(d,null,l,h)}}let c=o?e.parseWordFromString(o,t.quoted,t.singleQuoted,!0):null,u=a!==void 0?`${n}[${a}]`:n;return w.assignment(u,c,l,null)}var Tr=new Set([p.AMP,p.PIPE,p.PIPE_AMP,p.SEMICOLON,p.AND_AND,p.OR_OR,p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND]);function Xe(e){let t=[];for(e.skipNewlines();!e.check(p.RPAREN,p.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):Tr.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function Je(e,t){e.expect(p.IF);let r=[],s=e.parseCompoundList();e.expect(p.THEN);let n=e.parseCompoundList();if(n.length===0){let l=e.check(p.FI)?"fi":e.check(p.ELSE)?"else":e.check(p.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${l}'`)}for(r.push({condition:s,body:n});e.check(p.ELIF);){e.advance();let l=e.parseCompoundList();e.expect(p.THEN);let o=e.parseCompoundList();if(o.length===0){let c=e.check(p.FI)?"fi":e.check(p.ELSE)?"else":e.check(p.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${c}'`)}r.push({condition:l,body:o})}let a=null;e.check(p.ELSE)&&(e.advance(),a=e.parseCompoundList(),a.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(p.FI);let i=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.ifNode(r,a,i)}function Ye(e,t){let r=e.expect(p.FOR);if(e.check(p.DPAREN_START))return Vr(e,t,r.line);e.isWord()||e.error("Expected variable name in for loop");let n=e.advance().value,a=null;if(e.skipNewlines(),e.check(p.IN))for(e.advance(),a=[];!e.check(p.SEMICOLON,p.NEWLINE,p.DO,p.EOF)&&e.isWord();)a.push(e.parseWord());e.check(p.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(p.DO);let i=e.parseCompoundList();e.expect(p.DONE);let l=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.forNode(n,a,i,l)}function Vr(e,t,r){e.expect(p.DPAREN_START);let s=null,n=null,a=null,i=["","",""],l=0,o=0;for(;!e.check(p.DPAREN_END,p.EOF);){let f=e.advance();if(f.type===p.SEMICOLON&&o===0){if(l++,l>2)break}else f.value==="("&&o++,f.value===")"&&o--,i[l]+=f.value}e.expect(p.DPAREN_END),i[0].trim()&&(s=M(e,i[0].trim())),i[1].trim()&&(n=M(e,i[1].trim())),i[2].trim()&&(a=M(e,i[2].trim())),e.skipNewlines(),e.check(p.SEMICOLON)&&e.advance(),e.skipNewlines();let c;e.check(p.LBRACE)?(e.advance(),c=e.parseCompoundList(),e.expect(p.RBRACE)):(e.expect(p.DO),c=e.parseCompoundList(),e.expect(p.DONE));let u=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:s,condition:n,update:a,body:c,redirections:u,line:r}}function et(e,t){e.expect(p.WHILE);let r=e.parseCompoundList();e.expect(p.DO);let s=e.parseCompoundList();s.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(p.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.whileNode(r,s,n)}function tt(e,t){e.expect(p.UNTIL);let r=e.parseCompoundList();e.expect(p.DO);let s=e.parseCompoundList();s.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(p.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.untilNode(r,s,n)}function nt(e,t){e.expect(p.CASE),e.isWord()||e.error("Expected word after 'case'");let r=e.parseWord();e.skipNewlines(),e.expect(p.IN),e.skipNewlines();let s=[];for(;!e.check(p.ESAC,p.EOF);){e.checkIterationLimit();let a=e.getPos(),i=qr(e);if(i&&s.push(i),e.skipNewlines(),e.getPos()===a&&!i)break}e.expect(p.ESAC);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.caseNode(r,s,n)}function qr(e){e.check(p.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(p.PIPE));)e.advance();if(t.length===0)return null;e.expect(p.RPAREN),e.skipNewlines();let r=[];for(;!e.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND,p.ESAC,p.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===p.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(p.LPAREN)&&e.peek(1).type===p.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let n=e.getPos(),a=e.parseStatement();if(a&&r.push(a),e.skipSeparators(!1),e.getPos()===n&&!a)break}let s=";;";return e.check(p.DSEMI)?(e.advance(),s=";;"):e.check(p.SEMI_AND)?(e.advance(),s=";&"):e.check(p.SEMI_SEMI_AND)&&(e.advance(),s=";;&"),w.caseItem(t,r,s)}function rt(e,t){e.expect(p.LPAREN);let r=e.parseCompoundList();e.expect(p.RPAREN);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.subshell(r,s)}function st(e,t){e.expect(p.LBRACE);let r=e.parseCompoundList();e.expect(p.RBRACE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.group(r,s)}var Fr=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],zr=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function sn(e){return e.isWord()||e.check(p.LBRACE)||e.check(p.RBRACE)||e.check(p.ASSIGNMENT_WORD)}function an(e){if(e.check(p.BANG)&&e.peek(1).type===p.LPAREN){e.advance(),e.advance();let t=1,r="!(";for(;t>0&&!e.check(p.EOF);)if(e.check(p.LPAREN))t++,r+="(",e.advance();else if(e.check(p.RPAREN))t--,t>0&&(r+=")"),e.advance();else if(e.isWord())r+=e.advance().value;else if(e.check(p.PIPE))r+="|",e.advance();else break;return r+=")",e.parseWordFromString(r,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function at(e){return e.skipNewlines(),Gr(e)}function Gr(e){let t=on(e);for(e.skipNewlines();e.check(p.OR_OR);){e.advance(),e.skipNewlines();let r=on(e);t={type:"CondOr",left:t,right:r},e.skipNewlines()}return t}function on(e){let t=it(e);for(e.skipNewlines();e.check(p.AND_AND);){e.advance(),e.skipNewlines();let r=it(e);t={type:"CondAnd",left:t,right:r},e.skipNewlines()}return t}function it(e){return e.skipNewlines(),e.check(p.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:it(e)}):Qr(e)}function Qr(e){if(e.check(p.LPAREN)){e.advance();let t=at(e);return e.expect(p.RPAREN),{type:"CondGroup",expression:t}}if(sn(e)){let t=e.current(),r=t.value;if(Fr.includes(r)&&!t.quoted){if(e.advance(),e.check(p.DBRACK_END)&&e.error(`Expected operand after ${r}`),sn(e)){let a=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:r,operand:a}}let n=e.current();e.error(`unexpected argument \`${n.value}' to conditional unary operator`)}let s=e.parseWordNoBraceExpansion();if(e.isWord()&&zr.includes(e.current().value)){let n=e.advance().value,a;return n==="=~"?a=Zr(e):n==="=="||n==="!="?a=an(e):a=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:n,left:s,right:a}}if(e.check(p.LESS)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:s,right:n}}if(e.check(p.GREAT)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:s,right:n}}if(e.isWord()&&e.current().value==="="){e.advance();let n=an(e);return{type:"CondBinary",operator:"==",left:s,right:n}}return{type:"CondWord",word:s}}e.error("Expected conditional expression")}function Zr(e){let t=[],r=0,s=-1,n=e.getInput(),a=()=>e.check(p.DBRACK_END)||e.check(p.AND_AND)||e.check(p.OR_OR)||e.check(p.NEWLINE)||e.check(p.EOF);for(;!a();){let i=e.current(),l=s>=0&&i.start>s;if(r===0&&l)break;if(r>0&&l){let o=n.slice(s,i.start);t.push({type:"Literal",value:o})}if(e.isWord()||e.check(p.ASSIGNMENT_WORD)){let o=e.parseWordForRegex();t.push(...o.parts),s=e.peek(-1).end}else if(e.check(p.LPAREN)){let o=e.advance();t.push({type:"Literal",value:"("}),r++,s=o.end}else if(e.check(p.DPAREN_START)){let o=e.advance();t.push({type:"Literal",value:"(("}),r+=2,s=o.end}else if(e.check(p.DPAREN_END))if(r>=2){let o=e.advance();t.push({type:"Literal",value:"))"}),r-=2,s=o.end}else{if(r===1)break;break}else if(e.check(p.RPAREN))if(r>0){let o=e.advance();t.push({type:"Literal",value:")"}),r--,s=o.end}else break;else if(e.check(p.PIPE)){let o=e.advance();t.push({type:"Literal",value:"|"}),s=o.end}else if(e.check(p.SEMICOLON))if(r>0){let o=e.advance();t.push({type:"Literal",value:";"}),s=o.end}else break;else if(r>0&&e.check(p.LESS)){let o=e.advance();t.push({type:"Literal",value:"<"}),s=o.end}else if(r>0&&e.check(p.GREAT)){let o=e.advance();t.push({type:"Literal",value:">"}),s=o.end}else if(r>0&&e.check(p.DGREAT)){let o=e.advance();t.push({type:"Literal",value:">>"}),s=o.end}else if(r>0&&e.check(p.DLESS)){let o=e.advance();t.push({type:"Literal",value:"<<"}),s=o.end}else if(r>0&&e.check(p.LESSAND)){let o=e.advance();t.push({type:"Literal",value:"<&"}),s=o.end}else if(r>0&&e.check(p.GREATAND)){let o=e.advance();t.push({type:"Literal",value:">&"}),s=o.end}else if(r>0&&e.check(p.LESSGREAT)){let o=e.advance();t.push({type:"Literal",value:"<>"}),s=o.end}else if(r>0&&e.check(p.CLOBBER)){let o=e.advance();t.push({type:"Literal",value:">|"}),s=o.end}else if(r>0&&e.check(p.TLESS)){let o=e.advance();t.push({type:"Literal",value:"<<<"}),s=o.end}else if(r>0&&e.check(p.AMP)){let o=e.advance();t.push({type:"Literal",value:"&"}),s=o.end}else if(r>0&&e.check(p.LBRACE)){let o=e.advance();t.push({type:"Literal",value:"{"}),s=o.end}else if(r>0&&e.check(p.RBRACE)){let o=e.advance();t.push({type:"Literal",value:"}"}),s=o.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function Ee(e){return e.length>0?e:[w.literal("")]}function Hr(e,t){let r=1,s=t+1;for(;s<e.length&&r>0;){let n=e[s];if(n==="\\"){s+=2;continue}if("@*+?!".includes(n)&&s+1<e.length&&e[s+1]==="("){s++,r++,s++;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function jr(e,t,r){let s=r+1,n=t[s];if("@*#?$!-0123456789".includes(n))return{part:w.parameterExpansion(n),endIndex:s+1};let a="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)a+=t[s],s++;return{part:w.parameterExpansion(a),endIndex:s}}function Kr(e,t,r,s=!1){let n=r+2,a=!1;t[n]==="!"&&(a=!0,n++);let i=!1;t[n]==="#"&&!/[}:#%/^,]/.test(t[n+1]||"}")&&(i=!0,n++);let l="",o=t[n];if(/[@*#?$!-]/.test(o)&&!/[a-zA-Z0-9_]/.test(t[n+1]||""))l=o,n++;else for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)l+=t[n],n++;if(t[n]==="["){let u=He(e,t,n,"[","]");if(l+=t.slice(n,u+1),n=u+1,t[n]==="["){let f=1,h=n;for(;h<t.length&&f>0;)t[h]==="{"?f++:t[h]==="}"&&f--,f>0&&h++;let d=t.slice(r+2,h);return{part:w.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:h+1}}}if(l===""&&!a&&!i&&t[n]!=="}"){let u=1,f=n;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;if(u>0)throw new G("unexpected EOF while looking for matching '}'",0,0);let h=t.slice(r+2,f);return{part:w.parameterExpansion("",{type:"BadSubstitution",text:h}),endIndex:f+1}}let c=null;if(a){let u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)if(n<t.length&&t[n]!=="}"&&/[:=\-+?#%/^,@]/.test(t[n])){let f=ot(e,t,n,l,s);f.operation?(c={type:"Indirection",innerOp:f.operation},n=f.endIndex):(c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},l="")}else c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},l="";else if(t[n]==="*"||t[n]==="@"&&!/[QPaAEKkuUL]/.test(t[n+1]||"")){let f=t[n];n++,c={type:"VarNamePrefix",prefix:l,star:f==="*"},l=""}else if(n<t.length&&t[n]!=="}"&&/[:=\-+?#%/^,@]/.test(t[n])){let f=ot(e,t,n,l,s);f.operation?(c={type:"Indirection",innerOp:f.operation},n=f.endIndex):c={type:"Indirection"}}else c={type:"Indirection"}}else if(i)if(t[n]===":")for(c={type:"LengthSliceError"};n<t.length&&t[n]!=="}";)n++;else t[n]!=="}"&&/[-+=?]/.test(t[n])?e.error(`\${#${l}${t.slice(n,t.indexOf("}",n))}}: bad substitution`):t[n]==="/"?e.error(`\${#${l}${t.slice(n,t.indexOf("}",n))}}: bad substitution`):c={type:"Length"};if(!c&&n<t.length&&t[n]!=="}"){let u=ot(e,t,n,l,s);c=u.operation,n=u.endIndex}if(n<t.length&&t[n]!=="}"){let u=t[n];if(!/[:\-+=?#%/^,@[]/.test(u)){let f=n;for(;f<t.length&&t[f]!=="}";)f++;let h=t.slice(r,f+1);e.error(`\${${h.slice(2,-1)}}: bad substitution`)}}for(;n<t.length&&t[n]!=="}";)n++;if(n>=t.length)throw new G("unexpected EOF while looking for matching '}'",0,0);return{part:w.parameterExpansion(l,c),endIndex:n+1}}function ot(e,t,r,s,n=!1){let a=r,i=t[a],l=t[a+1]||"";if(i===":"){let o=l;if("-=?+".includes(o)){a+=2;let A=fe(e,t,a),S=t.slice(a,A),y=ae(e,S,!1,!1,!0,!1,n,!1,!1,!0),b=w.word(Ee(y));if(o==="-")return{operation:{type:"DefaultValue",word:b,checkEmpty:!0},endIndex:A};if(o==="=")return{operation:{type:"AssignDefault",word:b,checkEmpty:!0},endIndex:A};if(o==="?")return{operation:{type:"ErrorIfUnset",word:b,checkEmpty:!0},endIndex:A};if(o==="+")return{operation:{type:"UseAlternative",word:b,checkEmpty:!0},endIndex:A}}a++;let c=fe(e,t,a),u=t.slice(a,c),f=-1,h=0,d=0;for(let E=0;E<u.length;E++){let A=u[E];if(A==="("||A==="[")h++;else if(A===")"||A==="]")h--;else if(A==="?"&&h===0)d++;else if(A===":"&&h===0)if(d>0)d--;else{f=E;break}}let m=f>=0?u.slice(0,f):u,g=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:je(e,m),length:g!==null?je(e,g):null},endIndex:c}}if("-=?+".includes(i)){a++;let o=fe(e,t,a),c=t.slice(a,o),u=ae(e,c,!1,!1,!0,!1,n,!1,!1,!0),f=w.word(Ee(u));if(i==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:o};if(i==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:o};if(i==="?")return{operation:{type:"ErrorIfUnset",word:c?f:null,checkEmpty:!1},endIndex:o};if(i==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:o}}if(i==="#"||i==="%"){let o=l===i,c=i==="#"?"prefix":"suffix";a+=o?2:1;let u=fe(e,t,a),f=t.slice(a,u),h=ae(e,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:w.word(Ee(h)),side:c,greedy:o},endIndex:u}}if(i==="/"){let o=l==="/";a+=o?2:1;let c=null;t[a]==="#"?(c="start",a++):t[a]==="%"&&(c="end",a++);let u;c!==null&&(t[a]==="/"||t[a]==="}")?u=a:u=Xt(e,t,a);let f=t.slice(a,u),h=ae(e,f,!1,!1,!1),d=w.word(Ee(h)),m=null,g=u;if(t[u]==="/"){let E=u+1,A=fe(e,t,E),S=t.slice(E,A),y=ae(e,S,!1,!1,!1);m=w.word(Ee(y)),g=A}return{operation:{type:"PatternReplacement",pattern:d,replacement:m,all:o,anchor:c},endIndex:g}}if(i==="^"||i===","){let o=l===i,c=i==="^"?"upper":"lower";a+=o?2:1;let u=fe(e,t,a),f=t.slice(a,u),h=f?w.word([w.literal(f)]):null;return{operation:{type:"CaseModification",direction:c,all:o,pattern:h},endIndex:u}}return i==="@"&&/[QPaAEKkuUL]/.test(l)?{operation:{type:"Transform",operator:l},endIndex:a+2}:{operation:null,endIndex:a}}function lt(e,t,r,s=!1){let n=r+1;if(n>=t.length)return{part:w.literal("$"),endIndex:n};let a=t[n];if(a==="("&&t[n+1]==="(")return e.isDollarDparenSubshell(t,r)?e.parseCommandSubstitution(t,r):e.parseArithmeticExpansion(t,r);if(a==="["){let i=1,l=n+1;for(;l<t.length&&i>0;)t[l]==="["?i++:t[l]==="]"&&i--,i>0&&l++;if(i===0){let o=t.slice(n+1,l),c=M(e,o);return{part:w.arithmeticExpansion(c),endIndex:l+1}}}return a==="("?e.parseCommandSubstitution(t,r):a==="{"?Kr(e,t,r,s):/[a-zA-Z_0-9@*#?$!-]/.test(a)?jr(e,t,r):{part:w.literal("$"),endIndex:n}}function ln(e,t){let r=[],s=0,n="",a=()=>{n&&(r.push(w.literal(n)),n="")};for(;s<t.length;){let i=t[s];if(i==="\\"&&s+1<t.length){let l=t[s+1];if(l==="$"||l==="`"||l==='"'||l==="\\"){n+=l,s+=2;continue}n+=i,s++;continue}if(i==="$"){a();let{part:l,endIndex:o}=lt(e,t,s,!0);l&&r.push(l),s=o;continue}if(i==="`"){a();let{part:l,endIndex:o}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=o;continue}n+=i,s++}return a(),r}function Xr(e,t,r){let s=[],n=r,a="",i=()=>{a&&(s.push(w.literal(a)),a="")};for(;n<t.length&&t[n]!=='"';){let l=t[n];if(l==="\\"&&n+1<t.length){let o=t[n+1];if('"\\$`\n'.includes(o)){a+=o,n+=2;continue}a+=l,n++;continue}if(l==="$"){i();let{part:o,endIndex:c}=lt(e,t,n,!0);o&&s.push(o),n=c;continue}if(l==="`"){i();let{part:o,endIndex:c}=e.parseBacktickSubstitution(t,n,!0);s.push(o),n=c;continue}a+=l,n++}return i(),{part:w.doubleQuoted(s),endIndex:n}}function ae(e,t,r=!1,s=!1,n=!1,a=!1,i=!1,l=!1,o=!1,c=!1){if(s)return[w.singleQuoted(t)];if(r){let m=ln(e,t);return[w.doubleQuoted(m)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let m=t.slice(1,-1),g=!1;for(let E=0;E<m.length;E++){if(m[E]==='"'){g=!0;break}m[E]==="\\"&&E+1<m.length&&E++}if(!g){let E=ln(e,m);return[w.doubleQuoted(E)]}}let u=[],f=0,h="",d=()=>{h&&(u.push(w.literal(h)),h="")};for(;f<t.length;){let m=t[f];if(m==="\\"&&f+1<t.length){let g=t[f+1];if(o){d(),u.push(w.escaped(g)),f+=2;continue}let E=a?g==="$"||g==="`"||g===`
|
|
45
45
|
`:g==="$"||g==="`"||g==='"'||g==="'"||g===`
|
|
46
|
-
`||c&&g==="}",A=i?"*?[]\\".includes(g):"*?[]\\(){}.^+".includes(g);E?h+=g:A?(d(),u.push(w.escaped(g))):h+=`\\${g}`,f+=2;continue}if(m==="'"&&!i&&!a){d();let g=t.indexOf("'",f+1);if(g===-1){h+=t.slice(f);break}u.push(w.singleQuoted(t.slice(f+1,g))),f=g+1;continue}if(m==='"'&&!a){d();let{part:g,endIndex:E}=
|
|
46
|
+
`||c&&g==="}",A=i?"*?[]\\".includes(g):"*?[]\\(){}.^+".includes(g);E?h+=g:A?(d(),u.push(w.escaped(g))):h+=`\\${g}`,f+=2;continue}if(m==="'"&&!i&&!a){d();let g=t.indexOf("'",f+1);if(g===-1){h+=t.slice(f);break}u.push(w.singleQuoted(t.slice(f+1,g))),f=g+1;continue}if(m==='"'&&!a){d();let{part:g,endIndex:E}=Xr(e,t,f+1);u.push(g),f=E+1;continue}if(m==="$"&&t[f+1]==="'"){d();let{part:g,endIndex:E}=Yt(e,t,f+2);u.push(g),f=E;continue}if(m==="$"){d();let{part:g,endIndex:E}=lt(e,t,f);g&&u.push(g),f=E;continue}if(m==="`"){d();let{part:g,endIndex:E}=e.parseBacktickSubstitution(t,f);u.push(g),f=E;continue}if(m==="~"){let g=f>0?t[f-1]:"";if(f===0||g==="="||n&&g===":"){let A=Kt(e,t,f),S=t[A];if(S===void 0||S==="/"||S===":"){d();let y=t.slice(f+1,A)||null;u.push({type:"TildeExpansion",user:y}),f=A;continue}}}if("@*+?!".includes(m)&&f+1<t.length&&t[f+1]==="("){let g=Hr(t,f+1);if(g!==-1){d();let E=t.slice(f,g+1);u.push({type:"Glob",pattern:E}),f=g+1;continue}}if(m==="*"||m==="?"||m==="["){d();let{pattern:g,endIndex:E}=Jt(e,t,f);u.push({type:"Glob",pattern:g}),f=E;continue}if(m==="{"&&!n&&!l){let g=en(e,t,f,ae);if(g){d(),u.push(g.part),f=g.endIndex;continue}}h+=m,f++}return d(),u}function un(e,t){let r=e.length,s=t+3,n=2,a=!1,i=!1;for(;s<r&&n>0;){let l=e[s];if(a){l==="'"&&(a=!1),s++;continue}if(i){if(l==="\\"){s+=2;continue}l==='"'&&(i=!1),s++;continue}if(l==="'"){a=!0,s++;continue}if(l==='"'){i=!0,s++;continue}if(l==="\\"){s+=2;continue}if(l==="("){n++,s++;continue}if(l===")"){if(n--,n===1){let o=s+1;return!(o<r&&e[o]===")")}if(n===0)return!1;s++;continue}if(n===1&&(l==="|"&&s+1<r&&e[s+1]==="|"||l==="&"&&s+1<r&&e[s+1]==="&"||l==="|"&&s+1<r&&e[s+1]!=="|"))return!0;s++}return!1}function cn(e,t,r,s){let n=t+2,a=1,i=n,l=!1,o=!1,c=0,u=!1,f="";for(;i<e.length&&a>0;){let g=e[i];l?g==="'"&&(l=!1):o?g==="\\"&&i+1<e.length?i++:g==='"'&&(o=!1):g==="'"?(l=!0,f=""):g==='"'?(o=!0,f=""):g==="\\"&&i+1<e.length?(i++,f=""):/[a-zA-Z_]/.test(g)?f+=g:(f==="case"?(c++,u=!1):f==="in"&&c>0?u=!0:f==="esac"&&c>0&&(c--,u=!1),f="",g==="("?i>0&&e[i-1]==="$"?a++:u||a++:g===")"?u?u=!1:a--:g===";"&&c>0&&i+1<e.length&&e[i+1]===";"&&(u=!0)),a>0&&i++}a>0&&s("unexpected EOF while looking for matching `)'");let h=e.slice(n,i),m=r().parse(h);return{part:w.commandSubstitution(m,!1),endIndex:i+1}}function fn(e,t,r,s,n){let i=t+1,l="";for(;i<e.length&&e[i]!=="`";)if(e[i]==="\\"){let u=e[i+1];u==="$"||u==="`"||u==="\\"||u===`
|
|
47
47
|
`||r&&u==='"'?(u!==`
|
|
48
|
-
`&&(l+=u),i+=2):(l+=e[i],i++)}else l+=e[i],i++;i>=e.length&&n("unexpected EOF while looking for matching ``'");let c=s().parse(l);return{part:w.commandSubstitution(c,!0),endIndex:i+1}}var V=class e{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;parseDepth=0;_input="";getInput(){return this._input}checkIterationLimit(){if(this.parseIterations++,this.parseIterations>Gt)throw new G("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}enterDepth(){if(this.parseDepth++,this.parseDepth>Ze)throw new G(`Maximum parser nesting depth exceeded (${Ze})`,this.current().line,this.current().column);return()=>{this.parseDepth--}}parse(t,r){if(t.length>Ge)throw new G(`Input too large: ${t.length} bytes exceeds limit of ${Ge}`,1,1);this._input=t;let s=new Ie(t,r);if(this.tokens=s.tokenize(),this.tokens.length>Qe)throw new G(`Too many tokens: ${this.tokens.length} exceeds limit of ${Qe}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}parseTokens(t){return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos<this.tokens.length-1&&this.pos++,t}getPos(){return this.pos}check(t,r,s,n,...a){let i=this.tokens[this.pos]?.type;return i===t||r!==void 0&&i===r||s!==void 0&&i===s||n!==void 0&&i===n?!0:a.length>0?a.includes(i):!1}expect(t,r){if(this.check(t))return this.advance();let s=this.current();throw new G(r||`Expected ${t}, got ${s.type}`,s.line,s.column,s)}error(t){let r=this.current();throw new G(t,r.line,r.column,r)}skipNewlines(){for(;this.check(p.NEWLINE,p.COMMENT);)this.check(p.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(p.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(p.SEMICOLON,p.COMMENT)){this.advance();continue}if(t&&this.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,r,s,n){this.pendingHeredocs.push({redirect:t,delimiter:r,stripTabs:s,quoted:n})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(p.HEREDOC_CONTENT)){let r=this.advance(),s;t.quoted?s=w.word([w.literal(r.value)]):s=this.parseWordFromString(r.value,!1,!1,!1,!0),t.redirect.target=w.hereDoc(t.delimiter,s,t.stripTabs,t.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(p.EOF,p.NEWLINE,p.SEMICOLON,p.AMP,p.AND_AND,p.OR_OR,p.RPAREN,p.RBRACE,p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return t===p.WORD||t===p.NAME||t===p.NUMBER||t===p.ASSIGNMENT_WORD||t===p.IF||t===p.FOR||t===p.WHILE||t===p.UNTIL||t===p.CASE||t===p.LPAREN||t===p.LBRACE||t===p.DPAREN_START||t===p.DBRACK_START||t===p.FUNCTION||t===p.BANG||t===p.TIME||t===p.IN||t===p.LESS||t===p.GREAT||t===p.DLESS||t===p.DGREAT||t===p.LESSAND||t===p.GREATAND||t===p.LESSGREAT||t===p.DLESSDASH||t===p.CLOBBER||t===p.TLESS||t===p.AND_GREAT||t===p.AND_DGREAT}parseScript(){let t=[],s=0;for(this.skipNewlines();!this.check(p.EOF);){s++,s>1e4&&this.error("Parser stuck: too many iterations (>10000)");let n=this.checkUnexpectedToken();if(n){t.push(n),this.skipSeparators(!1);continue}let a=this.pos,i=this.parseStatement();i&&t.push(i),this.skipSeparators(!1),this.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===a&&!this.check(p.EOF)&&this.advance()}return w.script(t)}checkUnexpectedToken(){let t=this.current().type,r=this.current().value;if((t===p.DO||t===p.DONE||t===p.THEN||t===p.ELSE||t===p.ELIF||t===p.FI||t===p.ESAC)&&this.error(`syntax error near unexpected token \`${r}'`),t===p.RBRACE||t===p.RPAREN){let s=`syntax error near unexpected token \`${r}'`;return this.advance(),w.statement([w.pipeline([w.simpleCommand(null,[],[],[])])],[],!1,{message:s,token:r})}return(t===p.DSEMI||t===p.SEMI_AND||t===p.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${r}'`),t===p.SEMICOLON&&this.error(`syntax error near unexpected token \`${r}'`),(t===p.PIPE||t===p.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${r}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,r=[],s=[],n=!1,a=this.parsePipeline();for(r.push(a);this.check(p.AND_AND,p.OR_OR);){let o=this.advance();s.push(o.type===p.AND_AND?"&&":"||"),this.skipNewlines();let c=this.parsePipeline();r.push(c)}this.check(p.AMP)&&(this.advance(),n=!0);let i=this.pos>0?this.tokens[this.pos-1].end:t,l=this._input.slice(t,i);return w.statement(r,s,n,void 0,l)}parsePipeline(){let t=!1,r=!1;this.check(p.TIME)&&(this.advance(),t=!0,this.check(p.WORD,p.NAME)&&this.current().value==="-p"&&(this.advance(),r=!0));let s=0;for(;this.check(p.BANG);)this.advance(),s++;let n=s%2===1,a=[],i=[],l=this.parseCommand();for(a.push(l);this.check(p.PIPE,p.PIPE_AMP);){let o=this.advance();this.skipNewlines(),i.push(o.type===p.PIPE_AMP);let c=this.parseCommand();a.push(c)}return w.pipeline(a,n,t,r,i.length>0?i:void 0)}parseCommand(){return this.check(p.IF)?Xe(this):this.check(p.FOR)?Je(this):this.check(p.WHILE)?Ye(this):this.check(p.UNTIL)?et(this):this.check(p.CASE)?tt(this):this.check(p.LPAREN)?nt(this):this.check(p.LBRACE)?rt(this):this.check(p.DPAREN_START)?this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand():this.check(p.DBRACK_START)?this.parseConditionalCommand():this.check(p.FUNCTION)?this.parseFunctionDef():this.check(p.NAME,p.WORD)&&this.peek(1).type===p.LPAREN&&this.peek(2).type===p.RPAREN?this.parseFunctionDef():nn(this)}dparenClosesWithSpacedParens(){let t=1,r=1;for(;r<this.tokens.length-this.pos;){let s=this.peek(r);if(s.type===p.EOF)return!1;if(s.type===p.DPAREN_START||s.type===p.LPAREN)t++;else if(s.type===p.DPAREN_END){if(t-=2,t<=0)return!1}else if(s.type===p.RPAREN&&(t--,t===0&&this.peek(r+1).type===p.RPAREN))return!0;r++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(p.RPAREN),this.expect(p.RPAREN);let r=this.parseOptionalRedirections(),s=w.subshell(t,[]);return w.subshell([w.statement([w.pipeline([s],!1,!1,!1)])],r)}isWord(){let t=this.current().type;return t===p.WORD||t===p.NAME||t===p.NUMBER||t===p.IF||t===p.FOR||t===p.WHILE||t===p.UNTIL||t===p.CASE||t===p.FUNCTION||t===p.ELSE||t===p.ELIF||t===p.FI||t===p.THEN||t===p.DO||t===p.DONE||t===p.ESAC||t===p.IN||t===p.SELECT||t===p.TIME||t===p.COPROC||t===p.BANG}parseWord(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted)}parseWordNoBraceExpansion(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0)}parseWordForRegex(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0,!0)}parseWordFromString(t,r=!1,s=!1,n=!1,a=!1,i=!1,l=!1){let o=ae(this,t,r,s,n,a,!1,i,l);return w.word(o)}parseCommandSubstitution(t,r){return un(t,r,()=>new e,s=>this.error(s))}parseBacktickSubstitution(t,r,s=!1){return cn(t,r,s,()=>new e,n=>this.error(n))}isDollarDparenSubshell(t,r){return ln(t,r)}parseArithmeticExpansion(t,r){let s=r+3,n=1,a=0,i=s;for(;i<t.length-1&&n>0;)t[i]==="$"&&t[i+1]==="("?t[i+2]==="("?(n++,i+=3):(a++,i+=2):t[i]==="("&&t[i+1]==="("?(n++,i+=2):t[i]===")"&&t[i+1]===")"?a>0?(a--,i++):(n--,n>0&&(i+=2)):t[i]==="("?(a++,i++):(t[i]===")"&&a>0&&a--,i++);let l=t.slice(s,i),o=this.parseArithmeticExpression(l);return{part:w.arithmeticExpansion(o),endIndex:i+2}}parseArithmeticCommand(){let t=this.expect(p.DPAREN_START),r="",s=1,n=0,a=!1,i=!1;for(;s>0&&!this.check(p.EOF);){if(a){if(a=!1,n>0){n--,r+=")";continue}if(this.check(p.RPAREN)){s--,i=!0,this.advance();continue}if(this.check(p.DPAREN_END)){s--,i=!0;continue}r+=")";continue}if(this.check(p.DPAREN_START))s++,r+="((",this.advance();else if(this.check(p.DPAREN_END))n>=2?(n-=2,r+="))",this.advance()):n===1?(n--,r+=")",a=!0,this.advance()):(s--,i=!0,s>0&&(r+="))"),this.advance());else if(this.check(p.LPAREN))n++,r+="(",this.advance();else if(this.check(p.RPAREN))n>0&&n--,r+=")",this.advance();else{let c=this.current().value,u=r.length>0?r[r.length-1]:"";r.length>0&&!r.endsWith(" ")&&!(c==="="&&/[|&^+\-*/%<>]$/.test(r))&&!(c==="<"&&u==="<")&&!(c===">"&&u===">")&&(r+=" "),r+=c,this.advance()}}i||this.expect(p.DPAREN_END);let l=this.parseArithmeticExpression(r.trim()),o=this.parseOptionalRedirections();return w.arithmeticCommand(l,o,t.line)}parseConditionalCommand(){let t=this.expect(p.DBRACK_START),r=it(this);this.expect(p.DBRACK_END);let s=this.parseOptionalRedirections();return w.conditionalCommand(r,s,t.line)}parseFunctionDef(){let t;if(this.check(p.FUNCTION)){if(this.advance(),this.check(p.NAME)||this.check(p.WORD))t=this.advance().value;else{let n=this.current();throw new G("Expected function name",n.line,n.column,n)}this.check(p.LPAREN)&&(this.advance(),this.expect(p.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(p.LPAREN),this.expect(p.RPAREN);this.skipNewlines();let r=this.parseCompoundCommandBody({forFunctionBody:!0}),s=this.parseOptionalRedirections();return w.functionDef(t,r,s)}parseCompoundCommandBody(t){let r=t?.forFunctionBody;if(this.check(p.LBRACE))return rt(this,{skipRedirections:r});if(this.check(p.LPAREN))return nt(this,{skipRedirections:r});if(this.check(p.IF))return Xe(this,{skipRedirections:r});if(this.check(p.FOR))return Je(this,{skipRedirections:r});if(this.check(p.WHILE))return Ye(this,{skipRedirections:r});if(this.check(p.UNTIL))return et(this,{skipRedirections:r});if(this.check(p.CASE))return tt(this,{skipRedirections:r});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth(),r=[];for(this.skipNewlines();!this.check(p.EOF,p.FI,p.ELSE,p.ELIF,p.THEN,p.DO,p.DONE,p.ESAC,p.RPAREN,p.RBRACE,p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let s=this.pos,n=this.parseStatement();if(n&&r.push(n),this.skipSeparators(),this.pos===s&&!n)break}return t(),r}parseOptionalRedirections(){let t=[];for(;ve(this);){this.checkIterationLimit();let r=this.pos;if(t.push(De(this)),this.pos===r)break}return t}parseArithmeticExpression(t){return M(this,t)}};function pi(e,t){return new V().parse(e,t)}var Jr=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function lt(e){return Jr.get(e)??""}function fn(e){let t=[],r="",s=0;for(;s<e.length;){let n=e[s];if(n==="["){for(r+=n,s++,s<e.length&&(e[s]==="!"||e[s]==="^")&&(r+=e[s],s++),s<e.length&&e[s]==="]"&&(r+=e[s],s++);s<e.length&&e[s]!=="]";){if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let a=e.indexOf(":]",s+2);if(a!==-1){r+=e.slice(s,a+2),s=a+2;continue}}if(e[s]==="\\"&&s+1<e.length){r+=e[s]+e[s+1],s+=2;continue}r+=e[s],s++}s<e.length&&e[s]==="]"&&(r+=e[s],s++)}else n===":"?(r!==""&&t.push(r),r="",s++):n==="\\"&&s+1<e.length?(r+=n+e[s+1],s+=2):(r+=n,s++)}return r!==""&&t.push(r),t}function hn(e){let t="^";for(let r=0;r<e.length;r++){let s=e[r];if(s==="*")t+="[^/]*";else if(s==="?")t+="[^/]";else if(s==="["){let n=r+1,a="[";n<e.length&&(e[n]==="^"||e[n]==="!")&&(a+="^",n++),n<e.length&&e[n]==="]"&&(a+="\\]",n++);let i=n;for(;i<e.length;){if(e[i]==="\\"&&i+1<e.length){i+=2;continue}if(e[i]==="["&&i+1<e.length&&e[i+1]===":"){let o=e.indexOf(":]",i+2);if(o!==-1){i=o+2;continue}}if(e[i]==="]")break;i++}let l=n;for(;n<e.length&&e[n]!=="]";){if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let o=e.indexOf(":]",n+2);if(o!==-1){let c=e.slice(n+2,o),u=lt(c);a+=u,n=o+2;continue}}if(e[n]==="\\"&&n+1<e.length){a+=`\\${e[n+1]}`,n+=2;continue}if(e[n]==="-"){let o=n===l,c=n+1===i;o||c?a+="\\-":a+="-"}else a+=e[n];n++}a+="]",t+=a,r=n}else if(s==="\\"&&r+1<e.length){let n=e[r+1];/[.+^${}()|\\*?[\]]/.test(n)?t+=`\\${n}`:t+=n,r++}else/[.+^${}()|]/.test(s)?t+=`\\${s}`:t+=s}return t+="$",O(t)}function ut(e,t){let r=1,s=t+1;for(;s<e.length&&r>0;){let n=e[s];if(n==="\\"){s+=2;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function ct(e){let t=[],r="",s=0,n=!1,a=0;for(;a<e.length;){let i=e[a];if(i==="'"&&!n){n=!0,r+="\0QUOTE_START\0",a++;continue}if(i==="'"&&n){n=!1,r+="\0QUOTE_END\0",a++;continue}if(n){r+=i,a++;continue}if(i==="\\"){r+=i,a+1<e.length?(r+=e[a+1],a+=2):a++;continue}i==="("?(s++,r+=i):i===")"?(s--,r+=i):i==="|"&&s===0?(t.push(r),r=""):r+=i,a++}return t.push(r),t}var pn=5,oe=class{fs;cwd;globignorePatterns=[];hasGlobignore=!1;globstar=!1;nullglob=!1;failglob=!1;dotglob=!1;extglob=!1;globskipdots=!0;ops={count:0};maxOps;constructor(t,r,s,n){this.fs=t,this.cwd=r,typeof n=="boolean"?(this.globstar=n,this.maxOps=1e5):n?(this.globstar=n.globstar??!1,this.nullglob=n.nullglob??!1,this.failglob=n.failglob??!1,this.dotglob=n.dotglob??!1,this.extglob=n.extglob??!1,this.globskipdots=n.globskipdots??!0,this.maxOps=n.maxGlobOperations??1e5):this.maxOps=1e5;let a=s?.get("GLOBIGNORE");a!==void 0&&a!==""&&(this.hasGlobignore=!0,this.globignorePatterns=fn(a))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new L(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations")}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(r=>{let s=r.split("/").pop()||r;if((this.hasGlobignore||this.globskipdots)&&(s==="."||s===".."))return!1;if(this.hasGlobignore){for(let n of this.globignorePatterns)if(this.matchGlobignorePattern(r,n))return!1}return!0})}matchGlobignorePattern(t,r){return hn(r).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,r){let s=t.map((i,l)=>(r?.[l]??!1)||!this.isGlobPattern(i)?null:this.expand(i)),n=await Promise.all(s.map(i=>i||Promise.resolve(null))),a=[];for(let i=0;i<t.length;i++){let l=n[i];l===null?a.push(t[i]):l.length>0?a.push(...l):a.push(t[i])}return a}async expand(t){if(this.globstar){let s=t.split("/"),n=0;for(let a of s)if(a==="**"&&(n++,n>pn))throw new L(`Glob pattern has too many ** segments (max ${pn})`,"glob_operations")}let r;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))r=await this.expandRecursive(t);else{let s=t.replace(/\*\*+/g,"*");r=await this.expandSimple(s)}return this.filterGlobignore(r)}isGlobstarValid(t){let r=t.split("/");for(let s of r)if(s.includes("**")&&s!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let r=t.startsWith("/"),s=t.split("/").filter(c=>c!==""),n=-1;for(let c=0;c<s.length;c++)if(this.hasGlobChars(s[c])){n=c;break}if(n===-1)return[t];let a,i;if(n===0)r?(a="/",i="/"):(a=this.cwd,i="");else{let c=s.slice(0,n);r?(a=`/${c.join("/")}`,i=`/${c.join("/")}`):(a=this.fs.resolvePath(this.cwd,c.join("/")),i=c.join("/"))}let l=s.slice(n);return(await this.expandSegments(a,i,l)).sort()}async expandSegments(t,r,s){if(this.checkOpsLimit(),s.length===0)return[r];let[n,...a]=s,i=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let l=await this.fs.readdirWithFileTypes(t),o=[],c=[...l],u=this.dotglob||this.hasGlobignore;if(n.startsWith(".")||this.dotglob){let h=l.some(m=>m.name==="."),d=l.some(m=>m.name==="..");h||c.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),d||c.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let h of c)if(!(h.name.startsWith(".")&&!n.startsWith(".")&&!u)&&this.matchPattern(h.name,n)){let d=t==="/"?`/${h.name}`:`${t}/${h.name}`,m;r===""?m=h.name:r==="/"?m=`/${h.name}`:m=`${r}/${h.name}`,a.length===0?o.push(Promise.resolve([m])):h.isDirectory&&o.push(this.expandSegments(d,m,a))}let f=await Promise.all(o);for(let h of f)i.push(...h)}else{this.checkOpsLimit();let l=await this.fs.readdir(t),o=[],c=[...l],u=this.dotglob||this.hasGlobignore;(n.startsWith(".")||this.dotglob)&&(l.includes(".")||c.push("."),l.includes("..")||c.push(".."));for(let h of c)if(!(h.startsWith(".")&&!n.startsWith(".")&&!u)&&this.matchPattern(h,n)){let d=t==="/"?`/${h}`:`${t}/${h}`,m;r===""?m=h:r==="/"?m=`/${h}`:m=`${r}/${h}`,a.length===0?o.push(Promise.resolve([m])):o.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory)return this.expandSegments(d,m,a)}catch(g){if(g instanceof L)throw g}return[]})())}let f=await Promise.all(o);for(let h of f)i.push(...h)}}catch(l){if(l instanceof L)throw l}return i}async expandRecursive(t){let r=[],s=t.indexOf("**"),n=t.slice(0,s).replace(/\/$/,"")||".",i=t.slice(s+2).replace(/^\//,"");return i.includes("**")&&this.isGlobstarValid(i)?(await this.walkDirectoryMultiGlobstar(n,i,r),[...new Set(r)].sort()):(await this.walkDirectory(n,i,r),r.sort())}async walkDirectoryMultiGlobstar(t,r,s){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let a=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(n):null;if(a){let i=[];for(let c of a){let u=t==="."?c.name:`${t}/${c.name}`;c.isDirectory&&i.push(u)}let l=t==="."?r:`${t}/${r}`,o=await this.expandRecursive(l);s.push(...o);for(let c=0;c<i.length;c+=100){let u=i.slice(c,c+100);await Promise.all(u.map(f=>this.walkDirectoryMultiGlobstar(f,r,s)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(n),l=[];for(let u of i){let f=t==="."?u:`${t}/${u}`,h=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(h)).isDirectory&&l.push(f)}catch(d){if(d instanceof L)throw d}}let o=t==="."?r:`${t}/${r}`,c=await this.expandRecursive(o);s.push(...c);for(let u=0;u<l.length;u+=100){let f=l.slice(u,u+100);await Promise.all(f.map(h=>this.walkDirectoryMultiGlobstar(h,r,s)))}}}catch(a){if(a instanceof L)throw a}}async walkDirectory(t,r,s){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let a=await this.fs.readdirWithFileTypes(n),i=[],l=[];for(let o of a){let c=t==="."?o.name:`${t}/${o.name}`;o.isDirectory?l.push(c):r&&this.matchPattern(o.name,r)&&i.push(c)}s.push(...i);for(let o=0;o<l.length;o+=100){let c=l.slice(o,o+100);await Promise.all(c.map(u=>this.walkDirectory(u,r,s)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(n),i=[];for(let o=0;o<a.length;o+=100){let c=a.slice(o,o+100),u=await Promise.all(c.map(async f=>{let h=t==="."?f:`${t}/${f}`,d=this.fs.resolvePath(this.cwd,h);try{this.checkOpsLimit();let m=await this.fs.stat(d);return{name:f,path:h,isDirectory:m.isDirectory}}catch(m){if(m instanceof L)throw m;return null}}));i.push(...u.filter(f=>f!==null))}for(let o of i)!o.isDirectory&&r&&this.matchPattern(o.name,r)&&s.push(o.path);let l=i.filter(o=>o.isDirectory);for(let o=0;o<l.length;o+=100){let c=l.slice(o,o+100);await Promise.all(c.map(u=>this.walkDirectory(u.path,r,s)))}}}catch(a){if(a instanceof L)throw a}}matchPattern(t,r){return this.patternToRegex(r).test(t)}patternToRegex(t){let r=this.patternToRegexStr(t);return O(`^${r}$`)}patternToRegexStr(t){let r="",s=!1;for(let n=0;n<t.length;n++){if(t.slice(n,n+13)==="\0QUOTE_START\0"){s=!0,n+=12;continue}if(t.slice(n,n+11)==="\0QUOTE_END\0"){s=!1,n+=10;continue}let a=t[n];if(s){/[.+^${}()|\\*?[\]]/.test(a)?r+=`\\${a}`:r+=a;continue}if(this.extglob&&(a==="@"||a==="*"||a==="+"||a==="?"||a==="!")&&n+1<t.length&&t[n+1]==="("){let i=ut(t,n+1);if(i!==-1){let l=t.slice(n+2,i),o=ct(l),c=o.map(f=>this.patternToRegexStr(f)),u=c.length>0?c.join("|"):"(?:)";if(a==="@")r+=`(?:${u})`;else if(a==="*")r+=`(?:${u})*`;else if(a==="+")r+=`(?:${u})+`;else if(a==="?")r+=`(?:${u})?`;else if(a==="!")if(i<t.length-1){let h=o.map(m=>this.computePatternLength(m));if(h.every(m=>m!==null)&&h.every(m=>m===h[0])&&h[0]!==null){let m=h[0];if(m===0)r+="(?:.+)";else{let g=[];m>0&&g.push(`.{0,${m-1}}`),g.push(`.{${m+1},}`),g.push(`(?!(?:${u})).{${m}}`),r+=`(?:${g.join("|")})`}}else r+=`(?:(?!(?:${u})).)*?`}else r+=`(?!(?:${u})$).*`;n=i;continue}}if(a==="*")r+=".*";else if(a==="?")r+=".";else if(a==="["){let i=n+1,l="[";i<t.length&&(t[i]==="^"||t[i]==="!")&&(l+="^",i++),i<t.length&&t[i]==="]"&&(l+="\\]",i++);let o=i;for(;o<t.length;){if(t[o]==="\\"&&o+1<t.length){o+=2;continue}if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let u=t.indexOf(":]",o+2);if(u!==-1){o=u+2;continue}}if(t[o]==="]")break;o++}let c=i;for(;i<t.length&&t[i]!=="]";){if(t[i]==="["&&i+1<t.length&&t[i+1]===":"){let u=t.indexOf(":]",i+2);if(u!==-1){let f=t.slice(i+2,u),h=lt(f);l+=h,i=u+2;continue}}if(t[i]==="\\"&&i+1<t.length){l+=`\\${t[i+1]}`,i+=2;continue}if(t[i]==="-"){let u=i===c,f=i+1===o;u||f?l+="\\-":l+="-"}else l+=t[i];i++}l+="]",r+=l,n=i}else if(a==="\\"&&n+1<t.length){let i=t[n+1];/[.+^${}()|\\*?[\]]/.test(i)?r+=`\\${i}`:r+=i,n++}else/[.+^${}()|]/.test(a)?r+=`\\${a}`:r+=a}return r}computePatternLength(t){let r=0,s=0,n=!1;for(;s<t.length;){if(t.slice(s,s+13)==="\0QUOTE_START\0"){n=!0,s+=13;continue}if(t.slice(s,s+11)==="\0QUOTE_END\0"){n=!1,s+=11;continue}let a=t[s];if(n){r+=1,s++;continue}if((a==="@"||a==="*"||a==="+"||a==="?"||a==="!")&&s+1<t.length&&t[s+1]==="("){let i=ut(t,s+1);if(i!==-1){if(a==="@"){let l=t.slice(s+2,i),c=ct(l).map(u=>this.computePatternLength(u));if(c.every(u=>u!==null)&&c.every(u=>u===c[0])){r+=c[0],s=i+1;continue}return null}return null}}if(a==="*")return null;if(a==="?"){r+=1,s++;continue}if(a==="["){let i=t.indexOf("]",s+1);if(i!==-1){r+=1,s=i+1;continue}r+=1,s++;continue}if(a==="\\"){r+=1,s+=2;continue}r+=1,s++}return r}};function Yr(e,t,r){switch(r){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new C("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new C("division by 0");return e%t;case"**":if(t<0)throw new C("exponent less than 0");return e**t;case"<<":return e<<t;case">>":return e>>t;case"<":return e<t?1:0;case"<=":return e<=t?1:0;case">":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function dn(e,t,r){switch(r){case"=":return t;case"+=":return e+t;case"-=":return e-t;case"*=":return e*t;case"/=":return t!==0?Math.trunc(e/t):0;case"%=":return t!==0?e%t:0;case"<<=":return e<<t;case">>=":return e>>t;case"&=":return e&t;case"|=":return e|t;case"^=":return e^t;default:return t}}function es(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function ts(e,t){let r=e.state.env.get(t);if(r!==void 0)return r;let s=e.state.env.get(`${t}_0`);return s!==void 0?s:await v(e,t)}function ns(e){if(!e)return 0;let t=Number.parseInt(e,10);if(!Number.isNaN(t)&&/^-?\d+$/.test(e.trim()))return t;let r=e.trim();if(!r)return 0;try{let s=new V,{expr:n,pos:a}=Z(s,r,0);if(a<r.length){let i=r.slice(a).trim().split(/\s+/)[0];throw new C(`${r}: syntax error in expression (error token is "${i}")`)}return n.type==="ArithNumber"?n.value:t||0}catch(s){if(s instanceof C)throw s;let n=r.split(/\s+/).slice(1)[0]||r;throw new C(`${r}: syntax error in expression (error token is "${n}")`)}}async function ft(e,t){if(!t)return 0;let r=Number.parseInt(t,10);if(!Number.isNaN(r)&&/^-?\d+$/.test(t.trim()))return r;let s=t.trim();if(!s)return 0;let n=new V,{expr:a,pos:i}=Z(n,s,0);if(i<s.length){let l=s.slice(i).trim(),o=l.split(/\s+/)[0]||l;throw new C(`syntax error in expression (error token is "${o}")`,"","")}return await R(e,a)}async function ht(e,t,r=new Set,s=0){if(s>100)throw new C("maximum variable indirection depth exceeded");if(r.has(t))return 0;r.add(t);let n=await ts(e,t);if(!n)return 0;let a=Number.parseInt(n,10);if(!Number.isNaN(a)&&/^-?\d+$/.test(n.trim()))return a;let i=n.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return await ht(e,i,r,s+1);let l=new V,{expr:o,pos:c}=Z(l,i,0);if(c<i.length){let u=i.slice(c).trim(),f=u.split(/\s+/)[0]||u;throw new C(`${i}: syntax error in expression (error token is "${f}")`)}return await R(e,o)}async function xe(e,t){if(t.startsWith("#")){let f=t.slice(1),h=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(h){let m=h[1],g=P(e,m);return String(g.length)}let d=e.state.env.get(f)||"";return String(d.length)}if(t.startsWith("!")){let f=t.slice(1),h=e.state.env.get(f)||"";return e.state.env.get(h)||""}let r=[":-",":=",":?",":+","-","=","?","+"],s=-1,n="";for(let f of r){let h=t.indexOf(f);h>0&&(s===-1||h<s)&&(s=h,n=f)}if(s===-1)return await v(e,t);let a=t.slice(0,s),i=t.slice(s+n.length),l=e.state.env.get(a),o=l===void 0,c=l==="",u=n.startsWith(":");switch(n){case":-":case"-":return o||u&&c?i:l||"";case":=":case"=":return o||u&&c?(e.state.env.set(a,i),i):l||"";case":+":case"+":return!(o||u&&c)?i:"";case":?":case"?":{if(o||u&&c)throw new Error(i||`${a}: parameter null or not set`);return l||""}default:return l||""}}async function R(e,t,r=!1){switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new C("value too great for base");return t.value;case"ArithVariable":return await ht(e,t.name);case"ArithSpecialVar":{let n=(await v(e,t.name)).trim();if(!n)return 0;let a=Number.parseInt(n,10);if(!Number.isNaN(a)&&/^-?\d+$/.test(n))return a;let i=new V,{expr:l}=Z(i,n,0);return await R(e,l)}case"ArithNested":return await R(e,t.expression);case"ArithCommandSubst":{if(e.execFn){let s=await e.execFn(t.command,{signal:e.state.signal});s.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+s.stderr);let n=s.stdout.trim();return Number.parseInt(n,10)||0}return 0}case"ArithBracedExpansion":{let s=await xe(e,t.content);return Number.parseInt(s,10)||0}case"ArithDynamicBase":{let s=await xe(e,t.baseExpr),n=Number.parseInt(s,10);if(n<2||n>64)return 0;let a=`${n}#${t.value}`;return ge(a)}case"ArithDynamicNumber":{let n=await xe(e,t.prefix)+t.suffix;return ge(n)}case"ArithArrayElement":{let s=e.state.associativeArrays?.has(t.array),n=async a=>{let i=e.state.env.get(a);return i!==void 0?await ft(e,i):0};if(t.stringKey!==void 0)return await n(`${t.array}_${t.stringKey}`);if(s&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await n(`${t.array}_${t.index.name}`);if(s&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let a=await v(e,t.index.name);return await n(`${t.array}_${a}`)}if(t.index){let a=await R(e,t.index,r);if(a<0){let o=P(e,t.array),c=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${c}: ${t.array}: bad array subscript
|
|
48
|
+
`&&(l+=u),i+=2):(l+=e[i],i++)}else l+=e[i],i++;i>=e.length&&n("unexpected EOF while looking for matching ``'");let c=s().parse(l);return{part:w.commandSubstitution(c,!0),endIndex:i+1}}var V=class e{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;parseDepth=0;_input="";getInput(){return this._input}checkIterationLimit(){if(this.parseIterations++,this.parseIterations>Qt)throw new G("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}enterDepth(){if(this.parseDepth++,this.parseDepth>Ue)throw new G(`Maximum parser nesting depth exceeded (${Ue})`,this.current().line,this.current().column);return()=>{this.parseDepth--}}parse(t,r){if(t.length>Qe)throw new G(`Input too large: ${t.length} bytes exceeds limit of ${Qe}`,1,1);this._input=t;let s=new ve(t,r);if(this.tokens=s.tokenize(),this.tokens.length>Ze)throw new G(`Too many tokens: ${this.tokens.length} exceeds limit of ${Ze}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}parseTokens(t){return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos<this.tokens.length-1&&this.pos++,t}getPos(){return this.pos}check(t,r,s,n,...a){let i=this.tokens[this.pos]?.type;return i===t||r!==void 0&&i===r||s!==void 0&&i===s||n!==void 0&&i===n?!0:a.length>0?a.includes(i):!1}expect(t,r){if(this.check(t))return this.advance();let s=this.current();throw new G(r||`Expected ${t}, got ${s.type}`,s.line,s.column,s)}error(t){let r=this.current();throw new G(t,r.line,r.column,r)}skipNewlines(){for(;this.check(p.NEWLINE,p.COMMENT);)this.check(p.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(p.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(p.SEMICOLON,p.COMMENT)){this.advance();continue}if(t&&this.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,r,s,n){this.pendingHeredocs.push({redirect:t,delimiter:r,stripTabs:s,quoted:n})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(p.HEREDOC_CONTENT)){let r=this.advance(),s;t.quoted?s=w.word([w.literal(r.value)]):s=this.parseWordFromString(r.value,!1,!1,!1,!0),t.redirect.target=w.hereDoc(t.delimiter,s,t.stripTabs,t.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(p.EOF,p.NEWLINE,p.SEMICOLON,p.AMP,p.AND_AND,p.OR_OR,p.RPAREN,p.RBRACE,p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return t===p.WORD||t===p.NAME||t===p.NUMBER||t===p.ASSIGNMENT_WORD||t===p.IF||t===p.FOR||t===p.WHILE||t===p.UNTIL||t===p.CASE||t===p.LPAREN||t===p.LBRACE||t===p.DPAREN_START||t===p.DBRACK_START||t===p.FUNCTION||t===p.BANG||t===p.TIME||t===p.IN||t===p.LESS||t===p.GREAT||t===p.DLESS||t===p.DGREAT||t===p.LESSAND||t===p.GREATAND||t===p.LESSGREAT||t===p.DLESSDASH||t===p.CLOBBER||t===p.TLESS||t===p.AND_GREAT||t===p.AND_DGREAT}parseScript(){let t=[],s=0;for(this.skipNewlines();!this.check(p.EOF);){s++,s>1e4&&this.error("Parser stuck: too many iterations (>10000)");let n=this.checkUnexpectedToken();if(n){t.push(n),this.skipSeparators(!1);continue}let a=this.pos,i=this.parseStatement();i&&t.push(i),this.skipSeparators(!1),this.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===a&&!this.check(p.EOF)&&this.advance()}return w.script(t)}checkUnexpectedToken(){let t=this.current().type,r=this.current().value;if((t===p.DO||t===p.DONE||t===p.THEN||t===p.ELSE||t===p.ELIF||t===p.FI||t===p.ESAC)&&this.error(`syntax error near unexpected token \`${r}'`),t===p.RBRACE||t===p.RPAREN){let s=`syntax error near unexpected token \`${r}'`;return this.advance(),w.statement([w.pipeline([w.simpleCommand(null,[],[],[])])],[],!1,{message:s,token:r})}return(t===p.DSEMI||t===p.SEMI_AND||t===p.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${r}'`),t===p.SEMICOLON&&this.error(`syntax error near unexpected token \`${r}'`),(t===p.PIPE||t===p.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${r}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,r=[],s=[],n=!1,a=this.parsePipeline();for(r.push(a);this.check(p.AND_AND,p.OR_OR);){let o=this.advance();s.push(o.type===p.AND_AND?"&&":"||"),this.skipNewlines();let c=this.parsePipeline();r.push(c)}this.check(p.AMP)&&(this.advance(),n=!0);let i=this.pos>0?this.tokens[this.pos-1].end:t,l=this._input.slice(t,i);return w.statement(r,s,n,void 0,l)}parsePipeline(){let t=!1,r=!1;this.check(p.TIME)&&(this.advance(),t=!0,this.check(p.WORD,p.NAME)&&this.current().value==="-p"&&(this.advance(),r=!0));let s=0;for(;this.check(p.BANG);)this.advance(),s++;let n=s%2===1,a=[],i=[],l=this.parseCommand();for(a.push(l);this.check(p.PIPE,p.PIPE_AMP);){let o=this.advance();this.skipNewlines(),i.push(o.type===p.PIPE_AMP);let c=this.parseCommand();a.push(c)}return w.pipeline(a,n,t,r,i.length>0?i:void 0)}parseCommand(){return this.check(p.IF)?Je(this):this.check(p.FOR)?Ye(this):this.check(p.WHILE)?et(this):this.check(p.UNTIL)?tt(this):this.check(p.CASE)?nt(this):this.check(p.LPAREN)?rt(this):this.check(p.LBRACE)?st(this):this.check(p.DPAREN_START)?this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand():this.check(p.DBRACK_START)?this.parseConditionalCommand():this.check(p.FUNCTION)?this.parseFunctionDef():this.check(p.NAME,p.WORD)&&this.peek(1).type===p.LPAREN&&this.peek(2).type===p.RPAREN?this.parseFunctionDef():rn(this)}dparenClosesWithSpacedParens(){let t=1,r=1;for(;r<this.tokens.length-this.pos;){let s=this.peek(r);if(s.type===p.EOF)return!1;if(s.type===p.DPAREN_START||s.type===p.LPAREN)t++;else if(s.type===p.DPAREN_END){if(t-=2,t<=0)return!1}else if(s.type===p.RPAREN&&(t--,t===0&&this.peek(r+1).type===p.RPAREN))return!0;r++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(p.RPAREN),this.expect(p.RPAREN);let r=this.parseOptionalRedirections(),s=w.subshell(t,[]);return w.subshell([w.statement([w.pipeline([s],!1,!1,!1)])],r)}isWord(){let t=this.current().type;return t===p.WORD||t===p.NAME||t===p.NUMBER||t===p.IF||t===p.FOR||t===p.WHILE||t===p.UNTIL||t===p.CASE||t===p.FUNCTION||t===p.ELSE||t===p.ELIF||t===p.FI||t===p.THEN||t===p.DO||t===p.DONE||t===p.ESAC||t===p.IN||t===p.SELECT||t===p.TIME||t===p.COPROC||t===p.BANG}parseWord(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted)}parseWordNoBraceExpansion(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0)}parseWordForRegex(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0,!0)}parseWordFromString(t,r=!1,s=!1,n=!1,a=!1,i=!1,l=!1){let o=ae(this,t,r,s,n,a,!1,i,l);return w.word(o)}parseCommandSubstitution(t,r){return cn(t,r,()=>new e,s=>this.error(s))}parseBacktickSubstitution(t,r,s=!1){return fn(t,r,s,()=>new e,n=>this.error(n))}isDollarDparenSubshell(t,r){return un(t,r)}parseArithmeticExpansion(t,r){let s=r+3,n=1,a=0,i=s;for(;i<t.length-1&&n>0;)t[i]==="$"&&t[i+1]==="("?t[i+2]==="("?(n++,i+=3):(a++,i+=2):t[i]==="("&&t[i+1]==="("?(n++,i+=2):t[i]===")"&&t[i+1]===")"?a>0?(a--,i++):(n--,n>0&&(i+=2)):t[i]==="("?(a++,i++):(t[i]===")"&&a>0&&a--,i++);let l=t.slice(s,i),o=this.parseArithmeticExpression(l);return{part:w.arithmeticExpansion(o),endIndex:i+2}}parseArithmeticCommand(){let t=this.expect(p.DPAREN_START),r="",s=1,n=0,a=!1,i=!1;for(;s>0&&!this.check(p.EOF);){if(a){if(a=!1,n>0){n--,r+=")";continue}if(this.check(p.RPAREN)){s--,i=!0,this.advance();continue}if(this.check(p.DPAREN_END)){s--,i=!0;continue}r+=")";continue}if(this.check(p.DPAREN_START))s++,r+="((",this.advance();else if(this.check(p.DPAREN_END))n>=2?(n-=2,r+="))",this.advance()):n===1?(n--,r+=")",a=!0,this.advance()):(s--,i=!0,s>0&&(r+="))"),this.advance());else if(this.check(p.LPAREN))n++,r+="(",this.advance();else if(this.check(p.RPAREN))n>0&&n--,r+=")",this.advance();else{let c=this.current().value,u=r.length>0?r[r.length-1]:"";r.length>0&&!r.endsWith(" ")&&!(c==="="&&/[|&^+\-*/%<>]$/.test(r))&&!(c==="<"&&u==="<")&&!(c===">"&&u===">")&&(r+=" "),r+=c,this.advance()}}i||this.expect(p.DPAREN_END);let l=this.parseArithmeticExpression(r.trim()),o=this.parseOptionalRedirections();return w.arithmeticCommand(l,o,t.line)}parseConditionalCommand(){let t=this.expect(p.DBRACK_START),r=at(this);this.expect(p.DBRACK_END);let s=this.parseOptionalRedirections();return w.conditionalCommand(r,s,t.line)}parseFunctionDef(){let t;if(this.check(p.FUNCTION)){if(this.advance(),this.check(p.NAME)||this.check(p.WORD))t=this.advance().value;else{let n=this.current();throw new G("Expected function name",n.line,n.column,n)}this.check(p.LPAREN)&&(this.advance(),this.expect(p.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(p.LPAREN),this.expect(p.RPAREN);this.skipNewlines();let r=this.parseCompoundCommandBody({forFunctionBody:!0}),s=this.parseOptionalRedirections();return w.functionDef(t,r,s)}parseCompoundCommandBody(t){let r=t?.forFunctionBody;if(this.check(p.LBRACE))return st(this,{skipRedirections:r});if(this.check(p.LPAREN))return rt(this,{skipRedirections:r});if(this.check(p.IF))return Je(this,{skipRedirections:r});if(this.check(p.FOR))return Ye(this,{skipRedirections:r});if(this.check(p.WHILE))return et(this,{skipRedirections:r});if(this.check(p.UNTIL))return tt(this,{skipRedirections:r});if(this.check(p.CASE))return nt(this,{skipRedirections:r});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth(),r=[];for(this.skipNewlines();!this.check(p.EOF,p.FI,p.ELSE,p.ELIF,p.THEN,p.DO,p.DONE,p.ESAC,p.RPAREN,p.RBRACE,p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let s=this.pos,n=this.parseStatement();if(n&&r.push(n),this.skipSeparators(),this.pos===s&&!n)break}return t(),r}parseOptionalRedirections(){let t=[];for(;De(this);){this.checkIterationLimit();let r=this.pos;if(t.push(xe(this)),this.pos===r)break}return t}parseArithmeticExpression(t){return M(this,t)}};function di(e,t){return new V().parse(e,t)}var Yr=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function ut(e){return Yr.get(e)??""}function hn(e){let t=[],r="",s=0;for(;s<e.length;){let n=e[s];if(n==="["){for(r+=n,s++,s<e.length&&(e[s]==="!"||e[s]==="^")&&(r+=e[s],s++),s<e.length&&e[s]==="]"&&(r+=e[s],s++);s<e.length&&e[s]!=="]";){if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let a=e.indexOf(":]",s+2);if(a!==-1){r+=e.slice(s,a+2),s=a+2;continue}}if(e[s]==="\\"&&s+1<e.length){r+=e[s]+e[s+1],s+=2;continue}r+=e[s],s++}s<e.length&&e[s]==="]"&&(r+=e[s],s++)}else n===":"?(r!==""&&t.push(r),r="",s++):n==="\\"&&s+1<e.length?(r+=n+e[s+1],s+=2):(r+=n,s++)}return r!==""&&t.push(r),t}function pn(e){let t="^";for(let r=0;r<e.length;r++){let s=e[r];if(s==="*")t+="[^/]*";else if(s==="?")t+="[^/]";else if(s==="["){let n=r+1,a="[";n<e.length&&(e[n]==="^"||e[n]==="!")&&(a+="^",n++),n<e.length&&e[n]==="]"&&(a+="\\]",n++);let i=n;for(;i<e.length;){if(e[i]==="\\"&&i+1<e.length){i+=2;continue}if(e[i]==="["&&i+1<e.length&&e[i+1]===":"){let o=e.indexOf(":]",i+2);if(o!==-1){i=o+2;continue}}if(e[i]==="]")break;i++}let l=n;for(;n<e.length&&e[n]!=="]";){if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let o=e.indexOf(":]",n+2);if(o!==-1){let c=e.slice(n+2,o),u=ut(c);a+=u,n=o+2;continue}}if(e[n]==="\\"&&n+1<e.length){a+=`\\${e[n+1]}`,n+=2;continue}if(e[n]==="-"){let o=n===l,c=n+1===i;o||c?a+="\\-":a+="-"}else a+=e[n];n++}a+="]",t+=a,r=n}else if(s==="\\"&&r+1<e.length){let n=e[r+1];/[.+^${}()|\\*?[\]]/.test(n)?t+=`\\${n}`:t+=n,r++}else/[.+^${}()|]/.test(s)?t+=`\\${s}`:t+=s}return t+="$",O(t)}function ct(e,t){let r=1,s=t+1;for(;s<e.length&&r>0;){let n=e[s];if(n==="\\"){s+=2;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function ft(e){let t=[],r="",s=0,n=!1,a=0;for(;a<e.length;){let i=e[a];if(i==="'"&&!n){n=!0,r+="\0QUOTE_START\0",a++;continue}if(i==="'"&&n){n=!1,r+="\0QUOTE_END\0",a++;continue}if(n){r+=i,a++;continue}if(i==="\\"){r+=i,a+1<e.length?(r+=e[a+1],a+=2):a++;continue}i==="("?(s++,r+=i):i===")"?(s--,r+=i):i==="|"&&s===0?(t.push(r),r=""):r+=i,a++}return t.push(r),t}var dn=5,oe=class{fs;cwd;globignorePatterns=[];hasGlobignore=!1;globstar=!1;nullglob=!1;failglob=!1;dotglob=!1;extglob=!1;globskipdots=!0;ops={count:0};maxOps;constructor(t,r,s,n){this.fs=t,this.cwd=r,typeof n=="boolean"?(this.globstar=n,this.maxOps=1e5):n?(this.globstar=n.globstar??!1,this.nullglob=n.nullglob??!1,this.failglob=n.failglob??!1,this.dotglob=n.dotglob??!1,this.extglob=n.extglob??!1,this.globskipdots=n.globskipdots??!0,this.maxOps=n.maxGlobOperations??1e5):this.maxOps=1e5;let a=s?.get("GLOBIGNORE");a!==void 0&&a!==""&&(this.hasGlobignore=!0,this.globignorePatterns=hn(a))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new L(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations")}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(r=>{let s=r.split("/").pop()||r;if((this.hasGlobignore||this.globskipdots)&&(s==="."||s===".."))return!1;if(this.hasGlobignore){for(let n of this.globignorePatterns)if(this.matchGlobignorePattern(r,n))return!1}return!0})}matchGlobignorePattern(t,r){return pn(r).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,r){let s=t.map((i,l)=>(r?.[l]??!1)||!this.isGlobPattern(i)?null:this.expand(i)),n=await Promise.all(s.map(i=>i||Promise.resolve(null))),a=[];for(let i=0;i<t.length;i++){let l=n[i];l===null?a.push(t[i]):l.length>0?a.push(...l):a.push(t[i])}return a}async expand(t){if(this.globstar){let s=t.split("/"),n=0;for(let a of s)if(a==="**"&&(n++,n>dn))throw new L(`Glob pattern has too many ** segments (max ${dn})`,"glob_operations")}let r;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))r=await this.expandRecursive(t);else{let s=t.replace(/\*\*+/g,"*");r=await this.expandSimple(s)}return this.filterGlobignore(r)}isGlobstarValid(t){let r=t.split("/");for(let s of r)if(s.includes("**")&&s!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let r=t.startsWith("/"),s=t.split("/").filter(c=>c!==""),n=-1;for(let c=0;c<s.length;c++)if(this.hasGlobChars(s[c])){n=c;break}if(n===-1)return[t];let a,i;if(n===0)r?(a="/",i="/"):(a=this.cwd,i="");else{let c=s.slice(0,n);r?(a=`/${c.join("/")}`,i=`/${c.join("/")}`):(a=this.fs.resolvePath(this.cwd,c.join("/")),i=c.join("/"))}let l=s.slice(n);return(await this.expandSegments(a,i,l)).sort()}async expandSegments(t,r,s){if(this.checkOpsLimit(),s.length===0)return[r];let[n,...a]=s,i=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let l=await this.fs.readdirWithFileTypes(t),o=[],c=[...l],u=this.dotglob||this.hasGlobignore;if(n.startsWith(".")||this.dotglob){let h=l.some(m=>m.name==="."),d=l.some(m=>m.name==="..");h||c.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),d||c.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let h of c)if(!(h.name.startsWith(".")&&!n.startsWith(".")&&!u)&&this.matchPattern(h.name,n)){let d=t==="/"?`/${h.name}`:`${t}/${h.name}`,m;r===""?m=h.name:r==="/"?m=`/${h.name}`:m=`${r}/${h.name}`,a.length===0?o.push(Promise.resolve([m])):h.isDirectory&&o.push(this.expandSegments(d,m,a))}let f=await Promise.all(o);for(let h of f)i.push(...h)}else{this.checkOpsLimit();let l=await this.fs.readdir(t),o=[],c=[...l],u=this.dotglob||this.hasGlobignore;(n.startsWith(".")||this.dotglob)&&(l.includes(".")||c.push("."),l.includes("..")||c.push(".."));for(let h of c)if(!(h.startsWith(".")&&!n.startsWith(".")&&!u)&&this.matchPattern(h,n)){let d=t==="/"?`/${h}`:`${t}/${h}`,m;r===""?m=h:r==="/"?m=`/${h}`:m=`${r}/${h}`,a.length===0?o.push(Promise.resolve([m])):o.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory)return this.expandSegments(d,m,a)}catch(g){if(g instanceof L)throw g}return[]})())}let f=await Promise.all(o);for(let h of f)i.push(...h)}}catch(l){if(l instanceof L)throw l}return i}async expandRecursive(t){let r=[],s=t.indexOf("**"),n=t.slice(0,s).replace(/\/$/,"")||".",i=t.slice(s+2).replace(/^\//,"");return i.includes("**")&&this.isGlobstarValid(i)?(await this.walkDirectoryMultiGlobstar(n,i,r),[...new Set(r)].sort()):(await this.walkDirectory(n,i,r),r.sort())}async walkDirectoryMultiGlobstar(t,r,s){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let a=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(n):null;if(a){let i=[];for(let c of a){let u=t==="."?c.name:`${t}/${c.name}`;c.isDirectory&&i.push(u)}let l=t==="."?r:`${t}/${r}`,o=await this.expandRecursive(l);s.push(...o);for(let c=0;c<i.length;c+=100){let u=i.slice(c,c+100);await Promise.all(u.map(f=>this.walkDirectoryMultiGlobstar(f,r,s)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(n),l=[];for(let u of i){let f=t==="."?u:`${t}/${u}`,h=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(h)).isDirectory&&l.push(f)}catch(d){if(d instanceof L)throw d}}let o=t==="."?r:`${t}/${r}`,c=await this.expandRecursive(o);s.push(...c);for(let u=0;u<l.length;u+=100){let f=l.slice(u,u+100);await Promise.all(f.map(h=>this.walkDirectoryMultiGlobstar(h,r,s)))}}}catch(a){if(a instanceof L)throw a}}async walkDirectory(t,r,s){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let a=await this.fs.readdirWithFileTypes(n),i=[],l=[];for(let o of a){let c=t==="."?o.name:`${t}/${o.name}`;o.isDirectory?l.push(c):r&&this.matchPattern(o.name,r)&&i.push(c)}s.push(...i);for(let o=0;o<l.length;o+=100){let c=l.slice(o,o+100);await Promise.all(c.map(u=>this.walkDirectory(u,r,s)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(n),i=[];for(let o=0;o<a.length;o+=100){let c=a.slice(o,o+100),u=await Promise.all(c.map(async f=>{let h=t==="."?f:`${t}/${f}`,d=this.fs.resolvePath(this.cwd,h);try{this.checkOpsLimit();let m=await this.fs.stat(d);return{name:f,path:h,isDirectory:m.isDirectory}}catch(m){if(m instanceof L)throw m;return null}}));i.push(...u.filter(f=>f!==null))}for(let o of i)!o.isDirectory&&r&&this.matchPattern(o.name,r)&&s.push(o.path);let l=i.filter(o=>o.isDirectory);for(let o=0;o<l.length;o+=100){let c=l.slice(o,o+100);await Promise.all(c.map(u=>this.walkDirectory(u.path,r,s)))}}}catch(a){if(a instanceof L)throw a}}matchPattern(t,r){return this.patternToRegex(r).test(t)}patternToRegex(t){let r=this.patternToRegexStr(t);return O(`^${r}$`)}patternToRegexStr(t){let r="",s=!1;for(let n=0;n<t.length;n++){if(t.slice(n,n+13)==="\0QUOTE_START\0"){s=!0,n+=12;continue}if(t.slice(n,n+11)==="\0QUOTE_END\0"){s=!1,n+=10;continue}let a=t[n];if(s){/[.+^${}()|\\*?[\]]/.test(a)?r+=`\\${a}`:r+=a;continue}if(this.extglob&&(a==="@"||a==="*"||a==="+"||a==="?"||a==="!")&&n+1<t.length&&t[n+1]==="("){let i=ct(t,n+1);if(i!==-1){let l=t.slice(n+2,i),o=ft(l),c=o.map(f=>this.patternToRegexStr(f)),u=c.length>0?c.join("|"):"(?:)";if(a==="@")r+=`(?:${u})`;else if(a==="*")r+=`(?:${u})*`;else if(a==="+")r+=`(?:${u})+`;else if(a==="?")r+=`(?:${u})?`;else if(a==="!")if(i<t.length-1){let h=o.map(m=>this.computePatternLength(m));if(h.every(m=>m!==null)&&h.every(m=>m===h[0])&&h[0]!==null){let m=h[0];if(m===0)r+="(?:.+)";else{let g=[];m>0&&g.push(`.{0,${m-1}}`),g.push(`.{${m+1},}`),g.push(`(?!(?:${u})).{${m}}`),r+=`(?:${g.join("|")})`}}else r+=`(?:(?!(?:${u})).)*?`}else r+=`(?!(?:${u})$).*`;n=i;continue}}if(a==="*")r+=".*";else if(a==="?")r+=".";else if(a==="["){let i=n+1,l="[";i<t.length&&(t[i]==="^"||t[i]==="!")&&(l+="^",i++),i<t.length&&t[i]==="]"&&(l+="\\]",i++);let o=i;for(;o<t.length;){if(t[o]==="\\"&&o+1<t.length){o+=2;continue}if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let u=t.indexOf(":]",o+2);if(u!==-1){o=u+2;continue}}if(t[o]==="]")break;o++}let c=i;for(;i<t.length&&t[i]!=="]";){if(t[i]==="["&&i+1<t.length&&t[i+1]===":"){let u=t.indexOf(":]",i+2);if(u!==-1){let f=t.slice(i+2,u),h=ut(f);l+=h,i=u+2;continue}}if(t[i]==="\\"&&i+1<t.length){l+=`\\${t[i+1]}`,i+=2;continue}if(t[i]==="-"){let u=i===c,f=i+1===o;u||f?l+="\\-":l+="-"}else l+=t[i];i++}l+="]",r+=l,n=i}else if(a==="\\"&&n+1<t.length){let i=t[n+1];/[.+^${}()|\\*?[\]]/.test(i)?r+=`\\${i}`:r+=i,n++}else/[.+^${}()|]/.test(a)?r+=`\\${a}`:r+=a}return r}computePatternLength(t){let r=0,s=0,n=!1;for(;s<t.length;){if(t.slice(s,s+13)==="\0QUOTE_START\0"){n=!0,s+=13;continue}if(t.slice(s,s+11)==="\0QUOTE_END\0"){n=!1,s+=11;continue}let a=t[s];if(n){r+=1,s++;continue}if((a==="@"||a==="*"||a==="+"||a==="?"||a==="!")&&s+1<t.length&&t[s+1]==="("){let i=ct(t,s+1);if(i!==-1){if(a==="@"){let l=t.slice(s+2,i),c=ft(l).map(u=>this.computePatternLength(u));if(c.every(u=>u!==null)&&c.every(u=>u===c[0])){r+=c[0],s=i+1;continue}return null}return null}}if(a==="*")return null;if(a==="?"){r+=1,s++;continue}if(a==="["){let i=t.indexOf("]",s+1);if(i!==-1){r+=1,s=i+1;continue}r+=1,s++;continue}if(a==="\\"){r+=1,s+=2;continue}r+=1,s++}return r}};function es(e,t,r){switch(r){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new C("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new C("division by 0");return e%t;case"**":if(t<0)throw new C("exponent less than 0");return e**t;case"<<":return e<<t;case">>":return e>>t;case"<":return e<t?1:0;case"<=":return e<=t?1:0;case">":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function mn(e,t,r){switch(r){case"=":return t;case"+=":return e+t;case"-=":return e-t;case"*=":return e*t;case"/=":return t!==0?Math.trunc(e/t):0;case"%=":return t!==0?e%t:0;case"<<=":return e<<t;case">>=":return e>>t;case"&=":return e&t;case"|=":return e|t;case"^=":return e^t;default:return t}}function ts(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function ns(e,t){let r=e.state.env.get(t);if(r!==void 0)return r;let s=e.state.env.get(`${t}_0`);return s!==void 0?s:await v(e,t)}function rs(e){if(!e)return 0;let t=Number.parseInt(e,10);if(!Number.isNaN(t)&&/^-?\d+$/.test(e.trim()))return t;let r=e.trim();if(!r)return 0;try{let s=new V,{expr:n,pos:a}=Z(s,r,0);if(a<r.length){let i=r.slice(a).trim().split(/\s+/)[0];throw new C(`${r}: syntax error in expression (error token is "${i}")`)}return n.type==="ArithNumber"?n.value:t||0}catch(s){if(s instanceof C)throw s;let n=r.split(/\s+/).slice(1)[0]||r;throw new C(`${r}: syntax error in expression (error token is "${n}")`)}}async function ht(e,t){if(!t)return 0;let r=Number.parseInt(t,10);if(!Number.isNaN(r)&&/^-?\d+$/.test(t.trim()))return r;let s=t.trim();if(!s)return 0;let n=new V,{expr:a,pos:i}=Z(n,s,0);if(i<s.length){let l=s.slice(i).trim(),o=l.split(/\s+/)[0]||l;throw new C(`syntax error in expression (error token is "${o}")`,"","")}return await R(e,a)}async function pt(e,t,r=new Set,s=0){if(s>100)throw new C("maximum variable indirection depth exceeded");if(r.has(t))return 0;r.add(t);let n=await ns(e,t);if(!n)return 0;let a=Number.parseInt(n,10);if(!Number.isNaN(a)&&/^-?\d+$/.test(n.trim()))return a;let i=n.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return await pt(e,i,r,s+1);let l=new V,{expr:o,pos:c}=Z(l,i,0);if(c<i.length){let u=i.slice(c).trim(),f=u.split(/\s+/)[0]||u;throw new C(`${i}: syntax error in expression (error token is "${f}")`)}return await R(e,o)}async function _e(e,t){if(t.startsWith("#")){let f=t.slice(1),h=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(h){let m=h[1],g=P(e,m);return String(g.length)}let d=e.state.env.get(f)||"";return String(d.length)}if(t.startsWith("!")){let f=t.slice(1),h=e.state.env.get(f)||"";return e.state.env.get(h)||""}let r=[":-",":=",":?",":+","-","=","?","+"],s=-1,n="";for(let f of r){let h=t.indexOf(f);h>0&&(s===-1||h<s)&&(s=h,n=f)}if(s===-1)return await v(e,t);let a=t.slice(0,s),i=t.slice(s+n.length),l=e.state.env.get(a),o=l===void 0,c=l==="",u=n.startsWith(":");switch(n){case":-":case"-":return o||u&&c?i:l||"";case":=":case"=":return o||u&&c?(e.state.env.set(a,i),i):l||"";case":+":case"+":return!(o||u&&c)?i:"";case":?":case"?":{if(o||u&&c)throw new Error(i||`${a}: parameter null or not set`);return l||""}default:return l||""}}async function R(e,t,r=!1){switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new C("value too great for base");return t.value;case"ArithVariable":return await pt(e,t.name);case"ArithSpecialVar":{let n=(await v(e,t.name)).trim();if(!n)return 0;let a=Number.parseInt(n,10);if(!Number.isNaN(a)&&/^-?\d+$/.test(n))return a;let i=new V,{expr:l}=Z(i,n,0);return await R(e,l)}case"ArithNested":return await R(e,t.expression);case"ArithCommandSubst":{if(e.execFn){let s=await e.execFn(t.command,{signal:e.state.signal});s.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+s.stderr);let n=s.stdout.trim();return Number.parseInt(n,10)||0}return 0}case"ArithBracedExpansion":{let s=await _e(e,t.content);return Number.parseInt(s,10)||0}case"ArithDynamicBase":{let s=await _e(e,t.baseExpr),n=Number.parseInt(s,10);if(n<2||n>64)return 0;let a=`${n}#${t.value}`;return ge(a)}case"ArithDynamicNumber":{let n=await _e(e,t.prefix)+t.suffix;return ge(n)}case"ArithArrayElement":{let s=e.state.associativeArrays?.has(t.array),n=async a=>{let i=e.state.env.get(a);return i!==void 0?await ht(e,i):0};if(t.stringKey!==void 0)return await n(`${t.array}_${t.stringKey}`);if(s&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await n(`${t.array}_${t.index.name}`);if(s&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let a=await v(e,t.index.name);return await n(`${t.array}_${a}`)}if(t.index){let a=await R(e,t.index,r);if(a<0){let o=P(e,t.array),c=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${c}: ${t.array}: bad array subscript
|
|
49
49
|
`,0;let f=Math.max(...o.map(([h])=>typeof h=="number"?h:0))+1+a;if(f<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${c}: ${t.array}: bad array subscript
|
|
50
|
-
`,0;a=f}let i=`${t.array}_${a}`,l=e.state.env.get(i);if(l!==void 0)return
|
|
50
|
+
`,0;a=f}let i=`${t.array}_${a}`,l=e.state.env.get(i);if(l!==void 0)return ht(e,l);if(a===0){let o=e.state.env.get(t.array);if(o!==void 0)return ht(e,o)}if(e.state.options.nounset&&!Array.from(e.state.env.keys()).some(c=>c===t.array||c.startsWith(`${t.array}_`)))throw new j(`${t.array}[${a}]`);return 0}return 0}case"ArithDoubleSubscript":throw new C("double subscript","","");case"ArithNumberSubscript":throw new C(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new C(t.message,"","",!0);case"ArithSingleQuote":{if(r)throw new C(`syntax error: operand expected (error token is "'${t.content}'")`);return t.value}case"ArithBinary":{if(t.operator==="||")return await R(e,t.left,r)||await R(e,t.right,r)?1:0;if(t.operator==="&&")return await R(e,t.left,r)&&await R(e,t.right,r)?1:0;let s=await R(e,t.left,r),n=await R(e,t.right,r);return es(s,n,t.operator)}case"ArithUnary":{let s=await R(e,t.operand,r);if(t.operator==="++"||t.operator==="--"){if(t.operand.type==="ArithVariable"){let n=t.operand.name,a=Number.parseInt(await v(e,n),10)||0,i=t.operator==="++"?a+1:a-1;return e.state.env.set(n,String(i)),t.prefix?i:a}if(t.operand.type==="ArithArrayElement"){let n=t.operand.array,a=e.state.associativeArrays?.has(n),i;if(t.operand.stringKey!==void 0)i=`${n}_${t.operand.stringKey}`;else if(a&&t.operand.index?.type==="ArithVariable"&&!t.operand.index.hasDollarPrefix)i=`${n}_${t.operand.index.name}`;else if(a&&t.operand.index?.type==="ArithVariable"&&t.operand.index.hasDollarPrefix){let c=await v(e,t.operand.index.name);i=`${n}_${c}`}else if(t.operand.index){let c=await R(e,t.operand.index,r);i=`${n}_${c}`}else return s;let l=Number.parseInt(e.state.env.get(i)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(i,String(o)),t.prefix?o:l}if(t.operand.type==="ArithConcat"){let n="";for(let a of t.operand.parts)n+=await de(e,a,r);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let a=Number.parseInt(e.state.env.get(n)||"0",10)||0,i=t.operator==="++"?a+1:a-1;return e.state.env.set(n,String(i)),t.prefix?i:a}}if(t.operand.type==="ArithDynamicElement"){let n="";if(t.operand.nameExpr.type==="ArithConcat")for(let a of t.operand.nameExpr.parts)n+=await de(e,a,r);else t.operand.nameExpr.type==="ArithVariable"&&(n=t.operand.nameExpr.hasDollarPrefix?await v(e,t.operand.nameExpr.name):t.operand.nameExpr.name);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let a=await R(e,t.operand.subscript,r),i=`${n}_${a}`,l=Number.parseInt(e.state.env.get(i)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(i,String(o)),t.prefix?o:l}}return s}return ts(s,t.operator)}case"ArithTernary":return await R(e,t.condition,r)?await R(e,t.consequent,r):await R(e,t.alternate,r);case"ArithAssignment":{let s=t.variable,n=s;if(t.stringKey!==void 0)n=`${s}_${t.stringKey}`;else if(t.subscript){let o=e.state.associativeArrays?.has(s);if(o&&t.subscript.type==="ArithVariable"&&!t.subscript.hasDollarPrefix)n=`${s}_${t.subscript.name}`;else if(o&&t.subscript.type==="ArithVariable"&&t.subscript.hasDollarPrefix){let c=await v(e,t.subscript.name);n=`${s}_${c||"\\"}`}else if(o){let c=await R(e,t.subscript,r);n=`${s}_${c}`}else{let c=await R(e,t.subscript,r);if(c<0){let u=P(e,s);u.length>0&&(c=Math.max(...u.map(([h])=>typeof h=="number"?h:0))+1+c)}n=`${s}_${c}`}}let a=Number.parseInt(e.state.env.get(n)||"0",10)||0,i=await R(e,t.value,r),l=mn(a,i,t.operator);return e.state.env.set(n,String(l)),l}case"ArithGroup":return await R(e,t.expression,r);case"ArithConcat":{let s="";for(let n of t.parts)s+=await de(e,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)?await pt(e,s):Number.parseInt(s,10)||0}case"ArithDynamicAssignment":{let s="";if(t.target.type==="ArithConcat")for(let o of t.target.parts)s+=await de(e,o,r);else t.target.type==="ArithVariable"&&(s=t.target.hasDollarPrefix?await v(e,t.target.name):t.target.name);if(!s||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s))return 0;let n=s;if(t.subscript){let o=await R(e,t.subscript,r);n=`${s}_${o}`}let a=Number.parseInt(e.state.env.get(n)||"0",10)||0,i=await R(e,t.value,r),l=mn(a,i,t.operator);return e.state.env.set(n,String(l)),l}case"ArithDynamicElement":{let s="";if(t.nameExpr.type==="ArithConcat")for(let l of t.nameExpr.parts)s+=await de(e,l,r);else t.nameExpr.type==="ArithVariable"&&(s=t.nameExpr.hasDollarPrefix?await v(e,t.nameExpr.name):t.nameExpr.name);if(!s||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s))return 0;let n=await R(e,t.subscript,r),a=`${s}_${n}`,i=e.state.env.get(a);return i!==void 0?rs(i):0}default:return 0}}async function de(e,t,r=!1){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await R(e,t,r));case"ArithVariable":return t.hasDollarPrefix?await v(e,t.name):t.name;case"ArithSpecialVar":return await v(e,t.name);case"ArithBracedExpansion":return await _e(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command,{signal:e.state.signal})).stdout.trim():"0";case"ArithConcat":{let s="";for(let n of t.parts)s+=await de(e,n,r);return s}default:return String(await R(e,t,r))}}function dt(e){for(let t=0;t<e.length;t++){if(e[t]==="\\"){t++;continue}if(e[t]==="$"){let r=e[t+1];if(r==="{"||r&&/[a-zA-Z_]/.test(r))return!0}}return!1}function ss(e){if(!e.operation)return!1;let t=e.operation,r;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(r=t.word?.parts),!r)return!1;for(let s of r)if(s.type==="DoubleQuoted"||s.type==="SingleQuoted")return!0;return!1}function gn(e){if(!e.operation)return!1;let t=e.operation,r;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(r=t.word?.parts),!r||r.length===0)return!1;for(let s of r)if(s.type!=="DoubleQuoted"&&s.type!=="SingleQuoted")return!1;return!0}function Ae(e){let t=!1,r=!1,s=!1,n=!1,a=!1,i=!1,l=!1;for(let o of e){if((o.type==="SingleQuoted"||o.type==="DoubleQuoted")&&(t=!0,o.type==="DoubleQuoted"))for(let c of o.parts)c.type==="ParameterExpansion"&&(c.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!c.operation||c.operation.type==="PatternRemoval"||c.operation.type==="PatternReplacement")&&(n=!0),(c.operation?.type==="VarNamePrefix"||c.operation?.type==="ArrayKeys")&&(i=!0),c.operation?.type==="Indirection"&&(l=!0));o.type==="CommandSubstitution"&&(r=!0),o.type==="ParameterExpansion"&&(a=!0,(o.parameter==="@"||o.parameter==="*")&&(s=!0),ss(o)&&(t=!0),(o.operation?.type==="VarNamePrefix"||o.operation?.type==="ArrayKeys")&&(i=!0),o.operation?.type==="Indirection"&&(l=!0)),o.type==="Glob"&&dt(o.pattern)&&(a=!0)}return{hasQuoted:t,hasCommandSub:r,hasArrayVar:s,hasArrayAtExpansion:n,hasParamExpansion:a,hasVarNamePrefixExpansion:i,hasIndirection:l}}var yn="5.1.0(1)-release",xi="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function _i(e){let{pid:t,ppid:r,uid:s,gid:n}=e;return`Name: bash
|
|
51
51
|
State: R (running)
|
|
52
52
|
Pid: ${t}
|
|
53
53
|
PPid: ${r}
|
|
54
54
|
Uid: ${s} ${s} ${s} ${s}
|
|
55
55
|
Gid: ${n} ${n} ${n} ${n}
|
|
56
|
-
`}function
|
|
57
|
-
`}function q(e){return e.get("IFS")===""}function
|
|
58
|
-
`)return!1;return!0}function
|
|
59
|
-
`?r.push("\\n"):r.push(s);return t&&r.push("\\-"),r.join("")}function N(e){let t=e.get("IFS");return t===void 0?" ":t[0]||""}var
|
|
60
|
-
`;function
|
|
56
|
+
`}function mt(e,t){let r=`${t}_`,s=[];for(let n of e.state.env.keys())if(n.startsWith(r)){let a=n.slice(r.length),i=Number.parseInt(a,10);!Number.isNaN(i)&&String(i)===a&&s.push(i)}return s.sort((n,a)=>n-a)}function Ci(e,t){let r=`${t}_`;for(let s of e.state.env.keys())s.startsWith(r)&&e.state.env.delete(s)}function gt(e,t){let r=`${t}_`,s=`${t}__length`,n=[];for(let a of e.state.env.keys())if(a!==s&&a.startsWith(r)){let i=a.slice(r.length);if(i.startsWith("_length"))continue;n.push(i)}return n.sort()}function $e(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function Oi(e){if(e.parts.length<2)return null;let t=e.parts[0],r=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let s,n=r,a=1;if(r.type==="Literal"&&r.value.startsWith("]")){let f=r.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))s=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let h=e.parts[2];if(h.type!=="Literal"||!h.value.startsWith("=")&&!h.value.startsWith("+="))return null;s=t.pattern.slice(1),n=h,a=2}else return null}else if(t.pattern==="["&&(r.type==="DoubleQuoted"||r.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(r.type==="SingleQuoted")s=r.value;else{s="";for(let h of r.parts)(h.type==="Literal"||h.type==="Escaped")&&(s+=h.value)}n=f,a=2}else if(t.pattern.endsWith("]")){if(r.type!=="Literal"||!r.value.startsWith("=")&&!r.value.startsWith("+="))return null;s=t.pattern.slice(1,-1)}else return null;s=$e(s);let i;if(n.type!=="Literal")return null;n.value.startsWith("]=")||n.value.startsWith("]+=")?i=n.value.slice(1):i=n.value;let l=i.startsWith("+=");if(!l&&!i.startsWith("="))return null;let o=[],c=l?2:1,u=i.slice(c);u&&o.push({type:"Literal",value:u});for(let f=a+1;f<e.parts.length;f++){let h=e.parts[f];h.type==="BraceExpansion"?o.push({type:"Literal",value:is(h)}):o.push(h)}return{key:s,valueParts:o,append:l}}function is(e){return`{${e.items.map(r=>{if(r.type==="Range"){let s=r.startStr??String(r.start),n=r.endStr??String(r.end),a=`${s}..${n}`;return r.step&&(a+=`..${r.step}`),a}return En(r.word)}).join(",")}}`}function En(e){let t="";for(let r of e.parts)switch(r.type){case"Literal":t+=r.value;break;case"Glob":t+=r.pattern;break;case"SingleQuoted":t+=r.value;break;case"DoubleQuoted":for(let s of r.parts)(s.type==="Literal"||s.type==="Escaped")&&(t+=s.value);break;case"Escaped":t+=r.value;break;case"BraceExpansion":t+="{",t+=r.items.map(s=>s.type==="Range"?`${s.startStr}..${s.endStr}${s.step?`..${s.step}`:""}`:En(s.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",r.user&&(t+=r.user);break}return t}function T(e){return e.get("IFS")??`
|
|
57
|
+
`}function q(e){return e.get("IFS")===""}function Ce(e){let t=T(e);if(t==="")return!0;for(let r of t)if(r!==" "&&r!==" "&&r!==`
|
|
58
|
+
`)return!1;return!0}function An(e){let t=!1,r=[];for(let s of e.split(""))s==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(s)?r.push(`\\${s}`):s===" "?r.push("\\t"):s===`
|
|
59
|
+
`?r.push("\\n"):r.push(s);return t&&r.push("\\-"),r.join("")}function N(e){let t=e.get("IFS");return t===void 0?" ":t[0]||""}var as=`
|
|
60
|
+
`;function os(e){return as.includes(e)}function yt(e){let t=new Set,r=new Set;for(let s of e)os(s)?t.add(s):r.add(s);return{whitespace:t,nonWhitespace:r}}function Wi(e,t,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:{words:[e],wordStarts:[0]};let{whitespace:n,nonWhitespace:a}=yt(t),i=[],l=[],o=0;for(;o<e.length&&n.has(e[o]);)o++;if(o>=e.length)return{words:[],wordStarts:[]};if(a.has(e[o]))for(i.push(""),l.push(o),o++;o<e.length&&n.has(e[o]);)o++;for(;o<e.length&&!(r!==void 0&&i.length>=r);){let c=o;for(l.push(c);o<e.length;){let u=e[o];if(!s&&u==="\\"){o++,o<e.length&&o++;continue}if(n.has(u)||a.has(u))break;o++}if(i.push(e.substring(c,o)),o>=e.length)break;for(;o<e.length&&n.has(e[o]);)o++;if(o<e.length&&a.has(e[o])){for(o++;o<e.length&&n.has(e[o]);)o++;for(;o<e.length&&a.has(e[o])&&!(r!==void 0&&i.length>=r);)for(i.push(""),l.push(o),o++;o<e.length&&n.has(e[o]);)o++}}return{words:i,wordStarts:l}}function Oe(e,t){if(t==="")return{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:r,nonWhitespace:s}=yt(t),n=[],a=0,i=!1,l=!1,o=a;for(;a<e.length&&r.has(e[a]);)a++;if(a>o&&(i=!0),a>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[a]))for(n.push(""),a++;a<e.length&&r.has(e[a]);)a++;for(;a<e.length;){let c=a;for(;a<e.length;){let f=e[a];if(r.has(f)||s.has(f))break;a++}if(n.push(e.substring(c,a)),a>=e.length){l=!1;break}let u=a;for(;a<e.length&&r.has(e[a]);)a++;if(a<e.length&&s.has(e[a])){for(a++;a<e.length&&r.has(e[a]);)a++;for(;a<e.length&&s.has(e[a]);)for(n.push(""),a++;a<e.length&&r.has(e[a]);)a++}a>=e.length&&a>u&&(l=!0)}return{words:n,hadLeadingDelimiter:i,hadTrailingDelimiter:l}}function x(e,t){return Oe(e,t).words}function ls(e,t){for(let r of e)if(t.has(r))return!0;return!1}function Ti(e,t,r){if(t==="")return e;let{whitespace:s,nonWhitespace:n}=yt(t),a=e.length;for(;a>0&&s.has(e[a-1]);){if(!r&&a>=2){let l=0,o=a-2;for(;o>=0&&e[o]==="\\";)l++,o--;if(l%2===1)break}a--}let i=e.substring(0,a);if(i.length>=1&&n.has(i[i.length-1])){if(!r&&i.length>=2){let o=0,c=i.length-2;for(;c>=0&&i[c]==="\\";)o++,c--;if(o%2===1)return i}let l=i.substring(0,i.length-1);if(!ls(l,n))return l}return i}function W(e,t){return e.state.namerefs?.has(t)??!1}function Vi(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function qi(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Bi(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function Sn(e,t){return e.state.invalidNamerefs?.has(t)??!1}function Fi(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function us(e,t){let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let n=r[1],a=Array.from(e.state.env.keys()).some(l=>l.startsWith(`${n}_`)&&!l.includes("__")),i=e.state.associativeArrays?.has(n)??!1;return a||i}return Array.from(e.state.env.keys()).some(n=>n.startsWith(`${t}_`)&&!n.includes("__"))?!0:e.state.env.has(t)}function he(e,t,r=100){if(!W(e,t)||Sn(e,t))return t;let s=new Set,n=t;for(;r-- >0;){if(s.has(n))return;if(s.add(n),!W(e,n))return n;let a=e.state.env.get(n);if(a===void 0||a===""||!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(a))return n;n=a}}function Se(e,t){if(W(e,t))return e.state.env.get(t)}function zi(e,t,r,s=100){if(!W(e,t)||Sn(e,t))return t;let n=new Set,a=t;for(;s-- >0;){if(n.has(a))return;if(n.add(a),!W(e,a))return a;let i=e.state.env.get(a);if(i===void 0||i==="")return r!==void 0?/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&us(e,r)?a:null:a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(i))return a;a=i}}function cs(e,t){let r=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(s,n)=>e.state.env.get(n)??"");return r=r.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(s,n)=>e.state.env.get(n)??""),r}function P(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((a,i)=>[i,a]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((a,i)=>[i,String(a)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((a,i)=>[i,a]):e.state.associativeArrays?.has(t)?gt(e,t).map(a=>[a,e.state.env.get(`${t}_${a}`)??""]):mt(e,t).map(n=>[n,e.state.env.get(`${t}_${n}`)??""])}function be(e,t){return t==="FUNCNAME"?(e.state.funcNameStack?.length??0)>0:t==="BASH_LINENO"?(e.state.callLineStack?.length??0)>0:t==="BASH_SOURCE"?(e.state.sourceStack?.length??0)>0:e.state.associativeArrays?.has(t)?gt(e,t).length>0:mt(e,t).length>0}async function v(e,t,r=!0,s=!1){switch(t){case"?":return String(e.state.lastExitCode);case"$":return String(e.state.virtualPid);case"#":return e.state.env.get("#")||"0";case"@":return e.state.env.get("@")||"";case"_":return e.state.lastArg;case"-":{let i="";return i+="h",e.state.options.errexit&&(i+="e"),e.state.options.noglob&&(i+="f"),e.state.options.nounset&&(i+="u"),e.state.options.verbose&&(i+="v"),e.state.options.xtrace&&(i+="x"),i+="B",e.state.options.noclobber&&(i+="C"),i+="s",i}case"*":{let i=Number.parseInt(e.state.env.get("#")||"0",10);if(i===0)return"";let l=[];for(let o=1;o<=i;o++)l.push(e.state.env.get(String(o))||"");return l.join(N(e.state.env))}case"0":return e.state.env.get("0")||"bash";case"PWD":return e.state.env.get("PWD")??"";case"OLDPWD":return e.state.env.get("OLDPWD")??"";case"PPID":return String(e.state.virtualPpid);case"UID":return String(e.state.virtualUid);case"EUID":return String(e.state.virtualUid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-e.state.startTime)/1e3));case"BASH_VERSION":return yn;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let i=e.state.funcNameStack?.[0];if(i!==void 0)return i;if(r&&e.state.options.nounset)throw new j("FUNCNAME");return""}case"BASH_LINENO":{let i=e.state.callLineStack?.[0];if(i!==void 0)return String(i);if(r&&e.state.options.nounset)throw new j("BASH_LINENO");return""}case"BASH_SOURCE":{let i=e.state.sourceStack?.[0];if(i!==void 0)return i;if(r&&e.state.options.nounset)throw new j("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new re(`\${${t}}`);let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let i=n[1],l=n[2];if(W(e,i)){let f=he(e,i);if(f&&f!==i){if(f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";i=f}}if(l==="@"||l==="*"){let f=P(e,i);if(f.length>0)return f.map(([,d])=>d).join(" ");let h=e.state.env.get(i);return h!==void 0?h:""}if(i==="FUNCNAME"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.funcNameStack?.[f]??"":""}if(i==="BASH_LINENO"){let f=Number.parseInt(l,10);if(!Number.isNaN(f)&&f>=0){let h=e.state.callLineStack?.[f];return h!==void 0?String(h):""}return""}if(i==="BASH_SOURCE"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.sourceStack?.[f]??"":""}if(e.state.associativeArrays?.has(i)){let f=$e(l);f=cs(e,f);let h=e.state.env.get(`${i}_${f}`);if(h===void 0&&r&&e.state.options.nounset)throw new j(`${i}[${l}]`);return h||""}let c;if(/^-?\d+$/.test(l))c=Number.parseInt(l,10);else try{let f=new V,h=M(f,l);c=await R(e,h.expression)}catch{let f=e.state.env.get(l);c=f?Number.parseInt(f,10):0,Number.isNaN(c)&&(c=0)}if(c<0){let f=P(e,i),h=e.state.currentLine;if(f.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${h}: ${i}: bad array subscript
|
|
61
61
|
`,"";let m=Math.max(...f.map(([E])=>typeof E=="number"?E:0))+1+c;return m<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${h}: ${i}: bad array subscript
|
|
62
|
-
`,""):e.state.env.get(`${i}_${m}`)||""}let u=e.state.env.get(`${i}_${c}`);if(u!==void 0)return u;if(c===0){let f=e.state.env.get(i);if(f!==void 0)return f}if(r&&e.state.options.nounset)throw new j(`${i}[${c}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let i=e.state.env.get(t);if(i===void 0&&r&&e.state.options.nounset)throw new j(t);return i||""}if(W(e,t)){let i=he(e,t);if(i===void 0)return"";if(i!==t)return await v(e,i,r,s);let l=e.state.env.get(t);if((l===void 0||l==="")&&r&&e.state.options.nounset)throw new j(t);return l||""}let a=e.state.env.get(t);if(a!==void 0)return e.state.tempEnvBindings?.some(i=>i.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),a;if(Se(e,t)){let i=e.state.env.get(`${t}_0`);return i!==void 0?i:""}if(r&&e.state.options.nounset)throw new j(t);return""}async function te(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],a=s[2];if(W(e,n)){let o=he(e,n);if(o&&o!==n){if(o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;n=o}}if(a==="@"||a==="*")return P(e,n).length>0?!0:e.state.env.has(n);if(e.state.associativeArrays?.has(n)){let o=_e(a);return e.state.env.has(`${n}_${o}`)}let l;if(/^-?\d+$/.test(a))l=Number.parseInt(a,10);else try{let o=new V,c=M(o,a);l=await R(e,c.expression)}catch{let o=e.state.env.get(a);l=o?Number.parseInt(o,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let o=P(e,n);if(o.length===0)return!1;let u=Math.max(...o.map(([f])=>typeof f=="number"?f:0))+1+l;return u<0?!1:e.state.env.has(`${n}_${u}`)}return e.state.env.has(`${n}_${l}`)}if(W(e,t)){let n=he(e,t);return n===void 0||n===t?e.state.env.has(t):te(e,n)}return!!(e.state.env.has(t)||Se(e,t))}async function Sn(e,t){let r="",s=0;for(;s<t.length;){if(t[s]==="$"){if(t[s+1]==="{"){let n=1,a=s+2;for(;a<t.length&&n>0;)t[a]==="{"?n++:t[a]==="}"&&n--,a++;r+=t.slice(s,a),s=a;continue}if(t[s+1]==="("){let n=1,a=s+2;for(;a<t.length&&n>0;)t[a]==="("?n++:t[a]===")"&&n--,a++;r+=t.slice(s,a),s=a;continue}if(/[a-zA-Z_]/.test(t[s+1]||"")){let n=s+1;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)n++;let a=t.slice(s+1,n),i=await v(e,a);r+=i,s=n;continue}if(/[0-9]/.test(t[s+1]||"")){let n=s+1;for(;n<t.length&&/[0-9]/.test(t[n]);)n++;let a=t.slice(s+1,n),i=await v(e,a);r+=i,s=n;continue}if(/[*@#?\-!$]/.test(t[s+1]||"")){let n=t[s+1],a=await v(e,n);r+=a,s+=2;continue}}if(t[s]==='"'){for(r+='"',s++;s<t.length&&t[s]!=='"';)if(t[s]==="$"&&/[a-zA-Z_]/.test(t[s+1]||"")){let n=s+1;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)n++;let a=t.slice(s+1,n),i=await v(e,a);r+=i,s=n}else t[s]==="\\"?(r+=t[s],s++,s<t.length&&(r+=t[s],s++)):(r+=t[s],s++);s<t.length&&(r+='"',s++);continue}r+=t[s],s++}return r}async function yt(e,t){let r=t,s=t.startsWith('"')&&t.endsWith('"'),n=t.startsWith("'")&&t.endsWith("'");if((s||n)&&(r=t.slice(1,-1)),n)return r;let a="",i=0;for(;i<r.length;)if(r[i]==="$")if(r[i+1]==="("){let l=1,o=i+2;for(;o<r.length&&l>0;)r[o]==="("&&r[o-1]==="$"||r[o]==="("?l++:r[o]===")"&&l--,o++;let c=r.slice(i+2,o-1);if(e.execFn){let u=await e.execFn(c,{signal:e.state.signal});a+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}i=o}else if(r[i+1]==="{"){let l=1,o=i+2;for(;o<r.length&&l>0;)r[o]==="{"?l++:r[o]==="}"&&l--,o++;let c=r.slice(i+2,o-1),u=await v(e,c);a+=u,i=o}else if(/[a-zA-Z_]/.test(r[i+1]||"")){let l=i+1;for(;l<r.length&&/[a-zA-Z0-9_]/.test(r[l]);)l++;let o=r.slice(i+1,l),c=await v(e,o);a+=c,i=l}else a+=r[i],i++;else if(r[i]==="`"){let l=i+1;for(;l<r.length&&r[l]!=="`";)l++;let o=r.slice(i+1,l);if(e.execFn){let c=await e.execFn(o,{signal:e.state.signal});a+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}i=l+1}else a+=r[i],i++;return a}var Oe=1e4;function cs(e,t,r,s,n){let a=r??1;a===0&&(a=1);let i=Math.abs(a),l=[],o=0;s?.match(/^-?0\d/)&&(o=Math.max(o,s.replace(/^-/,"").length)),n?.match(/^-?0\d/)&&(o=Math.max(o,n.replace(/^-/,"").length));let c=u=>{if(o>0){let f=u<0,h=String(Math.abs(u)).padStart(o,"0");return f?`-${h}`:h}return String(u)};if(e<=t)for(let u=e,f=0;u<=t&&f<Oe;u+=i,f++)l.push(c(u));else for(let u=e,f=0;u>=t&&f<Oe;u-=i,f++)l.push(c(u));return l}function fs(e,t,r){let s=r??1;s===0&&(s=1);let n=e.charCodeAt(0),a=t.charCodeAt(0),i=Math.abs(s),l=e>="A"&&e<="Z",o=e>="a"&&e<="z",c=t>="A"&&t<="Z",u=t>="a"&&t<="z";if(l&&u||o&&c){let h=r!==void 0?`..${r}`:"";throw new Rt(`{${e}..${t}${h}}: invalid sequence`)}let f=[];if(n<=a)for(let h=n,d=0;h<=a&&d<Oe;h+=i,d++)f.push(String.fromCharCode(h));else for(let h=n,d=0;h>=a&&d<Oe;h-=i,d++)f.push(String.fromCharCode(h));return f}function Et(e,t,r,s,n){let a=r!==void 0?`..${r}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:cs(e,t,r,s,n),literal:`{${e}..${t}${a}}`}:typeof e=="string"&&typeof t=="string"?{expanded:fs(e,t,r),literal:`{${e}..${t}${a}}`}:{expanded:null,literal:`{${e}..${t}${a}}`}}function bn(e){if(e.statements.length!==1)return null;let t=e.statements[0];if(t.operators.length!==0||t.pipelines.length!==1)return null;let r=t.pipelines[0];if(r.negated||r.commands.length!==1)return null;let s=r.commands[0];if(s.type!=="SimpleCommand")return null;let n=s;if(n.name!==null||n.args.length!==0||n.assignments.length!==0||n.redirections.length!==1)return null;let a=n.redirections[0];return a.operator!=="<"||a.target.type!=="Word"?null:{target:a.target}}function ne(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function At(e){let t="",r=0;for(;r<e.length;)e[r]==="\\"&&r+1<e.length?(t+=e[r+1],r+=2):(t+=e[r],r++);return t}function X(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function St(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function I(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function k(e,t,r=!1){let s="",n=0;for(;n<e.length;){let a=e[n];if(r&&(a==="@"||a==="*"||a==="+"||a==="?"||a==="!")&&n+1<e.length&&e[n+1]==="("){let i=hs(e,n+1);if(i!==-1){let l=e.slice(n+2,i),c=ps(l).map(f=>k(f,t,r)),u=c.length>0?c.join("|"):"(?:)";a==="@"?s+=`(?:${u})`:a==="*"?s+=`(?:${u})*`:a==="+"?s+=`(?:${u})+`:a==="?"?s+=`(?:${u})?`:a==="!"&&(s+=`(?!(?:${u})$).*`),n=i+1;continue}}if(a==="\\")if(n+1<e.length){let i=e[n+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,n+=2}else s+="\\\\",n++;else if(a==="*")s+=t?".*":".*?",n++;else if(a==="?")s+=".",n++;else if(a==="["){let i=ds(e,n);if(i===-1)s+="\\[",n++;else{let l=e.slice(n+1,i);s+=ms(l),n=i+1}}else/[\^$.|+(){}]/.test(a)?(s+=`\\${a}`,n++):(s+=a,n++)}return s}function hs(e,t){let r=1,s=t+1;for(;s<e.length&&r>0;){let n=e[s];if(n==="\\"){s+=2;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function ps(e){let t=[],r="",s=0,n=0;for(;n<e.length;){let a=e[n];if(a==="\\"){r+=a,n+1<e.length?(r+=e[n+1],n+=2):n++;continue}a==="("?(s++,r+=a):a===")"?(s--,r+=a):a==="|"&&s===0?(t.push(r),r=""):r+=a,n++}return t.push(r),t}function ds(e,t){let r=t+1;for(r<e.length&&e[r]==="^"&&r++,r<e.length&&e[r]==="]"&&r++;r<e.length;){if(e[r]==="\\"&&r+1<e.length){r+=2;continue}if(e[r]==="]")return r;if(e[r]==="'"){let s=e.indexOf("'",r+1);if(s!==-1){r=s+1;continue}}if(e[r]==="["&&r+1<e.length&&e[r+1]===":"){let s=e.indexOf(":]",r+2);if(s!==-1){r=s+2;continue}}r++}return-1}function ms(e){let t="[",r=0;for((e[0]==="^"||e[0]==="!")&&(t+="^",r++);r<e.length;){if(e[r]==="'"){let n=e.indexOf("'",r+1);if(n!==-1){let a=e.slice(r+1,n);for(let i of a)i==="\\"?t+="\\\\":i==="]"?t+="\\]":i==="^"&&t==="["?t+="\\^":t+=i;r=n+1;continue}}if(e[r]==="["&&r+1<e.length&&e[r+1]===":"){let n=e.indexOf(":]",r+2);if(n!==-1){let a=e.slice(r+2,n);t+=ys(a),r=n+2;continue}}let s=e[r];s==="\\"?r+1<e.length?(t+=`\\${e[r+1]}`,r+=2):(t+="\\\\",r++):s==="-"&&r>0&&r<e.length-1?(t+="-",r++):s==="^"&&r===0?(t+="^",r++):(s==="]"&&r===0?t+="\\]":t+=s,r++)}return t+="]",t}var gs=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]);function ys(e){return gs.get(e)??""}function se(e,t,r,s){if(r==="prefix")return O(`^${t}`,"s").replace(e,"");let n=O(`${t}$`,"s");if(s)return n.replace(e,"");for(let a=e.length;a>=0;a--){let i=e.slice(a);if(n.test(i))return e.slice(0,a)}return e}function me(e,t){let r=Array.from(e.state.env.keys()),s=new Set,n=e.state.associativeArrays??new Set,a=new Set;for(let l of r){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o&&a.add(o[1]);let c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);c&&a.add(c[1])}let i=l=>{for(let o of n){let c=`${o}_`;if(l.startsWith(c)&&l!==o)return!0}return!1};for(let l of r)if(l.startsWith(t))if(l.includes("__")){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);o?.[1].startsWith(t)&&s.add(o[1])}else if(/_\d+$/.test(l)){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o?.[1].startsWith(t)&&s.add(o[1])}else i(l)||s.add(l);return[...s].sort()}function Es(e,t){let r=(a,i=2)=>String(a).padStart(i,"0");if(e===""){let a=r(t.getHours()),i=r(t.getMinutes()),l=r(t.getSeconds());return`${a}:${i}:${l}`}let s="",n=0;for(;n<e.length;)if(e[n]==="%"){if(n+1>=e.length){s+="%",n++;continue}let a=e[n+1];switch(a){case"H":s+=r(t.getHours());break;case"M":s+=r(t.getMinutes());break;case"S":s+=r(t.getSeconds());break;case"d":s+=r(t.getDate());break;case"m":s+=r(t.getMonth()+1);break;case"Y":s+=t.getFullYear();break;case"y":s+=r(t.getFullYear()%100);break;case"I":{let i=t.getHours()%12;i===0&&(i=12),s+=r(i);break}case"p":s+=t.getHours()<12?"AM":"PM";break;case"P":s+=t.getHours()<12?"am":"pm";break;case"%":s+="%";break;case"a":{s+=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][t.getDay()];break}case"b":{s+=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][t.getMonth()];break}default:s+=`%${a}`}n+=2}else s+=e[n],n++;return s}function be(e,t){let r="",s=0,n=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",a=e.state.env.get("HOSTNAME")||"localhost",i=a.split(".")[0],l=e.state.env.get("PWD")||"/",o=e.state.env.get("HOME")||"/",c=l.startsWith(o)?`~${l.slice(o.length)}`:l,u=l.split("/").pop()||l,f=new Date,h=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],d=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],m=e.state.env.get("__COMMAND_NUMBER")||"1";for(;s<t.length;){let g=t[s];if(g==="\\"){if(s+1>=t.length){r+="\\",s++;continue}let E=t[s+1];if(E>="0"&&E<="7"){let A="",S=s+1;for(;S<t.length&&S<s+4&&t[S]>="0"&&t[S]<="7";)A+=t[S],S++;let y=Number.parseInt(A,8)%256;r+=String.fromCharCode(y),s=S;continue}switch(E){case"\\":r+="\\",s+=2;break;case"a":r+="\x07",s+=2;break;case"e":r+="\x1B",s+=2;break;case"n":r+=`
|
|
63
|
-
`,s+=2;break;case"r":r+="\r",s+=2;break;case"$":r+="$",s+=2;break;case"[":case"]":s+=2;break;case"u":r+=n,s+=2;break;case"h":r+=i,s+=2;break;case"H":r+=a,s+=2;break;case"w":r+=c,s+=2;break;case"W":r+=u,s+=2;break;case"d":{let A=String(f.getDate()).padStart(2," ");r+=`${h[f.getDay()]} ${d[f.getMonth()]} ${A}`,s+=2;break}case"t":{let A=String(f.getHours()).padStart(2,"0"),S=String(f.getMinutes()).padStart(2,"0"),y=String(f.getSeconds()).padStart(2,"0");r+=`${A}:${S}:${y}`,s+=2;break}case"T":{let A=f.getHours()%12;A===0&&(A=12);let S=String(A).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),b=String(f.getSeconds()).padStart(2,"0");r+=`${S}:${y}:${b}`,s+=2;break}case"@":{let A=f.getHours()%12;A===0&&(A=12);let S=String(A).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),b=f.getHours()<12?"AM":"PM";r+=`${S}:${y} ${b}`,s+=2;break}case"A":{let A=String(f.getHours()).padStart(2,"0"),S=String(f.getMinutes()).padStart(2,"0");r+=`${A}:${S}`,s+=2;break}case"D":if(s+2<t.length&&t[s+2]==="{"){let A=t.indexOf("}",s+3);if(A!==-1){let S=t.slice(s+3,A);r+=
|
|
64
|
-
`:r+="\\n";break;case"\r":r+="\\r";break;case" ":r+="\\t";break;default:{let n=s.charCodeAt(0);n<32||n===127?r+=`\\${n.toString(8).padStart(3,"0")}`:r+=s}}return`${r}'`}return`'${e}'`}function
|
|
65
|
-
`;throw new K(1,"",s)}return null}function
|
|
66
|
-
`)}return s.effectiveValue}async function
|
|
67
|
-
`);let u=P(e,c),f=0;if(n<0){if(u.length>0){let h=u[u.length-1][0],m=(typeof h=="number"?h:0)+1+n;if(m<0||(f=u.findIndex(([g])=>typeof g=="number"&&g>=m),f<0))return""}}else if(f=u.findIndex(([h])=>typeof h=="number"&&h>=n),f<0)return"";if(a!==void 0){if(a<0)throw new C(`${i[1]}[@]: substring expression < 0`);return u.slice(f,f+a).map(([,h])=>h).join(" ")}return u.slice(f).map(([,h])=>h).join(" ")}let l=[...r],o=n;if(o<0&&(o=Math.max(0,l.length+o)),a!==void 0){if(a<0){let c=l.length+a;return l.slice(o,Math.max(o,c)).join("")}return l.slice(o,o+a).join("")}return l.slice(o).join("")}async function
|
|
68
|
-
`;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return o}});case"K":case"k":return s?"":le(r);case"u":return r.charAt(0).toUpperCase()+r.slice(1);case"U":return r.toUpperCase();case"L":return r.toLowerCase();default:return r}}async function $n(e,t,r,s,n,a,i=!1){if(e.coverage?.hit("bash:expansion:indirection"),W(e,t))return Ae(e,t)||"";let l=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(s){if(n.innerOp?.type==="UseAlternative")return"";throw new re(`\${!${t}}`)}let o=r;if(l&&(o===""||o.includes(" ")))throw new re(`\${!${t}}`);let c=o.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(c&&c[1].includes("~"))throw new re(`\${!${t}}`);if(n.innerOp){let u={type:"ParameterExpansion",parameter:o,operation:n.innerOp};return a(e,u,i)}return await v(e,o)}function Cn(e,t){e.coverage?.hit("bash:expansion:array_keys");let s=P(e,t.array).map(([n])=>String(n));return t.star?s.join(N(e.state.env)):s.join(" ")}function On(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let r=me(e,t.prefix);return t.star?r.join(N(e.state.env)):r.join(" ")}function Ln(e,t,r,s){let n=Number.parseInt(e.state.env.get("#")||"0",10),a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:n===0,effectiveValue:r};if(t==="@")return{isEmpty:n===0||n===1&&e.state.env.get("1")==="",effectiveValue:r};if(a){let[,i,l]=a,o=P(e,i);if(o.length===0)return{isEmpty:!0,effectiveValue:""};if(l==="*"){let c=N(e.state.env),u=o.map(([,f])=>f).join(c);return{isEmpty:s?u==="":!1,effectiveValue:u}}return{isEmpty:o.length===1&&o.every(([,c])=>c===""),effectiveValue:o.map(([,c])=>c).join(" ")}}return{isEmpty:r==="",effectiveValue:r}}function Wn(e){let t=0;for(;t<e.length;){let r=e[t];if(r==="\\"&&t+1<e.length){t+=2;continue}if(r==="'"){let s=e.indexOf("'",t+1);if(s!==-1){t=s+1;continue}}if(r==="$"&&t+1<e.length&&e[t+1]==="("||r==="`")return!0;t++}return!1}function Tn(e,t){let r=1,s=t,n=!1,a=!1;for(;s<e.length&&r>0;){let i=e[s];if(i==="\\"&&!n&&s+1<e.length){s+=2;continue}if(i==="'"&&!a){n=!n,s++;continue}if(i==='"'&&!n){a=!a,s++;continue}if(!n&&!a){if(i==="(")r++;else if(i===")"&&(r--,r===0))return s}s++}return-1}async function Le(e,t){let r=new V,s;try{s=r.parse(t)}catch{return""}let n=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let a=new Map(e.state.env),i=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let o=await e.executeScript(s),c=o.exitCode;return e.state.env=a,e.state.cwd=i,e.state.suppressVerbose=l,e.state.lastExitCode=c,e.state.env.set("?",String(c)),o.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+o.stderr),e.state.bashPid=n,o.stdout.replace(/\n+$/,"")}catch(o){if(e.state.env=a,e.state.cwd=i,e.state.bashPid=n,e.state.suppressVerbose=l,o instanceof L)throw o;return o instanceof K?(e.state.lastExitCode=o.exitCode,e.state.env.set("?",String(o.exitCode)),o.stdout?.replace(/\n+$/,"")??""):""}}function wt(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="'"){let a=t.indexOf("'",s+1);if(a!==-1){let i=t.slice(s+1,a);r+=X(i),s=a+1;continue}}if(n==='"'){let a=-1,i=s+1;for(;i<t.length;){if(t[i]==="\\"){i+=2;continue}if(t[i]==='"'){a=i;break}i++}if(a!==-1){let l=t.slice(s+1,a),o=As(e,l);r+=X(o),s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}if(n==="\\"&&s+1<t.length){r+=n+t[s+1],s+=2;continue}r+=n,s++}return r}function As(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="\\"&&s+1<t.length){let a=t[s+1];if(a==="$"||a==="`"||a==="\\"||a==='"'){r+=a,s+=2;continue}r+=n,s++;continue}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}r+=n,s++}return r}async function Mn(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="'"){let a=t.indexOf("'",s+1);if(a!==-1){let i=t.slice(s+1,a);r+=X(i),s=a+1;continue}}if(n==='"'){let a=-1,i=s+1;for(;i<t.length;){if(t[i]==="\\"){i+=2;continue}if(t[i]==='"'){a=i;break}i++}if(a!==-1){let l=t.slice(s+1,a),o=await Ss(e,l);r+=X(o),s=a+1;continue}}if(n==="$"&&s+1<t.length&&t[s+1]==="("){let a=Tn(t,s+2);if(a!==-1){let i=t.slice(s+2,a),l=await Le(e,i);r+=l,s=a+1;continue}}if(n==="`"){let a=t.indexOf("`",s+1);if(a!==-1){let i=t.slice(s+1,a),l=await Le(e,i);r+=l,s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}if(n==="\\"&&s+1<t.length){r+=n+t[s+1],s+=2;continue}r+=n,s++}return r}async function Ss(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="\\"&&s+1<t.length){let a=t[s+1];if(a==="$"||a==="`"||a==="\\"||a==='"'){r+=a,s+=2;continue}r+=n,s++;continue}if(n==="$"&&s+1<t.length&&t[s+1]==="("){let a=Tn(t,s+2);if(a!==-1){let i=t.slice(s+2,a),l=await Le(e,i);r+=l,s=a+1;continue}}if(n==="`"){let a=t.indexOf("`",s+1);if(a!==-1){let i=t.slice(s+1,a),l=await Le(e,i);r+=l,s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}r+=n,s++}return r}function Vn(e,t){if(!t.startsWith("~"))return t;e.coverage?.hit("bash:expansion:tilde");let r=e.state.env.get("HOME")!==void 0?e.state.env.get("HOME"):"/home/user";if(t==="~"||t.startsWith("~/"))return r+t.slice(1);let s=1;for(;s<t.length&&/[a-zA-Z0-9_-]/.test(t[s]);)s++;let n=t.slice(1,s),a=t.slice(s);return a!==""&&!a.startsWith("/")?t:n==="root"?`/root${a}`:t}async function bs(e,t,r,s){let n="";for(let a of t.parts)if(a.type==="Glob")n+=k(a.pattern,!0,e.state.shoptOptions.extglob);else if(a.type==="Literal")n+=k(a.value,!0,e.state.shoptOptions.extglob);else if(a.type==="SingleQuoted"||a.type==="Escaped")n+=I(a.value);else if(a.type==="DoubleQuoted"){let i=await r(e,a.parts);n+=I(i)}else if(a.type==="ParameterExpansion"){let i=await s(e,a);n+=k(i,!0,e.state.shoptOptions.extglob)}else{let i=await s(e,a);n+=I(i)}return n}async function qn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternReplacement")return null;let a=n.parts[0],i=a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let l=i[1],o=i[2]==="*",c=a.operation,u=P(e,l),f=u.map(([,E])=>E);if(u.length===0){let E=e.state.env.get(l);E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let h="";c.pattern&&(h=await bs(e,c.pattern,r,s));let d=c.replacement?await r(e,c.replacement.parts):"",m=h;c.anchor==="start"?m=`^${h}`:c.anchor==="end"&&(m=`${h}$`);let g=[];try{let E=O(m,c.all?"g":"");for(let A of f)g.push(E.replace(A,d))}catch{g.push(...f)}if(o){let E=N(e.state.env);return{values:[g.join(E)],quoted:!0}}return{values:g,quoted:!0}}async function Bn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternRemoval")return null;let a=n.parts[0],i=a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let l=i[1],o=i[2]==="*",c=a.operation,u=P(e,l),f=u.map(([,g])=>g);if(u.length===0){let g=e.state.env.get(l);g!==void 0&&f.push(g)}if(f.length===0)return{values:[],quoted:!0};let h="",d=e.state.shoptOptions.extglob;if(c.pattern)for(let g of c.pattern.parts)if(g.type==="Glob")h+=k(g.pattern,c.greedy,d);else if(g.type==="Literal")h+=k(g.value,c.greedy,d);else if(g.type==="SingleQuoted"||g.type==="Escaped")h+=I(g.value);else if(g.type==="DoubleQuoted"){let E=await r(e,g.parts);h+=I(E)}else if(g.type==="ParameterExpansion"){let E=await s(e,g);h+=k(E,c.greedy,d)}else{let E=await s(e,g);h+=I(E)}let m=[];for(let g of f)m.push(se(g,h,c.side,c.greedy));if(o){let g=N(e.state.env);return{values:[m.join(g)],quoted:!0}}return{values:m,quoted:!0}}async function Fn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="DefaultValue"&&r.parts[0].operation?.type!=="UseAlternative"&&r.parts[0].operation?.type!=="AssignDefault")return null;let s=r.parts[0],n=s.operation,a=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/),i,l=!1;if(a){let o=a[1];l=a[2]==="*";let c=P(e,o),u=c.length>0||e.state.env.has(o),f=c.length===0||c.length===1&&c.every(([,d])=>d===""),h=n.checkEmpty??!1;if(n.type==="UseAlternative"?i=u&&!(h&&f):i=!u||h&&f,!i){if(c.length>0){let m=c.map(([,g])=>g);if(l){let g=N(e.state.env);return{values:[m.join(g)],quoted:!0}}return{values:m,quoted:!0}}let d=e.state.env.get(o);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}else{let o=s.parameter,c=await te(e,o),u=await v(e,o),f=u==="",h=n.checkEmpty??!1;if(n.type==="UseAlternative"?i=c&&!(h&&f):i=!c||h&&f,!i)return{values:[u],quoted:!0}}if(i&&n.word){let o=n.word.parts,c=null,u=!1;for(let f of o)if(f.type==="ParameterExpansion"&&!f.operation){let h=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(h){c=h[1],u=h[2]==="*";break}}if(c){let f=P(e,c);if(f.length>0){let d=f.map(([,m])=>m);if(u||l){let m=N(e.state.env);return{values:[d.join(m)],quoted:!0}}return{values:d,quoted:!0}}let h=e.state.env.get(c);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}}return null}async function zn(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0],i=-1,l="",o=!1,c=null;for(let g=0;g<a.parts.length;g++){let E=a.parts[g];if(E.type==="ParameterExpansion"&&(E.operation?.type==="PatternRemoval"||E.operation?.type==="PatternReplacement")){let A=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(A){i=g,l=A[1],o=A[2]==="*",c=E.operation;break}}}if(i===-1||i===0&&i===a.parts.length-1)return null;let u="";for(let g=0;g<i;g++)u+=await s(e,a.parts[g]);let f="";for(let g=i+1;g<a.parts.length;g++)f+=await s(e,a.parts[g]);let h=P(e,l),d=h.map(([,g])=>g);if(h.length===0){let g=e.state.env.get(l);if(g!==void 0)d=[g];else{if(o)return{values:[u+f],quoted:!0};let E=u+f;return{values:E?[E]:[],quoted:!0}}}if(c?.type==="PatternRemoval"){let g=c,E="",A=e.state.shoptOptions.extglob;if(g.pattern)for(let S of g.pattern.parts)if(S.type==="Glob")E+=k(S.pattern,g.greedy,A);else if(S.type==="Literal")E+=k(S.value,g.greedy,A);else if(S.type==="SingleQuoted"||S.type==="Escaped")E+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await n(e,S.parts);E+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);E+=k(y,g.greedy,A)}else{let y=await s(e,S);E+=I(y)}d=d.map(S=>se(S,E,g.side,g.greedy))}else if(c?.type==="PatternReplacement"){let g=c,E="";if(g.pattern)for(let y of g.pattern.parts)if(y.type==="Glob")E+=k(y.pattern,!0,e.state.shoptOptions.extglob);else if(y.type==="Literal")E+=k(y.value,!0,e.state.shoptOptions.extglob);else if(y.type==="SingleQuoted"||y.type==="Escaped")E+=I(y.value);else if(y.type==="DoubleQuoted"){let b=await n(e,y.parts);E+=I(b)}else if(y.type==="ParameterExpansion"){let b=await s(e,y);E+=k(b,!0,e.state.shoptOptions.extglob)}else{let b=await s(e,y);E+=I(b)}let A=g.replacement?await n(e,g.replacement.parts):"",S=E;g.anchor==="start"?S=`^${E}`:g.anchor==="end"&&(S=`${E}$`);try{let y=O(S,g.all?"g":"");d=d.map(b=>y.replace(b,A))}catch{}}if(o){let g=N(e.state.env);return{values:[u+d.join(g)+f],quoted:!0}}return d.length===1?{values:[u+d[0]+f],quoted:!0}:{values:[u+d[0],...d.slice(1,-1),d[d.length-1]+f],quoted:!0}}async function Gn(e,t,r,s){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i="",l=!1;for(let d=0;d<n.parts.length;d++){let m=n.parts[d];if(m.type==="ParameterExpansion"&&!m.operation){let g=m.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(g){a=d,i=g[1],l=g[2]==="*";break}}}if(a===-1)return null;let o="";for(let d=0;d<a;d++)o+=await s(e,n.parts[d]);let c="";for(let d=a+1;d<n.parts.length;d++)c+=await s(e,n.parts[d]);let u=P(e,i),f=u.map(([,d])=>d);if(u.length===0){let d=e.state.env.get(i);if(d!==void 0)return{values:[o+d+c],quoted:!0};if(l)return{values:[o+c],quoted:!0};let m=o+c;return{values:m?[m]:[],quoted:!0}}if(l){let d=N(e.state.env);return{values:[o+f.join(d)+c],quoted:!0}}return f.length===1?{values:[o+f[0]+c],quoted:!0}:{values:[o+f[0],...f.slice(1,-1),f[f.length-1]+c],quoted:!0}}async function Qn(e,t,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="Substring")return null;let n=s.parts[0],a=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let i=a[1],l=a[2]==="*",o=n.operation;if(e.state.associativeArrays?.has(i))throw new K(1,"",`bash: \${${i}[@]: 0: 3}: bad substitution
|
|
69
|
-
`);let c=o.offset?await r(e,o.offset.expression):0,u=o.length?await r(e,o.length.expression):void 0,f=P(e,i),h=0;if(c<0){if(f.length>0){let m=f[f.length-1][0],E=(typeof m=="number"?m:0)+1+c;if(E<0)return{values:[],quoted:!0};h=f.findIndex(([A])=>typeof A=="number"&&A>=E),h<0&&(h=f.length)}}else h=f.findIndex(([m])=>typeof m=="number"&&m>=c),h<0&&(h=f.length);let d;if(u!==void 0){if(u<0)throw new C(`${i}[@]: substring expression < 0`);d=f.slice(h,h+u).map(([,m])=>m)}else d=f.slice(h).map(([,m])=>m);if(d.length===0)return{values:[],quoted:!0};if(l){let m=N(e.state.env);return{values:[d.join(m)],quoted:!0}}return{values:d,quoted:!0}}function Zn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Transform")return null;let s=r.parts[0],n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let a=n[1],i=n[2]==="*",l=s.operation,o=P(e,a);if(o.length===0){let f=e.state.env.get(a);if(f!==void 0){let h;switch(l.operator){case"a":h="";break;case"P":h=be(e,f);break;case"Q":h=le(f);break;default:h=f}return{values:[h],quoted:!0}}return i?{values:[""],quoted:!0}:{values:[],quoted:!0}}let c=ue(e,a),u;switch(l.operator){case"a":u=o.map(()=>c);break;case"P":u=o.map(([,f])=>be(e,f));break;case"Q":u=o.map(([,f])=>le(f));break;case"u":u=o.map(([,f])=>f.charAt(0).toUpperCase()+f.slice(1));break;case"U":u=o.map(([,f])=>f.toUpperCase());break;case"L":u=o.map(([,f])=>f.toLowerCase());break;default:u=o.map(([,f])=>f)}if(i){let f=N(e.state.env);return{values:[u.join(f)],quoted:!0}}return{values:u,quoted:!0}}function Un(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion")return null;let s=r.parts[0];if(s.operation)return null;let n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!n)return null;let a=n[1];if(W(e,a)){let o=Ae(e,a);if(o?.endsWith("[@]")||o?.endsWith("[*]"))return{values:[],quoted:!0}}let i=P(e,a);if(i.length>0)return{values:i.map(([,o])=>o),quoted:!0};let l=e.state.env.get(a);return l!==void 0?{values:[l],quoted:!0}:{values:[],quoted:!0}}function Hn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation)return null;let n=r.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||!W(e,n))return null;let a=Ae(e,n);if(!a)return null;let i=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!i)return null;let l=i[1],o=P(e,l);if(o.length>0)return{values:o.map(([,u])=>u),quoted:!0};let c=e.state.env.get(l);return c!==void 0?{values:[c],quoted:!0}:{values:[],quoted:!0}}async function jn(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],l=i.operation,o=await v(e,i.parameter),c=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c){if(!l.innerOp&&(o==="@"||o==="*")){let m=Number.parseInt(e.state.env.get("#")||"0",10),g=[];for(let E=1;E<=m;E++)g.push(e.state.env.get(String(E))||"");return o==="*"?{values:[g.join(N(e.state.env))],quoted:!0}:{values:g,quoted:!0}}return null}let u=c[1],f=c[2]==="*",h=P(e,u);if(l.innerOp){if(l.innerOp.type==="Substring")return ws(e,h,u,f,l.innerOp);if(l.innerOp.type==="DefaultValue"||l.innerOp.type==="UseAlternative"||l.innerOp.type==="AssignDefault"||l.innerOp.type==="ErrorIfUnset")return Ns(e,h,u,f,l.innerOp,n);if(l.innerOp.type==="Transform"&&l.innerOp.operator==="a"){let g=ue(e,u),E=h.map(()=>g);return f?{values:[E.join(N(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let m=[];for(let[,g]of h){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:l.innerOp},A=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",g);try{let S=await s(e,E,!0);m.push(S)}finally{A!==void 0?e.state.env.set("_indirect_elem_",A):e.state.env.delete("_indirect_elem_")}}return f?{values:[m.join(N(e.state.env))],quoted:!0}:{values:m,quoted:!0}}if(h.length>0){let m=h.map(([,g])=>g);return f?{values:[m.join(N(e.state.env))],quoted:!0}:{values:m,quoted:!0}}let d=e.state.env.get(u);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}async function ws(e,t,r,s,n){let a=n.offset?await R(e,n.offset.expression):0,i=n.length?await R(e,n.length.expression):void 0,l=0;if(a<0){if(t.length>0){let u=t[t.length-1][0],h=(typeof u=="number"?u:0)+1+a;if(h<0)return{values:[],quoted:!0};if(l=t.findIndex(([d])=>typeof d=="number"&&d>=h),l<0)return{values:[],quoted:!0}}}else if(l=t.findIndex(([u])=>typeof u=="number"&&u>=a),l<0)return{values:[],quoted:!0};let o;if(i!==void 0){if(i<0)throw new C(`${r}[@]: substring expression < 0`);o=t.slice(l,l+i)}else o=t.slice(l);let c=o.map(([,u])=>u);return s?{values:[c.join(N(e.state.env))],quoted:!0}:{values:c,quoted:!0}}async function Ns(e,t,r,s,n,a){let i=n.checkEmpty??!1,l=t.map(([,u])=>u),o=t.length===0,c=t.length===0;if(n.type==="UseAlternative")return!c&&!(i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(n.type==="DefaultValue")return(c||i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0};if(n.type==="AssignDefault"){if((c||i&&o)&&n.word){let f=await a(e,n.word.parts,!0);return e.state.env.set(`${r}_0`,f),e.state.env.set(`${r}__length`,"1"),{values:[f],quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}async function Kn(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let r=t[0],s=r.operation,n=s?.word;if(!n||n.parts.length!==1||n.parts[0].type!=="DoubleQuoted")return null;let a=n.parts[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],o=(await v(e,i.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let c=await te(e,r.parameter),u=await v(e,r.parameter)==="",f=s.checkEmpty??!1,h;if(s.type==="UseAlternative"?h=c&&!(f&&u):h=!c||f&&u,h){let d=o[1],m=o[2]==="*",g=P(e,d);if(g.length>0){let A=g.map(([,S])=>S);return m?{values:[A.join(N(e.state.env))],quoted:!0}:{values:A,quoted:!0}}let E=e.state.env.get(d);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function Xn(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let r=t[0],n=r.operation.innerOp;if(!n||n.type!=="UseAlternative"&&n.type!=="DefaultValue")return null;let a=n.word;if(!a||a.parts.length!==1||a.parts[0].type!=="DoubleQuoted")return null;let i=a.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let l=i.parts[0],c=(await v(e,l.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c)return null;let u=await v(e,r.parameter),f=await te(e,r.parameter),h=u==="",d=n.checkEmpty??!1,m;if(n.type==="UseAlternative"?m=f&&!(d&&h):m=!f||d&&h,m){let g=c[1],E=c[2]==="*",A=P(e,g);if(A.length>0){let y=A.map(([,b])=>b);return E?{values:[y.join(N(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let S=e.state.env.get(g);return S!==void 0?{values:[S],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function Jn(e){let t=Number.parseInt(e.state.env.get("#")||"0",10),r=[];for(let s=1;s<=t;s++)r.push(e.state.env.get(String(s))||"");return r}async function Yn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let S=0;S<n.parts.length;S++){let y=n.parts[S];if(y.type==="ParameterExpansion"&&(y.parameter==="@"||y.parameter==="*")&&y.operation?.type==="Substring"){a=S,i=y.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,c=o.offset?await r(e,o.offset.expression):0,u=o.length?await r(e,o.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),h=[];for(let S=1;S<=f;S++)h.push(e.state.env.get(String(S))||"");let d=e.state.env.get("0")||"bash",m;if(c<=0){let S=[d,...h],y=S.length+c;if(y<0)m=[];else{let b=c<0?y:0;if(u!==void 0){let D=u<0?S.length+u:b+u;m=S.slice(b,Math.max(b,D))}else m=S.slice(b)}}else{let S=c-1;if(S>=h.length)m=[];else if(u!==void 0){let y=u<0?h.length+u:S+u;m=h.slice(S,Math.max(S,y))}else m=h.slice(S)}let g="";for(let S=0;S<a;S++)g+=await s(e,n.parts[S]);let E="";for(let S=a+1;S<n.parts.length;S++)E+=await s(e,n.parts[S]);if(m.length===0){let S=g+E;return{values:S?[S]:[],quoted:!0}}if(i){let S=N(e.state.env);return{values:[g+m.join(S)+E],quoted:!0}}return m.length===1?{values:[g+m[0]+E],quoted:!0}:{values:[g+m[0],...m.slice(1,-1),m[m.length-1]+E],quoted:!0}}async function er(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let A=0;A<n.parts.length;A++){let S=n.parts[A];if(S.type==="ParameterExpansion"&&(S.parameter==="@"||S.parameter==="*")&&S.operation?.type==="PatternReplacement"){a=A,i=S.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,c=Jn(e),u="";for(let A=0;A<a;A++)u+=await r(e,n.parts[A]);let f="";for(let A=a+1;A<n.parts.length;A++)f+=await r(e,n.parts[A]);if(c.length===0){let A=u+f;return{values:A?[A]:[],quoted:!0}}let h="";if(o.pattern)for(let A of o.pattern.parts)if(A.type==="Glob")h+=k(A.pattern,!0,e.state.shoptOptions.extglob);else if(A.type==="Literal")h+=k(A.value,!0,e.state.shoptOptions.extglob);else if(A.type==="SingleQuoted"||A.type==="Escaped")h+=I(A.value);else if(A.type==="DoubleQuoted"){let S=await s(e,A.parts);h+=I(S)}else if(A.type==="ParameterExpansion"){let S=await r(e,A);h+=k(S,!0,e.state.shoptOptions.extglob)}else{let S=await r(e,A);h+=I(S)}let d=o.replacement?await s(e,o.replacement.parts):"",m=h;o.anchor==="start"?m=`^${h}`:o.anchor==="end"&&(m=`${h}$`);let g=[];try{let A=O(m,o.all?"g":"");for(let S of c)g.push(A.replace(S,d))}catch{g.push(...c)}if(i){let A=N(e.state.env);return{values:[u+g.join(A)+f],quoted:!0}}return g.length===1?{values:[u+g[0]+f],quoted:!0}:{values:[u+g[0],...g.slice(1,-1),g[g.length-1]+f],quoted:!0}}async function tr(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let E=0;E<n.parts.length;E++){let A=n.parts[E];if(A.type==="ParameterExpansion"&&(A.parameter==="@"||A.parameter==="*")&&A.operation?.type==="PatternRemoval"){a=E,i=A.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,c=Jn(e),u="";for(let E=0;E<a;E++)u+=await r(e,n.parts[E]);let f="";for(let E=a+1;E<n.parts.length;E++)f+=await r(e,n.parts[E]);if(c.length===0){let E=u+f;return{values:E?[E]:[],quoted:!0}}let h="",d=e.state.shoptOptions.extglob;if(o.pattern)for(let E of o.pattern.parts)if(E.type==="Glob")h+=k(E.pattern,o.greedy,d);else if(E.type==="Literal")h+=k(E.value,o.greedy,d);else if(E.type==="SingleQuoted"||E.type==="Escaped")h+=I(E.value);else if(E.type==="DoubleQuoted"){let A=await s(e,E.parts);h+=I(A)}else if(E.type==="ParameterExpansion"){let A=await r(e,E);h+=k(A,o.greedy,d)}else{let A=await r(e,E);h+=I(A)}let m=[];for(let E of c)m.push(se(E,h,o.side,o.greedy));if(i){let E=N(e.state.env);return{values:[u+m.join(E)+f],quoted:!0}}return m.length===1?{values:[u+m[0]+f],quoted:!0}:{values:[u+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function nr(e,t,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],n=-1,a=!1;for(let h=0;h<s.parts.length;h++){let d=s.parts[h];if(d.type==="ParameterExpansion"&&(d.parameter==="@"||d.parameter==="*")){n=h,a=d.parameter==="*";break}}if(n===-1)return null;let i=s.parts[n];if(i.type==="ParameterExpansion"&&i.operation)return null;let l=Number.parseInt(e.state.env.get("#")||"0",10),o="";for(let h=0;h<n;h++)o+=await r(e,s.parts[h]);let c="";for(let h=n+1;h<s.parts.length;h++)c+=await r(e,s.parts[h]);if(l===0){if(a)return{values:[o+c],quoted:!0};let h=o+c;return{values:h?[h]:[],quoted:!0}}let u=[];for(let h=1;h<=l;h++)u.push(e.state.env.get(String(h))||"");if(a){let h=N(e.state.env);return{values:[o+u.join(h)+c],quoted:!0}}return u.length===1?{values:[o+u[0]+c],quoted:!0}:{values:[o+u[0],...u.slice(1,-1),u[u.length-1]+c],quoted:!0}}function ks(e){return new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations})}async function We(e,t){if(e.state.options.noglob)return t;let r=ks(e),s=[];for(let n of t)if(ne(n,e.state.shoptOptions.extglob)){let a=await r.expand(n);if(a.length>0)s.push(...a);else{if(r.hasFailglob())throw new ke(n);r.hasNullglob()||s.push(n)}}else s.push(n);return s}async function rr(e,t,r,s){let n=-1,a="",i=!1;for(let S=0;S<t.length;S++){let y=t[S];if(y.type==="ParameterExpansion"&&y.operation?.type==="PatternReplacement"){let b=y.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){n=S,a=b[1],i=b[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,c=P(e,a),u=c.map(([,S])=>S);if(c.length===0){let S=e.state.env.get(a);S!==void 0&&(u=[S])}if(u.length===0)return{values:[],quoted:!1};let f="";if(o.pattern)for(let S of o.pattern.parts)if(S.type==="Glob")f+=k(S.pattern,!0,e.state.shoptOptions.extglob);else if(S.type==="Literal")f+=k(S.value,!0,e.state.shoptOptions.extglob);else if(S.type==="SingleQuoted"||S.type==="Escaped")f+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await r(e,S.parts);f+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);f+=k(y,!0,e.state.shoptOptions.extglob)}else{let y=await s(e,S);f+=I(y)}let h=o.replacement?await r(e,o.replacement.parts):"",d=f;o.anchor==="start"?d=`^${f}`:o.anchor==="end"&&(d=`${f}$`);let m=[];try{let S=O(d,o.all?"g":"");for(let y of u)m.push(S.replace(y,h))}catch{m.push(...u)}let g=T(e.state.env),E=q(e.state.env);if(i){let S=N(e.state.env),y=m.join(S);return E?{values:y?[y]:[],quoted:!1}:{values:x(y,g),quoted:!1}}if(E)return{values:m,quoted:!1};let A=[];for(let S of m)S===""?A.push(""):A.push(...x(S,g));return{values:A,quoted:!1}}async function sr(e,t,r,s){let n=-1,a="",i=!1;for(let A=0;A<t.length;A++){let S=t[A];if(S.type==="ParameterExpansion"&&S.operation?.type==="PatternRemoval"){let y=S.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(y){n=A,a=y[1],i=y[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,c=P(e,a),u=c.map(([,A])=>A);if(c.length===0){let A=e.state.env.get(a);A!==void 0&&(u=[A])}if(u.length===0)return{values:[],quoted:!1};let f="",h=e.state.shoptOptions.extglob;if(o.pattern)for(let A of o.pattern.parts)if(A.type==="Glob")f+=k(A.pattern,o.greedy,h);else if(A.type==="Literal")f+=k(A.value,o.greedy,h);else if(A.type==="SingleQuoted"||A.type==="Escaped")f+=I(A.value);else if(A.type==="DoubleQuoted"){let S=await r(e,A.parts);f+=I(S)}else if(A.type==="ParameterExpansion"){let S=await s(e,A);f+=k(S,o.greedy,h)}else{let S=await s(e,A);f+=I(S)}let d=[];for(let A of u)d.push(se(A,f,o.side,o.greedy));let m=T(e.state.env),g=q(e.state.env);if(i){let A=N(e.state.env),S=d.join(A);return g?{values:S?[S]:[],quoted:!1}:{values:x(S,m),quoted:!1}}if(g)return{values:d,quoted:!1};let E=[];for(let A of d)A===""?E.push(""):E.push(...x(A,m));return{values:E,quoted:!1}}async function ir(e,t,r,s){let n=-1,a=!1;for(let E=0;E<t.length;E++){let A=t[E];if(A.type==="ParameterExpansion"&&(A.parameter==="@"||A.parameter==="*")&&A.operation?.type==="PatternRemoval"){n=E,a=A.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let E=1;E<=o;E++)c.push(e.state.env.get(String(E))||"");if(c.length===0)return{values:[],quoted:!1};let u="",f=e.state.shoptOptions.extglob;if(l.pattern)for(let E of l.pattern.parts)if(E.type==="Glob")u+=k(E.pattern,l.greedy,f);else if(E.type==="Literal")u+=k(E.value,l.greedy,f);else if(E.type==="SingleQuoted"||E.type==="Escaped")u+=I(E.value);else if(E.type==="DoubleQuoted"){let A=await r(e,E.parts);u+=I(A)}else if(E.type==="ParameterExpansion"){let A=await s(e,E);u+=k(A,l.greedy,f)}else{let A=await s(e,E);u+=I(A)}let h=[];for(let E of c)h.push(se(E,u,l.side,l.greedy));let d=T(e.state.env),m=q(e.state.env);if(a){let E=N(e.state.env),A=h.join(E);return m?{values:A?[A]:[],quoted:!1}:{values:x(A,d),quoted:!1}}if(m)return{values:h,quoted:!1};let g=[];for(let E of h)E===""?g.push(""):g.push(...x(E,d));return{values:g,quoted:!1}}async function ar(e,t,r,s){let n=-1,a=!1;for(let y=0;y<t.length;y++){let b=t[y];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="Substring"){n=y,a=b.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=l.offset?await r(e,l.offset.expression):0,c=l.length?await r(e,l.length.expression):void 0,u=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let y=1;y<=u;y++)f.push(e.state.env.get(String(y))||"");let h=e.state.env.get("0")||"bash",d;if(o<=0){let y=[h,...f],b=y.length+o;if(b<0)d=[];else{let D=o<0?b:0;if(c!==void 0){let Q=c<0?y.length+c:D+c;d=y.slice(D,Math.max(D,Q))}else d=y.slice(D)}}else{let y=o-1;if(y>=f.length)d=[];else if(c!==void 0){let b=c<0?f.length+c:y+c;d=f.slice(y,Math.max(y,b))}else d=f.slice(y)}let m="";for(let y=0;y<n;y++)m+=await s(e,t[y]);let g="";for(let y=n+1;y<t.length;y++)g+=await s(e,t[y]);let E=T(e.state.env),A=q(e.state.env);if(d.length===0){let y=m+g;return y?A?{values:[y],quoted:!1}:{values:x(y,E),quoted:!1}:{values:[],quoted:!1}}let S;if(a){let y=N(e.state.env),b=m+d.join(y)+g;A?S=b?[b]:[]:S=x(b,E)}else if(A)d.length===1?S=[m+d[0]+g]:S=[m+d[0],...d.slice(1,-1),d[d.length-1]+g];else{S=[];for(let y=0;y<d.length;y++){let b=d[y];if(y===0&&(b=m+b),y===d.length-1&&(b=b+g),b==="")S.push("");else{let D=x(b,E);S.push(...D)}}}return{values:await We(e,S),quoted:!1}}async function or(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let r=t[0].parameter==="*",s=Number.parseInt(e.state.env.get("#")||"0",10);if(s===0)return{values:[],quoted:!1};let n=[];for(let c=1;c<=s;c++)n.push(e.state.env.get(String(c))||"");let a=T(e.state.env),i=q(e.state.env),l=$e(e.state.env),o;if(r)if(i)o=n.filter(c=>c!=="");else{let c=N(e.state.env),u=n.join(c);o=x(u,a)}else if(i)o=n.filter(c=>c!=="");else if(l){o=[];for(let c of n){if(c==="")continue;let u=x(c,a);o.push(...u)}}else{o=[];for(let c of n)if(c==="")o.push("");else{let u=x(c,a);o.push(...u)}for(;o.length>0&&o[o.length-1]==="";)o.pop()}return{values:await We(e,o),quoted:!1}}async function lr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let r=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!r)return null;let s=r[1],n=r[2]==="*",a=P(e,s),i;if(a.length===0){let f=e.state.env.get(s);if(f!==void 0)i=[f];else return{values:[],quoted:!1}}else i=a.map(([,f])=>f);let l=T(e.state.env),o=q(e.state.env),c=$e(e.state.env),u;if(n)if(o)u=i.filter(f=>f!=="");else{let f=N(e.state.env),h=i.join(f);u=x(h,l)}else if(o)u=i.filter(f=>f!=="");else if(c){u=[];for(let f of i){if(f==="")continue;let h=x(f,l);u.push(...h)}}else{u=[];for(let f of i)if(f==="")u.push("");else{let h=x(f,l);u.push(...h)}for(;u.length>0&&u[u.length-1]==="";)u.pop()}return{values:await We(e,u),quoted:!1}}function ur(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let r=t[0].operation,s=me(e,r.prefix);if(s.length===0)return{values:[],quoted:!1};let n=T(e.state.env),a=q(e.state.env),i;if(r.star)if(a)i=s;else{let l=N(e.state.env),o=s.join(l);i=x(o,n)}else if(a)i=s;else{i=[];for(let l of s){let o=x(l,n);i.push(...o)}}return{values:i,quoted:!1}}function cr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let r=t[0].operation,n=P(e,r.array).map(([o])=>String(o));if(n.length===0)return{values:[],quoted:!1};let a=T(e.state.env),i=q(e.state.env),l;if(r.star)if(i)l=n;else{let o=N(e.state.env),c=n.join(o);l=x(c,a)}else if(i)l=n;else{l=[];for(let o of n){let c=x(o,a);l.push(...c)}}return{values:l,quoted:!1}}async function fr(e,t,r){let s=-1;for(let h=0;h<t.length;h++){let d=t[h];if(d.type==="ParameterExpansion"&&(d.parameter==="@"||d.parameter==="*")&&!d.operation){s=h;break}}if(s===-1||t.length<=1)return null;let n=Number.parseInt(e.state.env.get("#")||"0",10),a=[];for(let h=1;h<=n;h++)a.push(e.state.env.get(String(h))||"");let i="";for(let h=0;h<s;h++)i+=await r(e,t[h]);let l="";for(let h=s+1;h<t.length;h++)l+=await r(e,t[h]);let o=T(e.state.env),c=q(e.state.env),u=$e(e.state.env);if(n===0){let h=i+l;return{values:h?[h]:[],quoted:!1}}let f;{let h=[];for(let d=0;d<a.length;d++){let m=a[d];d===0&&(m=i+m),d===a.length-1&&(m=m+l),h.push(m)}if(c)f=h.filter(d=>d!=="");else if(u){f=[];for(let d of h){if(d==="")continue;let m=x(d,o);f.push(...m)}}else{f=[];for(let d of h)if(d==="")f.push("");else{let m=x(d,o);f.push(...m)}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await We(e,f),quoted:!1}}async function dr(e,t,r){e.coverage?.hit("bash:expansion:word_glob");let s=t.parts,{hasQuoted:n,hasCommandSub:a,hasArrayVar:i,hasArrayAtExpansion:l,hasParamExpansion:o,hasVarNamePrefixExpansion:c,hasIndirection:u}=Ee(s),h=r.hasBraceExpansion(s)?await r.expandWordWithBracesAsync(e,t):null;if(h&&h.length>1)return Ps(e,h,n);let d=await Rs(e,s,l,c,u,r);if(d!==null)return d;let m=await vs(e,s,r);if(m!==null)return m;let g=await Ds(e,s,r);if(g!==null)return g;let E=await _s(e,s,r.expandPart);if(E!==null)return pr(e,E);if((a||i||o)&&!q(e.state.env)){let S=T(e.state.env),y=r.buildIfsCharClassPattern(S),b=await r.smartWordSplit(e,s,S,y,r.expandPart);return pr(e,b)}let A=await r.expandWordAsync(e,t);return $s(e,t,s,A,n,r.expandWordForGlobbing)}async function Ps(e,t,r){let s=[];for(let n of t)if(!(!r&&n===""))if(!r&&!e.state.options.noglob&&ne(n,e.state.shoptOptions.extglob)){let a=await Te(e,n);s.push(...a)}else s.push(n);return{values:s,quoted:!1}}async function Rs(e,t,r,s,n,a){if(r){let i=Un(e,t);if(i!==null)return i}{let i=Hn(e,t);if(i!==null)return i}{let i=await Fn(e,t);if(i!==null)return i}{let i=await zn(e,t,r,a.expandPart,a.expandWordPartsAsync);if(i!==null)return i}{let i=await Gn(e,t,r,a.expandPart);if(i!==null)return i}{let i=await Qn(e,t,a.evaluateArithmetic);if(i!==null)return i}{let i=Zn(e,t);if(i!==null)return i}{let i=await qn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}{let i=await Bn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}if(s&&t.length===1&&t[0].type==="DoubleQuoted"){let i=Is(e,t);if(i!==null)return i}{let i=await jn(e,t,n,a.expandParameterAsync,a.expandWordPartsAsync);if(i!==null)return i}{let i=await Kn(e,t);if(i!==null)return i}{let i=await Xn(e,t);if(i!==null)return i}return null}function Is(e,t){let r=t[0];if(r.type!=="DoubleQuoted")return null;if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="VarNamePrefix"){let s=r.parts[0].operation,n=me(e,s.prefix);return s.star?{values:[n.join(N(e.state.env))],quoted:!0}:{values:n,quoted:!0}}if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="ArrayKeys"){let s=r.parts[0].operation,a=P(e,s.array).map(([i])=>String(i));return s.star?{values:[a.join(N(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return null}async function vs(e,t,r){{let s=await Yn(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await er(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await tr(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await nr(e,t,r.expandPart);if(s!==null)return s}return null}async function Ds(e,t,r){{let s=await rr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await sr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await ir(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await ar(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await or(e,t);if(s!==null)return s}{let s=await lr(e,t);if(s!==null)return s}{let s=ur(e,t);if(s!==null)return s}{let s=cr(e,t);if(s!==null)return s}{let s=await fr(e,t,r.expandPart);if(s!==null)return s}return null}function hr(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;t<e.parts.length;t++){let r=e.parts[t];if(r.type!=="ParameterExpansion"||r.operation)continue;let s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(s)return{type:"array",name:s[1],atIndex:t,isStar:s[2]==="*"};if(r.parameter==="@"||r.parameter==="*")return{type:"positional",atIndex:t,isStar:r.parameter==="*"}}return null}async function xs(e,t,r,s){let n="";for(let l=0;l<r.atIndex;l++)n+=await s(e,t.parts[l]);let a="";for(let l=r.atIndex+1;l<t.parts.length;l++)a+=await s(e,t.parts[l]);let i;if(r.type==="array"){if(i=P(e,r.name).map(([,o])=>o),i.length===0){let o=e.state.env.get(r.name);o!==void 0&&(i=[o])}}else{let l=Number.parseInt(e.state.env.get("#")||"0",10);i=[];for(let o=1;o<=l;o++)i.push(e.state.env.get(String(o))||"")}if(r.isStar){let l=N(e.state.env),o=i.join(l);return[n+o+a]}if(i.length===0){let l=n+a;return l?[l]:[]}return i.length===1?[n+i[0]+a]:[n+i[0],...i.slice(1,-1),i[i.length-1]+a]}async function _s(e,t,r){if(t.length<2)return null;let s=!1;for(let o of t)if(hr(o)){s=!0;break}if(!s)return null;let n=T(e.state.env),a=q(e.state.env),i=[];for(let o of t){let c=hr(o);if(c&&o.type==="DoubleQuoted"){let u=await xs(e,o,c,r);i.push(u)}else if(o.type==="DoubleQuoted"||o.type==="SingleQuoted"){let u=await r(e,o);i.push([u])}else if(o.type==="Literal")i.push([o.value]);else if(o.type==="ParameterExpansion"){let u=await r(e,o);if(a)i.push(u?[u]:[]);else{let f=x(u,n);i.push(f)}}else{let u=await r(e,o);if(a)i.push(u?[u]:[]);else{let f=x(u,n);i.push(f)}}}let l=[];for(let o of i)if(o.length!==0)if(l.length===0)l.push(...o);else{let c=l.length-1;l[c]=l[c]+o[0];for(let u=1;u<o.length;u++)l.push(o[u])}return l}async function pr(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let r=[];for(let s of t)if(ne(s,e.state.shoptOptions.extglob)){let n=await Te(e,s);r.push(...n)}else r.push(s);return{values:r,quoted:!1}}async function Te(e,t){let r=new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),s=await r.expand(t);if(s.length>0)return s;if(r.hasFailglob())throw new ke(t);return r.hasNullglob()?[]:[t]}async function $s(e,t,r,s,n,a){let i=r.some(l=>l.type==="Glob");if(!e.state.options.noglob&&i){let l=await a(e,t);if(ne(l,e.state.shoptOptions.extglob)){let c=await Te(e,l);if(c.length>0&&c[0]!==l)return{values:c,quoted:!1};if(c.length===0)return{values:[],quoted:!1}}let o=At(s);if(!q(e.state.env)){let c=T(e.state.env);return{values:x(o,c),quoted:!1}}return{values:[o],quoted:!1}}if(!n&&!e.state.options.noglob&&ne(s,e.state.shoptOptions.extglob)){let l=await a(e,t);if(ne(l,e.state.shoptOptions.extglob)){let o=await Te(e,l);if(o.length>0&&o[0]!==l)return{values:o,quoted:!1}}}if(s===""&&!n)return{values:[],quoted:!1};if(i&&!n){let l=At(s);if(!q(e.state.env)){let o=T(e.state.env);return{values:x(l,o),quoted:!1}}return{values:[l],quoted:!1}}return{values:[s],quoted:n}}async function gr(e,t){let r=t.operation;if(!r||r.type!=="DefaultValue"&&r.type!=="AssignDefault"&&r.type!=="UseAlternative")return null;let s=r.word;if(!s||s.parts.length===0)return null;let n=await te(e,t.parameter),i=await v(e,t.parameter,!1)==="",l=r.checkEmpty??!1,o;return r.type==="UseAlternative"?o=n&&!(l&&i):o=!n||l&&i,o?s.parts:null}function Cs(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(r=>r.type==="Literal"):!1}async function Os(e,t){if(t.type!=="ParameterExpansion")return null;let r=await gr(e,t);if(!r||r.length<=1)return null;let s=r.some(a=>Cs(a)),n=r.some(a=>a.type==="Literal"||a.type==="ParameterExpansion"||a.type==="CommandSubstitution"||a.type==="ArithmeticExpansion");return s&&n?r:null}function Ls(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?pt(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&mn(e))}async function yr(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let h=t[0],d=await gr(e,h);if(d&&d.length>0&&d.length>1&&d.some(g=>g.type==="DoubleQuoted"||g.type==="SingleQuoted")&&d.some(g=>g.type==="Literal"||g.type==="ParameterExpansion"||g.type==="CommandSubstitution"||g.type==="ArithmeticExpansion"))return mr(e,d,r,s,n)}let a=[],i=!1;for(let h of t){let d=Ls(h),m=h.type==="DoubleQuoted"||h.type==="SingleQuoted",g=d?await Os(e,h):null,E=await n(e,h);a.push({value:E,isSplittable:d,isQuoted:m,mixedDefaultParts:g??void 0}),d&&(i=!0)}if(!i){let h=a.map(d=>d.value).join("");return h?[h]:[]}let l=[],o="",c=!1,u=!1,f=!1;for(let h of a)if(!h.isSplittable)u?h.isQuoted&&h.value===""?(o!==""&&l.push(o),l.push(""),c=!0,o="",u=!1,f=!0):h.value!==""?(o!==""&&l.push(o),o=h.value,u=!1,f=!1):(o+=h.value,f=!1):(o+=h.value,f=h.isQuoted&&h.value==="");else if(h.mixedDefaultParts){let d=await mr(e,h.mixedDefaultParts,r,s,n);if(d.length!==0)if(d.length===1)o+=d[0],c=!0;else{o+=d[0],l.push(o),c=!0;for(let m=1;m<d.length-1;m++)l.push(d[m]);o=d[d.length-1]}u=!1,f=!1}else{let{words:d,hadLeadingDelimiter:m,hadTrailingDelimiter:g}=Ce(h.value,r);if(f&&m&&o===""&&(l.push(""),c=!0),d.length===0)g&&(u=!0);else if(d.length===1)o+=d[0],c=!0,u=g;else{o+=d[0],l.push(o),c=!0;for(let E=1;E<d.length-1;E++)l.push(d[E]);o=d[d.length-1],u=g}f=!1}return o!==""?l.push(o):l.length===0&&c&&l.push(""),l}function Ws(e,t){return e.length>0&&t.includes(e[0])}async function mr(e,t,r,s,n){let a=[];for(let u of t){let h=!(u.type==="DoubleQuoted"||u.type==="SingleQuoted"),d=await n(e,u);a.push({value:d,isSplittable:h})}let i=[],l="",o=!1,c=!1;for(let u of a)if(!u.isSplittable)c&&u.value!==""?(l!==""&&i.push(l),l=u.value,c=!1):l+=u.value;else{Ws(u.value,r)&&l!==""&&(i.push(l),l="",o=!0);let{words:h,hadTrailingDelimiter:d}=Ce(u.value,r);if(h.length===0)d&&(c=!0);else if(h.length===1)l+=h[0],o=!0,c=d;else{l+=h[0],i.push(l),o=!0;for(let m=1;m<h.length-1;m++)i.push(h[m]);l=h[h.length-1],c=d}}return l!==""?i.push(l):i.length===0&&o&&i.push(""),i}function Er(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Ar(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}function ce(e,t,r){if(e.length>t)throw new L(`${r}: string length limit exceeded (${t} bytes)`,"string_length")}async function J(e,t,r=!1){let s=[];for(let n of t)s.push(await U(e,n,r));return s.join("")}function Ts(e){return Ar(e)}function El(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!Ts(t))return!1;return!0}function Ms(e,t,r=!1){let s=Er(t);if(s!==null)return s;switch(t.type){case"TildeExpansion":return r?t.user===null?"~":`~${t.user}`:(e.coverage?.hit("bash:expansion:tilde"),t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`);case"Glob":return wt(e,t.pattern);default:return null}}async function kt(e,t){return Pt(e,t)}async function Al(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped")r.push(`\\${s.value}`);else if(s.type==="SingleQuoted")r.push(s.value);else if(s.type==="DoubleQuoted"){let n=await J(e,s.parts);r.push(n)}else if(s.type==="TildeExpansion"){let n=await U(e,s);r.push(St(n))}else r.push(await U(e,s));return r.join("")}async function Sl(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped"){let n=s.value;"()|*?[]".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="SingleQuoted")r.push(X(s.value));else if(s.type==="DoubleQuoted"){let n=await J(e,s.parts);r.push(X(n))}else r.push(await U(e,s));return r.join("")}async function Sr(e,t){let r=[];for(let s of t.parts)if(s.type==="SingleQuoted")r.push(X(s.value));else if(s.type==="Escaped"){let n=s.value;"*?[]\\()|".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="DoubleQuoted"){let n=await J(e,s.parts);r.push(X(n))}else s.type==="Glob"?Wn(s.pattern)?r.push(await Mn(e,s.pattern)):r.push(wt(e,s.pattern)):s.type==="Literal"?r.push(s.value):r.push(await U(e,s));return r.join("")}function Ve(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&Ve(t.parts))return!0;return!1}var Nt=1e5;async function br(e,t,r={count:0}){if(r.count>Nt)return[[]];let s=[[]];for(let n of t)if(n.type==="BraceExpansion"){let a=[],i=!1,l="";for(let u of n.items)if(u.type==="Range"){let f=Et(u.start,u.end,u.step,u.startStr,u.endStr);if(f.expanded)for(let h of f.expanded)r.count++,a.push(h);else{i=!0,l=f.literal;break}}else{let f=await br(e,u.word.parts,r);for(let h of f){r.count++;let d=[];for(let m of h)typeof m=="string"?d.push(m):d.push(await U(e,m));a.push(d.join(""))}}if(i){for(let u of s)r.count++,u.push(l);continue}if(s.length*a.length>e.limits.maxBraceExpansionResults||r.count>Nt)return s;let c=[];for(let u of s)for(let f of a){if(r.count++,r.count>Nt)return c.length>0?c:s;c.push([...u,f])}s=c}else for(let a of s)r.count++,a.push(n);return s}async function wr(e,t){let r=t.parts;if(!Ve(r))return[await kt(e,t)];let s=await br(e,r),n=[];for(let a of s){let i=[];for(let l of a)typeof l=="string"?i.push(l):i.push(await U(e,l));n.push(Vn(e,i.join("")))}return n}function Vs(){return{expandWordAsync:Pt,expandWordForGlobbing:Sr,expandWordWithBracesAsync:wr,expandWordPartsAsync:J,expandPart:U,expandParameterAsync:Me,hasBraceExpansion:Ve,evaluateArithmetic:R,buildIfsCharClassPattern:En,smartWordSplit:yr}}async function bl(e,t){return dr(e,t,Vs())}function qs(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Bs(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function s(n){for(let a of n)if(a.type==="DoubleQuoted"){for(let i of a.parts)if(i.type==="ParameterExpansion"&&i.parameter==="@"&&!i.operation)return!0}return!1}return s(t.parts)}async function wl(e,t){if(Bs(e,t))return{error:`bash: $@: ambiguous redirect
|
|
70
|
-
`};let r=t.parts,{hasQuoted:s}=
|
|
71
|
-
`};let n=await
|
|
72
|
-
`}}if(s||e.state.options.noglob)return{target:n};let o=await
|
|
62
|
+
`,""):e.state.env.get(`${i}_${m}`)||""}let u=e.state.env.get(`${i}_${c}`);if(u!==void 0)return u;if(c===0){let f=e.state.env.get(i);if(f!==void 0)return f}if(r&&e.state.options.nounset)throw new j(`${i}[${c}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let i=e.state.env.get(t);if(i===void 0&&r&&e.state.options.nounset)throw new j(t);return i||""}if(W(e,t)){let i=he(e,t);if(i===void 0)return"";if(i!==t)return await v(e,i,r,s);let l=e.state.env.get(t);if((l===void 0||l==="")&&r&&e.state.options.nounset)throw new j(t);return l||""}let a=e.state.env.get(t);if(a!==void 0)return e.state.tempEnvBindings?.some(i=>i.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),a;if(be(e,t)){let i=e.state.env.get(`${t}_0`);return i!==void 0?i:""}if(r&&e.state.options.nounset)throw new j(t);return""}async function te(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],a=s[2];if(W(e,n)){let o=he(e,n);if(o&&o!==n){if(o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;n=o}}if(a==="@"||a==="*")return P(e,n).length>0?!0:e.state.env.has(n);if(e.state.associativeArrays?.has(n)){let o=$e(a);return e.state.env.has(`${n}_${o}`)}let l;if(/^-?\d+$/.test(a))l=Number.parseInt(a,10);else try{let o=new V,c=M(o,a);l=await R(e,c.expression)}catch{let o=e.state.env.get(a);l=o?Number.parseInt(o,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let o=P(e,n);if(o.length===0)return!1;let u=Math.max(...o.map(([f])=>typeof f=="number"?f:0))+1+l;return u<0?!1:e.state.env.has(`${n}_${u}`)}return e.state.env.has(`${n}_${l}`)}if(W(e,t)){let n=he(e,t);return n===void 0||n===t?e.state.env.has(t):te(e,n)}return!!(e.state.env.has(t)||be(e,t))}async function bn(e,t){let r="",s=0;for(;s<t.length;){if(t[s]==="$"){if(t[s+1]==="{"){let n=1,a=s+2;for(;a<t.length&&n>0;)t[a]==="{"?n++:t[a]==="}"&&n--,a++;r+=t.slice(s,a),s=a;continue}if(t[s+1]==="("){let n=1,a=s+2;for(;a<t.length&&n>0;)t[a]==="("?n++:t[a]===")"&&n--,a++;r+=t.slice(s,a),s=a;continue}if(/[a-zA-Z_]/.test(t[s+1]||"")){let n=s+1;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)n++;let a=t.slice(s+1,n),i=await v(e,a);r+=i,s=n;continue}if(/[0-9]/.test(t[s+1]||"")){let n=s+1;for(;n<t.length&&/[0-9]/.test(t[n]);)n++;let a=t.slice(s+1,n),i=await v(e,a);r+=i,s=n;continue}if(/[*@#?\-!$]/.test(t[s+1]||"")){let n=t[s+1],a=await v(e,n);r+=a,s+=2;continue}}if(t[s]==='"'){for(r+='"',s++;s<t.length&&t[s]!=='"';)if(t[s]==="$"&&/[a-zA-Z_]/.test(t[s+1]||"")){let n=s+1;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)n++;let a=t.slice(s+1,n),i=await v(e,a);r+=i,s=n}else t[s]==="\\"?(r+=t[s],s++,s<t.length&&(r+=t[s],s++)):(r+=t[s],s++);s<t.length&&(r+='"',s++);continue}r+=t[s],s++}return r}async function Et(e,t){let r=t,s=t.startsWith('"')&&t.endsWith('"'),n=t.startsWith("'")&&t.endsWith("'");if((s||n)&&(r=t.slice(1,-1)),n)return r;let a="",i=0;for(;i<r.length;)if(r[i]==="$")if(r[i+1]==="("){let l=1,o=i+2;for(;o<r.length&&l>0;)r[o]==="("&&r[o-1]==="$"||r[o]==="("?l++:r[o]===")"&&l--,o++;let c=r.slice(i+2,o-1);if(e.execFn){let u=await e.execFn(c,{signal:e.state.signal});a+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}i=o}else if(r[i+1]==="{"){let l=1,o=i+2;for(;o<r.length&&l>0;)r[o]==="{"?l++:r[o]==="}"&&l--,o++;let c=r.slice(i+2,o-1),u=await v(e,c);a+=u,i=o}else if(/[a-zA-Z_]/.test(r[i+1]||"")){let l=i+1;for(;l<r.length&&/[a-zA-Z0-9_]/.test(r[l]);)l++;let o=r.slice(i+1,l),c=await v(e,o);a+=c,i=l}else a+=r[i],i++;else if(r[i]==="`"){let l=i+1;for(;l<r.length&&r[l]!=="`";)l++;let o=r.slice(i+1,l);if(e.execFn){let c=await e.execFn(o,{signal:e.state.signal});a+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}i=l+1}else a+=r[i],i++;return a}var Le=1e4;function fs(e,t,r,s,n){let a=r??1;a===0&&(a=1);let i=Math.abs(a),l=[],o=0;s?.match(/^-?0\d/)&&(o=Math.max(o,s.replace(/^-/,"").length)),n?.match(/^-?0\d/)&&(o=Math.max(o,n.replace(/^-/,"").length));let c=u=>{if(o>0){let f=u<0,h=String(Math.abs(u)).padStart(o,"0");return f?`-${h}`:h}return String(u)};if(e<=t)for(let u=e,f=0;u<=t&&f<Le;u+=i,f++)l.push(c(u));else for(let u=e,f=0;u>=t&&f<Le;u-=i,f++)l.push(c(u));return l}function hs(e,t,r){let s=r??1;s===0&&(s=1);let n=e.charCodeAt(0),a=t.charCodeAt(0),i=Math.abs(s),l=e>="A"&&e<="Z",o=e>="a"&&e<="z",c=t>="A"&&t<="Z",u=t>="a"&&t<="z";if(l&&u||o&&c){let h=r!==void 0?`..${r}`:"";throw new It(`{${e}..${t}${h}}: invalid sequence`)}let f=[];if(n<=a)for(let h=n,d=0;h<=a&&d<Le;h+=i,d++)f.push(String.fromCharCode(h));else for(let h=n,d=0;h>=a&&d<Le;h-=i,d++)f.push(String.fromCharCode(h));return f}function At(e,t,r,s,n){let a=r!==void 0?`..${r}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:fs(e,t,r,s,n),literal:`{${e}..${t}${a}}`}:typeof e=="string"&&typeof t=="string"?{expanded:hs(e,t,r),literal:`{${e}..${t}${a}}`}:{expanded:null,literal:`{${e}..${t}${a}}`}}function wn(e){if(e.statements.length!==1)return null;let t=e.statements[0];if(t.operators.length!==0||t.pipelines.length!==1)return null;let r=t.pipelines[0];if(r.negated||r.commands.length!==1)return null;let s=r.commands[0];if(s.type!=="SimpleCommand")return null;let n=s;if(n.name!==null||n.args.length!==0||n.assignments.length!==0||n.redirections.length!==1)return null;let a=n.redirections[0];return a.operator!=="<"||a.target.type!=="Word"?null:{target:a.target}}function ne(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function St(e){let t="",r=0;for(;r<e.length;)e[r]==="\\"&&r+1<e.length?(t+=e[r+1],r+=2):(t+=e[r],r++);return t}function X(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function bt(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function I(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function k(e,t,r=!1){let s="",n=0;for(;n<e.length;){let a=e[n];if(r&&(a==="@"||a==="*"||a==="+"||a==="?"||a==="!")&&n+1<e.length&&e[n+1]==="("){let i=ps(e,n+1);if(i!==-1){let l=e.slice(n+2,i),c=ds(l).map(f=>k(f,t,r)),u=c.length>0?c.join("|"):"(?:)";a==="@"?s+=`(?:${u})`:a==="*"?s+=`(?:${u})*`:a==="+"?s+=`(?:${u})+`:a==="?"?s+=`(?:${u})?`:a==="!"&&(s+=`(?!(?:${u})$).*`),n=i+1;continue}}if(a==="\\")if(n+1<e.length){let i=e[n+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,n+=2}else s+="\\\\",n++;else if(a==="*")s+=t?".*":".*?",n++;else if(a==="?")s+=".",n++;else if(a==="["){let i=ms(e,n);if(i===-1)s+="\\[",n++;else{let l=e.slice(n+1,i);s+=gs(l),n=i+1}}else/[\^$.|+(){}]/.test(a)?(s+=`\\${a}`,n++):(s+=a,n++)}return s}function ps(e,t){let r=1,s=t+1;for(;s<e.length&&r>0;){let n=e[s];if(n==="\\"){s+=2;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function ds(e){let t=[],r="",s=0,n=0;for(;n<e.length;){let a=e[n];if(a==="\\"){r+=a,n+1<e.length?(r+=e[n+1],n+=2):n++;continue}a==="("?(s++,r+=a):a===")"?(s--,r+=a):a==="|"&&s===0?(t.push(r),r=""):r+=a,n++}return t.push(r),t}function ms(e,t){let r=t+1;for(r<e.length&&e[r]==="^"&&r++,r<e.length&&e[r]==="]"&&r++;r<e.length;){if(e[r]==="\\"&&r+1<e.length){r+=2;continue}if(e[r]==="]")return r;if(e[r]==="'"){let s=e.indexOf("'",r+1);if(s!==-1){r=s+1;continue}}if(e[r]==="["&&r+1<e.length&&e[r+1]===":"){let s=e.indexOf(":]",r+2);if(s!==-1){r=s+2;continue}}r++}return-1}function gs(e){let t="[",r=0;for((e[0]==="^"||e[0]==="!")&&(t+="^",r++);r<e.length;){if(e[r]==="'"){let n=e.indexOf("'",r+1);if(n!==-1){let a=e.slice(r+1,n);for(let i of a)i==="\\"?t+="\\\\":i==="]"?t+="\\]":i==="^"&&t==="["?t+="\\^":t+=i;r=n+1;continue}}if(e[r]==="["&&r+1<e.length&&e[r+1]===":"){let n=e.indexOf(":]",r+2);if(n!==-1){let a=e.slice(r+2,n);t+=Es(a),r=n+2;continue}}let s=e[r];s==="\\"?r+1<e.length?(t+=`\\${e[r+1]}`,r+=2):(t+="\\\\",r++):s==="-"&&r>0&&r<e.length-1?(t+="-",r++):s==="^"&&r===0?(t+="^",r++):(s==="]"&&r===0?t+="\\]":t+=s,r++)}return t+="]",t}var ys=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]);function Es(e){return ys.get(e)??""}function se(e,t,r,s){if(r==="prefix")return O(`^${t}`,"s").replace(e,"");let n=O(`${t}$`,"s");if(s)return n.replace(e,"");for(let a=e.length;a>=0;a--){let i=e.slice(a);if(n.test(i))return e.slice(0,a)}return e}function me(e,t){let r=Array.from(e.state.env.keys()),s=new Set,n=e.state.associativeArrays??new Set,a=new Set;for(let l of r){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o&&a.add(o[1]);let c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);c&&a.add(c[1])}let i=l=>{for(let o of n){let c=`${o}_`;if(l.startsWith(c)&&l!==o)return!0}return!1};for(let l of r)if(l.startsWith(t))if(l.includes("__")){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);o?.[1].startsWith(t)&&s.add(o[1])}else if(/_\d+$/.test(l)){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o?.[1].startsWith(t)&&s.add(o[1])}else i(l)||s.add(l);return[...s].sort()}function As(e,t){let r=(a,i=2)=>String(a).padStart(i,"0");if(e===""){let a=r(t.getHours()),i=r(t.getMinutes()),l=r(t.getSeconds());return`${a}:${i}:${l}`}let s="",n=0;for(;n<e.length;)if(e[n]==="%"){if(n+1>=e.length){s+="%",n++;continue}let a=e[n+1];switch(a){case"H":s+=r(t.getHours());break;case"M":s+=r(t.getMinutes());break;case"S":s+=r(t.getSeconds());break;case"d":s+=r(t.getDate());break;case"m":s+=r(t.getMonth()+1);break;case"Y":s+=t.getFullYear();break;case"y":s+=r(t.getFullYear()%100);break;case"I":{let i=t.getHours()%12;i===0&&(i=12),s+=r(i);break}case"p":s+=t.getHours()<12?"AM":"PM";break;case"P":s+=t.getHours()<12?"am":"pm";break;case"%":s+="%";break;case"a":{s+=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][t.getDay()];break}case"b":{s+=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][t.getMonth()];break}default:s+=`%${a}`}n+=2}else s+=e[n],n++;return s}function we(e,t){let r="",s=0,n=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",a=e.state.env.get("HOSTNAME")||"localhost",i=a.split(".")[0],l=e.state.env.get("PWD")||"/",o=e.state.env.get("HOME")||"/",c=l.startsWith(o)?`~${l.slice(o.length)}`:l,u=l.split("/").pop()||l,f=new Date,h=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],d=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],m=e.state.env.get("__COMMAND_NUMBER")||"1";for(;s<t.length;){let g=t[s];if(g==="\\"){if(s+1>=t.length){r+="\\",s++;continue}let E=t[s+1];if(E>="0"&&E<="7"){let A="",S=s+1;for(;S<t.length&&S<s+4&&t[S]>="0"&&t[S]<="7";)A+=t[S],S++;let y=Number.parseInt(A,8)%256;r+=String.fromCharCode(y),s=S;continue}switch(E){case"\\":r+="\\",s+=2;break;case"a":r+="\x07",s+=2;break;case"e":r+="\x1B",s+=2;break;case"n":r+=`
|
|
63
|
+
`,s+=2;break;case"r":r+="\r",s+=2;break;case"$":r+="$",s+=2;break;case"[":case"]":s+=2;break;case"u":r+=n,s+=2;break;case"h":r+=i,s+=2;break;case"H":r+=a,s+=2;break;case"w":r+=c,s+=2;break;case"W":r+=u,s+=2;break;case"d":{let A=String(f.getDate()).padStart(2," ");r+=`${h[f.getDay()]} ${d[f.getMonth()]} ${A}`,s+=2;break}case"t":{let A=String(f.getHours()).padStart(2,"0"),S=String(f.getMinutes()).padStart(2,"0"),y=String(f.getSeconds()).padStart(2,"0");r+=`${A}:${S}:${y}`,s+=2;break}case"T":{let A=f.getHours()%12;A===0&&(A=12);let S=String(A).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),b=String(f.getSeconds()).padStart(2,"0");r+=`${S}:${y}:${b}`,s+=2;break}case"@":{let A=f.getHours()%12;A===0&&(A=12);let S=String(A).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),b=f.getHours()<12?"AM":"PM";r+=`${S}:${y} ${b}`,s+=2;break}case"A":{let A=String(f.getHours()).padStart(2,"0"),S=String(f.getMinutes()).padStart(2,"0");r+=`${A}:${S}`,s+=2;break}case"D":if(s+2<t.length&&t[s+2]==="{"){let A=t.indexOf("}",s+3);if(A!==-1){let S=t.slice(s+3,A);r+=As(S,f),s=A+1}else r+="\\D",s+=2}else r+="\\D",s+=2;break;case"s":r+="bash",s+=2;break;case"v":r+="5.0",s+=2;break;case"V":r+="5.0.0",s+=2;break;case"j":r+="0",s+=2;break;case"l":r+="tty",s+=2;break;case"#":r+=m,s+=2;break;case"!":r+=m,s+=2;break;case"x":r+="\\x",s+=2;break;default:r+=`\\${E}`,s+=2}}else r+=g,s++}return r}function le(e){if(e==="")return"''";if(/[\n\r\t\x00-\x1f\x7f']/.test(e)){let r="$'";for(let s of e)switch(s){case"'":r+="\\'";break;case"\\":r+="\\\\";break;case`
|
|
64
|
+
`:r+="\\n";break;case"\r":r+="\\r";break;case" ":r+="\\t";break;default:{let n=s.charCodeAt(0);n<32||n===127?r+=`\\${n.toString(8).padStart(3,"0")}`:r+=s}}return`${r}'`}return`'${e}'`}function pa(e,t){e.state.readonlyVars=e.state.readonlyVars||new Set,e.state.readonlyVars.add(t)}function wt(e,t){return e.state.readonlyVars?.has(t)??!1}function da(e,t,r="bash"){if(wt(e,t)){let s=`${r}: ${t}: readonly variable
|
|
65
|
+
`;throw new K(1,"",s)}return null}function ma(e,t){let r=e.state.exportedVars?.has(t)??!1;if(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(t),e.state.localScopes.length>0&&e.state.localScopes[e.state.localScopes.length-1].has(t)&&!r){for(e.state.localExportedVars||(e.state.localExportedVars=[]);e.state.localExportedVars.length<e.state.localScopes.length;)e.state.localExportedVars.push(new Set);e.state.localExportedVars[e.state.localExportedVars.length-1].add(t)}}function ga(e,t){e.state.exportedVars?.delete(t)}function ue(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let r="",s=e.state.env.has(`${t}__length`)||Array.from(e.state.env.keys()).some(a=>a.startsWith(`${t}_`)&&/^[0-9]+$/.test(a.slice(t.length+1))),n=e.state.associativeArrays?.has(t)??!1;return s&&!n&&(r+="a"),n&&(r+="A"),e.state.integerVars?.has(t)&&(r+="i"),W(e,t)&&(r+="n"),wt(e,t)&&(r+="r"),e.state.exportedVars?.has(t)&&(r+="x"),r}async function Nn(e,t,r,s){return e.coverage?.hit("bash:expansion:default_value"),(r.isUnset||t.checkEmpty&&r.isEmpty)&&t.word?s(e,t.word.parts,r.inDoubleQuotes):r.effectiveValue}async function kn(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:assign_default"),(s.isUnset||r.checkEmpty&&s.isEmpty)&&r.word){let i=await n(e,r.word.parts,s.inDoubleQuotes),l=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let[,o,c]=l,u;if(/^\d+$/.test(c))u=Number.parseInt(c,10);else{try{let h=new V,d=M(h,c);u=await R(e,d.expression)}catch{let h=e.state.env.get(c);u=h?Number.parseInt(h,10):0}Number.isNaN(u)&&(u=0)}e.state.env.set(`${o}_${u}`,i);let f=Number.parseInt(e.state.env.get(`${o}__length`)||"0",10);u>=f&&e.state.env.set(`${o}__length`,String(u+1))}else e.state.env.set(t,i);return i}return s.effectiveValue}async function Pn(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:error_if_unset"),s.isUnset||r.checkEmpty&&s.isEmpty){let i=r.word?await n(e,r.word.parts,s.inDoubleQuotes):`${t}: parameter null or not set`;throw new K(1,"",`bash: ${i}
|
|
66
|
+
`)}return s.effectiveValue}async function Rn(e,t,r,s){return e.coverage?.hit("bash:expansion:use_alternative"),!(r.isUnset||t.checkEmpty&&r.isEmpty)&&t.word?s(e,t.word.parts,r.inDoubleQuotes):""}async function In(e,t,r,s,n){e.coverage?.hit("bash:expansion:pattern_removal");let a="",i=e.state.shoptOptions.extglob;if(r.pattern)for(let o of r.pattern.parts)if(o.type==="Glob")a+=k(o.pattern,r.greedy,i);else if(o.type==="Literal")a+=k(o.value,r.greedy,i);else if(o.type==="SingleQuoted"||o.type==="Escaped")a+=I(o.value);else if(o.type==="DoubleQuoted"){let c=await s(e,o.parts);a+=I(c)}else if(o.type==="ParameterExpansion"){let c=await n(e,o);a+=k(c,r.greedy,i)}else{let c=await n(e,o);a+=I(c)}if(r.side==="prefix")return O(`^${a}`,"s").replace(t,"");let l=O(`${a}$`,"s");if(r.greedy)return l.replace(t,"");for(let o=t.length;o>=0;o--){let c=t.slice(o);if(l.test(c))return t.slice(0,o)}return t}async function vn(e,t,r,s,n){e.coverage?.hit("bash:expansion:pattern_replacement");let a="",i=e.state.shoptOptions.extglob;if(r.pattern)for(let c of r.pattern.parts)if(c.type==="Glob")a+=k(c.pattern,!0,i);else if(c.type==="Literal")a+=k(c.value,!0,i);else if(c.type==="SingleQuoted"||c.type==="Escaped")a+=I(c.value);else if(c.type==="DoubleQuoted"){let u=await s(e,c.parts);a+=I(u)}else if(c.type==="ParameterExpansion"){let u=await n(e,c);a+=k(u,!0,i)}else{let u=await n(e,c);a+=I(u)}let l=r.replacement?await s(e,r.replacement.parts):"";if(r.anchor==="start"?a=`^${a}`:r.anchor==="end"&&(a=`${a}$`),a==="")return t;let o=r.all?"gs":"s";try{let c=O(a,o);if(r.all){let u="",f=0,h=0,d=e.limits.maxStringLength,m=c.exec(t);for(;m!==null&&!(m[0].length===0&&m.index===t.length);){if(u+=t.slice(f,m.index)+l,f=m.index+m[0].length,m[0].length===0&&f++,h++,h%100===0&&u.length>d)throw new L(`pattern replacement: string length limit exceeded (${d} bytes)`,"string_length");m=c.exec(t)}return u+=t.slice(f),u}return c.replace(t,l)}catch(c){if(c instanceof L)throw c;return t}}function Dn(e,t,r){e.coverage?.hit("bash:expansion:length");let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(s){let n=s[1],a=P(e,n);return a.length>0?String(a.length):e.state.env.get(n)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&be(e,t)){if(t==="FUNCNAME"){let a=e.state.funcNameStack?.[0]||"";return String([...a].length)}if(t==="BASH_LINENO"){let a=e.state.callLineStack?.[0];return String(a!==void 0?[...String(a)].length:0)}let n=e.state.env.get(`${t}_0`)||"";return String([...n].length)}return String([...r].length)}async function xn(e,t,r,s){e.coverage?.hit("bash:expansion:substring");let n=await R(e,s.offset.expression),a=s.length?await R(e,s.length.expression):void 0;if(t==="@"||t==="*"){let c=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let m=1;m<=c;m++)u.push(e.state.env.get(String(m))||"");let f=e.state.env.get("0")||"bash",h,d;if(n<=0)if(h=[f,...u],n<0){if(d=h.length+n,d<0)return""}else d=0;else h=u,d=n-1;if(d<0||d>=h.length)return"";if(a!==void 0){let m=a<0?h.length+a:d+a;return h.slice(d,Math.max(d,m)).join(" ")}return h.slice(d).join(" ")}let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i){let c=i[1];if(e.state.associativeArrays?.has(c))throw new K(1,"",`bash: \${${c}[@]: 0: 3}: bad substitution
|
|
67
|
+
`);let u=P(e,c),f=0;if(n<0){if(u.length>0){let h=u[u.length-1][0],m=(typeof h=="number"?h:0)+1+n;if(m<0||(f=u.findIndex(([g])=>typeof g=="number"&&g>=m),f<0))return""}}else if(f=u.findIndex(([h])=>typeof h=="number"&&h>=n),f<0)return"";if(a!==void 0){if(a<0)throw new C(`${i[1]}[@]: substring expression < 0`);return u.slice(f,f+a).map(([,h])=>h).join(" ")}return u.slice(f).map(([,h])=>h).join(" ")}let l=[...r],o=n;if(o<0&&(o=Math.max(0,l.length+o)),a!==void 0){if(a<0){let c=l.length+a;return l.slice(o,Math.max(o,c)).join("")}return l.slice(o,o+a).join("")}return l.slice(o).join("")}async function _n(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:case_modification"),r.pattern){let a=e.state.shoptOptions.extglob,i="";for(let f of r.pattern.parts)if(f.type==="Glob")i+=k(f.pattern,!0,a);else if(f.type==="Literal")i+=k(f.value,!0,a);else if(f.type==="SingleQuoted"||f.type==="Escaped")i+=I(f.value);else if(f.type==="DoubleQuoted"){let h=await s(e,f.parts);i+=I(h)}else if(f.type==="ParameterExpansion"){let h=await n(e,f);i+=k(h,!0,a)}let l=O(`^(?:${i})$`),o=r.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),c="",u=!1;for(let f of t)!r.all&&u?c+=f:l.test(f)?(c+=o(f),u=!0):c+=f;return c}return r.direction==="upper"?r.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):r.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function $n(e,t,r,s,n){e.coverage?.hit("bash:expansion:transform");let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(a&&n.operator==="Q")return P(e,a[1]).map(([,c])=>le(c)).join(" ");if(a&&n.operator==="a")return ue(e,a[1]);let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(i&&n.operator==="a")return ue(e,i[1]);switch(n.operator){case"Q":return s?"":le(r);case"P":return we(e,r);case"a":return ue(e,t);case"A":return s?"":`${t}=${le(r)}`;case"E":return r.replace(/\\([\\abefnrtv'"?])/g,(l,o)=>{switch(o){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return`
|
|
68
|
+
`;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return o}});case"K":case"k":return s?"":le(r);case"u":return r.charAt(0).toUpperCase()+r.slice(1);case"U":return r.toUpperCase();case"L":return r.toLowerCase();default:return r}}async function Cn(e,t,r,s,n,a,i=!1){if(e.coverage?.hit("bash:expansion:indirection"),W(e,t))return Se(e,t)||"";let l=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(s){if(n.innerOp?.type==="UseAlternative")return"";throw new re(`\${!${t}}`)}let o=r;if(l&&(o===""||o.includes(" ")))throw new re(`\${!${t}}`);let c=o.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(c&&c[1].includes("~"))throw new re(`\${!${t}}`);if(n.innerOp){let u={type:"ParameterExpansion",parameter:o,operation:n.innerOp};return a(e,u,i)}return await v(e,o)}function On(e,t){e.coverage?.hit("bash:expansion:array_keys");let s=P(e,t.array).map(([n])=>String(n));return t.star?s.join(N(e.state.env)):s.join(" ")}function Ln(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let r=me(e,t.prefix);return t.star?r.join(N(e.state.env)):r.join(" ")}function Wn(e,t,r,s){let n=Number.parseInt(e.state.env.get("#")||"0",10),a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:n===0,effectiveValue:r};if(t==="@")return{isEmpty:n===0||n===1&&e.state.env.get("1")==="",effectiveValue:r};if(a){let[,i,l]=a,o=P(e,i);if(o.length===0)return{isEmpty:!0,effectiveValue:""};if(l==="*"){let c=N(e.state.env),u=o.map(([,f])=>f).join(c);return{isEmpty:s?u==="":!1,effectiveValue:u}}return{isEmpty:o.length===1&&o.every(([,c])=>c===""),effectiveValue:o.map(([,c])=>c).join(" ")}}return{isEmpty:r==="",effectiveValue:r}}function Tn(e){let t=0;for(;t<e.length;){let r=e[t];if(r==="\\"&&t+1<e.length){t+=2;continue}if(r==="'"){let s=e.indexOf("'",t+1);if(s!==-1){t=s+1;continue}}if(r==="$"&&t+1<e.length&&e[t+1]==="("||r==="`")return!0;t++}return!1}function Mn(e,t){let r=1,s=t,n=!1,a=!1;for(;s<e.length&&r>0;){let i=e[s];if(i==="\\"&&!n&&s+1<e.length){s+=2;continue}if(i==="'"&&!a){n=!n,s++;continue}if(i==='"'&&!n){a=!a,s++;continue}if(!n&&!a){if(i==="(")r++;else if(i===")"&&(r--,r===0))return s}s++}return-1}async function We(e,t){let r=new V,s;try{s=r.parse(t)}catch{return""}let n=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let a=new Map(e.state.env),i=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let o=await e.executeScript(s),c=o.exitCode;return e.state.env=a,e.state.cwd=i,e.state.suppressVerbose=l,e.state.lastExitCode=c,e.state.env.set("?",String(c)),o.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+o.stderr),e.state.bashPid=n,o.stdout.replace(/\n+$/,"")}catch(o){if(e.state.env=a,e.state.cwd=i,e.state.bashPid=n,e.state.suppressVerbose=l,o instanceof L)throw o;return o instanceof K?(e.state.lastExitCode=o.exitCode,e.state.env.set("?",String(o.exitCode)),o.stdout?.replace(/\n+$/,"")??""):""}}function Nt(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="'"){let a=t.indexOf("'",s+1);if(a!==-1){let i=t.slice(s+1,a);r+=X(i),s=a+1;continue}}if(n==='"'){let a=-1,i=s+1;for(;i<t.length;){if(t[i]==="\\"){i+=2;continue}if(t[i]==='"'){a=i;break}i++}if(a!==-1){let l=t.slice(s+1,a),o=Ss(e,l);r+=X(o),s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}if(n==="\\"&&s+1<t.length){r+=n+t[s+1],s+=2;continue}r+=n,s++}return r}function Ss(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="\\"&&s+1<t.length){let a=t[s+1];if(a==="$"||a==="`"||a==="\\"||a==='"'){r+=a,s+=2;continue}r+=n,s++;continue}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}r+=n,s++}return r}async function Vn(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="'"){let a=t.indexOf("'",s+1);if(a!==-1){let i=t.slice(s+1,a);r+=X(i),s=a+1;continue}}if(n==='"'){let a=-1,i=s+1;for(;i<t.length;){if(t[i]==="\\"){i+=2;continue}if(t[i]==='"'){a=i;break}i++}if(a!==-1){let l=t.slice(s+1,a),o=await bs(e,l);r+=X(o),s=a+1;continue}}if(n==="$"&&s+1<t.length&&t[s+1]==="("){let a=Mn(t,s+2);if(a!==-1){let i=t.slice(s+2,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="`"){let a=t.indexOf("`",s+1);if(a!==-1){let i=t.slice(s+1,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}if(n==="\\"&&s+1<t.length){r+=n+t[s+1],s+=2;continue}r+=n,s++}return r}async function bs(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="\\"&&s+1<t.length){let a=t[s+1];if(a==="$"||a==="`"||a==="\\"||a==='"'){r+=a,s+=2;continue}r+=n,s++;continue}if(n==="$"&&s+1<t.length&&t[s+1]==="("){let a=Mn(t,s+2);if(a!==-1){let i=t.slice(s+2,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="`"){let a=t.indexOf("`",s+1);if(a!==-1){let i=t.slice(s+1,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}r+=n,s++}return r}function qn(e,t){if(!t.startsWith("~"))return t;e.coverage?.hit("bash:expansion:tilde");let r=e.state.env.get("HOME")!==void 0?e.state.env.get("HOME"):"/home/user";if(t==="~"||t.startsWith("~/"))return r+t.slice(1);let s=1;for(;s<t.length&&/[a-zA-Z0-9_-]/.test(t[s]);)s++;let n=t.slice(1,s),a=t.slice(s);return a!==""&&!a.startsWith("/")?t:n==="root"?`/root${a}`:t}async function ws(e,t,r,s){let n="";for(let a of t.parts)if(a.type==="Glob")n+=k(a.pattern,!0,e.state.shoptOptions.extglob);else if(a.type==="Literal")n+=k(a.value,!0,e.state.shoptOptions.extglob);else if(a.type==="SingleQuoted"||a.type==="Escaped")n+=I(a.value);else if(a.type==="DoubleQuoted"){let i=await r(e,a.parts);n+=I(i)}else if(a.type==="ParameterExpansion"){let i=await s(e,a);n+=k(i,!0,e.state.shoptOptions.extglob)}else{let i=await s(e,a);n+=I(i)}return n}async function Bn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternReplacement")return null;let a=n.parts[0],i=a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let l=i[1],o=i[2]==="*",c=a.operation,u=P(e,l),f=u.map(([,E])=>E);if(u.length===0){let E=e.state.env.get(l);E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let h="";c.pattern&&(h=await ws(e,c.pattern,r,s));let d=c.replacement?await r(e,c.replacement.parts):"",m=h;c.anchor==="start"?m=`^${h}`:c.anchor==="end"&&(m=`${h}$`);let g=[];try{let E=O(m,c.all?"g":"");for(let A of f)g.push(E.replace(A,d))}catch{g.push(...f)}if(o){let E=N(e.state.env);return{values:[g.join(E)],quoted:!0}}return{values:g,quoted:!0}}async function Fn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternRemoval")return null;let a=n.parts[0],i=a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let l=i[1],o=i[2]==="*",c=a.operation,u=P(e,l),f=u.map(([,g])=>g);if(u.length===0){let g=e.state.env.get(l);g!==void 0&&f.push(g)}if(f.length===0)return{values:[],quoted:!0};let h="",d=e.state.shoptOptions.extglob;if(c.pattern)for(let g of c.pattern.parts)if(g.type==="Glob")h+=k(g.pattern,c.greedy,d);else if(g.type==="Literal")h+=k(g.value,c.greedy,d);else if(g.type==="SingleQuoted"||g.type==="Escaped")h+=I(g.value);else if(g.type==="DoubleQuoted"){let E=await r(e,g.parts);h+=I(E)}else if(g.type==="ParameterExpansion"){let E=await s(e,g);h+=k(E,c.greedy,d)}else{let E=await s(e,g);h+=I(E)}let m=[];for(let g of f)m.push(se(g,h,c.side,c.greedy));if(o){let g=N(e.state.env);return{values:[m.join(g)],quoted:!0}}return{values:m,quoted:!0}}async function zn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="DefaultValue"&&r.parts[0].operation?.type!=="UseAlternative"&&r.parts[0].operation?.type!=="AssignDefault")return null;let s=r.parts[0],n=s.operation,a=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/),i,l=!1;if(a){let o=a[1];l=a[2]==="*";let c=P(e,o),u=c.length>0||e.state.env.has(o),f=c.length===0||c.length===1&&c.every(([,d])=>d===""),h=n.checkEmpty??!1;if(n.type==="UseAlternative"?i=u&&!(h&&f):i=!u||h&&f,!i){if(c.length>0){let m=c.map(([,g])=>g);if(l){let g=N(e.state.env);return{values:[m.join(g)],quoted:!0}}return{values:m,quoted:!0}}let d=e.state.env.get(o);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}else{let o=s.parameter,c=await te(e,o),u=await v(e,o),f=u==="",h=n.checkEmpty??!1;if(n.type==="UseAlternative"?i=c&&!(h&&f):i=!c||h&&f,!i)return{values:[u],quoted:!0}}if(i&&n.word){let o=n.word.parts,c=null,u=!1;for(let f of o)if(f.type==="ParameterExpansion"&&!f.operation){let h=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(h){c=h[1],u=h[2]==="*";break}}if(c){let f=P(e,c);if(f.length>0){let d=f.map(([,m])=>m);if(u||l){let m=N(e.state.env);return{values:[d.join(m)],quoted:!0}}return{values:d,quoted:!0}}let h=e.state.env.get(c);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}}return null}async function Gn(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0],i=-1,l="",o=!1,c=null;for(let g=0;g<a.parts.length;g++){let E=a.parts[g];if(E.type==="ParameterExpansion"&&(E.operation?.type==="PatternRemoval"||E.operation?.type==="PatternReplacement")){let A=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(A){i=g,l=A[1],o=A[2]==="*",c=E.operation;break}}}if(i===-1||i===0&&i===a.parts.length-1)return null;let u="";for(let g=0;g<i;g++)u+=await s(e,a.parts[g]);let f="";for(let g=i+1;g<a.parts.length;g++)f+=await s(e,a.parts[g]);let h=P(e,l),d=h.map(([,g])=>g);if(h.length===0){let g=e.state.env.get(l);if(g!==void 0)d=[g];else{if(o)return{values:[u+f],quoted:!0};let E=u+f;return{values:E?[E]:[],quoted:!0}}}if(c?.type==="PatternRemoval"){let g=c,E="",A=e.state.shoptOptions.extglob;if(g.pattern)for(let S of g.pattern.parts)if(S.type==="Glob")E+=k(S.pattern,g.greedy,A);else if(S.type==="Literal")E+=k(S.value,g.greedy,A);else if(S.type==="SingleQuoted"||S.type==="Escaped")E+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await n(e,S.parts);E+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);E+=k(y,g.greedy,A)}else{let y=await s(e,S);E+=I(y)}d=d.map(S=>se(S,E,g.side,g.greedy))}else if(c?.type==="PatternReplacement"){let g=c,E="";if(g.pattern)for(let y of g.pattern.parts)if(y.type==="Glob")E+=k(y.pattern,!0,e.state.shoptOptions.extglob);else if(y.type==="Literal")E+=k(y.value,!0,e.state.shoptOptions.extglob);else if(y.type==="SingleQuoted"||y.type==="Escaped")E+=I(y.value);else if(y.type==="DoubleQuoted"){let b=await n(e,y.parts);E+=I(b)}else if(y.type==="ParameterExpansion"){let b=await s(e,y);E+=k(b,!0,e.state.shoptOptions.extglob)}else{let b=await s(e,y);E+=I(b)}let A=g.replacement?await n(e,g.replacement.parts):"",S=E;g.anchor==="start"?S=`^${E}`:g.anchor==="end"&&(S=`${E}$`);try{let y=O(S,g.all?"g":"");d=d.map(b=>y.replace(b,A))}catch{}}if(o){let g=N(e.state.env);return{values:[u+d.join(g)+f],quoted:!0}}return d.length===1?{values:[u+d[0]+f],quoted:!0}:{values:[u+d[0],...d.slice(1,-1),d[d.length-1]+f],quoted:!0}}async function Qn(e,t,r,s){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i="",l=!1;for(let d=0;d<n.parts.length;d++){let m=n.parts[d];if(m.type==="ParameterExpansion"&&!m.operation){let g=m.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(g){a=d,i=g[1],l=g[2]==="*";break}}}if(a===-1)return null;let o="";for(let d=0;d<a;d++)o+=await s(e,n.parts[d]);let c="";for(let d=a+1;d<n.parts.length;d++)c+=await s(e,n.parts[d]);let u=P(e,i),f=u.map(([,d])=>d);if(u.length===0){let d=e.state.env.get(i);if(d!==void 0)return{values:[o+d+c],quoted:!0};if(l)return{values:[o+c],quoted:!0};let m=o+c;return{values:m?[m]:[],quoted:!0}}if(l){let d=N(e.state.env);return{values:[o+f.join(d)+c],quoted:!0}}return f.length===1?{values:[o+f[0]+c],quoted:!0}:{values:[o+f[0],...f.slice(1,-1),f[f.length-1]+c],quoted:!0}}async function Zn(e,t,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="Substring")return null;let n=s.parts[0],a=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let i=a[1],l=a[2]==="*",o=n.operation;if(e.state.associativeArrays?.has(i))throw new K(1,"",`bash: \${${i}[@]: 0: 3}: bad substitution
|
|
69
|
+
`);let c=o.offset?await r(e,o.offset.expression):0,u=o.length?await r(e,o.length.expression):void 0,f=P(e,i),h=0;if(c<0){if(f.length>0){let m=f[f.length-1][0],E=(typeof m=="number"?m:0)+1+c;if(E<0)return{values:[],quoted:!0};h=f.findIndex(([A])=>typeof A=="number"&&A>=E),h<0&&(h=f.length)}}else h=f.findIndex(([m])=>typeof m=="number"&&m>=c),h<0&&(h=f.length);let d;if(u!==void 0){if(u<0)throw new C(`${i}[@]: substring expression < 0`);d=f.slice(h,h+u).map(([,m])=>m)}else d=f.slice(h).map(([,m])=>m);if(d.length===0)return{values:[],quoted:!0};if(l){let m=N(e.state.env);return{values:[d.join(m)],quoted:!0}}return{values:d,quoted:!0}}function Un(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Transform")return null;let s=r.parts[0],n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let a=n[1],i=n[2]==="*",l=s.operation,o=P(e,a);if(o.length===0){let f=e.state.env.get(a);if(f!==void 0){let h;switch(l.operator){case"a":h="";break;case"P":h=we(e,f);break;case"Q":h=le(f);break;default:h=f}return{values:[h],quoted:!0}}return i?{values:[""],quoted:!0}:{values:[],quoted:!0}}let c=ue(e,a),u;switch(l.operator){case"a":u=o.map(()=>c);break;case"P":u=o.map(([,f])=>we(e,f));break;case"Q":u=o.map(([,f])=>le(f));break;case"u":u=o.map(([,f])=>f.charAt(0).toUpperCase()+f.slice(1));break;case"U":u=o.map(([,f])=>f.toUpperCase());break;case"L":u=o.map(([,f])=>f.toLowerCase());break;default:u=o.map(([,f])=>f)}if(i){let f=N(e.state.env);return{values:[u.join(f)],quoted:!0}}return{values:u,quoted:!0}}function Hn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion")return null;let s=r.parts[0];if(s.operation)return null;let n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!n)return null;let a=n[1];if(W(e,a)){let o=Se(e,a);if(o?.endsWith("[@]")||o?.endsWith("[*]"))return{values:[],quoted:!0}}let i=P(e,a);if(i.length>0)return{values:i.map(([,o])=>o),quoted:!0};let l=e.state.env.get(a);return l!==void 0?{values:[l],quoted:!0}:{values:[],quoted:!0}}function jn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation)return null;let n=r.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||!W(e,n))return null;let a=Se(e,n);if(!a)return null;let i=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!i)return null;let l=i[1],o=P(e,l);if(o.length>0)return{values:o.map(([,u])=>u),quoted:!0};let c=e.state.env.get(l);return c!==void 0?{values:[c],quoted:!0}:{values:[],quoted:!0}}async function Kn(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],l=i.operation,o=await v(e,i.parameter),c=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c){if(!l.innerOp&&(o==="@"||o==="*")){let m=Number.parseInt(e.state.env.get("#")||"0",10),g=[];for(let E=1;E<=m;E++)g.push(e.state.env.get(String(E))||"");return o==="*"?{values:[g.join(N(e.state.env))],quoted:!0}:{values:g,quoted:!0}}return null}let u=c[1],f=c[2]==="*",h=P(e,u);if(l.innerOp){if(l.innerOp.type==="Substring")return Ns(e,h,u,f,l.innerOp);if(l.innerOp.type==="DefaultValue"||l.innerOp.type==="UseAlternative"||l.innerOp.type==="AssignDefault"||l.innerOp.type==="ErrorIfUnset")return ks(e,h,u,f,l.innerOp,n);if(l.innerOp.type==="Transform"&&l.innerOp.operator==="a"){let g=ue(e,u),E=h.map(()=>g);return f?{values:[E.join(N(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let m=[];for(let[,g]of h){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:l.innerOp},A=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",g);try{let S=await s(e,E,!0);m.push(S)}finally{A!==void 0?e.state.env.set("_indirect_elem_",A):e.state.env.delete("_indirect_elem_")}}return f?{values:[m.join(N(e.state.env))],quoted:!0}:{values:m,quoted:!0}}if(h.length>0){let m=h.map(([,g])=>g);return f?{values:[m.join(N(e.state.env))],quoted:!0}:{values:m,quoted:!0}}let d=e.state.env.get(u);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}async function Ns(e,t,r,s,n){let a=n.offset?await R(e,n.offset.expression):0,i=n.length?await R(e,n.length.expression):void 0,l=0;if(a<0){if(t.length>0){let u=t[t.length-1][0],h=(typeof u=="number"?u:0)+1+a;if(h<0)return{values:[],quoted:!0};if(l=t.findIndex(([d])=>typeof d=="number"&&d>=h),l<0)return{values:[],quoted:!0}}}else if(l=t.findIndex(([u])=>typeof u=="number"&&u>=a),l<0)return{values:[],quoted:!0};let o;if(i!==void 0){if(i<0)throw new C(`${r}[@]: substring expression < 0`);o=t.slice(l,l+i)}else o=t.slice(l);let c=o.map(([,u])=>u);return s?{values:[c.join(N(e.state.env))],quoted:!0}:{values:c,quoted:!0}}async function ks(e,t,r,s,n,a){let i=n.checkEmpty??!1,l=t.map(([,u])=>u),o=t.length===0,c=t.length===0;if(n.type==="UseAlternative")return!c&&!(i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(n.type==="DefaultValue")return(c||i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0};if(n.type==="AssignDefault"){if((c||i&&o)&&n.word){let f=await a(e,n.word.parts,!0);return e.state.env.set(`${r}_0`,f),e.state.env.set(`${r}__length`,"1"),{values:[f],quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}async function Xn(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let r=t[0],s=r.operation,n=s?.word;if(!n||n.parts.length!==1||n.parts[0].type!=="DoubleQuoted")return null;let a=n.parts[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],o=(await v(e,i.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let c=await te(e,r.parameter),u=await v(e,r.parameter)==="",f=s.checkEmpty??!1,h;if(s.type==="UseAlternative"?h=c&&!(f&&u):h=!c||f&&u,h){let d=o[1],m=o[2]==="*",g=P(e,d);if(g.length>0){let A=g.map(([,S])=>S);return m?{values:[A.join(N(e.state.env))],quoted:!0}:{values:A,quoted:!0}}let E=e.state.env.get(d);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function Jn(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let r=t[0],n=r.operation.innerOp;if(!n||n.type!=="UseAlternative"&&n.type!=="DefaultValue")return null;let a=n.word;if(!a||a.parts.length!==1||a.parts[0].type!=="DoubleQuoted")return null;let i=a.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let l=i.parts[0],c=(await v(e,l.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c)return null;let u=await v(e,r.parameter),f=await te(e,r.parameter),h=u==="",d=n.checkEmpty??!1,m;if(n.type==="UseAlternative"?m=f&&!(d&&h):m=!f||d&&h,m){let g=c[1],E=c[2]==="*",A=P(e,g);if(A.length>0){let y=A.map(([,b])=>b);return E?{values:[y.join(N(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let S=e.state.env.get(g);return S!==void 0?{values:[S],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function Yn(e){let t=Number.parseInt(e.state.env.get("#")||"0",10),r=[];for(let s=1;s<=t;s++)r.push(e.state.env.get(String(s))||"");return r}async function er(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let S=0;S<n.parts.length;S++){let y=n.parts[S];if(y.type==="ParameterExpansion"&&(y.parameter==="@"||y.parameter==="*")&&y.operation?.type==="Substring"){a=S,i=y.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,c=o.offset?await r(e,o.offset.expression):0,u=o.length?await r(e,o.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),h=[];for(let S=1;S<=f;S++)h.push(e.state.env.get(String(S))||"");let d=e.state.env.get("0")||"bash",m;if(c<=0){let S=[d,...h],y=S.length+c;if(y<0)m=[];else{let b=c<0?y:0;if(u!==void 0){let D=u<0?S.length+u:b+u;m=S.slice(b,Math.max(b,D))}else m=S.slice(b)}}else{let S=c-1;if(S>=h.length)m=[];else if(u!==void 0){let y=u<0?h.length+u:S+u;m=h.slice(S,Math.max(S,y))}else m=h.slice(S)}let g="";for(let S=0;S<a;S++)g+=await s(e,n.parts[S]);let E="";for(let S=a+1;S<n.parts.length;S++)E+=await s(e,n.parts[S]);if(m.length===0){let S=g+E;return{values:S?[S]:[],quoted:!0}}if(i){let S=N(e.state.env);return{values:[g+m.join(S)+E],quoted:!0}}return m.length===1?{values:[g+m[0]+E],quoted:!0}:{values:[g+m[0],...m.slice(1,-1),m[m.length-1]+E],quoted:!0}}async function tr(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let A=0;A<n.parts.length;A++){let S=n.parts[A];if(S.type==="ParameterExpansion"&&(S.parameter==="@"||S.parameter==="*")&&S.operation?.type==="PatternReplacement"){a=A,i=S.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,c=Yn(e),u="";for(let A=0;A<a;A++)u+=await r(e,n.parts[A]);let f="";for(let A=a+1;A<n.parts.length;A++)f+=await r(e,n.parts[A]);if(c.length===0){let A=u+f;return{values:A?[A]:[],quoted:!0}}let h="";if(o.pattern)for(let A of o.pattern.parts)if(A.type==="Glob")h+=k(A.pattern,!0,e.state.shoptOptions.extglob);else if(A.type==="Literal")h+=k(A.value,!0,e.state.shoptOptions.extglob);else if(A.type==="SingleQuoted"||A.type==="Escaped")h+=I(A.value);else if(A.type==="DoubleQuoted"){let S=await s(e,A.parts);h+=I(S)}else if(A.type==="ParameterExpansion"){let S=await r(e,A);h+=k(S,!0,e.state.shoptOptions.extglob)}else{let S=await r(e,A);h+=I(S)}let d=o.replacement?await s(e,o.replacement.parts):"",m=h;o.anchor==="start"?m=`^${h}`:o.anchor==="end"&&(m=`${h}$`);let g=[];try{let A=O(m,o.all?"g":"");for(let S of c)g.push(A.replace(S,d))}catch{g.push(...c)}if(i){let A=N(e.state.env);return{values:[u+g.join(A)+f],quoted:!0}}return g.length===1?{values:[u+g[0]+f],quoted:!0}:{values:[u+g[0],...g.slice(1,-1),g[g.length-1]+f],quoted:!0}}async function nr(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let E=0;E<n.parts.length;E++){let A=n.parts[E];if(A.type==="ParameterExpansion"&&(A.parameter==="@"||A.parameter==="*")&&A.operation?.type==="PatternRemoval"){a=E,i=A.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,c=Yn(e),u="";for(let E=0;E<a;E++)u+=await r(e,n.parts[E]);let f="";for(let E=a+1;E<n.parts.length;E++)f+=await r(e,n.parts[E]);if(c.length===0){let E=u+f;return{values:E?[E]:[],quoted:!0}}let h="",d=e.state.shoptOptions.extglob;if(o.pattern)for(let E of o.pattern.parts)if(E.type==="Glob")h+=k(E.pattern,o.greedy,d);else if(E.type==="Literal")h+=k(E.value,o.greedy,d);else if(E.type==="SingleQuoted"||E.type==="Escaped")h+=I(E.value);else if(E.type==="DoubleQuoted"){let A=await s(e,E.parts);h+=I(A)}else if(E.type==="ParameterExpansion"){let A=await r(e,E);h+=k(A,o.greedy,d)}else{let A=await r(e,E);h+=I(A)}let m=[];for(let E of c)m.push(se(E,h,o.side,o.greedy));if(i){let E=N(e.state.env);return{values:[u+m.join(E)+f],quoted:!0}}return m.length===1?{values:[u+m[0]+f],quoted:!0}:{values:[u+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function rr(e,t,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],n=-1,a=!1;for(let h=0;h<s.parts.length;h++){let d=s.parts[h];if(d.type==="ParameterExpansion"&&(d.parameter==="@"||d.parameter==="*")){n=h,a=d.parameter==="*";break}}if(n===-1)return null;let i=s.parts[n];if(i.type==="ParameterExpansion"&&i.operation)return null;let l=Number.parseInt(e.state.env.get("#")||"0",10),o="";for(let h=0;h<n;h++)o+=await r(e,s.parts[h]);let c="";for(let h=n+1;h<s.parts.length;h++)c+=await r(e,s.parts[h]);if(l===0){if(a)return{values:[o+c],quoted:!0};let h=o+c;return{values:h?[h]:[],quoted:!0}}let u=[];for(let h=1;h<=l;h++)u.push(e.state.env.get(String(h))||"");if(a){let h=N(e.state.env);return{values:[o+u.join(h)+c],quoted:!0}}return u.length===1?{values:[o+u[0]+c],quoted:!0}:{values:[o+u[0],...u.slice(1,-1),u[u.length-1]+c],quoted:!0}}function Ps(e){return new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations})}async function Te(e,t){if(e.state.options.noglob)return t;let r=Ps(e),s=[];for(let n of t)if(ne(n,e.state.shoptOptions.extglob)){let a=await r.expand(n);if(a.length>0)s.push(...a);else{if(r.hasFailglob())throw new Pe(n);r.hasNullglob()||s.push(n)}}else s.push(n);return s}async function sr(e,t,r,s){let n=-1,a="",i=!1;for(let S=0;S<t.length;S++){let y=t[S];if(y.type==="ParameterExpansion"&&y.operation?.type==="PatternReplacement"){let b=y.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){n=S,a=b[1],i=b[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,c=P(e,a),u=c.map(([,S])=>S);if(c.length===0){let S=e.state.env.get(a);S!==void 0&&(u=[S])}if(u.length===0)return{values:[],quoted:!1};let f="";if(o.pattern)for(let S of o.pattern.parts)if(S.type==="Glob")f+=k(S.pattern,!0,e.state.shoptOptions.extglob);else if(S.type==="Literal")f+=k(S.value,!0,e.state.shoptOptions.extglob);else if(S.type==="SingleQuoted"||S.type==="Escaped")f+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await r(e,S.parts);f+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);f+=k(y,!0,e.state.shoptOptions.extglob)}else{let y=await s(e,S);f+=I(y)}let h=o.replacement?await r(e,o.replacement.parts):"",d=f;o.anchor==="start"?d=`^${f}`:o.anchor==="end"&&(d=`${f}$`);let m=[];try{let S=O(d,o.all?"g":"");for(let y of u)m.push(S.replace(y,h))}catch{m.push(...u)}let g=T(e.state.env),E=q(e.state.env);if(i){let S=N(e.state.env),y=m.join(S);return E?{values:y?[y]:[],quoted:!1}:{values:x(y,g),quoted:!1}}if(E)return{values:m,quoted:!1};let A=[];for(let S of m)S===""?A.push(""):A.push(...x(S,g));return{values:A,quoted:!1}}async function ir(e,t,r,s){let n=-1,a="",i=!1;for(let A=0;A<t.length;A++){let S=t[A];if(S.type==="ParameterExpansion"&&S.operation?.type==="PatternRemoval"){let y=S.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(y){n=A,a=y[1],i=y[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,c=P(e,a),u=c.map(([,A])=>A);if(c.length===0){let A=e.state.env.get(a);A!==void 0&&(u=[A])}if(u.length===0)return{values:[],quoted:!1};let f="",h=e.state.shoptOptions.extglob;if(o.pattern)for(let A of o.pattern.parts)if(A.type==="Glob")f+=k(A.pattern,o.greedy,h);else if(A.type==="Literal")f+=k(A.value,o.greedy,h);else if(A.type==="SingleQuoted"||A.type==="Escaped")f+=I(A.value);else if(A.type==="DoubleQuoted"){let S=await r(e,A.parts);f+=I(S)}else if(A.type==="ParameterExpansion"){let S=await s(e,A);f+=k(S,o.greedy,h)}else{let S=await s(e,A);f+=I(S)}let d=[];for(let A of u)d.push(se(A,f,o.side,o.greedy));let m=T(e.state.env),g=q(e.state.env);if(i){let A=N(e.state.env),S=d.join(A);return g?{values:S?[S]:[],quoted:!1}:{values:x(S,m),quoted:!1}}if(g)return{values:d,quoted:!1};let E=[];for(let A of d)A===""?E.push(""):E.push(...x(A,m));return{values:E,quoted:!1}}async function ar(e,t,r,s){let n=-1,a=!1;for(let E=0;E<t.length;E++){let A=t[E];if(A.type==="ParameterExpansion"&&(A.parameter==="@"||A.parameter==="*")&&A.operation?.type==="PatternRemoval"){n=E,a=A.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let E=1;E<=o;E++)c.push(e.state.env.get(String(E))||"");if(c.length===0)return{values:[],quoted:!1};let u="",f=e.state.shoptOptions.extglob;if(l.pattern)for(let E of l.pattern.parts)if(E.type==="Glob")u+=k(E.pattern,l.greedy,f);else if(E.type==="Literal")u+=k(E.value,l.greedy,f);else if(E.type==="SingleQuoted"||E.type==="Escaped")u+=I(E.value);else if(E.type==="DoubleQuoted"){let A=await r(e,E.parts);u+=I(A)}else if(E.type==="ParameterExpansion"){let A=await s(e,E);u+=k(A,l.greedy,f)}else{let A=await s(e,E);u+=I(A)}let h=[];for(let E of c)h.push(se(E,u,l.side,l.greedy));let d=T(e.state.env),m=q(e.state.env);if(a){let E=N(e.state.env),A=h.join(E);return m?{values:A?[A]:[],quoted:!1}:{values:x(A,d),quoted:!1}}if(m)return{values:h,quoted:!1};let g=[];for(let E of h)E===""?g.push(""):g.push(...x(E,d));return{values:g,quoted:!1}}async function or(e,t,r,s){let n=-1,a=!1;for(let y=0;y<t.length;y++){let b=t[y];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="Substring"){n=y,a=b.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=l.offset?await r(e,l.offset.expression):0,c=l.length?await r(e,l.length.expression):void 0,u=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let y=1;y<=u;y++)f.push(e.state.env.get(String(y))||"");let h=e.state.env.get("0")||"bash",d;if(o<=0){let y=[h,...f],b=y.length+o;if(b<0)d=[];else{let D=o<0?b:0;if(c!==void 0){let Q=c<0?y.length+c:D+c;d=y.slice(D,Math.max(D,Q))}else d=y.slice(D)}}else{let y=o-1;if(y>=f.length)d=[];else if(c!==void 0){let b=c<0?f.length+c:y+c;d=f.slice(y,Math.max(y,b))}else d=f.slice(y)}let m="";for(let y=0;y<n;y++)m+=await s(e,t[y]);let g="";for(let y=n+1;y<t.length;y++)g+=await s(e,t[y]);let E=T(e.state.env),A=q(e.state.env);if(d.length===0){let y=m+g;return y?A?{values:[y],quoted:!1}:{values:x(y,E),quoted:!1}:{values:[],quoted:!1}}let S;if(a){let y=N(e.state.env),b=m+d.join(y)+g;A?S=b?[b]:[]:S=x(b,E)}else if(A)d.length===1?S=[m+d[0]+g]:S=[m+d[0],...d.slice(1,-1),d[d.length-1]+g];else{S=[];for(let y=0;y<d.length;y++){let b=d[y];if(y===0&&(b=m+b),y===d.length-1&&(b=b+g),b==="")S.push("");else{let D=x(b,E);S.push(...D)}}}return{values:await Te(e,S),quoted:!1}}async function lr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let r=t[0].parameter==="*",s=Number.parseInt(e.state.env.get("#")||"0",10);if(s===0)return{values:[],quoted:!1};let n=[];for(let c=1;c<=s;c++)n.push(e.state.env.get(String(c))||"");let a=T(e.state.env),i=q(e.state.env),l=Ce(e.state.env),o;if(r)if(i)o=n.filter(c=>c!=="");else{let c=N(e.state.env),u=n.join(c);o=x(u,a)}else if(i)o=n.filter(c=>c!=="");else if(l){o=[];for(let c of n){if(c==="")continue;let u=x(c,a);o.push(...u)}}else{o=[];for(let c of n)if(c==="")o.push("");else{let u=x(c,a);o.push(...u)}for(;o.length>0&&o[o.length-1]==="";)o.pop()}return{values:await Te(e,o),quoted:!1}}async function ur(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let r=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!r)return null;let s=r[1],n=r[2]==="*",a=P(e,s),i;if(a.length===0){let f=e.state.env.get(s);if(f!==void 0)i=[f];else return{values:[],quoted:!1}}else i=a.map(([,f])=>f);let l=T(e.state.env),o=q(e.state.env),c=Ce(e.state.env),u;if(n)if(o)u=i.filter(f=>f!=="");else{let f=N(e.state.env),h=i.join(f);u=x(h,l)}else if(o)u=i.filter(f=>f!=="");else if(c){u=[];for(let f of i){if(f==="")continue;let h=x(f,l);u.push(...h)}}else{u=[];for(let f of i)if(f==="")u.push("");else{let h=x(f,l);u.push(...h)}for(;u.length>0&&u[u.length-1]==="";)u.pop()}return{values:await Te(e,u),quoted:!1}}function cr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let r=t[0].operation,s=me(e,r.prefix);if(s.length===0)return{values:[],quoted:!1};let n=T(e.state.env),a=q(e.state.env),i;if(r.star)if(a)i=s;else{let l=N(e.state.env),o=s.join(l);i=x(o,n)}else if(a)i=s;else{i=[];for(let l of s){let o=x(l,n);i.push(...o)}}return{values:i,quoted:!1}}function fr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let r=t[0].operation,n=P(e,r.array).map(([o])=>String(o));if(n.length===0)return{values:[],quoted:!1};let a=T(e.state.env),i=q(e.state.env),l;if(r.star)if(i)l=n;else{let o=N(e.state.env),c=n.join(o);l=x(c,a)}else if(i)l=n;else{l=[];for(let o of n){let c=x(o,a);l.push(...c)}}return{values:l,quoted:!1}}async function hr(e,t,r){let s=-1;for(let h=0;h<t.length;h++){let d=t[h];if(d.type==="ParameterExpansion"&&(d.parameter==="@"||d.parameter==="*")&&!d.operation){s=h;break}}if(s===-1||t.length<=1)return null;let n=Number.parseInt(e.state.env.get("#")||"0",10),a=[];for(let h=1;h<=n;h++)a.push(e.state.env.get(String(h))||"");let i="";for(let h=0;h<s;h++)i+=await r(e,t[h]);let l="";for(let h=s+1;h<t.length;h++)l+=await r(e,t[h]);let o=T(e.state.env),c=q(e.state.env),u=Ce(e.state.env);if(n===0){let h=i+l;return{values:h?[h]:[],quoted:!1}}let f;{let h=[];for(let d=0;d<a.length;d++){let m=a[d];d===0&&(m=i+m),d===a.length-1&&(m=m+l),h.push(m)}if(c)f=h.filter(d=>d!=="");else if(u){f=[];for(let d of h){if(d==="")continue;let m=x(d,o);f.push(...m)}}else{f=[];for(let d of h)if(d==="")f.push("");else{let m=x(d,o);f.push(...m)}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Te(e,f),quoted:!1}}async function mr(e,t,r){e.coverage?.hit("bash:expansion:word_glob");let s=t.parts,{hasQuoted:n,hasCommandSub:a,hasArrayVar:i,hasArrayAtExpansion:l,hasParamExpansion:o,hasVarNamePrefixExpansion:c,hasIndirection:u}=Ae(s),h=r.hasBraceExpansion(s)?await r.expandWordWithBracesAsync(e,t):null;if(h&&h.length>1)return Rs(e,h,n);let d=await Is(e,s,l,c,u,r);if(d!==null)return d;let m=await Ds(e,s,r);if(m!==null)return m;let g=await xs(e,s,r);if(g!==null)return g;let E=await $s(e,s,r.expandPart);if(E!==null)return dr(e,E);if((a||i||o)&&!q(e.state.env)){let S=T(e.state.env),y=r.buildIfsCharClassPattern(S),b=await r.smartWordSplit(e,s,S,y,r.expandPart);return dr(e,b)}let A=await r.expandWordAsync(e,t);return Cs(e,t,s,A,n,r.expandWordForGlobbing)}async function Rs(e,t,r){let s=[];for(let n of t)if(!(!r&&n===""))if(!r&&!e.state.options.noglob&&ne(n,e.state.shoptOptions.extglob)){let a=await Me(e,n);s.push(...a)}else s.push(n);return{values:s,quoted:!1}}async function Is(e,t,r,s,n,a){if(r){let i=Hn(e,t);if(i!==null)return i}{let i=jn(e,t);if(i!==null)return i}{let i=await zn(e,t);if(i!==null)return i}{let i=await Gn(e,t,r,a.expandPart,a.expandWordPartsAsync);if(i!==null)return i}{let i=await Qn(e,t,r,a.expandPart);if(i!==null)return i}{let i=await Zn(e,t,a.evaluateArithmetic);if(i!==null)return i}{let i=Un(e,t);if(i!==null)return i}{let i=await Bn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}{let i=await Fn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}if(s&&t.length===1&&t[0].type==="DoubleQuoted"){let i=vs(e,t);if(i!==null)return i}{let i=await Kn(e,t,n,a.expandParameterAsync,a.expandWordPartsAsync);if(i!==null)return i}{let i=await Xn(e,t);if(i!==null)return i}{let i=await Jn(e,t);if(i!==null)return i}return null}function vs(e,t){let r=t[0];if(r.type!=="DoubleQuoted")return null;if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="VarNamePrefix"){let s=r.parts[0].operation,n=me(e,s.prefix);return s.star?{values:[n.join(N(e.state.env))],quoted:!0}:{values:n,quoted:!0}}if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="ArrayKeys"){let s=r.parts[0].operation,a=P(e,s.array).map(([i])=>String(i));return s.star?{values:[a.join(N(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return null}async function Ds(e,t,r){{let s=await er(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await tr(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await nr(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await rr(e,t,r.expandPart);if(s!==null)return s}return null}async function xs(e,t,r){{let s=await sr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await ir(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await ar(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await or(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await lr(e,t);if(s!==null)return s}{let s=await ur(e,t);if(s!==null)return s}{let s=cr(e,t);if(s!==null)return s}{let s=fr(e,t);if(s!==null)return s}{let s=await hr(e,t,r.expandPart);if(s!==null)return s}return null}function pr(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;t<e.parts.length;t++){let r=e.parts[t];if(r.type!=="ParameterExpansion"||r.operation)continue;let s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(s)return{type:"array",name:s[1],atIndex:t,isStar:s[2]==="*"};if(r.parameter==="@"||r.parameter==="*")return{type:"positional",atIndex:t,isStar:r.parameter==="*"}}return null}async function _s(e,t,r,s){let n="";for(let l=0;l<r.atIndex;l++)n+=await s(e,t.parts[l]);let a="";for(let l=r.atIndex+1;l<t.parts.length;l++)a+=await s(e,t.parts[l]);let i;if(r.type==="array"){if(i=P(e,r.name).map(([,o])=>o),i.length===0){let o=e.state.env.get(r.name);o!==void 0&&(i=[o])}}else{let l=Number.parseInt(e.state.env.get("#")||"0",10);i=[];for(let o=1;o<=l;o++)i.push(e.state.env.get(String(o))||"")}if(r.isStar){let l=N(e.state.env),o=i.join(l);return[n+o+a]}if(i.length===0){let l=n+a;return l?[l]:[]}return i.length===1?[n+i[0]+a]:[n+i[0],...i.slice(1,-1),i[i.length-1]+a]}async function $s(e,t,r){if(t.length<2)return null;let s=!1;for(let o of t)if(pr(o)){s=!0;break}if(!s)return null;let n=T(e.state.env),a=q(e.state.env),i=[];for(let o of t){let c=pr(o);if(c&&o.type==="DoubleQuoted"){let u=await _s(e,o,c,r);i.push(u)}else if(o.type==="DoubleQuoted"||o.type==="SingleQuoted"){let u=await r(e,o);i.push([u])}else if(o.type==="Literal")i.push([o.value]);else if(o.type==="ParameterExpansion"){let u=await r(e,o);if(a)i.push(u?[u]:[]);else{let f=x(u,n);i.push(f)}}else{let u=await r(e,o);if(a)i.push(u?[u]:[]);else{let f=x(u,n);i.push(f)}}}let l=[];for(let o of i)if(o.length!==0)if(l.length===0)l.push(...o);else{let c=l.length-1;l[c]=l[c]+o[0];for(let u=1;u<o.length;u++)l.push(o[u])}return l}async function dr(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let r=[];for(let s of t)if(ne(s,e.state.shoptOptions.extglob)){let n=await Me(e,s);r.push(...n)}else r.push(s);return{values:r,quoted:!1}}async function Me(e,t){let r=new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),s=await r.expand(t);if(s.length>0)return s;if(r.hasFailglob())throw new Pe(t);return r.hasNullglob()?[]:[t]}async function Cs(e,t,r,s,n,a){let i=r.some(l=>l.type==="Glob");if(!e.state.options.noglob&&i){let l=await a(e,t);if(ne(l,e.state.shoptOptions.extglob)){let c=await Me(e,l);if(c.length>0&&c[0]!==l)return{values:c,quoted:!1};if(c.length===0)return{values:[],quoted:!1}}let o=St(s);if(!q(e.state.env)){let c=T(e.state.env);return{values:x(o,c),quoted:!1}}return{values:[o],quoted:!1}}if(!n&&!e.state.options.noglob&&ne(s,e.state.shoptOptions.extglob)){let l=await a(e,t);if(ne(l,e.state.shoptOptions.extglob)){let o=await Me(e,l);if(o.length>0&&o[0]!==l)return{values:o,quoted:!1}}}if(s===""&&!n)return{values:[],quoted:!1};if(i&&!n){let l=St(s);if(!q(e.state.env)){let o=T(e.state.env);return{values:x(l,o),quoted:!1}}return{values:[l],quoted:!1}}return{values:[s],quoted:n}}async function yr(e,t){let r=t.operation;if(!r||r.type!=="DefaultValue"&&r.type!=="AssignDefault"&&r.type!=="UseAlternative")return null;let s=r.word;if(!s||s.parts.length===0)return null;let n=await te(e,t.parameter),i=await v(e,t.parameter,!1)==="",l=r.checkEmpty??!1,o;return r.type==="UseAlternative"?o=n&&!(l&&i):o=!n||l&&i,o?s.parts:null}function Os(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(r=>r.type==="Literal"):!1}async function Ls(e,t){if(t.type!=="ParameterExpansion")return null;let r=await yr(e,t);if(!r||r.length<=1)return null;let s=r.some(a=>Os(a)),n=r.some(a=>a.type==="Literal"||a.type==="ParameterExpansion"||a.type==="CommandSubstitution"||a.type==="ArithmeticExpansion");return s&&n?r:null}function Ws(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?dt(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&gn(e))}async function Er(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let h=t[0],d=await yr(e,h);if(d&&d.length>0&&d.length>1&&d.some(g=>g.type==="DoubleQuoted"||g.type==="SingleQuoted")&&d.some(g=>g.type==="Literal"||g.type==="ParameterExpansion"||g.type==="CommandSubstitution"||g.type==="ArithmeticExpansion"))return gr(e,d,r,s,n)}let a=[],i=!1;for(let h of t){let d=Ws(h),m=h.type==="DoubleQuoted"||h.type==="SingleQuoted",g=d?await Ls(e,h):null,E=await n(e,h);a.push({value:E,isSplittable:d,isQuoted:m,mixedDefaultParts:g??void 0}),d&&(i=!0)}if(!i){let h=a.map(d=>d.value).join("");return h?[h]:[]}let l=[],o="",c=!1,u=!1,f=!1;for(let h of a)if(!h.isSplittable)u?h.isQuoted&&h.value===""?(o!==""&&l.push(o),l.push(""),c=!0,o="",u=!1,f=!0):h.value!==""?(o!==""&&l.push(o),o=h.value,u=!1,f=!1):(o+=h.value,f=!1):(o+=h.value,f=h.isQuoted&&h.value==="");else if(h.mixedDefaultParts){let d=await gr(e,h.mixedDefaultParts,r,s,n);if(d.length!==0)if(d.length===1)o+=d[0],c=!0;else{o+=d[0],l.push(o),c=!0;for(let m=1;m<d.length-1;m++)l.push(d[m]);o=d[d.length-1]}u=!1,f=!1}else{let{words:d,hadLeadingDelimiter:m,hadTrailingDelimiter:g}=Oe(h.value,r);if(f&&m&&o===""&&(l.push(""),c=!0),d.length===0)g&&(u=!0);else if(d.length===1)o+=d[0],c=!0,u=g;else{o+=d[0],l.push(o),c=!0;for(let E=1;E<d.length-1;E++)l.push(d[E]);o=d[d.length-1],u=g}f=!1}return o!==""?l.push(o):l.length===0&&c&&l.push(""),l}function Ts(e,t){return e.length>0&&t.includes(e[0])}async function gr(e,t,r,s,n){let a=[];for(let u of t){let h=!(u.type==="DoubleQuoted"||u.type==="SingleQuoted"),d=await n(e,u);a.push({value:d,isSplittable:h})}let i=[],l="",o=!1,c=!1;for(let u of a)if(!u.isSplittable)c&&u.value!==""?(l!==""&&i.push(l),l=u.value,c=!1):l+=u.value;else{Ts(u.value,r)&&l!==""&&(i.push(l),l="",o=!0);let{words:h,hadTrailingDelimiter:d}=Oe(u.value,r);if(h.length===0)d&&(c=!0);else if(h.length===1)l+=h[0],o=!0,c=d;else{l+=h[0],i.push(l),o=!0;for(let m=1;m<h.length-1;m++)i.push(h[m]);l=h[h.length-1],c=d}}return l!==""?i.push(l):i.length===0&&o&&i.push(""),i}function Ar(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Sr(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}function ce(e,t,r){if(e.length>t)throw new L(`${r}: string length limit exceeded (${t} bytes)`,"string_length")}async function J(e,t,r=!1){let s=[];for(let n of t)s.push(await U(e,n,r));return s.join("")}function Ms(e){return Sr(e)}function Al(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!Ms(t))return!1;return!0}function Vs(e,t,r=!1){let s=Ar(t);if(s!==null)return s;switch(t.type){case"TildeExpansion":return r?t.user===null?"~":`~${t.user}`:(e.coverage?.hit("bash:expansion:tilde"),t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`);case"Glob":return Nt(e,t.pattern);default:return null}}async function Pt(e,t){return Rt(e,t)}async function Sl(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped")r.push(`\\${s.value}`);else if(s.type==="SingleQuoted")r.push(s.value);else if(s.type==="DoubleQuoted"){let n=await J(e,s.parts);r.push(n)}else if(s.type==="TildeExpansion"){let n=await U(e,s);r.push(bt(n))}else r.push(await U(e,s));return r.join("")}async function bl(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped"){let n=s.value;"()|*?[]".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="SingleQuoted")r.push(X(s.value));else if(s.type==="DoubleQuoted"){let n=await J(e,s.parts);r.push(X(n))}else r.push(await U(e,s));return r.join("")}async function br(e,t){let r=[];for(let s of t.parts)if(s.type==="SingleQuoted")r.push(X(s.value));else if(s.type==="Escaped"){let n=s.value;"*?[]\\()|".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="DoubleQuoted"){let n=await J(e,s.parts);r.push(X(n))}else s.type==="Glob"?Tn(s.pattern)?r.push(await Vn(e,s.pattern)):r.push(Nt(e,s.pattern)):s.type==="Literal"?r.push(s.value):r.push(await U(e,s));return r.join("")}function qe(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&qe(t.parts))return!0;return!1}var kt=1e5;async function wr(e,t,r={count:0}){if(r.count>kt)return[[]];let s=[[]];for(let n of t)if(n.type==="BraceExpansion"){let a=[],i=!1,l="";for(let u of n.items)if(u.type==="Range"){let f=At(u.start,u.end,u.step,u.startStr,u.endStr);if(f.expanded)for(let h of f.expanded)r.count++,a.push(h);else{i=!0,l=f.literal;break}}else{let f=await wr(e,u.word.parts,r);for(let h of f){r.count++;let d=[];for(let m of h)typeof m=="string"?d.push(m):d.push(await U(e,m));a.push(d.join(""))}}if(i){for(let u of s)r.count++,u.push(l);continue}if(s.length*a.length>e.limits.maxBraceExpansionResults||r.count>kt)return s;let c=[];for(let u of s)for(let f of a){if(r.count++,r.count>kt)return c.length>0?c:s;c.push([...u,f])}s=c}else for(let a of s)r.count++,a.push(n);return s}async function Nr(e,t){let r=t.parts;if(!qe(r))return[await Pt(e,t)];let s=await wr(e,r),n=[];for(let a of s){let i=[];for(let l of a)typeof l=="string"?i.push(l):i.push(await U(e,l));n.push(qn(e,i.join("")))}return n}function qs(){return{expandWordAsync:Rt,expandWordForGlobbing:br,expandWordWithBracesAsync:Nr,expandWordPartsAsync:J,expandPart:U,expandParameterAsync:Ve,hasBraceExpansion:qe,evaluateArithmetic:R,buildIfsCharClassPattern:An,smartWordSplit:Er}}async function wl(e,t){return mr(e,t,qs())}function Bs(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Fs(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function s(n){for(let a of n)if(a.type==="DoubleQuoted"){for(let i of a.parts)if(i.type==="ParameterExpansion"&&i.parameter==="@"&&!i.operation)return!0}return!1}return s(t.parts)}async function Nl(e,t){if(Fs(e,t))return{error:`bash: $@: ambiguous redirect
|
|
70
|
+
`};let r=t.parts,{hasQuoted:s}=Ae(r);if(qe(r)&&(await Nr(e,t)).length>1)return{error:`bash: ${r.map(d=>d.type==="Literal"?d.value:d.type==="BraceExpansion"?`{${d.items.map(g=>{if(g.type==="Range"){let E=g.step?`..${g.step}`:"";return`${g.startStr??g.start}..${g.endStr??g.end}${E}`}return g.word.parts.map(E=>E.type==="Literal"?E.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect
|
|
71
|
+
`};let n=await Rt(e,t),{hasParamExpansion:a,hasCommandSub:i}=Ae(r);if((a||i)&&!s&&!q(e.state.env)){let f=T(e.state.env);if(x(n,f).length>1)return{error:`bash: $${Bs(r)}: ambiguous redirect
|
|
72
|
+
`}}if(s||e.state.options.noglob)return{target:n};let o=await br(e,t);if(!ne(o,e.state.shoptOptions.extglob))return{target:n};let c=new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),u=await c.expand(o);return u.length===0?c.hasFailglob()?{error:`bash: no match: ${n}
|
|
73
73
|
`}:{target:n}:u.length===1?{target:u[0]}:{error:`bash: ${n}: ambiguous redirect
|
|
74
|
-
`}}async function
|
|
74
|
+
`}}async function Rt(e,t){let r=t.parts,s=r.length;if(s===1){let i=await U(e,r[0]);return ce(i,e.limits.maxStringLength,"word expansion"),i}let n=[];for(let i=0;i<s;i++)n.push(await U(e,r[i]));let a=n.join("");return ce(a,e.limits.maxStringLength,"word expansion"),a}async function U(e,t,r=!1){if(t.type==="ParameterExpansion")return Ve(e,t,r);let s=Vs(e,t,r);if(s!==null)return s;switch(t.type){case"DoubleQuoted":{let n=[];for(let a of t.parts)n.push(await U(e,a,!0));return n.join("")}case"CommandSubstitution":{let n=wn(t.body);if(n)try{let h=await Pt(e,n.target),d=h.startsWith("/")?h:`${e.state.cwd}/${h}`,m=await e.fs.readFile(d);e.state.lastExitCode=0,e.state.env.set("?","0");let g=m.replace(/\n+$/,"");return ce(g,e.limits.maxStringLength,"command substitution"),g}catch(h){if(h instanceof L)throw h;return e.state.lastExitCode=1,e.state.env.set("?","1"),""}let a=e.substitutionDepth??0,i=e.limits.maxSubstitutionDepth;if(a>=i)throw new L(`Command substitution nesting limit exceeded (${i})`,"substitution_depth");let l=e.substitutionDepth;e.substitutionDepth=a+1;let o=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let c=new Map(e.state.env),u=e.state.cwd,f=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let h=await e.executeScript(t.body),d=h.exitCode;e.state.env=c,e.state.cwd=u,e.state.suppressVerbose=f,e.state.lastExitCode=d,e.state.env.set("?",String(d)),h.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+h.stderr),e.state.bashPid=o,e.substitutionDepth=l;let m=h.stdout.replace(/\n+$/,"");return ce(m,e.limits.maxStringLength,"command substitution"),m}catch(h){if(e.state.env=c,e.state.cwd=u,e.state.bashPid=o,e.substitutionDepth=l,e.state.suppressVerbose=f,h instanceof L)throw h;if(h instanceof K){e.state.lastExitCode=h.exitCode,e.state.env.set("?",String(h.exitCode)),h.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+h.stderr);let d=h.stdout.replace(/\n+$/,"");return ce(d,e.limits.maxStringLength,"command substitution"),d}throw h}}case"ArithmeticExpansion":{let n=t.expression.originalText;if(n&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(n)){let i=await bn(e,n),l=new V,o=M(l,i);return String(await R(e,o.expression,!0))}return String(await R(e,t.expression.expression,!0))}case"BraceExpansion":{let n=[];for(let a of t.items)if(a.type==="Range"){let i=At(a.start,a.end,a.step,a.startStr,a.endStr);if(i.expanded)n.push(...i.expanded);else return i.literal}else n.push(await Pt(e,a.word));return n.join(" ")}default:return""}}async function Ve(e,t,r=!1){let{parameter:s}=t,{operation:n}=t,a=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let[,h,d]=a;if(e.state.associativeArrays?.has(h)||d.includes("$(")||d.includes("`")||d.includes("${")){let g=await Et(e,d);s=`${h}[${g}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&W(e,s)){let h=he(e,s);if(h&&h!==s){let d=h.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(d){let[,m,g]=d;if(e.state.associativeArrays?.has(m)||g.includes("$(")||g.includes("`")||g.includes("${")){let A=await Et(e,g);s=`${m}[${A}]`}}}}let i=n&&(n.type==="DefaultValue"||n.type==="AssignDefault"||n.type==="UseAlternative"||n.type==="ErrorIfUnset"),l=await v(e,s,!i);if(!n)return l;let o=!await te(e,s),{isEmpty:c,effectiveValue:u}=Wn(e,s,l,r),f={value:l,isUnset:o,isEmpty:c,effectiveValue:u,inDoubleQuotes:r};switch(n.type){case"DefaultValue":return Nn(e,n,f,J);case"AssignDefault":return kn(e,s,n,f,J);case"ErrorIfUnset":return Pn(e,s,n,f,J);case"UseAlternative":return Rn(e,n,f,J);case"PatternRemoval":{let h=await In(e,l,n,J,U);return ce(h,e.limits.maxStringLength,"pattern removal"),h}case"PatternReplacement":{let h=await vn(e,l,n,J,U);return ce(h,e.limits.maxStringLength,"pattern replacement"),h}case"Length":return Dn(e,s,l);case"LengthSliceError":throw new re(s);case"BadSubstitution":throw new re(n.text);case"Substring":return xn(e,s,l,n);case"CaseModification":{let h=await _n(e,l,n,J,Ve);return ce(h,e.limits.maxStringLength,"case modification"),h}case"Transform":return $n(e,s,l,o,n);case"Indirection":return Cn(e,s,l,o,n,Ve,r);case"ArrayKeys":return On(e,n);case"VarNamePrefix":return Ln(e,n);default:return l}}export{xi as a,_i as b,pe as c,G as d,M as e,V as f,di as g,mt as h,Ci as i,gt as j,Oi as k,En as l,T as m,Wi as n,Ti as o,W as p,Vi as q,qi as r,Bi as s,Fi as t,us as u,he as v,Se as w,zi as x,P as y,be as z,v as A,X as B,bt as C,pa as D,wt as E,da as F,ma as G,ga as H,Al as I,Pt as J,Sl as K,bl as L,wl as M,Fs as N,Nl as O,R as P};
|