(
lines: string[],
rootRawExpr: string,
spec: GoVariantMatchSpec,
indent: string
)
| 1666 | } |
| 1667 | |
| 1668 | function pushGoJSONTargetedMatchSpecLines( |
| 1669 | lines: string[], |
| 1670 | rootRawExpr: string, |
| 1671 | spec: GoVariantMatchSpec, |
| 1672 | indent: string |
| 1673 | ): string | undefined { |
| 1674 | const groups = groupGoJSONMatchTerms(spec); |
| 1675 | for (const [index, group] of groups.entries()) { |
| 1676 | const emitFinalReturn = index === groups.length - 1; |
| 1677 | const groupVarPrefix = `rawGroup${index}`; |
| 1678 | const groupProperties = [ |
| 1679 | ...group.positiveTerms.map((term) => goJSONMatchPathProperty(term.path)), |
| 1680 | ...group.negativeProperties, |
| 1681 | ]; |
| 1682 | if (group.positiveTerms.length > 0) { |
| 1683 | const rawExpr = pushGoJSONRequiredRawPathLines(lines, rootRawExpr, group.parentPath, indent, groupVarPrefix); |
| 1684 | const structVar = goJSONPathVarName(groupVarPrefix, group.parentPath); |
| 1685 | const fieldNames = pushGoJSONRawStructUnmarshalLines(lines, rawExpr, structVar, groupProperties, indent); |
| 1686 | for (const term of group.positiveTerms) { |
| 1687 | pushGoJSONPositiveTermLines(lines, structVar, fieldNames, term, indent, groupVarPrefix); |
| 1688 | } |
| 1689 | const finalReturn = pushGoJSONNegativePropertyLines(lines, structVar, fieldNames, group.negativeProperties, indent, emitFinalReturn); |
| 1690 | if (finalReturn) return finalReturn; |
| 1691 | continue; |
| 1692 | } |
| 1693 | |
| 1694 | if (group.parentPath.length === 0) { |
| 1695 | const structVar = goJSONPathVarName(groupVarPrefix, group.parentPath); |
| 1696 | const fieldNames = pushGoJSONRawStructUnmarshalLines(lines, rootRawExpr, structVar, groupProperties, indent); |
| 1697 | const finalReturn = pushGoJSONNegativePropertyLines(lines, structVar, fieldNames, group.negativeProperties, indent, emitFinalReturn); |
| 1698 | if (finalReturn) return finalReturn; |
| 1699 | continue; |
| 1700 | } |
| 1701 | |
| 1702 | pushGoJSONOptionalRawPathLines(lines, rootRawExpr, group.parentPath, indent, groupVarPrefix, (rawExpr, structVar, innerIndent) => { |
| 1703 | const fieldNames = pushGoJSONRawStructDeclLines(lines, structVar, groupProperties, innerIndent); |
| 1704 | lines.push(`${innerIndent}if err := json.Unmarshal(${rawExpr}, &${structVar}); err == nil {`); |
| 1705 | pushGoJSONNegativePropertyLines(lines, structVar, fieldNames, group.negativeProperties, `${innerIndent}\t`); |
| 1706 | lines.push(`${innerIndent}}`); |
| 1707 | }); |
| 1708 | } |
| 1709 | return undefined; |
| 1710 | } |
| 1711 | |
| 1712 | function goVariantMatchFunctionLines( |
| 1713 | variant: GoDiscriminatedUnionVariant, |
no test coverage detected
searching dependent graphs…