Merge pull request #47 from github/joshmgross/for-of

Replace `for` loops with `for...of`
This commit is contained in:
Josh Gross
2022-12-09 18:03:05 -05:00
committed by GitHub
6 changed files with 12 additions and 25 deletions
+2 -5
View File
@@ -167,8 +167,7 @@ export function getExistingValues(token: TemplateToken | null, parent: TemplateT
if (isSequence(parent)) {
const sequenceValues = new Set<string>();
for (let i = 0; i < parent.count; i++) {
const t = parent.get(i);
for (const t of parent) {
if (isString(t)) {
// Should we support other literal values here?
sequenceValues.add(t.value);
@@ -184,9 +183,7 @@ export function getExistingValues(token: TemplateToken | null, parent: TemplateT
const mapKeys = new Set<string>();
const mapToken = parent as MappingToken;
for (let i = 0; i < mapToken.count; i++) {
const key = mapToken.get(i).key;
for (const {key} of mapToken) {
if (isString(key)) {
mapKeys.add(key.value);
}
@@ -99,8 +99,7 @@ function matrixProperties(matrix: MappingToken, mode: Mode): Map<string, Set<str
let include: SequenceToken | undefined;
for (let i = 0; i < matrix.count; i++) {
const pair = matrix.get(i);
for (const pair of matrix) {
if (!isString(pair.key)) {
continue;
}
@@ -129,8 +128,7 @@ function matrixProperties(matrix: MappingToken, mode: Mode): Map<string, Set<str
}
const values = new Set<string>();
for (let j = 0; j < pair.value.count; j++) {
const value = pair.value.get(j);
for (const value of pair.value) {
// The parser should coerce matrix values to strings, ignore expressions
if (isString(value)) {
values.add(value.value);
@@ -143,14 +141,12 @@ function matrixProperties(matrix: MappingToken, mode: Mode): Map<string, Set<str
}
if (include) {
for (let i = 0; i < include.count; i++) {
const item = include.get(i);
for (const item of include) {
if (!isMapping(item)) {
continue;
}
for (let j = 0; j < item.count; j++) {
const pair = item.get(j);
for (const pair of item) {
addValueToProperties(properties, pair);
}
}
@@ -34,8 +34,7 @@ function jobOutputs(job?: Job): data.Dictionary {
return d;
}
for (let i = 0; i < job.outputs.count; ++i) {
const output = job.outputs.get(i);
for (const output of job.outputs) {
if (!isString(output.key)) {
continue;
}
@@ -17,8 +17,7 @@ export function getStrategyContext(workflowContext: WorkflowContext): data.Dicti
}
const strategyContext = new data.Dictionary();
for (let i = 0; i < strategy.count; i++) {
const pair = strategy.get(i);
for (const pair of strategy) {
if (!isString(pair.key)) {
continue;
}
@@ -31,9 +31,7 @@ export function getWorkflowContext(
let stepToken: MappingToken | undefined = undefined;
// Iterate through the token path to find the job and step
for (let i = 0; i < tokenPath.length; ++i) {
const token = tokenPath[i];
for (const token of tokenPath) {
switch (token.definition?.key) {
case "job-id": {
const jobID = (token as StringToken).value;
@@ -69,9 +69,7 @@ export function findToken(pos: Position, root?: TemplateToken): TokenResult {
switch (token.templateTokenType) {
case TokenType.Mapping:
const mappingToken = token as MappingToken;
for (let i = 0; i < mappingToken.count; i++) {
const {key, value} = mappingToken.get(i);
for (const {key, value} of mappingToken) {
// If the position is within the key, immediately return it as the token.
if (posInToken(pos, key)) {
return {
@@ -104,11 +102,11 @@ export function findToken(pos: Position, root?: TemplateToken): TokenResult {
case TokenType.Sequence:
const sequenceToken = token as SequenceToken;
for (let i = 0; i < sequenceToken.count; i++) {
for (const token of sequenceToken) {
s.push({
parent: sequenceToken,
keyToken: null,
token: sequenceToken.get(i),
token: token,
path: [...path, sequenceToken]
});
}