(node: Descendant, path: number[])
| 241 | } |
| 242 | |
| 243 | const normalizeNode = (node: Descendant, path: number[]): Descendant => { |
| 244 | let nextNode = node; |
| 245 | let childrenChanged = false; |
| 246 | |
| 247 | if (shouldAssignNodeId([node, path], options)) { |
| 248 | nextNode = { |
| 249 | ...node, |
| 250 | [idKey]: idCreator(), |
| 251 | }; |
| 252 | } |
| 253 | |
| 254 | if (ElementApi.isElement(node)) { |
| 255 | const nextChildren = node.children.map((child, index) => { |
| 256 | const nextChild = normalizeNode(child as Descendant, [...path, index]); |
| 257 | |
| 258 | if (nextChild !== child) { |
| 259 | childrenChanged = true; |
| 260 | } |
| 261 | |
| 262 | return nextChild; |
| 263 | }); |
| 264 | |
| 265 | if (childrenChanged) { |
| 266 | nextNode = |
| 267 | nextNode === node |
| 268 | ? { |
| 269 | ...node, |
| 270 | children: nextChildren, |
| 271 | } |
| 272 | : { |
| 273 | ...nextNode, |
| 274 | children: nextChildren, |
| 275 | }; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | return nextNode; |
| 280 | }; |
| 281 | |
| 282 | let valueChanged = false; |
| 283 |
no test coverage detected
searching dependent graphs…