( conditional: ConditionalSelect, path: Array<string>, replacement: ValClass, )
| 1990 | } |
| 1991 | |
| 1992 | function replaceIncludesInConditionalSelect( |
| 1993 | conditional: ConditionalSelect, |
| 1994 | path: Array<string>, |
| 1995 | replacement: ValClass, |
| 1996 | ): { value: ConditionalSelect; replaced: boolean } { |
| 1997 | let replaced = false |
| 1998 | const branches = conditional.branches.map((branch) => { |
| 1999 | const result = |
| 2000 | path.length === 0 |
| 2001 | ? replaceIncludesValue(branch.value, replacement) |
| 2002 | : replaceIncludesInSelectValue(branch.value, path, replacement) |
| 2003 | if (!result.replaced) { |
| 2004 | return branch |
| 2005 | } |
| 2006 | replaced = true |
| 2007 | return { ...branch, value: result.value } |
| 2008 | }) |
| 2009 | |
| 2010 | let defaultValue = conditional.defaultValue |
| 2011 | if (conditional.defaultValue !== undefined) { |
| 2012 | const result = |
| 2013 | path.length === 0 |
| 2014 | ? replaceIncludesValue(conditional.defaultValue, replacement) |
| 2015 | : replaceIncludesInSelectValue( |
| 2016 | conditional.defaultValue, |
| 2017 | path, |
| 2018 | replacement, |
| 2019 | ) |
| 2020 | if (result.replaced) { |
| 2021 | replaced = true |
| 2022 | defaultValue = result.value |
| 2023 | } |
| 2024 | } |
| 2025 | |
| 2026 | if (!replaced) { |
| 2027 | return { value: conditional, replaced: false } |
| 2028 | } |
| 2029 | |
| 2030 | return { |
| 2031 | value: new ConditionalSelect(branches, defaultValue), |
| 2032 | replaced: true, |
| 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | /** |
| 2037 | * Gets a nested value from an object by path segments. |
no test coverage detected