* Escape and wrap key so it is safe to use as a reactid * * @param {string} key to be escaped. * @return {string} the escaped key.
(key: string)
| 37 | * @return {string} the escaped key. |
| 38 | */ |
| 39 | function escape(key: string): string { |
| 40 | const escapeRegex = /[=:]/g; |
| 41 | const escaperLookup = { |
| 42 | '=': '=0', |
| 43 | ':': '=2', |
| 44 | }; |
| 45 | const escapedString = key.replace(escapeRegex, function (match) { |
| 46 | // $FlowFixMe[invalid-computed-prop] |
| 47 | return escaperLookup[match]; |
| 48 | }); |
| 49 | |
| 50 | return '$' + escapedString; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * TODO: Test that a single child and an array with one item have the same key |
no outgoing calls