(input: string)
| 982 | } |
| 983 | |
| 984 | protected async replaceFieldVarInString(input: string) { |
| 985 | const regex = new RegExp(FIELD_VAR_REGEX_WITH_FILTERS.source, "gi"); |
| 986 | let output = ""; |
| 987 | let lastIndex = 0; |
| 988 | let match: RegExpExecArray | null; |
| 989 | |
| 990 | while ((match = regex.exec(input)) !== null) { |
| 991 | output += input.slice(lastIndex, match.index); |
| 992 | |
| 993 | // match[1] contains the field name (and potentially the old filter syntax if no pipe is used) |
| 994 | // match[2] contains the filter part starting with |, if present |
| 995 | const fullMatch = match[1] + (match[2] || ""); |
| 996 | |
| 997 | if (fullMatch) { |
| 998 | const fieldVariableKey = this.getFieldVariableKey(fullMatch); |
| 999 | const parsed = FieldSuggestionParser.parse(fullMatch, { |
| 1000 | warnUnknown: true, |
| 1001 | }); |
| 1002 | |
| 1003 | if (!this.hasConcreteVariable(fieldVariableKey)) { |
| 1004 | this.variables.set( |
| 1005 | fieldVariableKey, |
| 1006 | await this.suggestForField(fullMatch), |
| 1007 | ); |
| 1008 | } |
| 1009 | |
| 1010 | const rawValue = this.hasConcreteVariable(fieldVariableKey) |
| 1011 | ? this.variables.get(fieldVariableKey) |
| 1012 | : this.getVariableValue(fullMatch); |
| 1013 | let replacement: string; |
| 1014 | |
| 1015 | if (Array.isArray(rawValue)) { |
| 1016 | const structuredYamlValue = this.propertyCollector.maybeCollect({ |
| 1017 | input, |
| 1018 | matchStart: match.index, |
| 1019 | matchEnd: match.index + match[0].length, |
| 1020 | rawValue, |
| 1021 | fallbackKey: parsed.fieldName, |
| 1022 | collectionActive: this.templatePropertyCollectionDepth > 0, |
| 1023 | heuristicEnabled: false, |
| 1024 | }); |
| 1025 | replacement = |
| 1026 | getYamlPlaceholder(structuredYamlValue) ?? rawValue.join(","); |
| 1027 | } else { |
| 1028 | replacement = String(rawValue ?? ""); |
| 1029 | } |
| 1030 | |
| 1031 | output += replacement; |
| 1032 | } else { |
| 1033 | output += match[0]; |
| 1034 | } |
| 1035 | |
| 1036 | lastIndex = regex.lastIndex; |
| 1037 | } |
| 1038 | |
| 1039 | return output + input.slice(lastIndex); |
| 1040 | } |
| 1041 |
nothing calls this directly
no test coverage detected