(node: any, source?: string, lineStarts = source ? getLineStarts(source) : undefined)
| 972 | } |
| 973 | |
| 974 | function canonicalizeEditedTextSubtree(node: any, source?: string, lineStarts = source ? getLineStarts(source) : undefined): void { |
| 975 | const children = node.children; |
| 976 | if (!children || children.length === 0) return; |
| 977 | |
| 978 | for (const child of children) { |
| 979 | if (child.type === "JSXElement") { |
| 980 | canonicalizeEditedTextSubtree(child, source, lineStarts); |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | const normalized: any[] = []; |
| 985 | let pendingBoundarySpace = false; |
| 986 | |
| 987 | for (const child of children) { |
| 988 | if (isTextLikeChild(child)) { |
| 989 | const value = getTextLikeValue(child) ?? ""; |
| 990 | if (!value) continue; |
| 991 | |
| 992 | const { core, hasLeadingWhitespace, hasTrailingWhitespace } = trimTextLikeEdges(value); |
| 993 | if (!core) { |
| 994 | if (hasVisibleTextInEntries(normalized, source, lineStarts)) { |
| 995 | pendingBoundarySpace = true; |
| 996 | } |
| 997 | continue; |
| 998 | } |
| 999 | |
| 1000 | setTextLikeValue(child, core); |
| 1001 | if ((pendingBoundarySpace || hasLeadingWhitespace) && hasVisibleTextInEntries(normalized, source, lineStarts)) { |
| 1002 | insertSingleVisibleBoundarySpace(normalized, child); |
| 1003 | } |
| 1004 | |
| 1005 | normalized.push(child); |
| 1006 | pendingBoundarySpace = hasTrailingWhitespace; |
| 1007 | continue; |
| 1008 | } |
| 1009 | |
| 1010 | const childText = getRenderedChildText(child, source, lineStarts); |
| 1011 | const childHasVisibleText = /\S/.test(childText); |
| 1012 | if ((pendingBoundarySpace || /^\s/.test(childText)) && childHasVisibleText && hasVisibleTextInEntries(normalized, source, lineStarts)) { |
| 1013 | insertSingleVisibleBoundarySpace(normalized, child); |
| 1014 | } |
| 1015 | |
| 1016 | normalized.push(child); |
| 1017 | pendingBoundarySpace = childHasVisibleText && /\s$/.test(childText); |
| 1018 | } |
| 1019 | |
| 1020 | node.children = mergeAdjacentTextLikeChildren(normalized); |
| 1021 | } |
| 1022 | |
| 1023 | function canonicalizeVisibleWhitespace(node: any, source?: string, lineStarts = source ? getLineStarts(source) : undefined): void { |
| 1024 | const children = node.children; |
no test coverage detected