(
lines: string[],
rawExpr: string,
path: string[],
indent: string,
varPrefix: string,
pushInnerLines: (innerRawExpr: string, innerVarPrefix: string, innerIndent: string) => void,
pathPrefix: string[] = [],
requireObject: boolean = true
)
| 1586 | } |
| 1587 | |
| 1588 | function pushGoJSONOptionalRawPathLines( |
| 1589 | lines: string[], |
| 1590 | rawExpr: string, |
| 1591 | path: string[], |
| 1592 | indent: string, |
| 1593 | varPrefix: string, |
| 1594 | pushInnerLines: (innerRawExpr: string, innerVarPrefix: string, innerIndent: string) => void, |
| 1595 | pathPrefix: string[] = [], |
| 1596 | requireObject: boolean = true |
| 1597 | ): void { |
| 1598 | if (path.length === 0) { |
| 1599 | pushInnerLines(rawExpr, goJSONPathVarName(varPrefix, pathPrefix), indent); |
| 1600 | return; |
| 1601 | } |
| 1602 | |
| 1603 | const [head, ...tail] = path; |
| 1604 | const structVar = goJSONPathVarName(varPrefix, pathPrefix); |
| 1605 | const fieldNames = pushGoJSONRawStructDeclLines(lines, structVar, [head], indent); |
| 1606 | if (requireObject) { |
| 1607 | lines.push(`${indent}if err := json.Unmarshal(${rawExpr}, &${structVar}); err != nil {`); |
| 1608 | lines.push(`${indent}\treturn false`); |
| 1609 | lines.push(`${indent}}`); |
| 1610 | lines.push(`${indent}if ${structVar}.${fieldNames.get(head)!} != nil {`); |
| 1611 | } else { |
| 1612 | lines.push(`${indent}if err := json.Unmarshal(${rawExpr}, &${structVar}); err == nil && ${structVar}.${fieldNames.get(head)!} != nil {`); |
| 1613 | } |
| 1614 | pushGoJSONOptionalRawPathLines( |
| 1615 | lines, |
| 1616 | `${structVar}.${fieldNames.get(head)!}`, |
| 1617 | tail, |
| 1618 | `${indent}\t`, |
| 1619 | varPrefix, |
| 1620 | pushInnerLines, |
| 1621 | [...pathPrefix, head], |
| 1622 | false |
| 1623 | ); |
| 1624 | lines.push(`${indent}}`); |
| 1625 | } |
| 1626 | |
| 1627 | function pushGoJSONPositiveTermLines( |
| 1628 | lines: string[], |
no test coverage detected
searching dependent graphs…