@poe-platform/safe-bash 0.1.526 → 0.1.527

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.
@@ -38650,6 +38650,40 @@ var Parser4 = class {
38650
38650
  const body = this.nonemptyScript(/* @__PURE__ */ new Set(["done"]));
38651
38651
  this.expect("done", true);
38652
38652
  command7 = { kind, condition, body, redirects: [] };
38653
+ } else if (this.is("for") && this.peek().value === "(" && this.lexer.source.startsWith("((", this.peek().offset)) {
38654
+ this.advance();
38655
+ const start = this.current.offset + 2;
38656
+ let partStart = start;
38657
+ let depth = 0;
38658
+ let end = start;
38659
+ this.budget.admit(4);
38660
+ const sources2 = [];
38661
+ for (; end < this.lexer.source.length; end++) {
38662
+ this.budget.admit();
38663
+ const character = this.lexer.source[end];
38664
+ if (character === "(") depth++;
38665
+ else if (character === ")") {
38666
+ if (!depth && this.lexer.source[end + 1] === ")") break;
38667
+ if (--depth < 0) this.error("Unterminated arithmetic for", true);
38668
+ } else if (character === ";" && !depth) {
38669
+ if (sources2.length === 2) this.error("Arithmetic for requires three expressions");
38670
+ sources2.push(this.lexer.source.slice(partStart, end));
38671
+ partStart = end + 1;
38672
+ }
38673
+ }
38674
+ if (end === this.lexer.source.length) this.error("Unterminated arithmetic for", true);
38675
+ if (sources2.length !== 2) this.error("Arithmetic for requires three expressions");
38676
+ sources2.push(this.lexer.source.slice(partStart, end));
38677
+ const expressions = sources2.map((source2) => source2.trim() ? prepareArithmetic(source2, this.budget) : void 0);
38678
+ this.lexer.position = end + 2;
38679
+ this.lookahead = void 0;
38680
+ this.current = this.lexer.next();
38681
+ if (this.is(";")) this.advance();
38682
+ this.newlines();
38683
+ this.expect("do", true);
38684
+ const body = this.nonemptyScript(/* @__PURE__ */ new Set(["done"]));
38685
+ this.expect("done", true);
38686
+ command7 = { kind: "arithmetic-for", expressions, body, redirects: [] };
38653
38687
  } else if (this.is("for") || this.is("select")) {
38654
38688
  const kind = this.advance().value;
38655
38689
  const name2 = this.advance().value;
@@ -39654,6 +39688,12 @@ function commandText(command7, indent) {
39654
39688
  case "arithmetic":
39655
39689
  text3 = `(( ${command7.source} ))`;
39656
39690
  break;
39691
+ case "arithmetic-for":
39692
+ text3 = `for (( ${command7.expressions.map((expression) => expression?.source ?? "").join("; ")} ));
39693
+ do
39694
+ ${nested}${scriptText(command7.body, nested)};
39695
+ ${indent}done`;
39696
+ break;
39657
39697
  case "conditional":
39658
39698
  text3 = `[[${command7.source}]]`;
39659
39699
  break;
@@ -43178,6 +43218,18 @@ var Runtime = class _Runtime {
43178
43218
  this.signal.throwIfAborted();
43179
43219
  if (error instanceof NounsetFailure || error instanceof Flow2 || error instanceof ShellLimitError || error instanceof ShellSyntaxError) throw error;
43180
43220
  }
43221
+ arithmeticValue(program, state, io) {
43222
+ return evaluatePositionalArithmetic(program, {
43223
+ parseBudget: this.budget.parsing,
43224
+ positional: state.positional,
43225
+ arg0: state.arg0 ?? "virtual-bash",
43226
+ owner: arrayStore(state)?.owner,
43227
+ maximumBytes: this.budget.limits.maxExpansionBytes,
43228
+ checkpoint: () => this.signal.throwIfAborted(),
43229
+ requireParameter: (name2, value2) => this.requireParameter(value2, name2, state, io),
43230
+ limit: () => this.budget.fail("maxExpansionBytes")
43231
+ }, (prepared) => evaluateArithmetic(prepared, this.arithmeticVariables(state, io.diagnosticLine), this.budget.parsing));
43232
+ }
43181
43233
  arithmeticVariables(state, line) {
43182
43234
  return new Proxy(state.variables, {
43183
43235
  get: (target, key) => {
@@ -43878,16 +43930,7 @@ var Runtime = class _Runtime {
43878
43930
  }
43879
43931
  if (command7.kind === "arithmetic") {
43880
43932
  try {
43881
- return Number(evaluatePositionalArithmetic(command7.expression, {
43882
- parseBudget: this.budget.parsing,
43883
- positional: state.positional,
43884
- arg0: state.arg0 ?? "virtual-bash",
43885
- owner: arrayStore(state)?.owner,
43886
- maximumBytes: this.budget.limits.maxExpansionBytes,
43887
- checkpoint: () => this.signal.throwIfAborted(),
43888
- requireParameter: (name2, value2) => this.requireParameter(value2, name2, state, io),
43889
- limit: () => this.budget.fail("maxExpansionBytes")
43890
- }, (prepared) => evaluateArithmetic(prepared, this.arithmeticVariables(state, io.diagnosticLine), this.budget.parsing)) === 0n);
43933
+ return Number(this.arithmeticValue(command7.expression, state, io) === 0n);
43891
43934
  } catch (error) {
43892
43935
  this.rethrowArithmeticControl(error);
43893
43936
  throw new PublicDiagnostic(`((: ${message2(error, this.budget.onInternalError)}`);
@@ -43946,6 +43989,29 @@ var Runtime = class _Runtime {
43946
43989
  status3 = result2.status;
43947
43990
  if (result2.stop) break;
43948
43991
  }
43992
+ } else if (command7.kind === "arithmetic-for") {
43993
+ const evaluate = async (program) => {
43994
+ if (!program) return 1n;
43995
+ try {
43996
+ return this.arithmeticValue(program, state, io);
43997
+ } catch (error) {
43998
+ this.rethrowArithmeticControl(error);
43999
+ await this.diagnostic(io, `((: ${message2(error, this.budget.onInternalError)}`);
44000
+ return void 0;
44001
+ }
44002
+ };
44003
+ if (await evaluate(command7.expressions[0]) === void 0) return 1;
44004
+ while (true) {
44005
+ this.budget.loop();
44006
+ await yieldTurn(this.signal);
44007
+ const condition = await evaluate(command7.expressions[1]);
44008
+ if (condition === void 0) return 1;
44009
+ if (condition === 0n) break;
44010
+ const result2 = await this.loopBody(command7.body, state, io);
44011
+ status3 = result2.status;
44012
+ if (result2.stop) break;
44013
+ if (await evaluate(command7.expressions[2]) === void 0) return 1;
44014
+ }
43949
44015
  } else if (command7.kind === "select") {
43950
44016
  const values = command7.words ? await this.valueWords(command7.words, state, io) : this.positionalValues(state);
43951
44017
  if (!values.length) return 0;