(ast, options)
| 185 | } |
| 186 | |
| 187 | function extractInterpolation(ast, options) { |
| 188 | if (options.parser === "html") { |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | const interpolationRegex = /\{\{(.+?)\}\}/s; |
| 193 | ast.walk((node) => { |
| 194 | if (!canHaveInterpolation(node, options)) { |
| 195 | return; |
| 196 | } |
| 197 | |
| 198 | for (const child of node.children) { |
| 199 | if (child.kind !== "text") { |
| 200 | continue; |
| 201 | } |
| 202 | |
| 203 | let startSourceSpan = child.sourceSpan.start; |
| 204 | let endSourceSpan; |
| 205 | const components = child.value.split(interpolationRegex); |
| 206 | for ( |
| 207 | let i = 0; |
| 208 | i < components.length; |
| 209 | i++, startSourceSpan = endSourceSpan |
| 210 | ) { |
| 211 | const value = components[i]; |
| 212 | |
| 213 | if (i % 2 === 0) { |
| 214 | endSourceSpan = startSourceSpan.moveBy(value.length); |
| 215 | if (value.length > 0) { |
| 216 | node.insertChildBefore(child, { |
| 217 | kind: "text", |
| 218 | value, |
| 219 | sourceSpan: new ParseSourceSpan(startSourceSpan, endSourceSpan), |
| 220 | }); |
| 221 | } |
| 222 | continue; |
| 223 | } |
| 224 | |
| 225 | endSourceSpan = startSourceSpan.moveBy(value.length + 4); // `{{` + `}}` |
| 226 | node.insertChildBefore(child, { |
| 227 | kind: "interpolation", |
| 228 | sourceSpan: new ParseSourceSpan(startSourceSpan, endSourceSpan), |
| 229 | children: |
| 230 | value.length === 0 |
| 231 | ? [] |
| 232 | : [ |
| 233 | { |
| 234 | kind: "text", |
| 235 | value, |
| 236 | sourceSpan: new ParseSourceSpan( |
| 237 | startSourceSpan.moveBy(2), |
| 238 | endSourceSpan.moveBy(-2), |
| 239 | ), |
| 240 | }, |
| 241 | ], |
| 242 | }); |
| 243 | } |
| 244 |
nothing calls this directly
no test coverage detected
searching dependent graphs…