(source: string, varValues: Map<string, string>, fullStack = new Set<string>())
| 852 | } |
| 853 | |
| 854 | function insertVarValues(source: string, varValues: Map<string, string>, fullStack = new Set<string>()) { |
| 855 | let containsUnresolvedVar = false; |
| 856 | const matchReplacer = (match: string, count: number) => { |
| 857 | const {name, fallback} = getVariableNameAndFallback(match); |
| 858 | const stack = count > 1 ? new Set(fullStack) : fullStack; |
| 859 | if (stack.has(name)) { |
| 860 | containsUnresolvedVar = true; |
| 861 | return null; |
| 862 | } |
| 863 | stack.add(name); |
| 864 | const varValue = varValues.get(name) || fallback; |
| 865 | let inserted: string | null = null; |
| 866 | if (varValue) { |
| 867 | if (isVarDependant(varValue)) { |
| 868 | inserted = insertVarValues(varValue, varValues, stack); |
| 869 | } else { |
| 870 | inserted = varValue; |
| 871 | } |
| 872 | } |
| 873 | if (!inserted) { |
| 874 | containsUnresolvedVar = true; |
| 875 | return null; |
| 876 | } |
| 877 | return inserted; |
| 878 | }; |
| 879 | |
| 880 | const replaced = replaceVariablesMatches(source, matchReplacer); |
| 881 | if (containsUnresolvedVar) { |
| 882 | return null; |
| 883 | } |
| 884 | return replaced; |
| 885 | } |
no test coverage detected