(ast /* , options */)
| 139 | } |
| 140 | |
| 141 | function mergeSimpleElementIntoText(ast /* , options */) { |
| 142 | const isSimpleElement = (node) => |
| 143 | node.kind === "element" && |
| 144 | node.attrs.length === 0 && |
| 145 | !isNonEmptyArray(node.startTagComments) && |
| 146 | node.children.length === 1 && |
| 147 | node.firstChild.kind === "text" && |
| 148 | !htmlWhitespace.hasWhitespaceCharacter(node.children[0].value) && |
| 149 | !node.firstChild.hasLeadingSpaces && |
| 150 | !node.firstChild.hasTrailingSpaces && |
| 151 | node.isLeadingSpaceSensitive && |
| 152 | !node.hasLeadingSpaces && |
| 153 | node.isTrailingSpaceSensitive && |
| 154 | !node.hasTrailingSpaces && |
| 155 | node.prev?.kind === "text" && |
| 156 | node.next?.kind === "text"; |
| 157 | ast.walk((node) => { |
| 158 | if (node.children) { |
| 159 | for (let i = 0; i < node.children.length; i++) { |
| 160 | const child = node.children[i]; |
| 161 | if (!isSimpleElement(child)) { |
| 162 | continue; |
| 163 | } |
| 164 | |
| 165 | const prevChild = child.prev; |
| 166 | const nextChild = child.next; |
| 167 | prevChild.value += |
| 168 | `<${child.rawName}>` + |
| 169 | child.firstChild.value + |
| 170 | `</${child.rawName}>` + |
| 171 | nextChild.value; |
| 172 | prevChild.sourceSpan = new ParseSourceSpan( |
| 173 | prevChild.sourceSpan.start, |
| 174 | nextChild.sourceSpan.end, |
| 175 | ); |
| 176 | prevChild.isTrailingSpaceSensitive = nextChild.isTrailingSpaceSensitive; |
| 177 | prevChild.hasTrailingSpaces = nextChild.hasTrailingSpaces; |
| 178 | |
| 179 | node.removeChild(child); |
| 180 | i--; // because a node was removed |
| 181 | node.removeChild(nextChild); |
| 182 | } |
| 183 | } |
| 184 | }); |
| 185 | } |
| 186 | |
| 187 | function extractInterpolation(ast, options) { |
| 188 | if (options.parser === "html") { |
nothing calls this directly
no test coverage detected
searching dependent graphs…