Skip to content

Commit

Permalink
minor change in while loops to be consistent with for loops (#1491)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-henz authored Sep 29, 2023
1 parent f82bd10 commit 24e9ce7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ec-evaluator/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ const cmdEvaluators: { [type: string]: CmdEvaluator } = {
}
agenda.push(instr.whileInstr(command.test, command.body, command))
agenda.push(command.test)
stash.push(undefined) // Return undefined if there is no loop execution
agenda.push(ast.identifier('undefined', command.loc)) // Return undefined if there is no loop execution
},

ForStatement: function (command: es.ForStatement, context: Context, agenda: Agenda) {
Expand Down Expand Up @@ -816,7 +816,8 @@ const cmdEvaluators: { [type: string]: CmdEvaluator } = {
if (
next &&
!(isInstr(next) && next.instrType === InstrType.ENVIRONMENT) &&
args.length !== 0
args.length !== 0 &&
agenda.some(isNode)
) {
agenda.push(instr.envInstr(currentEnvironment(context), command.srcNode))
}
Expand Down
4 changes: 4 additions & 0 deletions src/ec-evaluator/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export class Stack<T> implements IStack<T> {
// return a copy of the stack's contents
return [...this.storage]
}

public some(predicate: (value: T) => boolean): boolean {
return this.storage.some(predicate)
}
}

/**
Expand Down

0 comments on commit 24e9ce7

Please sign in to comment.