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