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)) { 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);
@@ -176,9 +175,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);
} }
@@ -98,8 +98,7 @@ function matrixProperties(matrix: MappingToken): Map<string, Set<string> | undef
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;
} }
@@ -123,8 +122,7 @@ function matrixProperties(matrix: MappingToken): Map<string, Set<string> | undef
} }
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);
@@ -137,14 +135,12 @@ function matrixProperties(matrix: MappingToken): Map<string, Set<string> | undef
} }
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]
}); });
} }
+6 -6
View File
@@ -698,9 +698,9 @@
"link": true "link": true
}, },
"node_modules/@github/actions-workflow-parser": { "node_modules/@github/actions-workflow-parser": {
"version": "0.0.29", "version": "0.0.30",
"resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.29/ecf3d1c9727e4f5f71e52863f456672b173b7096", "resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.30/2c95f0614784e740bc544d2a8f7b1661e9526920",
"integrity": "sha512-VJLRv+GHD0E7S9uUCH89jIIA3iMdKRcqhrKwKq5TE5u/6Lap5nj1Juy48tBoCFAog07lhuqyqgWjP6FHHyAvPg==", "integrity": "sha512-Gr/fDCh+dVZVCgDAo67gPVqV+cVrrhBPkVIaxnpyBVnPUtVftthY4+Klg3r37gNRSchxuORyxKQk/cPDrZwxoQ==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@github/actions-expressions": "*", "@github/actions-expressions": "*",
@@ -13533,9 +13533,9 @@
} }
}, },
"@github/actions-workflow-parser": { "@github/actions-workflow-parser": {
"version": "0.0.29", "version": "0.0.30",
"resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.29/ecf3d1c9727e4f5f71e52863f456672b173b7096", "resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.30/2c95f0614784e740bc544d2a8f7b1661e9526920",
"integrity": "sha512-VJLRv+GHD0E7S9uUCH89jIIA3iMdKRcqhrKwKq5TE5u/6Lap5nj1Juy48tBoCFAog07lhuqyqgWjP6FHHyAvPg==", "integrity": "sha512-Gr/fDCh+dVZVCgDAo67gPVqV+cVrrhBPkVIaxnpyBVnPUtVftthY4+Klg3r37gNRSchxuORyxKQk/cPDrZwxoQ==",
"requires": { "requires": {
"@github/actions-expressions": "*", "@github/actions-expressions": "*",
"yaml": "^2.0.0-8" "yaml": "^2.0.0-8"