Replace for loops with for...of

This commit is contained in:
Josh Gross
2022-12-08 15:22:34 -05:00
parent 78182b3bba
commit 44239714e6
7 changed files with 18 additions and 31 deletions
+2 -5
View File
@@ -159,8 +159,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);
@@ -176,9 +175,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);
}
@@ -98,8 +98,7 @@ function matrixProperties(matrix: MappingToken): Map<string, Set<string> | undef
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;
}
@@ -123,8 +122,7 @@ function matrixProperties(matrix: MappingToken): Map<string, Set<string> | undef
}
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);
@@ -137,14 +135,12 @@ function matrixProperties(matrix: MappingToken): Map<string, Set<string> | undef
}
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]
});
}
+6 -6
View File
@@ -698,9 +698,9 @@
"link": true
},
"node_modules/@github/actions-workflow-parser": {
"version": "0.0.29",
"resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.29/ecf3d1c9727e4f5f71e52863f456672b173b7096",
"integrity": "sha512-VJLRv+GHD0E7S9uUCH89jIIA3iMdKRcqhrKwKq5TE5u/6Lap5nj1Juy48tBoCFAog07lhuqyqgWjP6FHHyAvPg==",
"version": "0.0.30",
"resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.30/2c95f0614784e740bc544d2a8f7b1661e9526920",
"integrity": "sha512-Gr/fDCh+dVZVCgDAo67gPVqV+cVrrhBPkVIaxnpyBVnPUtVftthY4+Klg3r37gNRSchxuORyxKQk/cPDrZwxoQ==",
"license": "MIT",
"dependencies": {
"@github/actions-expressions": "*",
@@ -13533,9 +13533,9 @@
}
},
"@github/actions-workflow-parser": {
"version": "0.0.29",
"resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.29/ecf3d1c9727e4f5f71e52863f456672b173b7096",
"integrity": "sha512-VJLRv+GHD0E7S9uUCH89jIIA3iMdKRcqhrKwKq5TE5u/6Lap5nj1Juy48tBoCFAog07lhuqyqgWjP6FHHyAvPg==",
"version": "0.0.30",
"resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.30/2c95f0614784e740bc544d2a8f7b1661e9526920",
"integrity": "sha512-Gr/fDCh+dVZVCgDAo67gPVqV+cVrrhBPkVIaxnpyBVnPUtVftthY4+Klg3r37gNRSchxuORyxKQk/cPDrZwxoQ==",
"requires": {
"@github/actions-expressions": "*",
"yaml": "^2.0.0-8"