diff --git a/src/helpers/ClauseResultsHelpers.ts b/src/helpers/ClauseResultsHelpers.ts index 0af4af3d..0cdd807f 100644 --- a/src/helpers/ClauseResultsHelpers.ts +++ b/src/helpers/ClauseResultsHelpers.ts @@ -74,6 +74,12 @@ export function findAllLocalIdsInStatement( emptyResultClauses: any[], parentNode: any | null ): any { + // Stop recursing if this node happens to be any TypeSpecifier. We do not want to collect localIds for these clauses + // as they are not executed and will negatively affect clause coverage if captured here. ChoiceTypeSpecifiers do not + // identify their type and instead put [] at the `type` attribute which is a deprecated field. + if (statement?.type && (Array.isArray(statement.type) || statement.type.endsWith('TypeSpecifier'))) { + return localIds; + } // looking at the key and value of everything on this object or array for (const k in statement) { let alId; @@ -94,8 +100,14 @@ export function findAllLocalIdsInStatement( if (statement.expression != null && statement.expression.localId != null) { // Keep track of the localId of the expression that the alias references aliasMap[v] = statement.expression.localId; - // Determine the localId in the elm_annotation for this alias. - alId = (parseInt(statement.expression.localId, 10) + 1).toString(); + // Determine the localId for this alias. + if (statement.localId) { + alId = statement.localId; + } else { + // Older translator versions created an elm_annotation localId that was not always in the elm. This was a + // single increment up from the expression that defines the alias. + alId = (parseInt(statement.expression.localId, 10) + 1).toString(); + } emptyResultClauses.push({ lib: libraryName, aliasLocalId: alId, expressionLocalId: aliasMap[v] }); } } else if (k === 'scope') {