just-bash 2.5.5 → 2.6.0
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/README.md +2 -2
- package/dist/AGENTS.md +2 -2
- package/dist/ast/types.d.ts +100 -11
- package/dist/bin/chunks/alias-EGIS5LUE.js +7 -0
- package/dist/bin/chunks/awk2-GFEJOWML.js +21 -0
- package/dist/bin/chunks/bash-PGDTHIM2.js +6 -0
- package/dist/bin/chunks/chmod-TYLTHXFR.js +9 -0
- package/dist/bin/chunks/chunk-D5WP4CKS.js +3 -0
- package/dist/bin/chunks/chunk-FSAGDARS.js +74 -0
- package/dist/bin/chunks/chunk-FSZWFMB4.js +16 -0
- package/dist/bin/chunks/chunk-IRUD2E3M.js +17 -0
- package/dist/bin/chunks/chunk-K5IXNHO5.js +8 -0
- package/dist/bin/chunks/chunk-KD3EODLB.js +6 -0
- package/dist/bin/{shell/chunks/echo-WSKTON6U.js → chunks/echo-7I42V66Q.js} +2 -2
- package/dist/bin/chunks/env-7A4MH7BJ.js +9 -0
- package/dist/bin/chunks/expansion-BOR3ELLC.js +2 -0
- package/dist/bin/{shell/chunks/find-CBEJ35BR.js → chunks/find-PHDZK64M.js} +1 -1
- package/dist/bin/{shell/chunks/grep-IIVQXFNI.js → chunks/grep-VX7MJMVN.js} +2 -2
- package/dist/bin/chunks/{head-DYK37Z24.js → head-TJHLLIMR.js} +1 -1
- package/dist/bin/{shell/chunks/jq-XXZPU5CA.js → chunks/jq-RGZHJNXC.js} +1 -1
- package/dist/bin/chunks/od-KRKGC2U3.js +5 -0
- package/dist/bin/chunks/printf-YPXD4CRE.js +15 -0
- package/dist/bin/chunks/pwd-L26WH2K4.js +3 -0
- package/dist/bin/{shell/chunks/rg-Q4OTJOEF.js → chunks/rg-RSDLLECO.js} +1 -1
- package/dist/bin/chunks/rmdir-GOODLY5W.js +14 -0
- package/dist/bin/chunks/sed-JPDTWF4W.js +100 -0
- package/dist/bin/{shell/chunks/tail-BES27CZT.js → chunks/tail-YAUIERGN.js} +1 -1
- package/dist/bin/{shell/chunks/tar-C27YYUAS.js → chunks/tar-LFENC54A.js} +7 -7
- package/dist/bin/chunks/time-37F5EBPK.js +14 -0
- package/dist/bin/chunks/touch-IBPHJBM3.js +7 -0
- package/dist/bin/chunks/wc-SAOHEZYP.js +6 -0
- package/dist/bin/chunks/{which-73KOOLC6.js → which-FCDFBOMN.js} +1 -1
- package/dist/bin/chunks/whoami-JVLUNKSG.js +3 -0
- package/dist/bin/{shell/chunks/xan-6K2NGTHM.js → chunks/xan-5HNHTFMB.js} +19 -19
- package/dist/bin/chunks/{yq-MF2SNFGL.js → yq-PFV4T2PV.js} +1 -1
- package/dist/bin/just-bash.js +659 -135
- package/dist/bin/shell/chunks/alias-EGIS5LUE.js +7 -0
- package/dist/bin/shell/chunks/awk2-GFEJOWML.js +21 -0
- package/dist/bin/shell/chunks/bash-PGDTHIM2.js +6 -0
- package/dist/bin/shell/chunks/chmod-TYLTHXFR.js +9 -0
- package/dist/bin/shell/chunks/chunk-D5WP4CKS.js +3 -0
- package/dist/bin/shell/chunks/chunk-FSAGDARS.js +74 -0
- package/dist/bin/shell/chunks/chunk-FSZWFMB4.js +16 -0
- package/dist/bin/shell/chunks/chunk-IRUD2E3M.js +17 -0
- package/dist/bin/shell/chunks/chunk-K5IXNHO5.js +8 -0
- package/dist/bin/shell/chunks/chunk-KD3EODLB.js +6 -0
- package/dist/bin/{chunks/echo-WSKTON6U.js → shell/chunks/echo-7I42V66Q.js} +2 -2
- package/dist/bin/shell/chunks/env-7A4MH7BJ.js +9 -0
- package/dist/bin/shell/chunks/expansion-BOR3ELLC.js +2 -0
- package/dist/bin/{chunks/find-CBEJ35BR.js → shell/chunks/find-PHDZK64M.js} +1 -1
- package/dist/bin/{chunks/grep-IIVQXFNI.js → shell/chunks/grep-VX7MJMVN.js} +2 -2
- package/dist/bin/shell/chunks/{head-DYK37Z24.js → head-TJHLLIMR.js} +1 -1
- package/dist/bin/{chunks/jq-XXZPU5CA.js → shell/chunks/jq-RGZHJNXC.js} +1 -1
- package/dist/bin/shell/chunks/od-KRKGC2U3.js +5 -0
- package/dist/bin/shell/chunks/printf-YPXD4CRE.js +15 -0
- package/dist/bin/shell/chunks/pwd-L26WH2K4.js +3 -0
- package/dist/bin/{chunks/rg-Q4OTJOEF.js → shell/chunks/rg-RSDLLECO.js} +1 -1
- package/dist/bin/shell/chunks/rmdir-GOODLY5W.js +14 -0
- package/dist/bin/shell/chunks/sed-JPDTWF4W.js +100 -0
- package/dist/bin/{chunks/tail-BES27CZT.js → shell/chunks/tail-YAUIERGN.js} +1 -1
- package/dist/bin/{chunks/tar-C27YYUAS.js → shell/chunks/tar-LFENC54A.js} +7 -7
- package/dist/bin/shell/chunks/time-37F5EBPK.js +14 -0
- package/dist/bin/shell/chunks/touch-IBPHJBM3.js +7 -0
- package/dist/bin/shell/chunks/wc-SAOHEZYP.js +6 -0
- package/dist/bin/shell/chunks/{which-73KOOLC6.js → which-FCDFBOMN.js} +1 -1
- package/dist/bin/shell/chunks/whoami-JVLUNKSG.js +3 -0
- package/dist/bin/{chunks/xan-6K2NGTHM.js → shell/chunks/xan-5HNHTFMB.js} +19 -19
- package/dist/bin/shell/chunks/{yq-MF2SNFGL.js → yq-PFV4T2PV.js} +1 -1
- package/dist/bin/shell/shell.js +664 -140
- package/dist/bundle/browser.js +1251 -606
- package/dist/bundle/chunks/alias-ATFBB6D2.js +6 -0
- package/dist/bundle/chunks/awk2-6FBZTP57.js +20 -0
- package/dist/bundle/chunks/bash-OLRNM52U.js +5 -0
- package/dist/bundle/chunks/chmod-ODWUR7E6.js +8 -0
- package/dist/bundle/chunks/chunk-3AWP5CWK.js +73 -0
- package/dist/bundle/chunks/chunk-CXEWLFNE.js +16 -0
- package/dist/bundle/chunks/chunk-CZPA5RBA.js +5 -0
- package/dist/bundle/chunks/chunk-EEXR5ZDP.js +2 -0
- package/dist/bundle/chunks/chunk-HDQ56CKY.js +15 -0
- package/dist/bundle/chunks/chunk-PSW6BMXW.js +7 -0
- package/dist/bundle/chunks/{echo-VUHWYV6L.js → echo-6S7WE7XB.js} +2 -2
- package/dist/bundle/chunks/env-2UI6XINU.js +8 -0
- package/dist/bundle/chunks/expansion-RIGCFEMA.js +1 -0
- package/dist/bundle/chunks/{find-ACOAWALE.js → find-YGMSVGUV.js} +1 -1
- package/dist/bundle/chunks/{grep-ACVE42JK.js → grep-NIC6JNLH.js} +2 -2
- package/dist/bundle/chunks/{head-FZ6IQHYW.js → head-SA7P5NJ7.js} +1 -1
- package/dist/bundle/chunks/{jq-3YU5HRKE.js → jq-RLRYRPOJ.js} +1 -1
- package/dist/bundle/chunks/od-3FPDPLWJ.js +4 -0
- package/dist/bundle/chunks/printf-66XGXFCD.js +14 -0
- package/dist/bundle/chunks/pwd-S4NVAMC4.js +2 -0
- package/dist/bundle/chunks/{rg-YLZJWCEJ.js → rg-SRMB7L6G.js} +1 -1
- package/dist/bundle/chunks/rmdir-XFQE4ZYV.js +13 -0
- package/dist/bundle/chunks/sed-IV6HLDXU.js +99 -0
- package/dist/bundle/chunks/{tail-PD4RZR6J.js → tail-52LRAWXT.js} +1 -1
- package/dist/bundle/chunks/{tar-QWBXMF7K.js → tar-LWIHPMT6.js} +7 -7
- package/dist/bundle/chunks/time-UWXBG6CS.js +13 -0
- package/dist/bundle/chunks/touch-TDTEBHHI.js +6 -0
- package/dist/bundle/chunks/wc-HE5XARI4.js +5 -0
- package/dist/bundle/chunks/{which-M5MQ6QXQ.js → which-UBLRBDHN.js} +1 -1
- package/dist/bundle/chunks/whoami-YUDAIS32.js +2 -0
- package/dist/bundle/chunks/{xan-2R2APJJ4.js → xan-A6VPI4HJ.js} +19 -19
- package/dist/bundle/chunks/{yq-KANM4MD2.js → yq-L665QPQU.js} +1 -1
- package/dist/bundle/index.js +657 -133
- package/dist/commands/awk/ast.d.ts +1 -0
- package/dist/commands/awk/interpreter/context.d.ts +14 -0
- package/dist/commands/awk/interpreter/interpreter.d.ts +2 -0
- package/dist/commands/awk/interpreter/{helpers.d.ts → type-coercion.d.ts} +4 -1
- package/dist/commands/awk/parser2-print.d.ts +35 -0
- package/dist/commands/awk/parser2.d.ts +42 -34
- package/dist/commands/printf/strftime.d.ts +9 -0
- package/dist/commands/query-engine/builtins/array-builtins.d.ts +20 -0
- package/dist/commands/query-engine/builtins/control-builtins.d.ts +18 -0
- package/dist/commands/query-engine/builtins/date-builtins.d.ts +15 -0
- package/dist/commands/query-engine/builtins/format-builtins.d.ts +11 -0
- package/dist/commands/query-engine/builtins/index-builtins.d.ts +16 -0
- package/dist/commands/query-engine/builtins/index.d.ts +17 -0
- package/dist/commands/query-engine/builtins/math-builtins.d.ts +15 -0
- package/dist/commands/query-engine/builtins/navigation-builtins.d.ts +18 -0
- package/dist/commands/query-engine/builtins/object-builtins.d.ts +15 -0
- package/dist/commands/query-engine/builtins/path-builtins.d.ts +20 -0
- package/dist/commands/query-engine/builtins/sql-builtins.d.ts +16 -0
- package/dist/commands/query-engine/builtins/string-builtins.d.ts +15 -0
- package/dist/commands/query-engine/builtins/type-builtins.d.ts +11 -0
- package/dist/commands/query-engine/evaluator.d.ts +10 -2
- package/dist/commands/query-engine/parser-types.d.ts +171 -0
- package/dist/commands/query-engine/parser.d.ts +2 -132
- package/dist/commands/query-engine/path-operations.d.ts +15 -0
- package/dist/commands/query-engine/value-operations.d.ts +39 -0
- package/dist/commands/registry.d.ts +1 -1
- package/dist/commands/rmdir/rmdir.d.ts +2 -0
- package/dist/commands/sed/lexer.d.ts +12 -0
- package/dist/commands/sed/parser.d.ts +9 -0
- package/dist/commands/sed/sed-regex.d.ts +23 -0
- package/dist/commands/sed/types.d.ts +13 -1
- package/dist/commands/tar/tar-options.d.ts +36 -0
- package/dist/commands/time/time.d.ts +25 -0
- package/dist/commands/whoami/whoami.d.ts +9 -0
- package/dist/commands/xan/moonblade-tokenizer.d.ts +25 -0
- package/dist/fs/in-memory-fs/in-memory-fs.d.ts +12 -0
- package/dist/fs/interface.d.ts +16 -0
- package/dist/fs/mountable-fs/mountable-fs.d.ts +12 -0
- package/dist/fs/overlay-fs/overlay-fs.d.ts +13 -1
- package/dist/fs/read-write-fs/read-write-fs.d.ts +13 -1
- package/dist/interpreter/alias-expansion.d.ts +23 -0
- package/dist/interpreter/arithmetic.d.ts +1 -6
- package/dist/interpreter/assignment-expansion.d.ts +24 -0
- package/dist/interpreter/builtin-dispatch.d.ts +39 -0
- package/dist/interpreter/builtins/compgen.d.ts +26 -0
- package/dist/interpreter/builtins/complete.d.ts +17 -0
- package/dist/interpreter/builtins/compopt.d.ts +28 -0
- package/dist/interpreter/builtins/declare-array-parsing.d.ts +14 -0
- package/dist/interpreter/builtins/declare-print.d.ts +39 -0
- package/dist/interpreter/builtins/declare.d.ts +10 -4
- package/dist/interpreter/builtins/dirs.d.ts +29 -0
- package/dist/interpreter/builtins/eval.d.ts +1 -1
- package/dist/interpreter/builtins/export.d.ts +1 -0
- package/dist/interpreter/builtins/getopts.d.ts +18 -0
- package/dist/interpreter/builtins/hash.d.ts +19 -0
- package/dist/interpreter/builtins/help.d.ts +12 -0
- package/dist/interpreter/builtins/index.d.ts +9 -1
- package/dist/interpreter/builtins/local.d.ts +1 -1
- package/dist/interpreter/builtins/read.d.ts +1 -1
- package/dist/interpreter/builtins/set.d.ts +3 -0
- package/dist/interpreter/builtins/shift.d.ts +3 -0
- package/dist/interpreter/builtins/shopt.d.ts +7 -0
- package/dist/interpreter/builtins/unset.d.ts +5 -1
- package/dist/interpreter/builtins/variable-assignment.d.ts +66 -0
- package/dist/interpreter/command-resolution.d.ts +43 -0
- package/dist/interpreter/conditionals.d.ts +1 -1
- package/dist/interpreter/errors.d.ts +36 -1
- package/dist/interpreter/expansion/analysis.d.ts +15 -17
- package/dist/interpreter/expansion/arith-text-expansion.d.ts +20 -0
- package/dist/interpreter/expansion/array-pattern-ops.d.ts +21 -0
- package/dist/interpreter/expansion/array-prefix-suffix.d.ts +46 -0
- package/dist/interpreter/expansion/array-slice-transform.d.ts +36 -0
- package/dist/interpreter/expansion/array-word-expansion.d.ts +39 -0
- package/dist/interpreter/expansion/command-substitution.d.ts +23 -0
- package/dist/interpreter/expansion/glob-escape.d.ts +32 -0
- package/dist/interpreter/expansion/indirect-expansion.d.ts +42 -0
- package/dist/interpreter/expansion/parameter-ops.d.ts +113 -0
- package/dist/interpreter/expansion/pattern-expansion.d.ts +23 -0
- package/dist/interpreter/expansion/pattern-removal.d.ts +18 -0
- package/dist/interpreter/expansion/pattern.d.ts +2 -1
- package/dist/interpreter/expansion/positional-params.d.ts +59 -0
- package/dist/interpreter/expansion/prompt.d.ts +39 -0
- package/dist/interpreter/expansion/quoting.d.ts +13 -0
- package/dist/interpreter/expansion/tilde.d.ts +12 -0
- package/dist/interpreter/expansion/unquoted-expansion.d.ts +76 -0
- package/dist/interpreter/expansion/variable-attrs.d.ts +19 -0
- package/dist/interpreter/expansion/variable.d.ts +10 -1
- package/dist/interpreter/expansion/word-glob-expansion.d.ts +33 -0
- package/dist/interpreter/expansion/word-split.d.ts +11 -6
- package/dist/interpreter/expansion.d.ts +30 -4
- package/dist/interpreter/functions.d.ts +1 -1
- package/dist/interpreter/helpers/array.d.ts +20 -0
- package/dist/interpreter/helpers/ifs.d.ts +66 -5
- package/dist/interpreter/helpers/nameref.d.ts +65 -0
- package/dist/interpreter/helpers/quoting.d.ts +24 -0
- package/dist/interpreter/helpers/readonly.d.ts +28 -4
- package/dist/interpreter/helpers/shell-constants.d.ts +25 -0
- package/dist/interpreter/helpers/shellopts.d.ts +28 -0
- package/dist/interpreter/helpers/string-compare.d.ts +3 -1
- package/dist/interpreter/helpers/tilde.d.ts +13 -0
- package/dist/interpreter/helpers/variable-tests.d.ts +1 -1
- package/dist/interpreter/helpers/word-matching.d.ts +26 -0
- package/dist/interpreter/helpers/xtrace.d.ts +18 -0
- package/dist/interpreter/interpreter.d.ts +13 -14
- package/dist/interpreter/pipeline-execution.d.ts +16 -0
- package/dist/interpreter/redirections.d.ts +38 -1
- package/dist/interpreter/simple-command-assignments.d.ts +29 -0
- package/dist/interpreter/subshell-group.d.ts +32 -0
- package/dist/interpreter/type-command.d.ts +37 -0
- package/dist/interpreter/types.d.ts +255 -21
- package/dist/parser/arithmetic-parser.d.ts +2 -4
- package/dist/parser/arithmetic-primaries.d.ts +45 -0
- package/dist/parser/compound-parser.d.ts +21 -7
- package/dist/parser/expansion-parser.d.ts +7 -1
- package/dist/parser/lexer.d.ts +57 -0
- package/dist/parser/parser-substitution.d.ts +62 -0
- package/dist/parser/parser.d.ts +39 -2
- package/dist/parser/types.d.ts +1 -0
- package/dist/types.d.ts +17 -0
- package/package.json +4 -1
- package/dist/bin/chunks/alias-PCMLRCRW.js +0 -7
- package/dist/bin/chunks/awk2-D2US2LMM.js +0 -20
- package/dist/bin/chunks/bash-UT3MT5UU.js +0 -7
- package/dist/bin/chunks/chmod-3DIKREF7.js +0 -9
- package/dist/bin/chunks/chunk-ACRTDIBO.js +0 -6
- package/dist/bin/chunks/chunk-DV5HL4K2.js +0 -17
- package/dist/bin/chunks/chunk-J7BCMQDI.js +0 -16
- package/dist/bin/chunks/chunk-NWWB2XRE.js +0 -6
- package/dist/bin/chunks/chunk-PM2DS2YW.js +0 -3
- package/dist/bin/chunks/env-YLLSNZZN.js +0 -9
- package/dist/bin/chunks/od-SLM7SRWU.js +0 -7
- package/dist/bin/chunks/printf-HWUQKYUM.js +0 -14
- package/dist/bin/chunks/pwd-53KG2MCJ.js +0 -3
- package/dist/bin/chunks/sed-5LQMJYRJ.js +0 -80
- package/dist/bin/chunks/touch-TSNAXMZ2.js +0 -4
- package/dist/bin/chunks/wc-QSBRKIF5.js +0 -6
- package/dist/bin/shell/chunks/alias-PCMLRCRW.js +0 -7
- package/dist/bin/shell/chunks/awk2-D2US2LMM.js +0 -20
- package/dist/bin/shell/chunks/bash-UT3MT5UU.js +0 -7
- package/dist/bin/shell/chunks/chmod-3DIKREF7.js +0 -9
- package/dist/bin/shell/chunks/chunk-ACRTDIBO.js +0 -6
- package/dist/bin/shell/chunks/chunk-DV5HL4K2.js +0 -17
- package/dist/bin/shell/chunks/chunk-J7BCMQDI.js +0 -16
- package/dist/bin/shell/chunks/chunk-NWWB2XRE.js +0 -6
- package/dist/bin/shell/chunks/chunk-PM2DS2YW.js +0 -3
- package/dist/bin/shell/chunks/env-YLLSNZZN.js +0 -9
- package/dist/bin/shell/chunks/od-SLM7SRWU.js +0 -7
- package/dist/bin/shell/chunks/printf-HWUQKYUM.js +0 -14
- package/dist/bin/shell/chunks/pwd-53KG2MCJ.js +0 -3
- package/dist/bin/shell/chunks/sed-5LQMJYRJ.js +0 -80
- package/dist/bin/shell/chunks/touch-TSNAXMZ2.js +0 -4
- package/dist/bin/shell/chunks/wc-QSBRKIF5.js +0 -6
- package/dist/bundle/chunks/alias-4UGRF4DM.js +0 -6
- package/dist/bundle/chunks/awk2-46RTIZKB.js +0 -19
- package/dist/bundle/chunks/bash-ZILV3VHA.js +0 -6
- package/dist/bundle/chunks/chmod-FBHLEIY6.js +0 -8
- package/dist/bundle/chunks/chunk-4JO5BKO4.js +0 -5
- package/dist/bundle/chunks/chunk-BOJ3OAZB.js +0 -16
- package/dist/bundle/chunks/chunk-CG2HXOFG.js +0 -5
- package/dist/bundle/chunks/chunk-NWEGHOXL.js +0 -2
- package/dist/bundle/chunks/chunk-W2EKKAIL.js +0 -15
- package/dist/bundle/chunks/env-EG5SQSAQ.js +0 -8
- package/dist/bundle/chunks/od-ECWXNUB4.js +0 -6
- package/dist/bundle/chunks/printf-VG2POOXB.js +0 -13
- package/dist/bundle/chunks/pwd-AC4P3JKI.js +0 -2
- package/dist/bundle/chunks/sed-ZKODWZ6F.js +0 -79
- package/dist/bundle/chunks/touch-MVQSKQKT.js +0 -3
- package/dist/bundle/chunks/wc-DFQKWSIZ.js +0 -5
- package/dist/interpreter/builtins/variable-helpers.d.ts +0 -30
- /package/dist/bin/chunks/{curl-LCMREE7R.js → curl-TH7YRBSA.js} +0 -0
- /package/dist/bin/chunks/{file-LNCFDPQZ.js → file-6PCTL3MH.js} +0 -0
- /package/dist/bin/shell/chunks/{curl-LCMREE7R.js → curl-TH7YRBSA.js} +0 -0
- /package/dist/bin/shell/chunks/{file-LNCFDPQZ.js → file-6PCTL3MH.js} +0 -0
- /package/dist/bundle/chunks/{curl-TVZH24MD.js → curl-XLP4VABU.js} +0 -0
- /package/dist/bundle/chunks/{file-XPA6O6H2.js → file-NQP3CKRV.js} +0 -0
- /package/dist/commands/curl/{utils.d.ts → response-formatting.d.ts} +0 -0
- /package/dist/commands/xan/{xan-utils.d.ts → column-selection.d.ts} +0 -0
- /package/dist/fs/{utils.d.ts → encoding.d.ts} +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import{e as Z,f as G,g as _,h as te,i as be,j as kt,k as we}from"./chunk-PSW6BMXW.js";function $(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
|
|
2
|
+
`){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var Ne=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function fe(e){if(e.includes("#")){let[t,r]=e.split("#"),s=Number.parseInt(t,10);if(s<2||s>64)return Number.NaN;if(s<=36)return Number.parseInt(r,s);let n=0;for(let a of r){let i;if(/[0-9]/.test(a))i=a.charCodeAt(0)-48;else if(/[a-z]/.test(a))i=a.charCodeAt(0)-97+10;else if(/[A-Z]/.test(a))i=a.charCodeAt(0)-65+36;else if(a==="@")i=62;else if(a==="_")i=63;else return Number.NaN;if(i>=s)return Number.NaN;n=n*s+i}return n}return e.startsWith("0x")||e.startsWith("0X")?Number.parseInt(e.slice(2),16):e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)?/[89]/.test(e)?Number.NaN:Number.parseInt(e,8):Number.parseInt(e,10)}function Pt(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 Rt(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+=`
|
|
3
|
+
`;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 It(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 Ar(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 W(e,t){let r=Ar(t),{expr:s,pos:n}=F(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 q(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function B(e,t){return $(e,t)>=e.length}function F(e,t,r){return Sr(e,t,r)}function Sr(e,t,r){let{expr:s,pos:n}=pe(e,t,r);for(n=$(t,n);t[n]===",";){if(n++,B(t,n))return q(",",n);let{expr:i,pos:l}=pe(e,t,n);s={type:"ArithBinary",operator:",",left:s,right:i},n=$(t,l)}return{expr:s,pos:n}}function pe(e,t,r){let{expr:s,pos:n}=br(e,t,r);if(n=$(t,n),t[n]==="?"){n++;let{expr:a,pos:i}=F(e,t,n);if(n=$(t,i),t[n]===":"){n++;let{expr:l,pos:o}=F(e,t,n);return{expr:{type:"ArithTernary",condition:s,consequent:a,alternate:l},pos:o}}}return{expr:s,pos:n}}function br(e,t,r){let{expr:s,pos:n}=vt(e,t,r);for(;n=$(t,n),t.slice(n,n+2)==="||";){if(n+=2,B(t,n))return q("||",n);let{expr:i,pos:l}=vt(e,t,n);s={type:"ArithBinary",operator:"||",left:s,right:i},n=l}return{expr:s,pos:n}}function vt(e,t,r){let{expr:s,pos:n}=Dt(e,t,r);for(;n=$(t,n),t.slice(n,n+2)==="&&";){if(n+=2,B(t,n))return q("&&",n);let{expr:i,pos:l}=Dt(e,t,n);s={type:"ArithBinary",operator:"&&",left:s,right:i},n=l}return{expr:s,pos:n}}function Dt(e,t,r){let{expr:s,pos:n}=xt(e,t,r);for(;n=$(t,n),t[n]==="|"&&t[n+1]!=="|";){if(n++,B(t,n))return q("|",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[n]==="^";){if(n++,B(t,n))return q("^",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++,B(t,n))return q("&",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.slice(n,n+2)==="=="||t.slice(n,n+2)==="!=";){let a=t.slice(n,n+2);if(n+=2,B(t,n))return q(a,n);let{expr:i,pos:l}=Ct(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Ct(e,t,r){let{expr:s,pos:n}=Be(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,B(t,n))return q(a,n);let{expr:i,pos:l}=Be(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++,B(t,n))return q(a,n);let{expr:i,pos:l}=Be(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else break;return{expr:s,pos:n}}function Be(e,t,r){let{expr:s,pos:n}=Ot(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,B(t,n))return q(a,n);let{expr:i,pos:l}=Ot(e,t,n);s={type:"ArithBinary",operator:a,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]==="-")&&t[n+1]!==t[n];){let a=t[n];if(n++,B(t,n))return q(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}=ke(e,t,r);for(;;)if(n=$(t,n),t[n]==="*"&&t[n+1]!=="*"){if(n++,B(t,n))return q("*",n);let{expr:i,pos:l}=ke(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++,B(t,n))return q(a,n);let{expr:i,pos:l}=ke(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else break;return{expr:s,pos:n}}function ke(e,t,r){let{expr:s,pos:n}=Fe(e,t,r),a=$(t,n);if(t.slice(a,a+2)==="**"){if(a+=2,B(t,a))return q("**",a);let{expr:l,pos:o}=ke(e,t,a);return{expr:{type:"ArithBinary",operator:"**",left:s,right:l},pos:o}}return{expr:s,pos:n}}function Fe(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}=Fe(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}=Fe(e,t,s);return{expr:{type:"ArithUnary",operator:n,operand:a,prefix:!0},pos:i}}return Nr(e,t,s)}function wr(e,t){let r=e[t];return r==="$"||r==="`"}function Nr(e,t,r){let{expr:s,pos:n}=Wt(e,t,r,!1),a=[s];for(;wr(t,n);){let{expr:l,pos:o}=Wt(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}=F(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 Ne)if(t.slice(n,n+l.length)===l&&t.slice(n,n+l.length+1)!=="=="){n+=l.length;let{expr:o,pos:c}=pe(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 Wt(e,t,r,s=!1){let n=$(t,r),a=Pt(F,e,t,n);if(a)return a;let i=Rt(t,n);if(i)return i;let l=It(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}=F(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}=F(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}.${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:fe(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 y=d+1;for(;y<t.length&&/[0-9a-zA-Z@_]/.test(t[y]);)y++;let g=t.slice(d+1,y);return{expr:{type:"ArithDynamicBase",baseExpr:h,value:g},pos:y}}if(/[0-9]/.test(t[d])||t[d]==="x"||t[d]==="X"){let y=d;if(t[d]==="x"||t[d]==="X")for(y++;y<t.length&&/[0-9a-fA-F]/.test(t[y]);)y++;else for(;y<t.length&&/[0-9]/.test(t[y]);)y++;let g=t.slice(d,y);return{expr:{type:"ArithDynamicNumber",prefix:h,suffix:g},pos:y}}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}=F(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 Ne)if(t.slice(n,n+h.length)===h&&t.slice(n,n+h.length+1)!=="=="){n+=h.length;let{expr:d,pos:y}=pe(e,t,n);return{expr:{type:"ArithAssignment",operator:h,variable:c,subscript:f,stringKey:u,value:d},pos:y}}}return{expr:{type:"ArithArrayElement",array:c,index:f,stringKey:u},pos:n}}if(n=$(t,n),!s){for(let u of Ne)if(t.slice(n,n+u.length)===u&&t.slice(n,n+u.length+1)!=="=="){n+=u.length;let{expr:f,pos:h}=pe(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]!==`
|
|
4
|
+
`;)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 b={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 he=class extends Error{line;column;constructor(t,r,s){super(`line ${r}: ${t}`),this.line=r,this.column=s,this.name="LexerError"}},Pe={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 Mt(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 Vt(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 kr=[[";",";","&",p.SEMI_SEMI_AND],["<","<","<",p.TLESS],["&",">",">",p.AND_DGREAT]],Pr=[["[","[",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]],Rr={"|":p.PIPE,"&":p.AMP,";":p.SEMICOLON,"(":p.LPAREN,")":p.RPAREN,"<":p.LESS,">":p.GREAT};function Ir(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function qt(e){return e===" "||e===" "||e===`
|
|
5
|
+
`||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var Re=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];dparenDepth=0;constructor(t){this.input=t}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]===`
|
|
6
|
+
`)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===`
|
|
7
|
+
`)return this.pos=r+1,this.line++,this.column=1,{type:p.NEWLINE,value:`
|
|
8
|
+
`,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 kr)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 Pr)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!==`
|
|
9
|
+
`&&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=Rr[a];if(o)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!==`
|
|
10
|
+
`?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===`
|
|
11
|
+
`||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]!==`
|
|
12
|
+
`;){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]!==`
|
|
13
|
+
`;)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 m=n[i];if(m===" "||m===" "||m===`
|
|
14
|
+
`||m===";"||m==="&"||m==="|"||m==="("||m===")"||m==="<"||m===">"||m==="'"||m==='"'||m==="\\"||m==="$"||m==="`"||m==="{"||m==="}"||m==="~"||m==="*"||m==="?"||m==="[")break;i++}if(i>l){let m=n[i];if(!(m==="("&&i>l&&"@*+?!".includes(n[i-1]))){if(i>=a||m===" "||m===" "||m===`
|
|
15
|
+
`||m===";"||m==="&"||m==="|"||m==="("||m===")"||m==="<"||m===">"){let A=n.slice(l,i);if(this.pos=i,this.column=s+(i-l),Pe[A])return{type:Pe[A],value:A,start:t,end:i,line:r,column:s};let w=Vt(A);return w>0&&Mt(A.slice(0,w))?{type:p.ASSIGNMENT_WORD,value:A,start:t,end:i,line:r,column:s}:/^[0-9]+$/.test(A)?{type:p.NUMBER,value:A,start:t,end:i,line:r,column:s}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(A)?{type:p.NAME,value:A,start:t,end:i,line:r,column:s,quoted:!1,singleQuoted:!1}:{type:p.WORD,value:A,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,y=!1,g=n[i]==='"'||n[i]==="'",E=!1,S=0;for(;i<a;){let m=n[i];if(!d&&!y){if(m==="("&&u.length>0&&"@*+?!".includes(u[u.length-1])){let A=this.scanExtglobPattern(i);if(A!==null){u+=A.content,i=A.end,o+=A.content.length;continue}}if(m==="["&&S===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)){let A=i+1<a?n[i+1]:"";if(A==="^"||A==="!"){u+=m,i++,o++;continue}S=1,u+=m,i++,o++;continue}}else if(m==="["&&S>0){u.length>0&&u[u.length-1]!=="\\"&&S++,u+=m,i++,o++;continue}else if(m==="]"&&S>0){u.length>0&&u[u.length-1]!=="\\"&&S--,u+=m,i++,o++;continue}if(S>0){if(m===`
|
|
16
|
+
`)break;u+=m,i++,o++;continue}if(m===" "||m===" "||m===`
|
|
17
|
+
`||m===";"||m==="&"||m==="|"||m==="("||m===")"||m==="<"||m===">")break}if(m==="$"&&i+1<a&&n[i+1]==="'"&&!d&&!y){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(m==="$"&&i+1<a&&n[i+1]==='"'&&!d&&!y){i++,o++,y=!0,f=!0,u===""&&(g=!0),i++,o++;continue}if(m==="'"&&!y){if(d)if(d=!1,!g||E)u+=m;else{let A=i+1<a?n[i+1]:"";A&&!qt(A)&&A!=="'"&&(A==='"'?(E=!0,u+=m,h=!1,f=!1):(E=!0,u+=m))}else d=!0,g&&!E?(h=!0,f=!0):u+=m;i++,o++;continue}if(m==='"'&&!d){if(y)if(y=!1,!g||E)u+=m;else{let A=i+1<a?n[i+1]:"";A&&!qt(A)&&A!=='"'&&(A==="'"?(E=!0,u+=m,h=!1,f=!1):(E=!0,u+=m))}else y=!0,g&&!E?f=!0:u+=m;i++,o++;continue}if(m==="\\"&&!d&&i+1<a){let A=n[i+1];if(A===`
|
|
18
|
+
`){i+=2,c++,o=1;continue}if(y){if(A==='"'||A==="\\"||A==="$"||A==="`"||A===`
|
|
19
|
+
`){if(A===`
|
|
20
|
+
`){i+=2,o=1,c++;continue}u+=m+A,i+=2,o+=2;continue}}else{A==="\\"||A==='"'||A==="'"||A==="`"||A==="*"||A==="?"||A==="["||A==="]"||A==="("||A===")"||A==="$"||A==="-"||A==="."||A==="^"||A==="+"||A==="{"||A==="}"?u+=m+A:u+=A,i+=2,o+=2;continue}}if(m==="$"&&i+1<a&&n[i+1]==="("&&!d){u+=m,i++,o++,u+=n[i],i++,o++;let A=1,w=!1,L=!1,H=0,K=!1,V="",Ae=n[i]==="("&&!this.dollarDparenIsSubshell(i);for(;A>0&&i<a;){let x=n[i];if(u+=x,w)x==="'"&&(w=!1);else if(L)x==="\\"&&i+1<a?(u+=n[i+1],i++,o++):x==='"'&&(L=!1);else if(x==="'")w=!0,V="";else if(x==='"')L=!0,V="";else if(x==="\\"&&i+1<a)u+=n[i+1],i++,o++,V="";else if(x==="$"&&i+1<a&&n[i+1]==="{"){i++,o++,u+=n[i],i++,o++;let Ve=1,Se=!1,qe=!1;for(;Ve>0&&i<a;){let X=n[i];if(X==="\\"&&i+1<a&&!Se){u+=X,i++,o++,u+=n[i],i++,o++;continue}u+=X,Se?X==="'"&&(Se=!1):qe?X==='"'&&(qe=!1):X==="'"?Se=!0:X==='"'?qe=!0:X==="{"?Ve++:X==="}"&&Ve--,X===`
|
|
21
|
+
`?(c++,o=0):o++,i++}V="";continue}else if(x==="#"&&!Ae&&(V===""||/\s/.test(n[i-1]||""))){for(;i+1<a&&n[i+1]!==`
|
|
22
|
+
`;)i++,o++,u+=n[i];V=""}else/[a-zA-Z_]/.test(x)?V+=x:(V==="case"?(H++,K=!1):V==="in"&&H>0?K=!0:V==="esac"&&H>0&&(H--,K=!1),V="",x==="("?i>0&&n[i-1]==="$"?A++:K||A++:x===")"?K?K=!1:A--:x===";"&&H>0&&i+1<a&&n[i+1]===";"&&(K=!0));x===`
|
|
23
|
+
`&&(c++,o=0,V=""),i++,o++}continue}if(m==="$"&&i+1<a&&n[i+1]==="["&&!d){u+=m,i++,o++,u+=n[i],i++,o++;let A=1;for(;A>0&&i<a;){let w=n[i];u+=w,w==="["?A++:w==="]"?A--:w===`
|
|
24
|
+
`&&(c++,o=0),i++,o++}continue}if(m==="$"&&i+1<a&&n[i+1]==="{"&&!d){u+=m,i++,o++,u+=n[i],i++,o++;let A=1,w=!1,L=!1,H=c,K=o,V=c,Ae=o;for(;A>0&&i<a;){let x=n[i];if(x==="\\"&&i+1<a&&n[i+1]===`
|
|
25
|
+
`){i+=2,c++,o=1;continue}if(x==="\\"&&i+1<a&&!w){u+=x,i++,o++,u+=n[i],i++,o++;continue}u+=x,w?x==="'"&&(w=!1):L?x==='"'&&(L=!1):x==="'"?(w=!0,H=c,K=o):x==='"'?(L=!0,V=c,Ae=o):x==="{"?A++:x==="}"&&A--,x===`
|
|
26
|
+
`&&(c++,o=0),i++,o++}if(w)throw new he("unexpected EOF while looking for matching `''",H,K);if(L)throw new he("unexpected EOF while looking for matching `\"'",V,Ae);continue}if(m==="$"&&i+1<a&&!d){let A=n[i+1];if(A==="#"||A==="?"||A==="$"||A==="!"||A==="@"||A==="*"||A==="-"||A>="0"&&A<="9"){u+=m+A,i+=2,o+=2;continue}}if(m==="`"&&!d){for(u+=m,i++,o++;i<a&&n[i]!=="`";){let A=n[i];u+=A,A==="\\"&&i+1<a&&(u+=n[i+1],i++,o++),A===`
|
|
27
|
+
`&&(c++,o=0),i++,o++}i<a&&(u+=n[i],i++,o++);continue}u+=m,i++,m===`
|
|
28
|
+
`?(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||y){let m=d?"'":'"';throw new he(`unexpected EOF while looking for matching \`${m}'`,r,s)}if(!g&&u.length>=2){if(u[0]==="'"&&u[u.length-1]==="'"){let m=u.slice(1,-1);!m.includes("'")&&!m.includes('"')&&(u=m,f=!0,h=!0)}else if(u[0]==='"'&&u[u.length-1]==='"'){let m=u.slice(1,-1),A=!1;for(let w=0;w<m.length;w++){if(m[w]==='"'){A=!0;break}m[w]==="\\"&&w+1<m.length&&w++}A||(u=m,f=!0,h=!1)}}if(u==="")return{type:p.WORD,value:"",start:t,end:i,line:r,column:s,quoted:f,singleQuoted:h};if(!f&&Pe[u])return{type:Pe[u],value:u,start:t,end:i,line:r,column:s};if(!g){let m=Vt(u);if(m>0&&Mt(u.slice(0,m)))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}:Ir(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=this.pos,l="";for(;this.pos<this.input.length&&this.input[this.pos]!==`
|
|
29
|
+
`;)l+=this.input[this.pos],this.pos++,this.column++;if((t.stripTabs?l.replace(/^\t+/,""):l)===t.delimiter){this.pos<this.input.length&&this.input[this.pos]===`
|
|
30
|
+
`&&(this.pos++,this.line++,this.column=1);break}a+=l,this.pos<this.input.length&&this.input[this.pos]===`
|
|
31
|
+
`&&(a+=`
|
|
32
|
+
`,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===`
|
|
33
|
+
`||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===`
|
|
34
|
+
`||c===";"||c==="&"||c==="|"||c==="("||c===")"||c==="<"||c===">")break;if(c==="{"){if(this.scanBraceExpansion(i)!==null){let f=1;for(i++,l++;i<a&&f>0;)n[i]==="{"?f++:n[i]==="}"&&f--,i++,l++;continue}i++,l++;continue}if(c==="}"){i++,l++;continue}if(c==="$"&&i+1<a&&n[i+1]==="("){i++,l++,i++,l++;let u=1;for(;u>0&&i<a;)n[i]==="("?u++:n[i]===")"&&u--,i++,l++;continue}if(c==="$"&&i+1<a&&n[i+1]==="{"){i++,l++,i++,l++;let u=1;for(;u>0&&i<a;)n[i]==="{"?u++:n[i]==="}"&&u--,i++,l++;continue}if(c==="`"){for(i++,l++;i<a&&n[i]!=="`";)n[i]==="\\"&&i+1<a?(i+=2,l+=2):(i++,l++);i<a&&(i++,l++);continue}i++,l++}let o=n.slice(t,i);return this.pos=i,this.column=l,{type:p.WORD,value:o,start:t,end:i,line:r,column:s,quoted:!1,singleQuoted:!1}}scanBraceExpansion(t){let r=this.input,s=r.length,n=t+1,a=1,i=!1,l=!1;for(;n<s&&a>0;){let o=r[n];if(o==="{")a++,n++;else if(o==="}")a--,n++;else if(o===","&&a===1)i=!0,n++;else if(o==="."&&n+1<s&&r[n+1]===".")l=!0,n+=2;else{if(o===" "||o===" "||o===`
|
|
35
|
+
`||o===";"||o==="&"||o==="|")return null;n++}}return a===0&&(i||l)?r.slice(t,n):null}scanLiteralBraceWord(t){let r=this.input,s=r.length,n=t+1,a=1;for(;n<s&&a>0;){let i=r[n];if(i==="{")a++,n++;else if(i==="}"){if(a--,a===0)return r.slice(t,n+1);n++}else{if(i===" "||i===" "||i===`
|
|
36
|
+
`||i===";"||i==="&"||i==="|")return null;n++}}return null}scanExtglobPattern(t){let r=this.input,s=r.length,n=t+1,a=1;for(;n<s&&a>0;){let i=r[n];if(i==="\\"&&n+1<s){n+=2;continue}if("@*+?!".includes(i)&&n+1<s&&r[n+1]==="("){n++,a++,n++;continue}if(i==="(")a++,n++;else if(i===")")a--,n++;else{if(i===`
|
|
37
|
+
`)return null;n++}}return a===0?{content:r.slice(t,n),end:n}:null}scanFdVariable(t){let r=this.input,s=r.length,n=t+1,a=n;for(;n<s;){let u=r[n];if(n===a){if(!(u>="a"&&u<="z"||u>="A"&&u<="Z"||u==="_"))return null}else if(!(u>="a"&&u<="z"||u>="A"&&u<="Z"||u>="0"&&u<="9"||u==="_"))break;n++}if(n===a)return null;let i=r.slice(a,n);if(n>=s||r[n]!=="}"||(n++,n>=s))return null;let l=r[n],o=n+1<s?r[n+1]:"";return l===">"||l==="<"||l==="&"&&(o===">"||o==="<")?{varname:i,end:n}:null}dollarDparenIsSubshell(t){let r=this.input,s=r.length,n=t+1,a=2,i=!1,l=!1,o=!1;for(;n<s&&a>0;){let c=r[n];if(i){c==="'"&&(i=!1),c===`
|
|
38
|
+
`&&(o=!0),n++;continue}if(l){if(c==="\\"){n+=2;continue}c==='"'&&(l=!1),c===`
|
|
39
|
+
`&&(o=!0),n++;continue}if(c==="'"){i=!0,n++;continue}if(c==='"'){l=!0,n++;continue}if(c==="\\"){n+=2;continue}if(c===`
|
|
40
|
+
`&&(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]===`
|
|
41
|
+
`);)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]===`
|
|
42
|
+
`);)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,Bt=1e6,Ft=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]),Qt=new Set([p.LESS,p.GREAT,p.DLESS,p.DGREAT,p.LESSAND,p.GREATAND,p.LESSGREAT,p.DLESSDASH,p.CLOBBER,p.TLESS]),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]),Q=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 vr(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 Gt(e,t,r){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_-]/.test(t[s]);)s++;return s}function Ze(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 oe(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 Ut(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=Dr(t,s);i===-1?(n+=a,s++):(n+=t.slice(s,i+1),s=i+1)}else break}return{pattern:n,endIndex:s}}function Dr(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 Ht(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+=`
|
|
43
|
+
`,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+=vr(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:b.literal(s),endIndex:n}}function Ge(e,t){let r=t.trim();return r===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:W(e,r)}function Zt(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 Kt(e,t,r,s){let n=Ze(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:Zt(a).map(u=>({type:"Word",word:b.word(s(e,u,!1,!1,!1))}))},endIndex:n+1}:a.includes(",")?{part:{type:"BraceExpansion",items:Zt(a).map(u=>({type:"Word",word:b.word([b.literal(u)])}))},endIndex:n+1}:null}function Ue(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(Ue(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 Xt(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 Ie(e){let t=e.current(),r=t.type;if(r===p.NUMBER){let s=e.peek(1);return t.end!==s.start?!1:Qt.has(s.type)}if(r===p.FD_VARIABLE){let s=e.peek(1);return zt.has(s.type)}return Ft.has(r)}function ve(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=Xt(e,s.type);if(s.type===p.DLESS||s.type===p.DLESSDASH)return xr(e,n,t,s.type===p.DLESSDASH);e.isWord()||e.error("Expected redirection target");let a=e.parseWord();return b.redirection(n,a,t,r)}function xr(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=b.redirection(s?"<<-":"<<",b.hereDoc(a,b.word([]),s,i),r);return e.addPendingHeredoc(l,a,s,i),l}function Yt(e){let t=e.current().line,r=[],s=null,n=[],a=[];for(;e.check(p.ASSIGNMENT_WORD)||Ie(e);)e.checkIterationLimit(),e.check(p.ASSIGNMENT_WORD)?r.push($r(e)):a.push(ve(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=b.word([b.literal(l.value)])}for(;(!e.isStatementEnd()||e.check(p.RBRACE))&&!e.check(p.PIPE,p.PIPE_AMP);)if(e.checkIterationLimit(),Ie(e))a.push(ve(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=je(e);e.expect(p.RPAREN);let d=h.map(g=>Ue(e,g)),y=`${f}=(${d.join(" ")})`;n.push(e.parseWordFromString(y,!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=b.simpleCommand(s,n,r,a);return i.line=t,i}function $r(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=je(e);e.expect(p.RPAREN);let h=a!==void 0?`${n}[${a}]`:n;return b.assignment(h,null,l,f)}if(o===""&&e.check(p.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let h=je(e);e.expect(p.RPAREN);let d=a!==void 0?`${n}[${a}]`:n;return b.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 b.assignment(u,c,l,null)}var _r=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 je(e){let t=[];for(e.skipNewlines();!e.check(p.RPAREN,p.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):_r.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function He(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 b.ifNode(r,a,i)}function Ke(e,t){let r=e.expect(p.FOR);if(e.check(p.DPAREN_START))return Or(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 b.forNode(n,a,i,l)}function Or(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=W(e,i[0].trim())),i[1].trim()&&(n=W(e,i[1].trim())),i[2].trim()&&(a=W(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 Xe(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 b.whileNode(r,s,n)}function Je(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 b.untilNode(r,s,n)}function Ye(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=Lr(e);if(i&&s.push(i),e.skipNewlines(),e.getPos()===a&&!i)break}e.expect(p.ESAC);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return b.caseNode(r,s,n)}function Lr(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=";;&"),b.caseItem(t,r,s)}function et(e,t){e.expect(p.LPAREN);let r=e.parseCompoundList();e.expect(p.RPAREN);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return b.subshell(r,s)}function tt(e,t){e.expect(p.LBRACE);let r=e.parseCompoundList();e.expect(p.RBRACE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return b.group(r,s)}var Tr=["-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"],Mr=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function en(e){return e.isWord()||e.check(p.LBRACE)||e.check(p.RBRACE)||e.check(p.ASSIGNMENT_WORD)}function tn(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 rt(e){return e.skipNewlines(),Vr(e)}function Vr(e){let t=nn(e);for(e.skipNewlines();e.check(p.OR_OR);){e.advance(),e.skipNewlines();let r=nn(e);t={type:"CondOr",left:t,right:r},e.skipNewlines()}return t}function nn(e){let t=nt(e);for(e.skipNewlines();e.check(p.AND_AND);){e.advance(),e.skipNewlines();let r=nt(e);t={type:"CondAnd",left:t,right:r},e.skipNewlines()}return t}function nt(e){return e.skipNewlines(),e.check(p.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:nt(e)}):qr(e)}function qr(e){if(e.check(p.LPAREN)){e.advance();let t=rt(e);return e.expect(p.RPAREN),{type:"CondGroup",expression:t}}if(en(e)){let t=e.current(),r=t.value;if(Tr.includes(r)&&!t.quoted){if(e.advance(),e.check(p.DBRACK_END)&&e.error(`Expected operand after ${r}`),en(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()&&Mr.includes(e.current().value)){let n=e.advance().value,a;return n==="=~"?a=Br(e):n==="=="||n==="!="?a=tn(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=tn(e);return{type:"CondBinary",operator:"==",left:s,right:n}}return{type:"CondWord",word:s}}e.error("Expected conditional expression")}function Br(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 Qr(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 zr(e,t,r){let s=r+1,n=t[s];if("@*#?$!-0123456789".includes(n))return{part:b.parameterExpansion(n),endIndex:s+1};let a="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)a+=t[s],s++;return{part:b.parameterExpansion(a),endIndex:s}}function Zr(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=Ze(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:b.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 Q("unexpected EOF while looking for matching '}'",0,0);let h=t.slice(r+2,f);return{part:b.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=st(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=st(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=st(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 Q("unexpected EOF while looking for matching '}'",0,0);return{part:b.parameterExpansion(l,c),endIndex:n+1}}function st(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 S=oe(e,t,a),m=t.slice(a,S),A=re(e,m,!1,!1,!0,!1,n,!1,!1,!0),w=b.word(A.length>0?A:[b.literal("")]);if(o==="-")return{operation:{type:"DefaultValue",word:w,checkEmpty:!0},endIndex:S};if(o==="=")return{operation:{type:"AssignDefault",word:w,checkEmpty:!0},endIndex:S};if(o==="?")return{operation:{type:"ErrorIfUnset",word:w,checkEmpty:!0},endIndex:S};if(o==="+")return{operation:{type:"UseAlternative",word:w,checkEmpty:!0},endIndex:S}}a++;let c=oe(e,t,a),u=t.slice(a,c),f=-1,h=0,d=0;for(let E=0;E<u.length;E++){let S=u[E];if(S==="("||S==="[")h++;else if(S===")"||S==="]")h--;else if(S==="?"&&h===0)d++;else if(S===":"&&h===0)if(d>0)d--;else{f=E;break}}let y=f>=0?u.slice(0,f):u,g=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:Ge(e,y),length:g!==null?Ge(e,g):null},endIndex:c}}if("-=?+".includes(i)){a++;let o=oe(e,t,a),c=t.slice(a,o),u=re(e,c,!1,!1,!0,!1,n,!1,!1,!0),f=b.word(u.length>0?u:[b.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=oe(e,t,a),f=t.slice(a,u),h=re(e,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:b.word(h.length>0?h:[b.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=Ut(e,t,a);let f=t.slice(a,u),h=re(e,f,!1,!1,!1),d=b.word(h.length>0?h:[b.literal("")]),y=null,g=u;if(t[u]==="/"){let E=u+1,S=oe(e,t,E),m=t.slice(E,S),A=re(e,m,!1,!1,!1);y=b.word(A.length>0?A:[b.literal("")]),g=S}return{operation:{type:"PatternReplacement",pattern:d,replacement:y,all:o,anchor:c},endIndex:g}}if(i==="^"||i===","){let o=l===i,c=i==="^"?"upper":"lower";a+=o?2:1;let u=oe(e,t,a),f=t.slice(a,u),h=f?b.word([b.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 it(e,t,r,s=!1){let n=r+1;if(n>=t.length)return{part:b.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=W(e,o);return{part:b.arithmeticExpansion(c),endIndex:l+1}}}return a==="("?e.parseCommandSubstitution(t,r):a==="{"?Zr(e,t,r,s):/[a-zA-Z_0-9@*#?$!-]/.test(a)?zr(e,t,r):{part:b.literal("$"),endIndex:n}}function rn(e,t){let r=[],s=0,n="",a=()=>{n&&(r.push(b.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}=it(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 Gr(e,t,r){let s=[],n=r,a="",i=()=>{a&&(s.push(b.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}=it(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:b.doubleQuoted(s),endIndex:n}}function re(e,t,r=!1,s=!1,n=!1,a=!1,i=!1,l=!1,o=!1,c=!1){if(s)return[b.singleQuoted(t)];if(r){let y=rn(e,t);return[b.doubleQuoted(y)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let y=t.slice(1,-1),g=!1;for(let E=0;E<y.length;E++){if(y[E]==='"'){g=!0;break}y[E]==="\\"&&E+1<y.length&&E++}if(!g){let E=rn(e,y);return[b.doubleQuoted(E)]}}let u=[],f=0,h="",d=()=>{h&&(u.push(b.literal(h)),h="")};for(;f<t.length;){let y=t[f];if(y==="\\"&&f+1<t.length){let g=t[f+1];if(o){d(),u.push(b.escaped(g)),f+=2;continue}let E=a?g==="$"||g==="`"||g===`
|
|
44
|
+
`:g==="$"||g==="`"||g==='"'||g==="'"||g===`
|
|
45
|
+
`||c&&g==="}",S=i?"*?[]\\".includes(g):"*?[]\\(){}.^+".includes(g);E?h+=g:S?(d(),u.push(b.escaped(g))):h+=`\\${g}`,f+=2;continue}if(y==="'"&&!i&&!a){d();let g=t.indexOf("'",f+1);if(g===-1){h+=t.slice(f);break}u.push(b.singleQuoted(t.slice(f+1,g))),f=g+1;continue}if(y==='"'&&!a){d();let{part:g,endIndex:E}=Gr(e,t,f+1);u.push(g),f=E+1;continue}if(y==="$"&&t[f+1]==="'"){d();let{part:g,endIndex:E}=Ht(e,t,f+2);u.push(g),f=E;continue}if(y==="$"){d();let{part:g,endIndex:E}=it(e,t,f);g&&u.push(g),f=E;continue}if(y==="`"){d();let{part:g,endIndex:E}=e.parseBacktickSubstitution(t,f);u.push(g),f=E;continue}if(y==="~"){let g=f>0?t[f-1]:"";if(f===0||g==="="||n&&g===":"){let S=Gt(e,t,f),m=t[S];if(m===void 0||m==="/"||m===":"){d();let A=t.slice(f+1,S)||null;u.push({type:"TildeExpansion",user:A}),f=S;continue}}}if("@*+?!".includes(y)&&f+1<t.length&&t[f+1]==="("){let g=Qr(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(y==="*"||y==="?"||y==="["){d();let{pattern:g,endIndex:E}=jt(e,t,f);u.push({type:"Glob",pattern:g}),f=E;continue}if(y==="{"&&!n&&!l){let g=Kt(e,t,f,re);if(g){d(),u.push(g.part),f=g.endIndex;continue}}h+=y,f++}return d(),u}function sn(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 an(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),y=r().parse(h);return{part:b.commandSubstitution(y,!1),endIndex:i+1}}function on(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===`
|
|
46
|
+
`||r&&u==='"'?(u!==`
|
|
47
|
+
`&&(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:b.commandSubstitution(c,!0),endIndex:i+1}}var T=class e{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;_input="";getInput(){return this._input}checkIterationLimit(){if(this.parseIterations++,this.parseIterations>Bt)throw new Q("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}parse(t){if(t.length>Qe)throw new Q(`Input too large: ${t.length} bytes exceeds limit of ${Qe}`,1,1);this._input=t;let r=new Re(t);if(this.tokens=r.tokenize(),this.tokens.length>ze)throw new Q(`Too many tokens: ${this.tokens.length} exceeds limit of ${ze}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseScript()}parseTokens(t){return this.tokens=t,this.pos=0,this.pendingHeredocs=[],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 Q(r||`Expected ${t}, got ${s.type}`,s.line,s.column,s)}error(t){let r=this.current();throw new Q(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=b.word([b.literal(r.value)]):s=this.parseWordFromString(r.value,!1,!1,!1,!0),t.redirect.target=b.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 b.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(),b.statement([b.pipeline([b.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 b.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 b.pipeline(a,n,t,r,i.length>0?i:void 0)}parseCommand(){return this.check(p.IF)?He(this):this.check(p.FOR)?Ke(this):this.check(p.WHILE)?Xe(this):this.check(p.UNTIL)?Je(this):this.check(p.CASE)?Ye(this):this.check(p.LPAREN)?et(this):this.check(p.LBRACE)?tt(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():Yt(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=b.subshell(t,[]);return b.subshell([b.statement([b.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=re(this,t,r,s,n,a,!1,i,l);return b.word(o)}parseCommandSubstitution(t,r){return an(t,r,()=>new e,s=>this.error(s))}parseBacktickSubstitution(t,r,s=!1){return on(t,r,s,()=>new e,n=>this.error(n))}isDollarDparenSubshell(t,r){return sn(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:b.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 b.arithmeticCommand(l,o,t.line)}parseConditionalCommand(){let t=this.expect(p.DBRACK_START),r=rt(this);this.expect(p.DBRACK_END);let s=this.parseOptionalRedirections();return b.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 Q("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 b.functionDef(t,r,s)}parseCompoundCommandBody(t){let r=t?.forFunctionBody;if(this.check(p.LBRACE))return tt(this,{skipRedirections:r});if(this.check(p.LPAREN))return et(this,{skipRedirections:r});if(this.check(p.IF))return He(this,{skipRedirections:r});if(this.check(p.FOR))return Ke(this,{skipRedirections:r});if(this.check(p.WHILE))return Xe(this,{skipRedirections:r});if(this.check(p.UNTIL))return Je(this,{skipRedirections:r});if(this.check(p.CASE))return Ye(this,{skipRedirections:r});this.error("Expected compound command for function body")}parseCompoundList(){let t=[];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 r=this.pos,s=this.parseStatement();if(s&&t.push(s),this.skipSeparators(),this.pos===r&&!s)break}return t}parseOptionalRedirections(){let t=[];for(;Ie(this);){this.checkIterationLimit();let r=this.pos;if(t.push(ve(this)),this.pos===r)break}return t}parseArithmeticExpression(t){return W(this,t)}};function ci(e){return new T().parse(e)}var jr={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 at(e){return jr[e]||""}function ln(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 un(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=at(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+="$",new RegExp(t)}function ot(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 lt(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 se=class{fs;cwd;globignorePatterns=[];hasGlobignore=!1;globstar=!1;nullglob=!1;failglob=!1;dotglob=!1;extglob=!1;globskipdots=!0;constructor(t,r,s,n){this.fs=t,this.cwd=r,typeof n=="boolean"?this.globstar=n: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);let a=s?.GLOBIGNORE;a!==void 0&&a!==""&&(this.hasGlobignore=!0,this.globignorePatterns=ln(a))}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 un(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){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(s.length===0)return[r];let[n,...a]=s,i=[];try{if(this.fs.readdirWithFileTypes){let l=await this.fs.readdirWithFileTypes(t),o=[],c=[...l],u=this.dotglob||this.hasGlobignore;if(n.startsWith(".")||this.dotglob){let h=l.some(y=>y.name==="."),d=l.some(y=>y.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}`,y;r===""?y=h.name:r==="/"?y=`/${h.name}`:y=`${r}/${h.name}`,a.length===0?o.push(Promise.resolve([y])):h.isDirectory&&o.push(this.expandSegments(d,y,a))}let f=await Promise.all(o);for(let h of f)i.push(...h)}else{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}`,y;r===""?y=h:r==="/"?y=`/${h}`:y=`${r}/${h}`,a.length===0?o.push(Promise.resolve([y])):o.push((async()=>{try{if((await this.fs.stat(d)).isDirectory)return this.expandSegments(d,y,a)}catch{}return[]})())}let f=await Promise.all(o);for(let h of f)i.push(...h)}}catch{}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){let n=this.fs.resolvePath(this.cwd,t);try{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{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{(await this.fs.stat(h)).isDirectory&&l.push(f)}catch{}}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{}}async walkDirectory(t,r,s){let n=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){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{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{let y=await this.fs.stat(d);return{name:f,path:h,isDirectory:y.isDirectory}}catch{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{}}matchPattern(t,r){return this.patternToRegex(r).test(t)}patternToRegex(t){let r=this.patternToRegexStr(t);return new RegExp(`^${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=ot(t,n+1);if(i!==-1){let l=t.slice(n+2,i),o=lt(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(y=>this.computePatternLength(y));if(h.every(y=>y!==null)&&h.every(y=>y===h[0])&&h[0]!==null){let y=h[0];if(y===0)r+="(?:.+)";else{let g=[];y>0&&g.push(`.{0,${y-1}}`),g.push(`.{${y+1},}`),g.push(`(?!(?:${u})).{${y}}`),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=at(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=ot(t,s+1);if(i!==-1){if(a==="@"){let l=t.slice(s+2,i),c=lt(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 Hr(e,t,r){switch(r){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new _("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new _("division by 0");return e%t;case"**":if(t<0)throw new _("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 cn(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 Kr(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function Xr(e,t){let r=e.state.env[t];if(r!==void 0)return r;let s=e.state.env[`${t}_0`];return s!==void 0?s:await v(e,t)}function Jr(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 T,{expr:n,pos:a}=F(s,r,0);if(a<r.length){let i=r.slice(a).trim().split(/\s+/)[0];throw new _(`${r}: syntax error in expression (error token is "${i}")`)}return n.type==="ArithNumber"?n.value:t||0}catch(s){if(s instanceof _)throw s;let n=r.split(/\s+/).slice(1)[0]||r;throw new _(`${r}: syntax error in expression (error token is "${n}")`)}}async function ut(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 T,{expr:a,pos:i}=F(n,s,0);if(i<s.length){let l=s.slice(i).trim(),o=l.split(/\s+/)[0]||l;throw new _(`syntax error in expression (error token is "${o}")`,"","")}return await R(e,a)}async function ct(e,t,r=new Set){if(r.has(t))return 0;r.add(t);let s=await Xr(e,t);if(!s)return 0;let n=Number.parseInt(s,10);if(!Number.isNaN(n)&&/^-?\d+$/.test(s.trim()))return n;let a=s.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return await ct(e,a,r);let i=new T,{expr:l,pos:o}=F(i,a,0);if(o<a.length){let c=a.slice(o).trim(),u=c.split(/\s+/)[0]||c;throw new _(`${a}: syntax error in expression (error token is "${u}")`)}return await R(e,l)}async function De(e,t){if(t.startsWith("#")){let f=t.slice(1),h=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(h){let y=h[1],g=P(e,y);return String(g.length)}let d=e.state.env[f]||"";return String(d.length)}if(t.startsWith("!")){let f=t.slice(1),h=e.state.env[f]||"";return e.state.env[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[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[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 _("value too great for base");return t.value;case"ArithVariable":return await ct(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 T,{expr:l}=F(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);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 De(e,t.content);return Number.parseInt(s,10)||0}case"ArithDynamicBase":{let s=await De(e,t.baseExpr),n=Number.parseInt(s,10);if(n<2||n>64)return 0;let a=`${n}#${t.value}`;return fe(a)}case"ArithDynamicNumber":{let n=await De(e,t.prefix)+t.suffix;return fe(n)}case"ArithArrayElement":{let s=e.state.associativeArrays?.has(t.array),n=async a=>{let i=e.state.env[a];return i!==void 0?await ut(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
|
+
`,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
|
|
49
|
+
`,0;a=f}let i=`${t.array}_${a}`,l=e.state.env[i];if(l!==void 0)return ut(e,l);if(a===0){let o=e.state.env[t.array];if(o!==void 0)return ut(e,o)}if(e.state.options.nounset&&!Object.keys(e.state.env).some(c=>c===t.array||c.startsWith(`${t.array}_`)))throw new Z(`${t.array}[${a}]`);return 0}return 0}case"ArithDoubleSubscript":throw new _("double subscript","","");case"ArithNumberSubscript":throw new _(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new _(t.message,"","",!0);case"ArithSingleQuote":{if(r)throw new _(`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 Hr(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[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[i]||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env[i]=String(o),t.prefix?o:l}if(t.operand.type==="ArithConcat"){let n="";for(let a of t.operand.parts)n+=await ue(e,a,r);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let a=Number.parseInt(e.state.env[n]||"0",10)||0,i=t.operator==="++"?a+1:a-1;return e.state.env[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 ue(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[i]||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env[i]=String(o),t.prefix?o:l}}return s}return Kr(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[n]||"0",10)||0,i=await R(e,t.value,r),l=cn(a,i,t.operator);return e.state.env[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 ue(e,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)?await ct(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 ue(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[n]||"0",10)||0,i=await R(e,t.value,r),l=cn(a,i,t.operator);return e.state.env[n]=String(l),l}case"ArithDynamicElement":{let s="";if(t.nameExpr.type==="ArithConcat")for(let l of t.nameExpr.parts)s+=await ue(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[a];return i!==void 0?Jr(i):0}default:return 0}}async function ue(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 De(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command)).stdout.trim():"0";case"ArithConcat":{let s="";for(let n of t.parts)s+=await ue(e,n,r);return s}default:return String(await R(e,t,r))}}function ft(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 Yr(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 fn(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 de(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),Yr(o)&&(t=!0),(o.operation?.type==="VarNamePrefix"||o.operation?.type==="ArrayKeys")&&(i=!0),o.operation?.type==="Indirection"&&(l=!0)),o.type==="Glob"&&ft(o.pattern)&&(a=!0)}return{hasQuoted:t,hasCommandSub:r,hasArrayVar:s,hasArrayAtExpansion:n,hasParamExpansion:a,hasVarNamePrefixExpansion:i,hasIndirection:l}}var pn="5.1.0(1)-release",Ni="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function me(){return{pid:process.pid,ppid:process.ppid,uid:process.getuid?.()??1e3,gid:process.getgid?.()??1e3}}function ki(){let{pid:e,ppid:t,uid:r,gid:s}=me();return`Name: bash
|
|
50
|
+
State: R (running)
|
|
51
|
+
Pid: ${e}
|
|
52
|
+
PPid: ${t}
|
|
53
|
+
Uid: ${r} ${r} ${r} ${r}
|
|
54
|
+
Gid: ${s} ${s} ${s} ${s}
|
|
55
|
+
`}function pt(e,t){let r=`${t}_`,s=[];for(let n of Object.keys(e.state.env))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 Ri(e,t){let r=`${t}_`;for(let s of Object.keys(e.state.env))s.startsWith(r)&&delete e.state.env[s]}function ht(e,t){let r=`${t}_`,s=`${t}__length`,n=[];for(let a of Object.keys(e.state.env))if(a!==s&&a.startsWith(r)){let i=a.slice(r.length);if(i.startsWith("_length"))continue;n.push(i)}return n.sort()}function xe(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function Ii(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=xe(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:es(h)}):o.push(h)}return{key:s,valueParts:o,append:l}}function es(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 hn(r.word)}).join(",")}}`}function hn(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}`:""}`:hn(s.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",r.user&&(t+=r.user);break}return t}function O(e){return e.IFS??`
|
|
56
|
+
`}function M(e){return e.IFS===""}function $e(e){let t=O(e);if(t==="")return!0;for(let r of t)if(r!==" "&&r!==" "&&r!==`
|
|
57
|
+
`)return!1;return!0}function dn(e){return e.split("").map(t=>/[\\^$.*+?()[\]{}|-]/.test(t)?`\\${t}`:t===" "?"\\t":t===`
|
|
58
|
+
`?"\\n":t).join("")}function N(e){let t=e.IFS;return t===void 0?" ":t[0]||""}var ts=`
|
|
59
|
+
`;function ns(e){return ts.includes(e)}function dt(e){let t=new Set,r=new Set;for(let s of e)ns(s)?t.add(s):r.add(s);return{whitespace:t,nonWhitespace:r}}function Di(e,t,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:{words:[e],wordStarts:[0]};let{whitespace:n,nonWhitespace:a}=dt(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 _e(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}=dt(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 D(e,t){return _e(e,t).words}function rs(e,t){for(let r of e)if(t.has(r))return!0;return!1}function xi(e,t,r){if(t==="")return e;let{whitespace:s,nonWhitespace:n}=dt(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(!rs(l,n))return l}return i}function C(e,t){return e.state.namerefs?.has(t)??!1}function _i(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function Ci(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Oi(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function mn(e,t){return e.state.invalidNamerefs?.has(t)??!1}function Li(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function ss(e,t){let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let n=r[1],a=Object.keys(e.state.env).some(l=>l.startsWith(`${n}_`)&&!l.includes("__")),i=e.state.associativeArrays?.has(n)??!1;return a||i}return Object.keys(e.state.env).some(n=>n.startsWith(`${t}_`)&&!n.includes("__"))?!0:e.state.env[t]!==void 0}function le(e,t,r=100){if(!C(e,t)||mn(e,t))return t;let s=new Set,n=t;for(;r-- >0;){if(s.has(n))return;if(s.add(n),!C(e,n))return n;let a=e.state.env[n];if(a===void 0||a===""||!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(a))return n;n=a}}function ge(e,t){if(C(e,t))return e.state.env[t]}function Wi(e,t,r,s=100){if(!C(e,t)||mn(e,t))return t;let n=new Set,a=t;for(;s-- >0;){if(n.has(a))return;if(n.add(a),!C(e,a))return a;let i=e.state.env[a];if(i===void 0||i==="")return r!==void 0?/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&ss(e,r)?a:null:a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(i))return a;a=i}}function is(e,t){let r=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(s,n)=>e.state.env[n]??"");return r=r.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(s,n)=>e.state.env[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)?ht(e,t).map(a=>[a,e.state.env[`${t}_${a}`]]):pt(e,t).map(n=>[n,e.state.env[`${t}_${n}`]])}function ye(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)?ht(e,t).length>0:pt(e,t).length>0}async function v(e,t,r=!0,s=!1){switch(t){case"?":return String(e.state.lastExitCode);case"$":return String(process.pid);case"#":return e.state.env["#"]||"0";case"@":return e.state.env["@"]||"";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["#"]||"0",10);if(i===0)return"";let l=[];for(let o=1;o<=i;o++)l.push(e.state.env[String(o)]||"");return l.join(N(e.state.env))}case"0":return e.state.env[0]||"bash";case"PWD":return e.state.env.PWD!==void 0?e.state.env.PWD:"";case"OLDPWD":return e.state.env.OLDPWD!==void 0?e.state.env.OLDPWD:"";case"PPID":{let{ppid:i}=me();return String(i)}case"UID":{let{uid:i}=me();return String(i)}case"EUID":return String(process.geteuid?.()??me().uid);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 pn;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 Z("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 Z("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 Z("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new te(`\${${t}}`);let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let i=n[1],l=n[2];if(C(e,i)){let f=le(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[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=xe(l);f=is(e,f);let h=e.state.env[`${i}_${f}`];if(h===void 0&&r&&e.state.options.nounset)throw new Z(`${i}[${l}]`);return h||""}let c;if(/^-?\d+$/.test(l))c=Number.parseInt(l,10);else try{let f=new T,h=W(f,l);c=await R(e,h.expression)}catch{let f=e.state.env[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
|
|
60
|
+
`,"";let y=Math.max(...f.map(([E])=>typeof E=="number"?E:0))+1+c;return y<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${h}: ${i}: bad array subscript
|
|
61
|
+
`,""):e.state.env[`${i}_${y}`]||""}let u=e.state.env[`${i}_${c}`];if(u!==void 0)return u;if(c===0){let f=e.state.env[i];if(f!==void 0)return f}if(r&&e.state.options.nounset)throw new Z(`${i}[${c}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let i=e.state.env[t];if(i===void 0&&r&&e.state.options.nounset)throw new Z(t);return i||""}if(C(e,t)){let i=le(e,t);if(i===void 0)return"";if(i!==t)return await v(e,i,r,s);let l=e.state.env[t];if((l===void 0||l==="")&&r&&e.state.options.nounset)throw new Z(t);return l||""}let a=e.state.env[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(ye(e,t)){let i=e.state.env[`${t}_0`];return i!==void 0?i:""}if(r&&e.state.options.nounset)throw new Z(t);return""}async function Y(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["#"]||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return t in e.state.env;let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],a=s[2];if(C(e,n)){let o=le(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:n in e.state.env;if(e.state.associativeArrays?.has(n)){let o=xe(a);return`${n}_${o}`in e.state.env}let l;if(/^-?\d+$/.test(a))l=Number.parseInt(a,10);else try{let o=new T,c=W(o,a);l=await R(e,c.expression)}catch{let o=e.state.env[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:`${n}_${u}`in e.state.env}return`${n}_${l}`in e.state.env}if(C(e,t)){let n=le(e,t);return n===void 0||n===t?t in e.state.env:Y(e,n)}return!!(t in e.state.env||ye(e,t))}async function gn(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 mt(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);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);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 Ce=1e4;function as(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<Ce;u+=i,f++)l.push(c(u));else for(let u=e,f=0;u>=t&&f<Ce;u-=i,f++)l.push(c(u));return l}function os(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 kt(`{${e}..${t}${h}}: invalid sequence`)}let f=[];if(n<=a)for(let h=n,d=0;h<=a&&d<Ce;h+=i,d++)f.push(String.fromCharCode(h));else for(let h=n,d=0;h>=a&&d<Ce;h-=i,d++)f.push(String.fromCharCode(h));return f}function gt(e,t,r,s,n){let a=r!==void 0?`..${r}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:as(e,t,r,s,n),literal:`{${e}..${t}${a}}`}:typeof e=="string"&&typeof t=="string"?{expanded:os(e,t,r),literal:`{${e}..${t}${a}}`}:{expanded:null,literal:`{${e}..${t}${a}}`}}function yn(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 ee(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function yt(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 U(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function Et(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=ls(e,n+1);if(i!==-1){let l=e.slice(n+2,i),c=us(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=cs(e,n);if(i===-1)s+="\\[",n++;else{let l=e.slice(n+1,i);s+=fs(l),n=i+1}}else/[\^$.|+(){}]/.test(a)?(s+=`\\${a}`,n++):(s+=a,n++)}return s}function ls(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 us(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 cs(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 fs(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+=hs(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 ps={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 hs(e){return ps[e]??""}function ne(e,t,r,s){if(r==="prefix")return e.replace(new RegExp(`^${t}`,"s"),"");let n=new RegExp(`${t}$`,"s");if(s)return e.replace(n,"");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 ce(e,t){let r=Object.keys(e.state.env),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 ds(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 Ee(e,t){let r="",s=0,n=e.state.env.USER||e.state.env.LOGNAME||"user",a=e.state.env.HOSTNAME||"localhost",i=a.split(".")[0],l=e.state.env.PWD||"/",o=e.state.env.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"],y=e.state.env.__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 S="",m=s+1;for(;m<t.length&&m<s+4&&t[m]>="0"&&t[m]<="7";)S+=t[m],m++;let A=Number.parseInt(S,8)%256;r+=String.fromCharCode(A),s=m;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+=`
|
|
62
|
+
`,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 S=String(f.getDate()).padStart(2," ");r+=`${h[f.getDay()]} ${d[f.getMonth()]} ${S}`,s+=2;break}case"t":{let S=String(f.getHours()).padStart(2,"0"),m=String(f.getMinutes()).padStart(2,"0"),A=String(f.getSeconds()).padStart(2,"0");r+=`${S}:${m}:${A}`,s+=2;break}case"T":{let S=f.getHours()%12;S===0&&(S=12);let m=String(S).padStart(2,"0"),A=String(f.getMinutes()).padStart(2,"0"),w=String(f.getSeconds()).padStart(2,"0");r+=`${m}:${A}:${w}`,s+=2;break}case"@":{let S=f.getHours()%12;S===0&&(S=12);let m=String(S).padStart(2,"0"),A=String(f.getMinutes()).padStart(2,"0"),w=f.getHours()<12?"AM":"PM";r+=`${m}:${A} ${w}`,s+=2;break}case"A":{let S=String(f.getHours()).padStart(2,"0"),m=String(f.getMinutes()).padStart(2,"0");r+=`${S}:${m}`,s+=2;break}case"D":if(s+2<t.length&&t[s+2]==="{"){let S=t.indexOf("}",s+3);if(S!==-1){let m=t.slice(s+3,S);r+=ds(m,f),s=S+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+=y,s+=2;break;case"!":r+=y,s+=2;break;case"x":r+="\\x",s+=2;break;default:r+=`\\${E}`,s+=2}}else r+=g,s++}return r}function ie(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`
|
|
63
|
+
`: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 ia(e,t){e.state.readonlyVars=e.state.readonlyVars||new Set,e.state.readonlyVars.add(t)}function At(e,t){return e.state.readonlyVars?.has(t)??!1}function aa(e,t,r="bash"){if(At(e,t)){let s=`${r}: ${t}: readonly variable
|
|
64
|
+
`;throw new G(1,"",s)}return null}function oa(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 la(e,t){e.state.exportedVars?.delete(t)}function ae(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let r="",s=e.state.env[`${t}__length`]!==void 0||Object.keys(e.state.env).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"),C(e,t)&&(r+="n"),At(e,t)&&(r+="r"),e.state.exportedVars?.has(t)&&(r+="x"),r}async function En(e,t,r,s){return(r.isUnset||t.checkEmpty&&r.isEmpty)&&t.word?s(e,t.word.parts,r.inDoubleQuotes):r.effectiveValue}async function An(e,t,r,s,n){if((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 T,d=W(h,c);u=await R(e,d.expression)}catch{let h=e.state.env[c];u=h?Number.parseInt(h,10):0}Number.isNaN(u)&&(u=0)}e.state.env[`${o}_${u}`]=i;let f=Number.parseInt(e.state.env[`${o}__length`]||"0",10);u>=f&&(e.state.env[`${o}__length`]=String(u+1))}else e.state.env[t]=i;return i}return s.effectiveValue}async function Sn(e,t,r,s,n){if(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 G(1,"",`bash: ${i}
|
|
65
|
+
`)}return s.effectiveValue}async function bn(e,t,r,s){return!(r.isUnset||t.checkEmpty&&r.isEmpty)&&t.word?s(e,t.word.parts,r.inDoubleQuotes):""}async function wn(e,t,r,s,n){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 t.replace(new RegExp(`^${a}`,"s"),"");let l=new RegExp(`${a}$`,"s");if(r.greedy)return t.replace(l,"");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 Nn(e,t,r,s,n){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=new RegExp(a,o);if(r.all){let u="",f=0,h=c.exec(t);for(;h!==null&&!(h[0].length===0&&h.index===t.length);)u+=t.slice(f,h.index)+l,f=h.index+h[0].length,h[0].length===0&&f++,h=c.exec(t);return u+=t.slice(f),u}return t.replace(c,l)}catch{return t}}function kn(e,t,r){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[n]!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&ye(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[`${t}_0`]||"";return String([...n].length)}return String([...r].length)}async function Pn(e,t,r,s){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["#"]||"0",10),u=[];for(let y=1;y<=c;y++)u.push(e.state.env[String(y)]||"");let f=e.state.env[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 y=a<0?h.length+a:d+a;return h.slice(d,Math.max(d,y)).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 G(1,"",`bash: \${${c}[@]: 0: 3}: bad substitution
|
|
66
|
+
`);let u=P(e,c),f=0;if(n<0){if(u.length>0){let h=u[u.length-1][0],y=(typeof h=="number"?h:0)+1+n;if(y<0||(f=u.findIndex(([g])=>typeof g=="number"&&g>=y),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 _(`${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 Rn(e,t,r,s,n){if(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=new RegExp(`^(?:${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 In(e,t,r,s,n){let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(a&&n.operator==="Q")return P(e,a[1]).map(([,c])=>ie(c)).join(" ");if(a&&n.operator==="a")return ae(e,a[1]);let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(i&&n.operator==="a")return ae(e,i[1]);switch(n.operator){case"Q":return s?"":ie(r);case"P":return Ee(e,r);case"a":return ae(e,t);case"A":return s?"":`${t}=${ie(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`
|
|
67
|
+
`;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?"":ie(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 vn(e,t,r,s,n,a,i=!1){if(C(e,t))return ge(e,t)||"";let l=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(s){if(n.innerOp?.type==="UseAlternative")return"";throw new te(`\${!${t}}`)}let o=r;if(l&&(o===""||o.includes(" ")))throw new te(`\${!${t}}`);let c=o.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(c&&c[1].includes("~"))throw new te(`\${!${t}}`);if(n.innerOp){let u={type:"ParameterExpansion",parameter:o,operation:n.innerOp};return a(e,u,i)}return await v(e,o)}function Dn(e,t){let s=P(e,t.array).map(([n])=>String(n));return t.star?s.join(N(e.state.env)):s.join(" ")}function xn(e,t){let r=ce(e,t.prefix);return t.star?r.join(N(e.state.env)):r.join(" ")}function $n(e,t,r,s){let n=Number.parseInt(e.state.env["#"]||"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[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 _n(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 Cn(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 Oe(e,t){let r=new T,s;try{s=r.parse(t)}catch{return""}let n=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let a={...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["?"]=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 we)throw o;return o instanceof G?(e.state.lastExitCode=o.exitCode,e.state.env["?"]=String(o.exitCode),o.stdout?.replace(/\n+$/,"")??""):""}}function St(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+=U(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=ms(e,l);r+=U(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[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[l]??"",s=i;continue}}if(n==="\\"&&s+1<t.length){r+=n+t[s+1],s+=2;continue}r+=n,s++}return r}function ms(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[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[l]??"",s=i;continue}}r+=n,s++}return r}async function On(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+=U(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 gs(e,l);r+=U(o),s=a+1;continue}}if(n==="$"&&s+1<t.length&&t[s+1]==="("){let a=Cn(t,s+2);if(a!==-1){let i=t.slice(s+2,a),l=await Oe(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 Oe(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[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[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 gs(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=Cn(t,s+2);if(a!==-1){let i=t.slice(s+2,a),l=await Oe(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 Oe(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[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[l]??"",s=i;continue}}r+=n,s++}return r}function Ln(e,t){if(!t.startsWith("~"))return t;let r=e.state.env.HOME!==void 0?e.state.env.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 ys(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 Wn(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[l];E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let h="";c.pattern&&(h=await ys(e,c.pattern,r,s));let d=c.replacement?await r(e,c.replacement.parts):"",y=h;c.anchor==="start"?y=`^${h}`:c.anchor==="end"&&(y=`${h}$`);let g=[];try{let E=new RegExp(y,c.all?"g":"");for(let S of f)g.push(S.replace(E,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 Tn(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[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 y=[];for(let g of f)y.push(ne(g,h,c.side,c.greedy));if(o){let g=N(e.state.env);return{values:[y.join(g)],quoted:!0}}return{values:y,quoted:!0}}async function Mn(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[o]!==void 0,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 y=c.map(([,g])=>g);if(l){let g=N(e.state.env);return{values:[y.join(g)],quoted:!0}}return{values:y,quoted:!0}}let d=e.state.env[o];return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}else{let o=s.parameter,c=await Y(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(([,y])=>y);if(u||l){let y=N(e.state.env);return{values:[d.join(y)],quoted:!0}}return{values:d,quoted:!0}}let h=e.state.env[c];return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}}return null}async function Vn(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 S=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(S){i=g,l=S[1],o=S[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[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="",S=e.state.shoptOptions.extglob;if(g.pattern)for(let m of g.pattern.parts)if(m.type==="Glob")E+=k(m.pattern,g.greedy,S);else if(m.type==="Literal")E+=k(m.value,g.greedy,S);else if(m.type==="SingleQuoted"||m.type==="Escaped")E+=I(m.value);else if(m.type==="DoubleQuoted"){let A=await n(e,m.parts);E+=I(A)}else if(m.type==="ParameterExpansion"){let A=await s(e,m);E+=k(A,g.greedy,S)}else{let A=await s(e,m);E+=I(A)}d=d.map(m=>ne(m,E,g.side,g.greedy))}else if(c?.type==="PatternReplacement"){let g=c,E="";if(g.pattern)for(let A of g.pattern.parts)if(A.type==="Glob")E+=k(A.pattern,!0,e.state.shoptOptions.extglob);else if(A.type==="Literal")E+=k(A.value,!0,e.state.shoptOptions.extglob);else if(A.type==="SingleQuoted"||A.type==="Escaped")E+=I(A.value);else if(A.type==="DoubleQuoted"){let w=await n(e,A.parts);E+=I(w)}else if(A.type==="ParameterExpansion"){let w=await s(e,A);E+=k(w,!0,e.state.shoptOptions.extglob)}else{let w=await s(e,A);E+=I(w)}let S=g.replacement?await n(e,g.replacement.parts):"",m=E;g.anchor==="start"?m=`^${E}`:g.anchor==="end"&&(m=`${E}$`);try{let A=new RegExp(m,g.all?"g":"");d=d.map(w=>w.replace(A,S))}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 y=n.parts[d];if(y.type==="ParameterExpansion"&&!y.operation){let g=y.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[i];if(d!==void 0)return{values:[o+d+c],quoted:!0};if(l)return{values:[o+c],quoted:!0};let y=o+c;return{values:y?[y]:[],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 Bn(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 G(1,"",`bash: \${${i}[@]: 0: 3}: bad substitution
|
|
68
|
+
`);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 y=f[f.length-1][0],E=(typeof y=="number"?y:0)+1+c;if(E<0)return{values:[],quoted:!0};h=f.findIndex(([S])=>typeof S=="number"&&S>=E),h<0&&(h=f.length)}}else h=f.findIndex(([y])=>typeof y=="number"&&y>=c),h<0&&(h=f.length);let d;if(u!==void 0){if(u<0)throw new _(`${i}[@]: substring expression < 0`);d=f.slice(h,h+u).map(([,y])=>y)}else d=f.slice(h).map(([,y])=>y);if(d.length===0)return{values:[],quoted:!0};if(l){let y=N(e.state.env);return{values:[d.join(y)],quoted:!0}}return{values:d,quoted:!0}}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!=="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[a];if(f!==void 0){let h;switch(l.operator){case"a":h="";break;case"P":h=Ee(e,f);break;case"Q":h=ie(f);break;default:h=f}return{values:[h],quoted:!0}}return i?{values:[""],quoted:!0}:{values:[],quoted:!0}}let c=ae(e,a),u;switch(l.operator){case"a":u=o.map(()=>c);break;case"P":u=o.map(([,f])=>Ee(e,f));break;case"Q":u=o.map(([,f])=>ie(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 Qn(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(C(e,a)){let o=ge(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[a];return l!==void 0?{values:[l],quoted:!0}:{values:[],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)return null;let n=r.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||!C(e,n))return null;let a=ge(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[l];return c!==void 0?{values:[c],quoted:!0}:{values:[],quoted:!0}}async function Zn(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 y=Number.parseInt(e.state.env["#"]||"0",10),g=[];for(let E=1;E<=y;E++)g.push(e.state.env[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 Es(e,h,u,f,l.innerOp);if(l.innerOp.type==="DefaultValue"||l.innerOp.type==="UseAlternative"||l.innerOp.type==="AssignDefault"||l.innerOp.type==="ErrorIfUnset")return As(e,h,u,f,l.innerOp,n);if(l.innerOp.type==="Transform"&&l.innerOp.operator==="a"){let g=ae(e,u),E=h.map(()=>g);return f?{values:[E.join(N(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let y=[];for(let[,g]of h){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:l.innerOp},S=e.state.env._indirect_elem_;e.state.env._indirect_elem_=g;try{let m=await s(e,E,!0);y.push(m)}finally{S!==void 0?e.state.env._indirect_elem_=S:delete e.state.env._indirect_elem_}}return f?{values:[y.join(N(e.state.env))],quoted:!0}:{values:y,quoted:!0}}if(h.length>0){let y=h.map(([,g])=>g);return f?{values:[y.join(N(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let d=e.state.env[u];return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}async function Es(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 _(`${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 As(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[`${r}_0`]=f,e.state.env[`${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 Gn(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 Y(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],y=o[2]==="*",g=P(e,d);if(g.length>0){let S=g.map(([,m])=>m);return y?{values:[S.join(N(e.state.env))],quoted:!0}:{values:S,quoted:!0}}let E=e.state.env[d];return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function Un(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 Y(e,r.parameter),h=u==="",d=n.checkEmpty??!1,y;if(n.type==="UseAlternative"?y=f&&!(d&&h):y=!f||d&&h,y){let g=c[1],E=c[2]==="*",S=P(e,g);if(S.length>0){let A=S.map(([,w])=>w);return E?{values:[A.join(N(e.state.env))],quoted:!0}:{values:A,quoted:!0}}let m=e.state.env[g];return m!==void 0?{values:[m],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function jn(e){let t=Number.parseInt(e.state.env["#"]||"0",10),r=[];for(let s=1;s<=t;s++)r.push(e.state.env[String(s)]||"");return r}async function Hn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let m=0;m<n.parts.length;m++){let A=n.parts[m];if(A.type==="ParameterExpansion"&&(A.parameter==="@"||A.parameter==="*")&&A.operation?.type==="Substring"){a=m,i=A.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["#"]||"0",10),h=[];for(let m=1;m<=f;m++)h.push(e.state.env[String(m)]||"");let d=e.state.env[0]||"bash",y;if(c<=0){let m=[d,...h],A=m.length+c;if(A<0)y=[];else{let w=c<0?A:0;if(u!==void 0){let L=u<0?m.length+u:w+u;y=m.slice(w,Math.max(w,L))}else y=m.slice(w)}}else{let m=c-1;if(m>=h.length)y=[];else if(u!==void 0){let A=u<0?h.length+u:m+u;y=h.slice(m,Math.max(m,A))}else y=h.slice(m)}let g="";for(let m=0;m<a;m++)g+=await s(e,n.parts[m]);let E="";for(let m=a+1;m<n.parts.length;m++)E+=await s(e,n.parts[m]);if(y.length===0){let m=g+E;return{values:m?[m]:[],quoted:!0}}if(i){let m=N(e.state.env);return{values:[g+y.join(m)+E],quoted:!0}}return y.length===1?{values:[g+y[0]+E],quoted:!0}:{values:[g+y[0],...y.slice(1,-1),y[y.length-1]+E],quoted:!0}}async function Kn(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 m=n.parts[S];if(m.type==="ParameterExpansion"&&(m.parameter==="@"||m.parameter==="*")&&m.operation?.type==="PatternReplacement"){a=S,i=m.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,c=jn(e),u="";for(let S=0;S<a;S++)u+=await r(e,n.parts[S]);let f="";for(let S=a+1;S<n.parts.length;S++)f+=await r(e,n.parts[S]);if(c.length===0){let S=u+f;return{values:S?[S]:[],quoted:!0}}let h="";if(o.pattern)for(let S of o.pattern.parts)if(S.type==="Glob")h+=k(S.pattern,!0,e.state.shoptOptions.extglob);else if(S.type==="Literal")h+=k(S.value,!0,e.state.shoptOptions.extglob);else if(S.type==="SingleQuoted"||S.type==="Escaped")h+=I(S.value);else if(S.type==="DoubleQuoted"){let m=await s(e,S.parts);h+=I(m)}else if(S.type==="ParameterExpansion"){let m=await r(e,S);h+=k(m,!0,e.state.shoptOptions.extglob)}else{let m=await r(e,S);h+=I(m)}let d=o.replacement?await s(e,o.replacement.parts):"",y=h;o.anchor==="start"?y=`^${h}`:o.anchor==="end"&&(y=`${h}$`);let g=[];try{let S=new RegExp(y,o.all?"g":"");for(let m of c)g.push(m.replace(S,d))}catch{g.push(...c)}if(i){let S=N(e.state.env);return{values:[u+g.join(S)+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 Xn(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 S=n.parts[E];if(S.type==="ParameterExpansion"&&(S.parameter==="@"||S.parameter==="*")&&S.operation?.type==="PatternRemoval"){a=E,i=S.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 S=await s(e,E.parts);h+=I(S)}else if(E.type==="ParameterExpansion"){let S=await r(e,E);h+=k(S,o.greedy,d)}else{let S=await r(e,E);h+=I(S)}let y=[];for(let E of c)y.push(ne(E,h,o.side,o.greedy));if(i){let E=N(e.state.env);return{values:[u+y.join(E)+f],quoted:!0}}return y.length===1?{values:[u+y[0]+f],quoted:!0}:{values:[u+y[0],...y.slice(1,-1),y[y.length-1]+f],quoted:!0}}async function Jn(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["#"]||"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[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 Ss(e){return new se(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})}async function Le(e,t){if(e.state.options.noglob)return t;let r=Ss(e),s=[];for(let n of t)if(ee(n,e.state.shoptOptions.extglob)){let a=await r.expand(n);if(a.length>0)s.push(...a);else{if(r.hasFailglob())throw new be(n);r.hasNullglob()||s.push(n)}}else s.push(n);return s}async function Yn(e,t,r,s){let n=-1,a="",i=!1;for(let m=0;m<t.length;m++){let A=t[m];if(A.type==="ParameterExpansion"&&A.operation?.type==="PatternReplacement"){let w=A.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(w){n=m,a=w[1],i=w[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,c=P(e,a),u=c.map(([,m])=>m);if(c.length===0){let m=e.state.env[a];m!==void 0&&(u=[m])}if(u.length===0)return{values:[],quoted:!1};let f="";if(o.pattern)for(let m of o.pattern.parts)if(m.type==="Glob")f+=k(m.pattern,!0,e.state.shoptOptions.extglob);else if(m.type==="Literal")f+=k(m.value,!0,e.state.shoptOptions.extglob);else if(m.type==="SingleQuoted"||m.type==="Escaped")f+=I(m.value);else if(m.type==="DoubleQuoted"){let A=await r(e,m.parts);f+=I(A)}else if(m.type==="ParameterExpansion"){let A=await s(e,m);f+=k(A,!0,e.state.shoptOptions.extglob)}else{let A=await s(e,m);f+=I(A)}let h=o.replacement?await r(e,o.replacement.parts):"",d=f;o.anchor==="start"?d=`^${f}`:o.anchor==="end"&&(d=`${f}$`);let y=[];try{let m=new RegExp(d,o.all?"g":"");for(let A of u)y.push(A.replace(m,h))}catch{y.push(...u)}let g=O(e.state.env),E=M(e.state.env);if(i){let m=N(e.state.env),A=y.join(m);return E?{values:A?[A]:[],quoted:!1}:{values:D(A,g),quoted:!1}}if(E)return{values:y,quoted:!1};let S=[];for(let m of y)m===""?S.push(""):S.push(...D(m,g));return{values:S,quoted:!1}}async function er(e,t,r,s){let n=-1,a="",i=!1;for(let S=0;S<t.length;S++){let m=t[S];if(m.type==="ParameterExpansion"&&m.operation?.type==="PatternRemoval"){let A=m.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(A){n=S,a=A[1],i=A[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[a];S!==void 0&&(u=[S])}if(u.length===0)return{values:[],quoted:!1};let f="",h=e.state.shoptOptions.extglob;if(o.pattern)for(let S of o.pattern.parts)if(S.type==="Glob")f+=k(S.pattern,o.greedy,h);else if(S.type==="Literal")f+=k(S.value,o.greedy,h);else if(S.type==="SingleQuoted"||S.type==="Escaped")f+=I(S.value);else if(S.type==="DoubleQuoted"){let m=await r(e,S.parts);f+=I(m)}else if(S.type==="ParameterExpansion"){let m=await s(e,S);f+=k(m,o.greedy,h)}else{let m=await s(e,S);f+=I(m)}let d=[];for(let S of u)d.push(ne(S,f,o.side,o.greedy));let y=O(e.state.env),g=M(e.state.env);if(i){let S=N(e.state.env),m=d.join(S);return g?{values:m?[m]:[],quoted:!1}:{values:D(m,y),quoted:!1}}if(g)return{values:d,quoted:!1};let E=[];for(let S of d)S===""?E.push(""):E.push(...D(S,y));return{values:E,quoted:!1}}async function tr(e,t,r,s){let n=-1,a=!1;for(let E=0;E<t.length;E++){let S=t[E];if(S.type==="ParameterExpansion"&&(S.parameter==="@"||S.parameter==="*")&&S.operation?.type==="PatternRemoval"){n=E,a=S.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=Number.parseInt(e.state.env["#"]||"0",10),c=[];for(let E=1;E<=o;E++)c.push(e.state.env[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 S=await r(e,E.parts);u+=I(S)}else if(E.type==="ParameterExpansion"){let S=await s(e,E);u+=k(S,l.greedy,f)}else{let S=await s(e,E);u+=I(S)}let h=[];for(let E of c)h.push(ne(E,u,l.side,l.greedy));let d=O(e.state.env),y=M(e.state.env);if(a){let E=N(e.state.env),S=h.join(E);return y?{values:S?[S]:[],quoted:!1}:{values:D(S,d),quoted:!1}}if(y)return{values:h,quoted:!1};let g=[];for(let E of h)E===""?g.push(""):g.push(...D(E,d));return{values:g,quoted:!1}}async function nr(e,t,r,s){let n=-1,a=!1;for(let A=0;A<t.length;A++){let w=t[A];if(w.type==="ParameterExpansion"&&(w.parameter==="@"||w.parameter==="*")&&w.operation?.type==="Substring"){n=A,a=w.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["#"]||"0",10),f=[];for(let A=1;A<=u;A++)f.push(e.state.env[String(A)]||"");let h=e.state.env[0]||"bash",d;if(o<=0){let A=[h,...f],w=A.length+o;if(w<0)d=[];else{let L=o<0?w:0;if(c!==void 0){let H=c<0?A.length+c:L+c;d=A.slice(L,Math.max(L,H))}else d=A.slice(L)}}else{let A=o-1;if(A>=f.length)d=[];else if(c!==void 0){let w=c<0?f.length+c:A+c;d=f.slice(A,Math.max(A,w))}else d=f.slice(A)}let y="";for(let A=0;A<n;A++)y+=await s(e,t[A]);let g="";for(let A=n+1;A<t.length;A++)g+=await s(e,t[A]);let E=O(e.state.env),S=M(e.state.env);if(d.length===0){let A=y+g;return A?S?{values:[A],quoted:!1}:{values:D(A,E),quoted:!1}:{values:[],quoted:!1}}let m;if(a){let A=N(e.state.env),w=y+d.join(A)+g;S?m=w?[w]:[]:m=D(w,E)}else if(S)d.length===1?m=[y+d[0]+g]:m=[y+d[0],...d.slice(1,-1),d[d.length-1]+g];else{m=[];for(let A=0;A<d.length;A++){let w=d[A];if(A===0&&(w=y+w),A===d.length-1&&(w=w+g),w==="")m.push("");else{let L=D(w,E);m.push(...L)}}}return{values:await Le(e,m),quoted:!1}}async function rr(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["#"]||"0",10);if(s===0)return{values:[],quoted:!1};let n=[];for(let c=1;c<=s;c++)n.push(e.state.env[String(c)]||"");let a=O(e.state.env),i=M(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=D(u,a)}else if(i)o=n.filter(c=>c!=="");else if(l){o=[];for(let c of n){if(c==="")continue;let u=D(c,a);o.push(...u)}}else{o=[];for(let c of n)if(c==="")o.push("");else{let u=D(c,a);o.push(...u)}for(;o.length>0&&o[o.length-1]==="";)o.pop()}return{values:await Le(e,o),quoted:!1}}async function sr(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[s];if(f!==void 0)i=[f];else return{values:[],quoted:!1}}else i=a.map(([,f])=>f);let l=O(e.state.env),o=M(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=D(h,l)}else if(o)u=i.filter(f=>f!=="");else if(c){u=[];for(let f of i){if(f==="")continue;let h=D(f,l);u.push(...h)}}else{u=[];for(let f of i)if(f==="")u.push("");else{let h=D(f,l);u.push(...h)}for(;u.length>0&&u[u.length-1]==="";)u.pop()}return{values:await Le(e,u),quoted:!1}}function ir(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let r=t[0].operation,s=ce(e,r.prefix);if(s.length===0)return{values:[],quoted:!1};let n=O(e.state.env),a=M(e.state.env),i;if(r.star)if(a)i=s;else{let l=N(e.state.env),o=s.join(l);i=D(o,n)}else if(a)i=s;else{i=[];for(let l of s){let o=D(l,n);i.push(...o)}}return{values:i,quoted:!1}}function ar(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=O(e.state.env),i=M(e.state.env),l;if(r.star)if(i)l=n;else{let o=N(e.state.env),c=n.join(o);l=D(c,a)}else if(i)l=n;else{l=[];for(let o of n){let c=D(o,a);l.push(...c)}}return{values:l,quoted:!1}}async function or(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["#"]||"0",10),a=[];for(let h=1;h<=n;h++)a.push(e.state.env[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=O(e.state.env),c=M(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 y=a[d];d===0&&(y=i+y),d===a.length-1&&(y=y+l),h.push(y)}if(c)f=h.filter(d=>d!=="");else if(u){f=[];for(let d of h){if(d==="")continue;let y=D(d,o);f.push(...y)}}else{f=[];for(let d of h)if(d==="")f.push("");else{let y=D(d,o);f.push(...y)}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Le(e,f),quoted:!1}}async function cr(e,t,r){let s=t.parts,{hasQuoted:n,hasCommandSub:a,hasArrayVar:i,hasArrayAtExpansion:l,hasParamExpansion:o,hasVarNamePrefixExpansion:c,hasIndirection:u}=de(s),h=r.hasBraceExpansion(s)?await r.expandWordWithBracesAsync(e,t):null;if(h&&h.length>1)return bs(e,h,n);let d=await ws(e,s,l,c,u,r);if(d!==null)return d;let y=await ks(e,s,r);if(y!==null)return y;let g=await Ps(e,s,r);if(g!==null)return g;let E=await Is(e,s,r.expandPart);if(E!==null)return ur(e,E);if((a||i||o)&&!M(e.state.env)){let m=O(e.state.env),A=r.buildIfsCharClassPattern(m),w=await r.smartWordSplit(e,s,m,A,r.expandPart);return ur(e,w)}let S=await r.expandWordAsync(e,t);return vs(e,t,s,S,n,r.expandWordForGlobbing)}async function bs(e,t,r){let s=[];for(let n of t)if(!(!r&&n===""))if(!r&&!e.state.options.noglob&&ee(n,e.state.shoptOptions.extglob)){let a=await We(e,n);s.push(...a)}else s.push(n);return{values:s,quoted:!1}}async function ws(e,t,r,s,n,a){if(r){let i=Qn(e,t);if(i!==null)return i}{let i=zn(e,t);if(i!==null)return i}{let i=await Mn(e,t);if(i!==null)return i}{let i=await Vn(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 Bn(e,t,a.evaluateArithmetic);if(i!==null)return i}{let i=Fn(e,t);if(i!==null)return i}{let i=await Wn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}{let i=await Tn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}if(s&&t.length===1&&t[0].type==="DoubleQuoted"){let i=Ns(e,t);if(i!==null)return i}{let i=await Zn(e,t,n,a.expandParameterAsync,a.expandWordPartsAsync);if(i!==null)return i}{let i=await Gn(e,t);if(i!==null)return i}{let i=await Un(e,t);if(i!==null)return i}return null}function Ns(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=ce(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 ks(e,t,r){{let s=await Hn(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await Kn(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await Xn(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await Jn(e,t,r.expandPart);if(s!==null)return s}return null}async function Ps(e,t,r){{let s=await Yn(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await er(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await tr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await nr(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await rr(e,t);if(s!==null)return s}{let s=await sr(e,t);if(s!==null)return s}{let s=ir(e,t);if(s!==null)return s}{let s=ar(e,t);if(s!==null)return s}{let s=await or(e,t,r.expandPart);if(s!==null)return s}return null}function lr(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 Rs(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[r.name];o!==void 0&&(i=[o])}}else{let l=Number.parseInt(e.state.env["#"]||"0",10);i=[];for(let o=1;o<=l;o++)i.push(e.state.env[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 Is(e,t,r){if(t.length<2)return null;let s=!1;for(let o of t)if(lr(o)){s=!0;break}if(!s)return null;let n=O(e.state.env),a=M(e.state.env),i=[];for(let o of t){let c=lr(o);if(c&&o.type==="DoubleQuoted"){let u=await Rs(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=D(u,n);i.push(f)}}else{let u=await r(e,o);if(a)i.push(u?[u]:[]);else{let f=D(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 ur(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let r=[];for(let s of t)if(ee(s,e.state.shoptOptions.extglob)){let n=await We(e,s);r.push(...n)}else r.push(s);return{values:r,quoted:!1}}async function We(e,t){let r=new se(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}),s=await r.expand(t);if(s.length>0)return s;if(r.hasFailglob())throw new be(t);return r.hasNullglob()?[]:[t]}async function vs(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(ee(l,e.state.shoptOptions.extglob)){let c=await We(e,l);if(c.length>0&&c[0]!==l)return{values:c,quoted:!1};if(c.length===0)return{values:[],quoted:!1}}let o=yt(s);if(!M(e.state.env)){let c=O(e.state.env);return{values:D(o,c),quoted:!1}}return{values:[o],quoted:!1}}if(!n&&!e.state.options.noglob&&ee(s,e.state.shoptOptions.extglob)){let l=await a(e,t);if(ee(l,e.state.shoptOptions.extglob)){let o=await We(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=yt(s);if(!M(e.state.env)){let o=O(e.state.env);return{values:D(l,o),quoted:!1}}return{values:[l],quoted:!1}}return{values:[s],quoted:n}}async function pr(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 Y(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 Ds(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(r=>r.type==="Literal"):!1}async function xs(e,t){if(t.type!=="ParameterExpansion")return null;let r=await pr(e,t);if(!r||r.length<=1)return null;let s=r.some(a=>Ds(a)),n=r.some(a=>a.type==="Literal"||a.type==="ParameterExpansion"||a.type==="CommandSubstitution"||a.type==="ArithmeticExpansion");return s&&n?r:null}function $s(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?ft(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&fn(e))}async function hr(e,t,r,s,n){if(t.length===1&&t[0].type==="ParameterExpansion"){let h=t[0],d=await pr(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 fr(e,d,r,s,n)}let a=[],i=!1;for(let h of t){let d=$s(h),y=h.type==="DoubleQuoted"||h.type==="SingleQuoted",g=d?await xs(e,h):null,E=await n(e,h);a.push({value:E,isSplittable:d,isQuoted:y,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 fr(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 y=1;y<d.length-1;y++)l.push(d[y]);o=d[d.length-1]}u=!1,f=!1}else{let{words:d,hadLeadingDelimiter:y,hadTrailingDelimiter:g}=_e(h.value,r);if(f&&y&&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 _s(e,t){return e.length>0&&t.includes(e[0])}async function fr(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{_s(u.value,r)&&l!==""&&(i.push(l),l="",o=!0);let{words:h,hadTrailingDelimiter:d}=_e(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 y=1;y<h.length-1;y++)i.push(h[y]);l=h[h.length-1],c=d}}return l!==""?i.push(l):i.length===0&&o&&i.push(""),i}function dr(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function mr(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}async function j(e,t,r=!1){let s=[];for(let n of t)s.push(await z(e,n,r));return s.join("")}function Cs(e){return mr(e)}function al(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!Cs(t))return!1;return!0}function Os(e,t,r=!1){let s=dr(t);if(s!==null)return s;switch(t.type){case"TildeExpansion":return r?t.user===null?"~":`~${t.user}`:t.user===null?e.state.env.HOME!==void 0?e.state.env.HOME:"/home/user":t.user==="root"?"/root":`~${t.user}`;case"Glob":return St(e,t.pattern);default:return null}}async function wt(e,t){return Nt(e,t)}async function ol(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 z(e,s);r.push(Et(n))}else r.push(await z(e,s));return r.join("")}async function ll(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(U(s.value));else if(s.type==="DoubleQuoted"){let n=await j(e,s.parts);r.push(U(n))}else r.push(await z(e,s));return r.join("")}async function gr(e,t){let r=[];for(let s of t.parts)if(s.type==="SingleQuoted")r.push(U(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(U(n))}else s.type==="Glob"?_n(s.pattern)?r.push(await On(e,s.pattern)):r.push(St(e,s.pattern)):s.type==="Literal"?r.push(s.value):r.push(await z(e,s));return r.join("")}function Me(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&Me(t.parts))return!0;return!1}var Ls=1e4,bt=1e5;async function yr(e,t,r={count:0}){if(r.count>bt)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=gt(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 yr(e,u.word.parts,r);for(let h of f){r.count++;let d=[];for(let y of h)typeof y=="string"?d.push(y):d.push(await z(e,y));a.push(d.join(""))}}if(i){for(let u of s)r.count++,u.push(l);continue}if(s.length*a.length>Ls||r.count>bt)return s;let c=[];for(let u of s)for(let f of a){if(r.count++,r.count>bt)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 Er(e,t){let r=t.parts;if(!Me(r))return[await wt(e,t)];let s=await yr(e,r),n=[];for(let a of s){let i=[];for(let l of a)typeof l=="string"?i.push(l):i.push(await z(e,l));n.push(Ln(e,i.join("")))}return n}function Ws(){return{expandWordAsync:Nt,expandWordForGlobbing:gr,expandWordWithBracesAsync:Er,expandWordPartsAsync:j,expandPart:z,expandParameterAsync:Te,hasBraceExpansion:Me,evaluateArithmetic:R,buildIfsCharClassPattern:dn,smartWordSplit:hr}}async function ul(e,t){return cr(e,t,Ws())}function Ts(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Ms(e,t){if(Number.parseInt(e.state.env["#"]||"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 cl(e,t){if(Ms(e,t))return{error:`bash: $@: ambiguous redirect
|
|
69
|
+
`};let r=t.parts,{hasQuoted:s}=de(r);if(Me(r)&&(await Er(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
|
|
70
|
+
`};let n=await Nt(e,t),{hasParamExpansion:a,hasCommandSub:i}=de(r);if((a||i)&&!s&&!M(e.state.env)){let f=O(e.state.env);if(D(n,f).length>1)return{error:`bash: $${Ts(r)}: ambiguous redirect
|
|
71
|
+
`}}if(s||e.state.options.noglob)return{target:n};let o=await gr(e,t);if(!ee(o,e.state.shoptOptions.extglob))return{target:n};let c=new se(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}),u=await c.expand(o);return u.length===0?c.hasFailglob()?{error:`bash: no match: ${n}
|
|
72
|
+
`}:{target:n}:u.length===1?{target:u[0]}:{error:`bash: ${n}: ambiguous redirect
|
|
73
|
+
`}}async function Nt(e,t){let r=t.parts,s=r.length;if(s===1)return z(e,r[0]);let n=[];for(let a=0;a<s;a++)n.push(await z(e,r[a]));return n.join("")}async function z(e,t,r=!1){if(t.type==="ParameterExpansion")return Te(e,t,r);let s=Os(e,t,r);if(s!==null)return s;switch(t.type){case"DoubleQuoted":{let n=[];for(let a of t.parts)n.push(await z(e,a,!0));return n.join("")}case"CommandSubstitution":{let n=yn(t.body);if(n)try{let c=await wt(e,n.target),u=c.startsWith("/")?c:`${e.state.cwd}/${c}`,f=await e.fs.readFile(u);return e.state.lastExitCode=0,e.state.env["?"]="0",f.replace(/\n+$/,"")}catch{return e.state.lastExitCode=1,e.state.env["?"]="1",""}let a=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let i={...e.state.env},l=e.state.cwd,o=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let c=await e.executeScript(t.body),u=c.exitCode;return e.state.env=i,e.state.cwd=l,e.state.suppressVerbose=o,e.state.lastExitCode=u,e.state.env["?"]=String(u),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr),e.state.bashPid=a,c.stdout.replace(/\n+$/,"")}catch(c){if(e.state.env=i,e.state.cwd=l,e.state.bashPid=a,e.state.suppressVerbose=o,c instanceof we)throw c;if(c instanceof G)return e.state.lastExitCode=c.exitCode,e.state.env["?"]=String(c.exitCode),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr),c.stdout.replace(/\n+$/,"");throw c}}case"ArithmeticExpansion":{let n=t.expression.originalText;if(n&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(n)){let i=await gn(e,n),l=new T,o=W(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=gt(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 wt(e,a.word));return n.join(" ")}default:return""}}async function Te(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 mt(e,d);s=`${h}[${g}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&C(e,s)){let h=le(e,s);if(h&&h!==s){let d=h.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(d){let[,y,g]=d;if(e.state.associativeArrays?.has(y)||g.includes("$(")||g.includes("`")||g.includes("${")){let S=await mt(e,g);s=`${y}[${S}]`}}}}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 Y(e,s),{isEmpty:c,effectiveValue:u}=$n(e,s,l,r),f={value:l,isUnset:o,isEmpty:c,effectiveValue:u,inDoubleQuotes:r};switch(n.type){case"DefaultValue":return En(e,n,f,j);case"AssignDefault":return An(e,s,n,f,j);case"ErrorIfUnset":return Sn(e,s,n,f,j);case"UseAlternative":return bn(e,n,f,j);case"PatternRemoval":return wn(e,l,n,j,z);case"PatternReplacement":return Nn(e,l,n,j,z);case"Length":return kn(e,s,l);case"LengthSliceError":throw new te(s);case"BadSubstitution":throw new te(n.text);case"Substring":return Pn(e,s,l,n);case"CaseModification":return Rn(e,l,n,j,Te);case"Transform":return In(e,s,l,o,n);case"Indirection":return vn(e,s,l,o,n,Te,r);case"ArrayKeys":return Dn(e,n);case"VarNamePrefix":return xn(e,n);default:return l}}export{Ni as a,ki as b,he as c,Q as d,W as e,T as f,ci as g,pt as h,Ri as i,ht as j,Ii as k,hn as l,O as m,Di as n,xi as o,C as p,_i as q,Ci as r,Oi as s,Li as t,ss as u,le as v,ge as w,Wi as x,P as y,ye as z,v as A,U as B,Et as C,ia as D,At as E,aa as F,oa as G,la as H,al as I,wt as J,ol as K,ll as L,ul as M,Ms as N,cl as O,R as P};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function N(n,t){return n.replace(/\$(&|\d+|<([^>]+)>)/g,(e,i,s)=>{if(i==="&")return t[0];if(s!==void 0)return t.groups?.[s]??"";let h=parseInt(i,10);return t[h]??""})}function K(n,t,e={}){let{invertMatch:i=!1,showLineNumbers:s=!1,countOnly:h=!1,countMatches:d=!1,filename:a="",onlyMatching:m=!1,beforeContext:b=0,afterContext:R=0,maxCount:S=0,contextSeparator:G="--",showColumn:O=!1,vimgrep:T=!1,showByteOffset:P=!1,replace:k=null,passthru:y=!1,multiline:j=!1,kResetGroup:A}=e;if(j)return D(n,t,{invertMatch:i,showLineNumbers:s,countOnly:h,countMatches:d,filename:a,onlyMatching:m,beforeContext:b,afterContext:R,maxCount:S,contextSeparator:G,showColumn:O,showByteOffset:P,replace:k,kResetGroup:A});let x=n.split(`
|
|
2
|
+
`),Z=x.length,v=Z>0&&x[Z-1]===""?Z-1:Z;if(h||d){let f=0,r=(d||m)&&!i;for(let l=0;l<v;l++)if(t.lastIndex=0,r)for(let u=t.exec(x[l]);u!==null;u=t.exec(x[l]))f++,u[0].length===0&&t.lastIndex++;else t.test(x[l])!==i&&f++;return{output:`${a?`${a}:${f}`:String(f)}
|
|
3
|
+
`,matched:f>0,matchCount:f}}if(b===0&&R===0&&!y){let f=[],r=!1,o=0,l=0;for(let u=0;u<v&&!(S>0&&o>=S);u++){let w=x[u];if(t.lastIndex=0,t.test(w)!==i)if(r=!0,o++,m){t.lastIndex=0;for(let $=t.exec(w);$!==null;$=t.exec(w)){let I=A!==void 0?$[A]??"":$[0],U=k!==null?N(k,$):I,z=a?`${a}:`:"";P&&(z+=`${l+$.index}:`),s&&(z+=`${u+1}:`),O&&(z+=`${$.index+1}:`),f.push(z+U),$[0].length===0&&t.lastIndex++}}else if(T){t.lastIndex=0;for(let $=t.exec(w);$!==null;$=t.exec(w)){let I=a?`${a}:`:"";P&&(I+=`${l+$.index}:`),s&&(I+=`${u+1}:`),O&&(I+=`${$.index+1}:`),f.push(I+w),$[0].length===0&&t.lastIndex++}}else{t.lastIndex=0;let $=t.exec(w),I=$?$.index+1:1,U=w;k!==null&&(t.lastIndex=0,U=w.replace(t,(...M)=>{if(M[0].length===0)return"";let E=M,_=M[M.length-1];return typeof _=="object"&&_!==null?(E.groups=_,E.input=M[M.length-2],E.index=M[M.length-3]):(E.input=M[M.length-1],E.index=M[M.length-2]),N(k,E)}));let z=a?`${a}:`:"";P&&(z+=`${l+($?$.index:0)}:`),s&&(z+=`${u+1}:`),O&&(z+=`${I}:`),f.push(z+U)}l+=w.length+1}return{output:f.length>0?`${f.join(`
|
|
4
|
+
`)}
|
|
5
|
+
`:"",matched:r,matchCount:o}}if(y){let f=[],r=!1,o=0;for(let l=0;l<v;l++){let u=x[l];t.lastIndex=0;let F=t.test(u)!==i;F&&(r=!0,o++);let $=F?":":"-",I=a?`${a}${$}`:"";s&&(I+=`${l+1}${$}`),f.push(I+u)}return{output:f.length>0?`${f.join(`
|
|
6
|
+
`)}
|
|
7
|
+
`:"",matched:r,matchCount:o}}let g=[],L=0,p=new Set,C=-1,c=[];for(let f=0;f<v&&!(S>0&&L>=S);f++)t.lastIndex=0,t.test(x[f])!==i&&(c.push(f),L++);for(let f of c){let r=Math.max(0,f-b);C>=0&&r>C+1&&g.push(G);for(let l=r;l<f;l++)if(!p.has(l)){p.add(l),C=l;let u=x[l];s&&(u=`${l+1}-${u}`),a&&(u=`${a}-${u}`),g.push(u)}if(!p.has(f)){p.add(f),C=f;let l=x[f];if(m){t.lastIndex=0;for(let u=t.exec(l);u!==null;u=t.exec(l)){let w=A!==void 0?u[A]??"":u[0],F=k!==null?k:w,$=a?`${a}:`:"";s&&($+=`${f+1}:`),O&&($+=`${u.index+1}:`),g.push($+F),u[0].length===0&&t.lastIndex++}}else{let u=l;s&&(u=`${f+1}:${u}`),a&&(u=`${a}:${u}`),g.push(u)}}let o=Math.min(v-1,f+R);for(let l=f+1;l<=o;l++)if(!p.has(l)){p.add(l),C=l;let u=x[l];s&&(u=`${l+1}-${u}`),a&&(u=`${a}-${u}`),g.push(u)}}return{output:g.length>0?`${g.join(`
|
|
8
|
+
`)}
|
|
9
|
+
`:"",matched:L>0,matchCount:L}}function D(n,t,e){let{invertMatch:i,showLineNumbers:s,countOnly:h,countMatches:d,filename:a,onlyMatching:m,beforeContext:b,afterContext:R,maxCount:S,contextSeparator:G,showColumn:O,showByteOffset:T,replace:P,kResetGroup:k}=e,y=n.split(`
|
|
10
|
+
`),j=y.length,A=j>0&&y[j-1]===""?j-1:j,x=[0];for(let c=0;c<n.length;c++)n[c]===`
|
|
11
|
+
`&&x.push(c+1);let Z=c=>{let f=0;for(let r=0;r<x.length&&!(x[r]>c);r++)f=r;return f},v=c=>{let f=Z(c);return c-x[f]+1},g=[];t.lastIndex=0;for(let c=t.exec(n);c!==null&&!(S>0&&g.length>=S);c=t.exec(n)){let f=Z(c.index),r=Z(c.index+Math.max(0,c[0].length-1)),o=k!==void 0?c[k]??"":c[0];g.push({startLine:f,endLine:r,byteOffset:c.index,column:v(c.index),matchText:o}),c[0].length===0&&t.lastIndex++}if(h||d){let c;if(d)c=i?0:g.length;else{let r=new Set;for(let o of g)for(let l=o.startLine;l<=o.endLine;l++)r.add(l);c=i?A-r.size:r.size}return{output:`${a?`${a}:${c}`:String(c)}
|
|
12
|
+
`,matched:c>0,matchCount:c}}if(i){let c=new Set;for(let r of g)for(let o=r.startLine;o<=r.endLine;o++)c.add(o);let f=[];for(let r=0;r<A;r++)if(!c.has(r)){let o=y[r];s&&(o=`${r+1}:${o}`),a&&(o=`${a}:${o}`),f.push(o)}return{output:f.length>0?`${f.join(`
|
|
13
|
+
`)}
|
|
14
|
+
`:"",matched:f.length>0,matchCount:f.length}}if(g.length===0)return{output:"",matched:!1,matchCount:0};let L=new Set,p=-1,C=[];for(let c of g){let f=Math.max(0,c.startLine-b),r=Math.min(A-1,c.endLine+R);p>=0&&f>p+1&&C.push(G);for(let o=f;o<c.startLine;o++)if(!L.has(o)){L.add(o),p=o;let l=y[o];s&&(l=`${o+1}-${l}`),a&&(l=`${a}-${l}`),C.push(l)}if(m){let o=P!==null?P:c.matchText,l=a?`${a}:`:"";T&&(l+=`${c.byteOffset}:`),s&&(l+=`${c.startLine+1}:`),O&&(l+=`${c.column}:`),C.push(l+o);for(let u=c.startLine;u<=c.endLine;u++)L.add(u),p=u}else for(let o=c.startLine;o<=c.endLine&&o<A;o++)if(!L.has(o)){L.add(o),p=o;let l=y[o];P!==null&&o===c.startLine&&(t.lastIndex=0,l=l.replace(t,P));let u=a?`${a}:`:"";T&&o===c.startLine&&(u+=`${c.byteOffset}:`),s&&(u+=`${o+1}:`),O&&o===c.startLine&&(u+=`${c.column}:`),C.push(u+l)}for(let o=c.endLine+1;o<=r;o++)if(!L.has(o)){L.add(o),p=o;let l=y[o];s&&(l=`${o+1}-${l}`),a&&(l=`${a}-${l}`),C.push(l)}}return{output:C.length>0?`${C.join(`
|
|
15
|
+
`)}
|
|
16
|
+
`:"",matched:!0,matchCount:g.length}}var Q={alpha:"a-zA-Z",digit:"0-9",alnum:"a-zA-Z0-9",lower:"a-z",upper:"A-Z",xdigit:"0-9A-Fa-f",space:" \\t\\n\\r\\f\\v",blank:" \\t",punct:"!-/:-@\\[-`{-~",graph:"!-~",print:" -~",cntrl:"\\x00-\\x1F\\x7F",ascii:"\\x00-\\x7F",word:"a-zA-Z0-9_"};function B(n){let t="",e=0;for(;e<n.length;){if(n.slice(e,e+7)==="[[:<:]]"){t+="(?<![\\w])",e+=7;continue}if(n.slice(e,e+7)==="[[:>:]]"){t+="(?![\\w])",e+=7;continue}if(n[e]==="["){let i="[";for(e++,e<n.length&&(n[e]==="^"||n[e]==="!")&&(i+="^",e++),e<n.length&&n[e]==="]"&&(i+="\\]",e++);e<n.length&&n[e]!=="]";){if(n[e]==="["&&e+1<n.length&&n[e+1]===":"){let s=n.indexOf(":]",e+2);if(s!==-1){let h=n.slice(e+2,s),d=Q[h];if(d){i+=d,e=s+2;continue}}}if(n[e]==="\\"&&e+1<n.length){i+=n[e]+n[e+1],e+=2;continue}i+=n[e],e++}e<n.length&&n[e]==="]"&&(i+="]",e++),t+=i;continue}if(n[e]==="\\"&&e+1<n.length){t+=n[e]+n[e+1],e+=2;continue}t+=n[e],e++}return t}function q(n,t){let e,i;switch(t.mode){case"fixed":e=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");break;case"extended":case"perl":{if(e=B(n),e=e.replace(/\(\?P<([^>]+)>/g,"(?<$1>"),t.mode==="perl"){e=W(e),e=X(e),e=H(e);let d=ee(e);e=d.pattern,i=d.kResetGroup}break}default:e=B(n),e=le(e);break}t.wholeWord&&(e=`(?<![\\w])(?:${e})(?![\\w])`),t.lineRegexp&&(e=`^${e}$`);let s=/\\u\{[0-9A-Fa-f]+\}/.test(e),h="g"+(t.ignoreCase?"i":"")+(t.multiline?"m":"")+(t.multilineDotall?"s":"")+(s?"u":"");return{regex:new RegExp(e,h),kResetGroup:i}}function W(n){let t="",e=0;for(;e<n.length;)if(n[e]==="\\"&&e+1<n.length&&n[e+1]==="Q"){e+=2;let i="";for(;e<n.length;){if(n[e]==="\\"&&e+1<n.length&&n[e+1]==="E"){e+=2;break}i+=n[e],e++}t+=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}else t+=n[e],e++;return t}function X(n){return n.replace(/\\x\{([0-9A-Fa-f]+)\}/g,"\\u{$1}")}function H(n){let t="",e=0;for(;e<n.length;){if(n[e]==="("&&e+1<n.length&&n[e+1]==="?"){let i=n.slice(e).match(/^\(\?([imsx]*)(-[imsx]*)?(:|$|\))/);if(i){let s=i[1]||"",h=i[2]||"",d=i[3];if(d===":"){let a=e+i[0].length-1,m=J(n,e);if(m!==-1){let b=n.slice(a+1,m),R=V(b,s,h);t+=`(?:${R})`,e=m+1;continue}}else if(d===")"||d===""){e+=i[0].length;continue}}}t+=n[e],e++}return t}function J(n,t){let e=0,i=t;for(;i<n.length;){if(n[i]==="\\"){i+=2;continue}if(n[i]==="["){for(i++;i<n.length&&n[i]!=="]";)n[i]==="\\"&&i++,i++;i++;continue}if(n[i]==="(")e++;else if(n[i]===")"&&(e--,e===0))return i;i++}return-1}function V(n,t,e){let i=n;return t.includes("i")&&(i=Y(i)),i}function Y(n){let t="",e=0;for(;e<n.length;){let i=n[e];if(i==="\\"){e+1<n.length?(t+=i+n[e+1],e+=2):(t+=i,e++);continue}if(i==="["){t+=i,e++,e<n.length&&n[e]==="^"&&(t+=n[e],e++);let s=[];for(;e<n.length&&n[e]!=="]";)if(n[e]==="\\")s.push(n[e]),e++,e<n.length&&(s.push(n[e]),e++);else if(n[e]==="-"&&s.length>0&&e+1<n.length&&n[e+1]!=="]"){let h=s[s.length-1],d=n[e+1];s.push("-"),s.push(d),/[a-z]/.test(h)&&/[a-z]/.test(d)?(s.push(h.toUpperCase()),s.push("-"),s.push(d.toUpperCase())):/[A-Z]/.test(h)&&/[A-Z]/.test(d)&&(s.push(h.toLowerCase()),s.push("-"),s.push(d.toLowerCase())),e+=2}else{let h=n[e];if(s.push(h),/[a-zA-Z]/.test(h)){let d=h===h.toLowerCase()?h.toUpperCase():h.toLowerCase();s.includes(d)||s.push(d)}e++}t+=s.join(""),e<n.length&&(t+=n[e],e++);continue}if(/[a-zA-Z]/.test(i)){let s=i.toLowerCase(),h=i.toUpperCase();t+=`[${h}${s}]`}else t+=i;e++}return t}function ee(n){let t=ne(n);if(t===-1)return{pattern:n};let e=n.slice(0,t),i=n.slice(t+2),s=te(e);return{pattern:`(?:${e})(${i})`,kResetGroup:s+1}}function ne(n){let t=0;for(;t<n.length-1;)if(n[t]==="\\"){if(n[t+1]==="K"){let e=0,i=t-1;for(;i>=0&&n[i]==="\\";)e++,i--;if(e%2===0)return t}t+=2}else t++;return-1}function te(n){let t=0,e=0;for(;e<n.length;){if(n[e]==="\\"){e+=2;continue}if(n[e]==="["){for(e++;e<n.length&&n[e]!=="]";)n[e]==="\\"&&e++,e++;e++;continue}if(n[e]==="(")if(e+1<n.length&&n[e+1]==="?"){if(e+2<n.length){let i=n[e+2];if(i===":"||i==="="||i==="!"){e++;continue}if(i==="<"&&e+3<n.length){let s=n[e+3];if(s==="="||s==="!"){e++;continue}t++,e++;continue}}}else t++;e++}return t}function ie(n){let t=n.replace(/\$\{0\}|\$0(?![0-9])/g,"$$&");return t=t.replace(/\$\{([^0-9}][^}]*)\}/g,"$$<$1>"),t=t.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)(?![>0-9])/g,"$$<$1>"),t}function le(n){let t="",e=0,i=!0,s=0;for(;e<n.length;){let h=n[e];if(h==="["){for(t+=h,e++,e<n.length&&(n[e]==="^"||n[e]==="!")&&(t+=n[e],e++),e<n.length&&n[e]==="]"&&(t+=n[e],e++);e<n.length&&n[e]!=="]";)n[e]==="\\"&&e+1<n.length?(t+=n[e]+n[e+1],e+=2):(t+=n[e],e++);e<n.length&&n[e]==="]"&&(t+=n[e],e++),i=!1;continue}if(h==="\\"&&e+1<n.length){let d=n[e+1];if(d==="|"){t+="|",e+=2,i=!0;continue}if(d==="("){t+="(",e+=2,s++,i=!0;continue}if(d===")"){t+=")",e+=2,s=Math.max(0,s-1),i=!1;continue}if(d==="{"){let m=n.slice(e).match(/^\\{(\d+)(,(\d*)?)?\\}/);if(m){let b=m[1],R=m[2]!==void 0,S=m[3]||"";R?t+=`{${b},${S}}`:t+=`{${b}}`,e+=m[0].length,i=!1;continue}t+="\\{",e+=2,i=!1;continue}if(d==="}"){t+="\\}",e+=2,i=!1;continue}t+=h+d,e+=2,i=!1;continue}if(h==="*"&&i){t+="\\*",e++;continue}if(h==="^"){if(i){t+="^",e++;continue}t+="\\^",e++;continue}if(h==="$"){let d=e===n.length-1,a=e+2<n.length&&n[e+1]==="\\"&&n[e+2]===")";d||a?t+="$":t+="\\$",e++,i=!1;continue}h==="+"||h==="?"||h==="|"||h==="("||h===")"||h==="{"||h==="}"?t+=`\\${h}`:t+=h,e++,i=!1}return t}export{K as a,q as b,ie as c};
|