just-bash 2.5.1 → 2.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -683,7 +683,7 @@ Gid: ${r} ${r} ${r} ${r}
683
683
  `:d==="$"||d==="`"||d==="\\"||d==='"'||d===`
684
684
  `)?c+=d:c+=`\\${d}`,l+=2;continue}if(f==="'"&&!o&&!i){u();let d=e.indexOf("'",l+1);if(d===-1){c+=e.slice(l);break}a.push(B.singleQuoted(e.slice(l+1,d))),l=d+1;continue}if(f==='"'&&!i){u();let{part:d,endIndex:p}=Zx(t,e,l+1);a.push(d),l=p+1;continue}if(f==="$"&&e[l+1]==="'"){u();let{part:d,endIndex:p}=Jf(t,e,l+2);a.push(d),l=p;continue}if(f==="$"){u();let{part:d,endIndex:p}=$i(t,e,l);d&&a.push(d),l=p;continue}if(f==="`"){u();let{part:d,endIndex:p}=t.parseBacktickSubstitution(e,l);a.push(d),l=p;continue}if(f==="~"){let d=l>0?e[l-1]:"";if(l===0||d==="="||s&&d===":"){let h=Kf(t,e,l),m=e[h];if(m===void 0||m==="/"||m===":"){u();let g=e.slice(l+1,h)||null;a.push({type:"TildeExpansion",user:g}),l=h;continue}}}if(f==="*"||f==="?"||f==="["){u();let{pattern:d,endIndex:p}=Xf(t,e,l);a.push({type:"Glob",pattern:d}),l=p;continue}if(f==="{"&&!s){let d=Yf(t,e,l,wt);if(d){u(),a.push(d.part),l=d.endIndex;continue}}c+=f,l++}return u(),a}var Fe=class t{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;checkIterationLimit(){if(this.parseIterations++,this.parseIterations>Gf)throw new pt("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}parse(e){if(e.length>mi)throw new pt(`Input too large: ${e.length} bytes exceeds limit of ${mi}`,1,1);let n=new Lr(e);if(this.tokens=n.tokenize(),this.tokens.length>gi)throw new pt(`Too many tokens: ${this.tokens.length} exceeds limit of ${gi}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseScript()}parseTokens(e){return this.tokens=e,this.pos=0,this.pendingHeredocs=[],this.parseScript()}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(e=0){return this.tokens[this.pos+e]||this.tokens[this.tokens.length-1]}advance(){let e=this.current();return this.pos<this.tokens.length-1&&this.pos++,e}getPos(){return this.pos}check(e,n,r,s,...i){let o=this.tokens[this.pos]?.type;return o===e||n!==void 0&&o===n||r!==void 0&&o===r||s!==void 0&&o===s?!0:i.length>0?i.includes(o):!1}expect(e,n){if(this.check(e))return this.advance();let r=this.current();throw new pt(n||`Expected ${e}, got ${r.type}`,r.line,r.column,r)}error(e){let n=this.current();throw new pt(e,n.line,n.column,n)}skipNewlines(){for(;this.check(y.NEWLINE,y.COMMENT);)this.check(y.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(e=!0){for(;;){if(this.check(y.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(y.SEMICOLON,y.COMMENT)){this.advance();continue}if(e&&this.check(y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(e,n,r,s){this.pendingHeredocs.push({redirect:e,delimiter:n,stripTabs:r,quoted:s})}processHeredocs(){for(let e of this.pendingHeredocs)if(this.check(y.HEREDOC_CONTENT)){let n=this.advance(),r;e.quoted?r=B.word([B.literal(n.value)]):r=this.parseWordFromString(n.value,!1,!1,!1,!0),e.redirect.target=B.hereDoc(e.delimiter,r,e.stripTabs,e.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(y.EOF,y.NEWLINE,y.SEMICOLON,y.AMP,y.AND_AND,y.OR_OR,y.RPAREN,y.RBRACE,y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)}isCommandStart(){let e=this.current().type;return e===y.WORD||e===y.NAME||e===y.NUMBER||e===y.ASSIGNMENT_WORD||e===y.IF||e===y.FOR||e===y.WHILE||e===y.UNTIL||e===y.CASE||e===y.LPAREN||e===y.LBRACE||e===y.DPAREN_START||e===y.DBRACK_START||e===y.FUNCTION||e===y.BANG||e===y.IN||e===y.LESS||e===y.GREAT||e===y.DLESS||e===y.DGREAT||e===y.LESSAND||e===y.GREATAND||e===y.LESSGREAT||e===y.DLESSDASH||e===y.CLOBBER||e===y.TLESS||e===y.AND_GREAT||e===y.AND_DGREAT}parseScript(){let e=[],r=0;for(this.skipNewlines();!this.check(y.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)"),this.checkUnexpectedToken();let s=this.pos,i=this.parseStatement();i&&e.push(i),this.skipSeparators(!1),this.check(y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===s&&!this.check(y.EOF)&&this.advance()}return B.script(e)}checkUnexpectedToken(){let e=this.current().type,n=this.current().value;(e===y.DO||e===y.DONE||e===y.THEN||e===y.ELSE||e===y.ELIF||e===y.FI||e===y.ESAC)&&this.error(`syntax error near unexpected token \`${n}'`),(e===y.RBRACE||e===y.RPAREN)&&this.error(`syntax error near unexpected token \`${n}'`),(e===y.DSEMI||e===y.SEMI_AND||e===y.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${n}'`),e===y.SEMICOLON&&this.error(`syntax error near unexpected token \`${n}'`)}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let e=[],n=[],r=!1,s=this.parsePipeline();for(e.push(s);this.check(y.AND_AND,y.OR_OR);){let i=this.advance();n.push(i.type===y.AND_AND?"&&":"||"),this.skipNewlines();let o=this.parsePipeline();e.push(o)}return this.check(y.AMP)&&(this.advance(),r=!0),B.statement(e,n,r)}parsePipeline(){let e=0;for(;this.check(y.BANG);)this.advance(),e++;let n=e%2===1,r=[],s=this.parseCommand();for(r.push(s);this.check(y.PIPE,y.PIPE_AMP);){let i=this.advance();this.skipNewlines();let o=this.parseCommand();i.type===y.PIPE_AMP&&o.type==="SimpleCommand"&&o.redirections.unshift(B.redirection(">&",B.word([B.literal("1")]),2)),r.push(o)}return B.pipeline(r,n)}parseCommand(){return this.check(y.IF)?bi(this):this.check(y.FOR)?Ei(this):this.check(y.WHILE)?Si(this):this.check(y.UNTIL)?Ci(this):this.check(y.CASE)?Ai(this):this.check(y.LPAREN)?ki(this):this.check(y.LBRACE)?Ni(this):this.check(y.DPAREN_START)?this.parseArithmeticCommand():this.check(y.DBRACK_START)?this.parseConditionalCommand():this.check(y.FUNCTION)?this.parseFunctionDef():this.check(y.NAME,y.WORD)&&this.peek(1).type===y.LPAREN&&this.peek(2).type===y.RPAREN?this.parseFunctionDef():rd(this)}isWord(){let e=this.current().type;return e===y.WORD||e===y.NAME||e===y.NUMBER||e===y.IF||e===y.FOR||e===y.WHILE||e===y.UNTIL||e===y.CASE||e===y.FUNCTION||e===y.ELSE||e===y.ELIF||e===y.FI||e===y.THEN||e===y.DO||e===y.DONE||e===y.ESAC||e===y.IN||e===y.SELECT||e===y.TIME||e===y.COPROC||e===y.BANG}parseWord(){let e=this.advance();return this.parseWordFromString(e.value,e.quoted,e.singleQuoted)}parseWordFromString(e,n=!1,r=!1,s=!1,i=!1){let o=wt(this,e,n,r,s,i);return B.word(o)}parseCommandSubstitution(e,n){let r=n+2,s=1,i=r,o=!1,a=!1,l=0,c=!1,u="";for(;i<e.length&&s>0;){let h=e[i];o?h==="'"&&(o=!1):a?h==="\\"&&i+1<e.length?i++:h==='"'&&(a=!1):h==="'"?(o=!0,u=""):h==='"'?(a=!0,u=""):h==="\\"&&i+1<e.length?(i++,u=""):/[a-zA-Z_]/.test(h)?u+=h:(u==="case"?(l++,c=!1):u==="in"&&l>0?c=!0:u==="esac"&&l>0&&(l--,c=!1),u="",h==="("?i>0&&e[i-1]==="$"?s++:c||s++:h===")"?c?c=!1:s--:h===";"&&l>0&&i+1<e.length&&e[i+1]===";"&&(c=!0)),s>0&&i++}s>0&&this.error("unexpected EOF while looking for matching `)'");let f=e.slice(r,i),p=new t().parse(f);return{part:B.commandSubstitution(p,!1),endIndex:i+1}}parseBacktickSubstitution(e,n,r=!1){let i=n+1,o="";for(;i<e.length&&e[i]!=="`";)if(e[i]==="\\"){let c=e[i+1];c==="$"||c==="`"||c==="\\"||c===`
685
685
  `||r&&c==='"'?(c!==`
686
- `&&(o+=c),i+=2):(o+=e[i],i++)}else o+=e[i],i++;i>=e.length&&this.error("unexpected EOF while looking for matching ``'");let l=new t().parse(o);return{part:B.commandSubstitution(l,!0),endIndex:i+1}}parseArithmeticExpansion(e,n){let r=n+3,s=1,i=0,o=r;for(;o<e.length-1&&s>0;)e[o]==="$"&&e[o+1]==="("?e[o+2]==="("?(s++,o+=3):(i++,o+=2):e[o]==="("&&e[o+1]==="("?(s++,o+=2):e[o]===")"&&e[o+1]===")"?i>0?(i--,o++):(s--,s>0&&(o+=2)):e[o]==="("?(i++,o++):(e[o]===")"&&i>0&&i--,o++);let a=e.slice(r,o),l=this.parseArithmeticExpression(a);return{part:B.arithmeticExpansion(l),endIndex:o+2}}parseArithmeticCommand(){this.expect(y.DPAREN_START);let e="",n=1,r=0,s=!1,i=!1;for(;n>0&&!this.check(y.EOF);){if(s){if(s=!1,r>0){r--,e+=")";continue}if(this.check(y.RPAREN)){n--,i=!0,this.advance();continue}if(this.check(y.DPAREN_END)){n--,i=!0;continue}e+=")";continue}this.check(y.DPAREN_START)?(n++,e+="((",this.advance()):this.check(y.DPAREN_END)?r>=2?(r-=2,e+="))",this.advance()):r===1?(r--,e+=")",s=!0,this.advance()):(n--,i=!0,n>0&&(e+="))"),this.advance()):this.check(y.LPAREN)?(r++,e+="(",this.advance()):this.check(y.RPAREN)?(r>0&&r--,e+=")",this.advance()):(e+=this.current().value,this.advance())}i||this.expect(y.DPAREN_END);let o=this.parseArithmeticExpression(e.trim()),a=this.parseOptionalRedirections();return B.arithmeticCommand(o,a)}parseConditionalCommand(){this.expect(y.DBRACK_START);let e=vi(this);this.expect(y.DBRACK_END);let n=this.parseOptionalRedirections();return B.conditionalCommand(e,n)}parseFunctionDef(){let e;this.check(y.FUNCTION)?(this.advance(),e=this.expect(y.NAME,"Expected function name").value,this.check(y.LPAREN)&&(this.advance(),this.expect(y.RPAREN))):(e=this.advance().value,this.expect(y.LPAREN),this.expect(y.RPAREN)),this.skipNewlines();let n=this.parseCompoundCommandBody(),r=this.parseOptionalRedirections();return B.functionDef(e,n,r)}parseCompoundCommandBody(){if(this.check(y.LBRACE))return Ni(this);if(this.check(y.LPAREN))return ki(this);if(this.check(y.IF))return bi(this);if(this.check(y.FOR))return Ei(this);if(this.check(y.WHILE))return Si(this);if(this.check(y.UNTIL))return Ci(this);if(this.check(y.CASE))return Ai(this);this.error("Expected compound command for function body")}parseCompoundList(){let e=[];for(this.skipNewlines();!this.check(y.EOF,y.FI,y.ELSE,y.ELIF,y.THEN,y.DO,y.DONE,y.ESAC,y.RPAREN,y.RBRACE,y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let n=this.pos,r=this.parseStatement();if(r&&e.push(r),this.skipSeparators(),this.pos===n&&!r)break}return e}parseOptionalRedirections(){let e=[];for(;Mr(this);){this.checkIterationLimit();let n=this.pos;if(e.push(_r(this)),this.pos===n)break}return e}parseArithmeticExpression(e){return ve(this,e)}};function bt(t){return new Fe().parse(t)}de();Gt();var fn=class{fs;cwd;constructor(e,n){this.fs=e,this.cwd=n}isGlobPattern(e){return e.includes("*")||e.includes("?")||/\[.*\]/.test(e)}async expandArgs(e,n){let r=e.map((o,a)=>(n?.[a]??!1)||!this.isGlobPattern(o)?null:this.expand(o)),s=await Promise.all(r.map(o=>o||Promise.resolve(null))),i=[];for(let o=0;o<e.length;o++){let a=s[o];a===null?i.push(e[o]):a.length>0?i.push(...a):i.push(e[o])}return i}async expand(e){return e.includes("**")?this.expandRecursive(e):this.expandSimple(e)}async expandSimple(e){let n=[],r=e.lastIndexOf("/"),s,i;r===-1?(s=this.cwd,i=e):(s=e.slice(0,r)||"/",i=e.slice(r+1));let o=this.fs.resolvePath(this.cwd,s);try{let a=await this.fs.readdir(o);for(let l of a)if(this.matchPattern(l,i)){let c=r===-1?l:`${s}/${l}`;n.push(c)}}catch{}return n.sort()}async expandRecursive(e){let n=[],r=e.indexOf("**"),s=e.slice(0,r).replace(/\/$/,"")||".",o=e.slice(r+2).replace(/^\//,"");return await this.walkDirectory(s,o,n),n.sort()}async walkDirectory(e,n,r){let s=this.fs.resolvePath(this.cwd,e);try{if(this.fs.readdirWithFileTypes){let i=await this.fs.readdirWithFileTypes(s),o=[],a=[];for(let l of i){let c=e==="."?l.name:`${e}/${l.name}`;l.isDirectory?a.push(c):n&&this.matchPattern(l.name,n)&&o.push(c)}r.push(...o);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u,n,r)))}}else{let i=await this.fs.readdir(s),o=[];for(let l=0;l<i.length;l+=100){let c=i.slice(l,l+100),u=await Promise.all(c.map(async f=>{let d=e==="."?f:`${e}/${f}`,p=this.fs.resolvePath(this.cwd,d);try{let h=await this.fs.stat(p);return{name:f,path:d,isDirectory:h.isDirectory}}catch{return null}}));o.push(...u.filter(f=>f!==null))}for(let l of o)!l.isDirectory&&n&&this.matchPattern(l.name,n)&&r.push(l.path);let a=o.filter(l=>l.isDirectory);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u.path,n,r)))}}}catch{}}matchPattern(e,n){return this.patternToRegex(n).test(e)}patternToRegex(e){let n="^";for(let r=0;r<e.length;r++){let s=e[r];if(s==="*")n+=".*";else if(s==="?")n+=".";else if(s==="["){let i=r+1,o="[";for(i<e.length&&(e[i]==="^"||e[i]==="!")&&(o+="^",i++),i<e.length&&e[i]==="]"&&(o+="\\]",i++);i<e.length&&e[i]!=="]";){if(e[i]==="["&&i+1<e.length&&e[i+1]===":"){let a=e.indexOf(":]",i+2);if(a!==-1){let l=e.slice(i+2,a),c=this.posixClassToRegex(l);o+=c,i=a+2;continue}}if(e[i]==="\\"&&i+1<e.length){o+=`\\${e[i+1]}`,i+=2;continue}e[i]==="-"?o+="\\-":o+=e[i],i++}o+="]",n+=o,r=i}else if(s==="\\"&&r+1<e.length){let i=e[r+1];/[.+^${}()|\\*?[\]]/.test(i)?n+=`\\${i}`:n+=i,r++}else/[.+^${}()|]/.test(s)?n+=`\\${s}`:n+=s}return n+="$",new RegExp(n)}posixClassToRegex(e){return{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"}[e]||""}};de();function Ye(t){switch(t.type){case"ArithCommandSubst":return!0;case"ArithNested":return Ye(t.expression);case"ArithBinary":return Ye(t.left)||Ye(t.right);case"ArithUnary":return Ye(t.operand);case"ArithTernary":return Ye(t.condition)||Ye(t.consequent)||Ye(t.alternate);case"ArithAssignment":return Ye(t.value);case"ArithGroup":return Ye(t.expression);case"ArithArrayElement":return t.index?Ye(t.index):!1;case"ArithConcat":return t.parts.some(Ye);default:return!1}}function Ri(t){let e=t.operation;return e?!!("word"in e&&e.word&&ht(e.word)||e.type==="PatternReplacement"&&(e.pattern&&ht(e.pattern)||e.replacement&&ht(e.replacement))||e.type==="PatternRemoval"&&e.pattern&&ht(e.pattern)):!1}function Br(t){switch(t.type){case"CommandSubstitution":return!0;case"ArithmeticExpansion":return Ye(t.expression.expression);case"DoubleQuoted":return t.parts.some(Br);case"BraceExpansion":return t.items.some(e=>e.type==="Word"&&ht(e.word));case"ParameterExpansion":return Ri(t);default:return!1}}function ht(t){return t.parts.some(Br)}function Fi(t){if(!t.operation)return!1;let e=t.operation,n;if((e.type==="DefaultValue"||e.type==="AssignDefault"||e.type==="UseAlternative"||e.type==="ErrorIfUnset")&&(n=e.word?.parts),!n)return!1;for(let r of n)if(r.type==="DoubleQuoted"||r.type==="SingleQuoted")return!0;return!1}function id(t){let e=!1,n=!1,r=!1,s=!1,i=!1;for(let o of t){if((o.type==="SingleQuoted"||o.type==="DoubleQuoted")&&(e=!0,o.type==="DoubleQuoted"))for(let a of o.parts)a.type==="ParameterExpansion"&&a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&!a.operation&&(s=!0);o.type==="CommandSubstitution"&&(n=!0),o.type==="ParameterExpansion"&&(i=!0,(o.parameter==="@"||o.parameter==="*")&&(r=!0),Fi(o)&&(e=!0))}return{hasQuoted:e,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i}}function Qx(t,e,n,r,s){let i=n??1;i===0&&(i=1);let o=Math.abs(i),a=[],l=0;r?.match(/^-?0\d/)&&(l=Math.max(l,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(l=Math.max(l,s.replace(/^-/,"").length));let c=u=>{if(l>0){let f=u<0,d=String(Math.abs(u)).padStart(l,"0");return f?`-${d}`:d}return String(u)};if(t<=e)for(let u=t,f=0;u<=e&&f<1e4;u+=o,f++)a.push(c(u));else for(let u=t,f=0;u>=e&&f<1e4;u-=o,f++)a.push(c(u));return a}function Xx(t,e,n){let r=n??1;r===0&&(r=1);let s=t.charCodeAt(0),i=e.charCodeAt(0),o=Math.abs(r),a=t>="A"&&t<="Z",l=t>="a"&&t<="z",c=e>="A"&&e<="Z",u=e>="a"&&e<="z";if(a&&u||l&&c)return null;let f=[];if(s<=i)for(let d=s,p=0;d<=i&&p<1e4;d+=o,p++)f.push(String.fromCharCode(d));else for(let d=s,p=0;d>=i&&p<1e4;d-=o,p++)f.push(String.fromCharCode(d));return f}function Wn(t,e,n,r,s){let i=n!==void 0?`..${n}`:"";return typeof t=="number"&&typeof e=="number"?{expanded:Qx(t,e,n,r,s),literal:`{${t}..${e}${i}}`}:typeof t=="string"&&typeof e=="string"?{expanded:Xx(t,e,n),literal:`{${t}..${e}${i}}`}:{expanded:null,literal:`{${t}..${e}${i}}`}}function qe(t,e){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\")if(r+1<t.length){let i=t[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?n+=`\\${i}`:n+=i,r+=2}else n+="\\\\",r++;else if(s==="*")n+=e?".*":".*?",r++;else if(s==="?")n+=".",r++;else if(s==="["){let i=Jx(t,r);if(i===-1)n+="\\[",r++;else{let o=t.slice(r+1,i);n+=Yx(o),r=i+1}}else/[\^$.|+(){}]/.test(s)?(n+=`\\${s}`,r++):(n+=s,r++)}return n}function Jx(t,e){let n=e+1;for(n<t.length&&t[n]==="^"&&n++,n<t.length&&t[n]==="]"&&n++;n<t.length;){if(t[n]==="\\"&&n+1<t.length){n+=2;continue}if(t[n]==="]")return n;if(t[n]==="'"){let r=t.indexOf("'",n+1);if(r!==-1){n=r+1;continue}}if(t[n]==="["&&n+1<t.length&&t[n+1]===":"){let r=t.indexOf(":]",n+2);if(r!==-1){n=r+2;continue}}n++}return-1}function Yx(t){let e="[",n=0;for((t[0]==="^"||t[0]==="!")&&(e+="^",n++);n<t.length;){if(t[n]==="'"){let s=t.indexOf("'",n+1);if(s!==-1){let i=t.slice(n+1,s);for(let o of i)o==="\\"?e+="\\\\":o==="]"?e+="\\]":o==="^"&&e==="["?e+="\\^":e+=o;n=s+1;continue}}if(t[n]==="["&&n+1<t.length&&t[n+1]===":"){let s=t.indexOf(":]",n+2);if(s!==-1){let i=t.slice(n+2,s);e+=tw(i),n=s+2;continue}}let r=t[n];r==="\\"?n+1<t.length?(e+=`\\${t[n+1]}`,n+=2):(e+="\\\\",n++):r==="-"&&n>0&&n<t.length-1?(e+="-",n++):r==="^"&&n===0?(e+="^",n++):(r==="]"&&n===0?e+="\\]":e+=r,n++)}return e+="]",e}var ew={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 tw(t){return ew[t]??""}de();function Un(t,e){let n=`${e}_`,r=[];for(let s of Object.keys(t.state.env))if(s.startsWith(n)){let i=s.slice(n.length),o=Number.parseInt(i,10);!Number.isNaN(o)&&String(o)===i&&r.push(o)}return r.sort((s,i)=>s-i)}function jn(t,e){let n=`${e}_`;for(let r of Object.keys(t.state.env))r.startsWith(n)&&delete t.state.env[r]}function Pi(t,e){let n=`${e}_`,r=[];for(let s of Object.keys(t.state.env))if(s.startsWith(n)&&!s.includes("__")){let i=s.slice(n.length);r.push(i)}return r.sort()}function od(t){return t.startsWith("'")&&t.endsWith("'")||t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function Wr(t){return t.IFS??`
686
+ `&&(o+=c),i+=2):(o+=e[i],i++)}else o+=e[i],i++;i>=e.length&&this.error("unexpected EOF while looking for matching ``'");let l=new t().parse(o);return{part:B.commandSubstitution(l,!0),endIndex:i+1}}parseArithmeticExpansion(e,n){let r=n+3,s=1,i=0,o=r;for(;o<e.length-1&&s>0;)e[o]==="$"&&e[o+1]==="("?e[o+2]==="("?(s++,o+=3):(i++,o+=2):e[o]==="("&&e[o+1]==="("?(s++,o+=2):e[o]===")"&&e[o+1]===")"?i>0?(i--,o++):(s--,s>0&&(o+=2)):e[o]==="("?(i++,o++):(e[o]===")"&&i>0&&i--,o++);let a=e.slice(r,o),l=this.parseArithmeticExpression(a);return{part:B.arithmeticExpansion(l),endIndex:o+2}}parseArithmeticCommand(){this.expect(y.DPAREN_START);let e="",n=1,r=0,s=!1,i=!1;for(;n>0&&!this.check(y.EOF);){if(s){if(s=!1,r>0){r--,e+=")";continue}if(this.check(y.RPAREN)){n--,i=!0,this.advance();continue}if(this.check(y.DPAREN_END)){n--,i=!0;continue}e+=")";continue}this.check(y.DPAREN_START)?(n++,e+="((",this.advance()):this.check(y.DPAREN_END)?r>=2?(r-=2,e+="))",this.advance()):r===1?(r--,e+=")",s=!0,this.advance()):(n--,i=!0,n>0&&(e+="))"),this.advance()):this.check(y.LPAREN)?(r++,e+="(",this.advance()):this.check(y.RPAREN)?(r>0&&r--,e+=")",this.advance()):(e+=this.current().value,this.advance())}i||this.expect(y.DPAREN_END);let o=this.parseArithmeticExpression(e.trim()),a=this.parseOptionalRedirections();return B.arithmeticCommand(o,a)}parseConditionalCommand(){this.expect(y.DBRACK_START);let e=vi(this);this.expect(y.DBRACK_END);let n=this.parseOptionalRedirections();return B.conditionalCommand(e,n)}parseFunctionDef(){let e;this.check(y.FUNCTION)?(this.advance(),e=this.expect(y.NAME,"Expected function name").value,this.check(y.LPAREN)&&(this.advance(),this.expect(y.RPAREN))):(e=this.advance().value,this.expect(y.LPAREN),this.expect(y.RPAREN)),this.skipNewlines();let n=this.parseCompoundCommandBody(),r=this.parseOptionalRedirections();return B.functionDef(e,n,r)}parseCompoundCommandBody(){if(this.check(y.LBRACE))return Ni(this);if(this.check(y.LPAREN))return ki(this);if(this.check(y.IF))return bi(this);if(this.check(y.FOR))return Ei(this);if(this.check(y.WHILE))return Si(this);if(this.check(y.UNTIL))return Ci(this);if(this.check(y.CASE))return Ai(this);this.error("Expected compound command for function body")}parseCompoundList(){let e=[];for(this.skipNewlines();!this.check(y.EOF,y.FI,y.ELSE,y.ELIF,y.THEN,y.DO,y.DONE,y.ESAC,y.RPAREN,y.RBRACE,y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let n=this.pos,r=this.parseStatement();if(r&&e.push(r),this.skipSeparators(),this.pos===n&&!r)break}return e}parseOptionalRedirections(){let e=[];for(;Mr(this);){this.checkIterationLimit();let n=this.pos;if(e.push(_r(this)),this.pos===n)break}return e}parseArithmeticExpression(e){return ve(this,e)}};function bt(t){return new Fe().parse(t)}de();Gt();var fn=class{fs;cwd;constructor(e,n){this.fs=e,this.cwd=n}isGlobPattern(e){return e.includes("*")||e.includes("?")||/\[.*\]/.test(e)}async expandArgs(e,n){let r=e.map((o,a)=>(n?.[a]??!1)||!this.isGlobPattern(o)?null:this.expand(o)),s=await Promise.all(r.map(o=>o||Promise.resolve(null))),i=[];for(let o=0;o<e.length;o++){let a=s[o];a===null?i.push(e[o]):a.length>0?i.push(...a):i.push(e[o])}return i}async expand(e){return e.includes("**")?this.expandRecursive(e):this.expandSimple(e)}hasGlobChars(e){return e.includes("*")||e.includes("?")||/\[.*\]/.test(e)}async expandSimple(e){let n=e.startsWith("/"),r=e.split("/").filter(c=>c!==""),s=-1;for(let c=0;c<r.length;c++)if(this.hasGlobChars(r[c])){s=c;break}if(s===-1)return[e];let i,o;if(s===0)n?(i="/",o="/"):(i=this.cwd,o="");else{let c=r.slice(0,s);n?(i=`/${c.join("/")}`,o=`/${c.join("/")}`):(i=this.fs.resolvePath(this.cwd,c.join("/")),o=c.join("/"))}let a=r.slice(s);return(await this.expandSegments(i,o,a)).sort()}async expandSegments(e,n,r){if(r.length===0)return[n];let[s,...i]=r,o=[];try{if(this.fs.readdirWithFileTypes){let a=await this.fs.readdirWithFileTypes(e),l=[];for(let u of a)if(!(u.name.startsWith(".")&&!s.startsWith("."))&&this.matchPattern(u.name,s)){let f=e==="/"?`/${u.name}`:`${e}/${u.name}`,d;n===""?d=u.name:n==="/"?d=`/${u.name}`:d=`${n}/${u.name}`,i.length===0?l.push(Promise.resolve([d])):u.isDirectory&&l.push(this.expandSegments(f,d,i))}let c=await Promise.all(l);for(let u of c)o.push(...u)}else{let a=await this.fs.readdir(e),l=[];for(let u of a)if(!(u.startsWith(".")&&!s.startsWith("."))&&this.matchPattern(u,s)){let f=e==="/"?`/${u}`:`${e}/${u}`,d;n===""?d=u:n==="/"?d=`/${u}`:d=`${n}/${u}`,i.length===0?l.push(Promise.resolve([d])):l.push((async()=>{try{if((await this.fs.stat(f)).isDirectory)return this.expandSegments(f,d,i)}catch{}return[]})())}let c=await Promise.all(l);for(let u of c)o.push(...u)}}catch{}return o}async expandRecursive(e){let n=[],r=e.indexOf("**"),s=e.slice(0,r).replace(/\/$/,"")||".",o=e.slice(r+2).replace(/^\//,"");return await this.walkDirectory(s,o,n),n.sort()}async walkDirectory(e,n,r){let s=this.fs.resolvePath(this.cwd,e);try{if(this.fs.readdirWithFileTypes){let i=await this.fs.readdirWithFileTypes(s),o=[],a=[];for(let l of i){let c=e==="."?l.name:`${e}/${l.name}`;l.isDirectory?a.push(c):n&&this.matchPattern(l.name,n)&&o.push(c)}r.push(...o);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u,n,r)))}}else{let i=await this.fs.readdir(s),o=[];for(let l=0;l<i.length;l+=100){let c=i.slice(l,l+100),u=await Promise.all(c.map(async f=>{let d=e==="."?f:`${e}/${f}`,p=this.fs.resolvePath(this.cwd,d);try{let h=await this.fs.stat(p);return{name:f,path:d,isDirectory:h.isDirectory}}catch{return null}}));o.push(...u.filter(f=>f!==null))}for(let l of o)!l.isDirectory&&n&&this.matchPattern(l.name,n)&&r.push(l.path);let a=o.filter(l=>l.isDirectory);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u.path,n,r)))}}}catch{}}matchPattern(e,n){return this.patternToRegex(n).test(e)}patternToRegex(e){let n="^";for(let r=0;r<e.length;r++){let s=e[r];if(s==="*")n+=".*";else if(s==="?")n+=".";else if(s==="["){let i=r+1,o="[";for(i<e.length&&(e[i]==="^"||e[i]==="!")&&(o+="^",i++),i<e.length&&e[i]==="]"&&(o+="\\]",i++);i<e.length&&e[i]!=="]";){if(e[i]==="["&&i+1<e.length&&e[i+1]===":"){let a=e.indexOf(":]",i+2);if(a!==-1){let l=e.slice(i+2,a),c=this.posixClassToRegex(l);o+=c,i=a+2;continue}}if(e[i]==="\\"&&i+1<e.length){o+=`\\${e[i+1]}`,i+=2;continue}e[i]==="-"?o+="\\-":o+=e[i],i++}o+="]",n+=o,r=i}else if(s==="\\"&&r+1<e.length){let i=e[r+1];/[.+^${}()|\\*?[\]]/.test(i)?n+=`\\${i}`:n+=i,r++}else/[.+^${}()|]/.test(s)?n+=`\\${s}`:n+=s}return n+="$",new RegExp(n)}posixClassToRegex(e){return{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"}[e]||""}};de();function Ye(t){switch(t.type){case"ArithCommandSubst":return!0;case"ArithNested":return Ye(t.expression);case"ArithBinary":return Ye(t.left)||Ye(t.right);case"ArithUnary":return Ye(t.operand);case"ArithTernary":return Ye(t.condition)||Ye(t.consequent)||Ye(t.alternate);case"ArithAssignment":return Ye(t.value);case"ArithGroup":return Ye(t.expression);case"ArithArrayElement":return t.index?Ye(t.index):!1;case"ArithConcat":return t.parts.some(Ye);default:return!1}}function Ri(t){let e=t.operation;return e?!!("word"in e&&e.word&&ht(e.word)||e.type==="PatternReplacement"&&(e.pattern&&ht(e.pattern)||e.replacement&&ht(e.replacement))||e.type==="PatternRemoval"&&e.pattern&&ht(e.pattern)):!1}function Br(t){switch(t.type){case"CommandSubstitution":return!0;case"ArithmeticExpansion":return Ye(t.expression.expression);case"DoubleQuoted":return t.parts.some(Br);case"BraceExpansion":return t.items.some(e=>e.type==="Word"&&ht(e.word));case"ParameterExpansion":return Ri(t);default:return!1}}function ht(t){return t.parts.some(Br)}function Fi(t){if(!t.operation)return!1;let e=t.operation,n;if((e.type==="DefaultValue"||e.type==="AssignDefault"||e.type==="UseAlternative"||e.type==="ErrorIfUnset")&&(n=e.word?.parts),!n)return!1;for(let r of n)if(r.type==="DoubleQuoted"||r.type==="SingleQuoted")return!0;return!1}function id(t){let e=!1,n=!1,r=!1,s=!1,i=!1;for(let o of t){if((o.type==="SingleQuoted"||o.type==="DoubleQuoted")&&(e=!0,o.type==="DoubleQuoted"))for(let a of o.parts)a.type==="ParameterExpansion"&&a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&!a.operation&&(s=!0);o.type==="CommandSubstitution"&&(n=!0),o.type==="ParameterExpansion"&&(i=!0,(o.parameter==="@"||o.parameter==="*")&&(r=!0),Fi(o)&&(e=!0))}return{hasQuoted:e,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i}}function Qx(t,e,n,r,s){let i=n??1;i===0&&(i=1);let o=Math.abs(i),a=[],l=0;r?.match(/^-?0\d/)&&(l=Math.max(l,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(l=Math.max(l,s.replace(/^-/,"").length));let c=u=>{if(l>0){let f=u<0,d=String(Math.abs(u)).padStart(l,"0");return f?`-${d}`:d}return String(u)};if(t<=e)for(let u=t,f=0;u<=e&&f<1e4;u+=o,f++)a.push(c(u));else for(let u=t,f=0;u>=e&&f<1e4;u-=o,f++)a.push(c(u));return a}function Xx(t,e,n){let r=n??1;r===0&&(r=1);let s=t.charCodeAt(0),i=e.charCodeAt(0),o=Math.abs(r),a=t>="A"&&t<="Z",l=t>="a"&&t<="z",c=e>="A"&&e<="Z",u=e>="a"&&e<="z";if(a&&u||l&&c)return null;let f=[];if(s<=i)for(let d=s,p=0;d<=i&&p<1e4;d+=o,p++)f.push(String.fromCharCode(d));else for(let d=s,p=0;d>=i&&p<1e4;d-=o,p++)f.push(String.fromCharCode(d));return f}function Wn(t,e,n,r,s){let i=n!==void 0?`..${n}`:"";return typeof t=="number"&&typeof e=="number"?{expanded:Qx(t,e,n,r,s),literal:`{${t}..${e}${i}}`}:typeof t=="string"&&typeof e=="string"?{expanded:Xx(t,e,n),literal:`{${t}..${e}${i}}`}:{expanded:null,literal:`{${t}..${e}${i}}`}}function qe(t,e){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\")if(r+1<t.length){let i=t[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?n+=`\\${i}`:n+=i,r+=2}else n+="\\\\",r++;else if(s==="*")n+=e?".*":".*?",r++;else if(s==="?")n+=".",r++;else if(s==="["){let i=Jx(t,r);if(i===-1)n+="\\[",r++;else{let o=t.slice(r+1,i);n+=Yx(o),r=i+1}}else/[\^$.|+(){}]/.test(s)?(n+=`\\${s}`,r++):(n+=s,r++)}return n}function Jx(t,e){let n=e+1;for(n<t.length&&t[n]==="^"&&n++,n<t.length&&t[n]==="]"&&n++;n<t.length;){if(t[n]==="\\"&&n+1<t.length){n+=2;continue}if(t[n]==="]")return n;if(t[n]==="'"){let r=t.indexOf("'",n+1);if(r!==-1){n=r+1;continue}}if(t[n]==="["&&n+1<t.length&&t[n+1]===":"){let r=t.indexOf(":]",n+2);if(r!==-1){n=r+2;continue}}n++}return-1}function Yx(t){let e="[",n=0;for((t[0]==="^"||t[0]==="!")&&(e+="^",n++);n<t.length;){if(t[n]==="'"){let s=t.indexOf("'",n+1);if(s!==-1){let i=t.slice(n+1,s);for(let o of i)o==="\\"?e+="\\\\":o==="]"?e+="\\]":o==="^"&&e==="["?e+="\\^":e+=o;n=s+1;continue}}if(t[n]==="["&&n+1<t.length&&t[n+1]===":"){let s=t.indexOf(":]",n+2);if(s!==-1){let i=t.slice(n+2,s);e+=tw(i),n=s+2;continue}}let r=t[n];r==="\\"?n+1<t.length?(e+=`\\${t[n+1]}`,n+=2):(e+="\\\\",n++):r==="-"&&n>0&&n<t.length-1?(e+="-",n++):r==="^"&&n===0?(e+="^",n++):(r==="]"&&n===0?e+="\\]":e+=r,n++)}return e+="]",e}var ew={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 tw(t){return ew[t]??""}de();function Un(t,e){let n=`${e}_`,r=[];for(let s of Object.keys(t.state.env))if(s.startsWith(n)){let i=s.slice(n.length),o=Number.parseInt(i,10);!Number.isNaN(o)&&String(o)===i&&r.push(o)}return r.sort((s,i)=>s-i)}function jn(t,e){let n=`${e}_`;for(let r of Object.keys(t.state.env))r.startsWith(n)&&delete t.state.env[r]}function Pi(t,e){let n=`${e}_`,r=[];for(let s of Object.keys(t.state.env))if(s.startsWith(n)&&!s.includes("__")){let i=s.slice(n.length);r.push(i)}return r.sort()}function od(t){return t.startsWith("'")&&t.endsWith("'")||t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function Wr(t){return t.IFS??`
687
687
  `}function ad(t){return t.IFS===""}function zn(t){return t.split("").map(e=>/[\\^$.*+?()[\]{}|-]/.test(e)?`\\${e}`:e===" "?"\\t":e===`
688
688
  `?"\\n":e).join("")}function nw(t,e){let n=zn(t);return new RegExp(`[${n}]+`,e)}function rw(t){let e=zn(t);return new RegExp(`^[${e}]+`)}function sw(t){let e=zn(t);return new RegExp(`[${e}]+$`)}function dn(t){let e=t.IFS;return e===void 0?" ":e[0]||""}function ld(t,e){if(e==="")return{words:[t],wordStarts:[0]};let n=[],r=[],s=nw(e,"g"),i=0,o=t.match(rw(e));o&&(i=o[0].length),s.lastIndex=i;let a=s.exec(t);for(;a!==null;)a.index>i&&(r.push(i),n.push(t.substring(i,a.index))),i=s.lastIndex,a=s.exec(t);return i<t.length&&(r.push(i),n.push(t.substring(i))),{words:n,wordStarts:r}}function cd(t,e){return e===""?t:t.replace(sw(e),"")}function $e(t,e){return t.state.associativeArrays?.has(e)?Pi(t,e).map(i=>[i,t.state.env[`${e}_${i}`]]):Un(t,e).map(s=>[s,t.state.env[`${e}_${s}`]])}function ud(t,e){return t.state.associativeArrays?.has(e)?Pi(t,e).length>0:Un(t,e).length>0}function et(t,e,n=!0,r=!1){switch(e){case"?":return String(t.state.lastExitCode);case"$":return String(process.pid);case"#":return t.state.env["#"]||"0";case"@":return t.state.env["@"]||"";case"_":return t.state.lastArg;case"-":{let o="";return t.state.options.errexit&&(o+="e"),t.state.options.nounset&&(o+="u"),t.state.options.verbose&&(o+="v"),t.state.options.xtrace&&(o+="x"),t.state.options.pipefail&&(o+="p"),o}case"*":{let o=Number.parseInt(t.state.env["#"]||"0",10);if(o===0)return"";let a=[];for(let l=1;l<=o;l++)a.push(t.state.env[String(l)]||"");return a.join(dn(t.state.env))}case"0":return t.state.env[0]||"bash";case"PWD":return t.state.env.PWD!==void 0?t.state.env.PWD:"";case"OLDPWD":return t.state.env.OLDPWD!==void 0?t.state.env.OLDPWD:"";case"PPID":{let{ppid:o}=Bn();return String(o)}case"UID":{let{uid:o}=Bn();return String(o)}case"EUID":return String(process.geteuid?.()??Bn().uid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-t.state.startTime)/1e3));case"BASH_VERSION":return $f;case"!":return String(t.state.lastBackgroundPid);case"LINENO":return String(t.state.currentLine)}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(e))throw new ut(`\${${e}}`);let s=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let o=s[1],a=s[2];if(a==="@"||a==="*"){let f=$e(t,o);if(f.length>0)return f.map(([,p])=>p).join(" ");let d=t.state.env[o];return d!==void 0?d:""}if(t.state.associativeArrays?.has(o)){let f=od(a),d=t.state.env[`${o}_${f}`];if(d===void 0&&n&&t.state.options.nounset)throw new Xe(`${o}[${a}]`);return d||""}let c;if(/^-?\d+$/.test(a))c=Number.parseInt(a,10);else try{let f=new Fe,d=ve(f,a);c=re(t,d.expression)}catch{let f=t.state.env[a];c=f?Number.parseInt(f,10):0,Number.isNaN(c)&&(c=0)}if(c<0){let f=$e(t,o);if(f.length===0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${o}: bad array subscript
689
689
  `,"";let p=Math.max(...f.map(([m])=>typeof m=="number"?m:0))+1+c;return p<0?(t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${o}: bad array subscript