* Inserts args in place of numerical tokens. String args are converted to * JSON that defines a label field. Newline characters are converted to * end-row inputs, and if necessary an extra dummy input is added to the end * of the elements. * * @param tokens The tokens to interpolate
(
tokens: Array<string | number>,
args: Array<AnyDuringMigration | string>,
implicitAlign: string | undefined,
)
| 2043 | * @returns The JSON definitions of field and inputs to add to the block. |
| 2044 | */ |
| 2045 | private interpolateArguments( |
| 2046 | tokens: Array<string | number>, |
| 2047 | args: Array<AnyDuringMigration | string>, |
| 2048 | implicitAlign: string | undefined, |
| 2049 | ): AnyDuringMigration[] { |
| 2050 | const elements = []; |
| 2051 | for (let i = 0; i < tokens.length; i++) { |
| 2052 | let element = tokens[i]; |
| 2053 | if (typeof element === 'number') { |
| 2054 | element = args[element - 1]; |
| 2055 | } |
| 2056 | // Args can be strings, which is why this isn't elseif. |
| 2057 | if (typeof element === 'string') { |
| 2058 | if (element === '\n') { |
| 2059 | // Convert newline tokens to end-row inputs. |
| 2060 | const newlineInput = {'type': 'input_end_row'}; |
| 2061 | if (implicitAlign) { |
| 2062 | (newlineInput as AnyDuringMigration)['align'] = implicitAlign; |
| 2063 | } |
| 2064 | element = newlineInput as AnyDuringMigration; |
| 2065 | } else { |
| 2066 | // AnyDuringMigration because: Type '{ text: string; type: string; } |
| 2067 | // | null' is not assignable to type 'string | number'. |
| 2068 | element = this.stringToFieldJson(element) as AnyDuringMigration; |
| 2069 | if (!element) { |
| 2070 | continue; |
| 2071 | } |
| 2072 | } |
| 2073 | } |
| 2074 | elements.push(element); |
| 2075 | } |
| 2076 | |
| 2077 | const length = elements.length; |
| 2078 | if ( |
| 2079 | length && |
| 2080 | !this.isInputKeyword((elements as AnyDuringMigration)[length - 1]['type']) |
| 2081 | ) { |
| 2082 | const dummyInput = {'type': 'input_dummy'}; |
| 2083 | if (implicitAlign) { |
| 2084 | (dummyInput as AnyDuringMigration)['align'] = implicitAlign; |
| 2085 | } |
| 2086 | elements.push(dummyInput); |
| 2087 | } |
| 2088 | |
| 2089 | return elements; |
| 2090 | } |
| 2091 | |
| 2092 | /** |
| 2093 | * Creates a field from the JSON definition of a field. If a field with the |
no test coverage detected