* Wrap bare text in a string-type expression into quoted string literals for jsep. * Splits by variable placeholders (__varN__), quotes text segments, joins with +. * E.g. `hello __var0__` → `"hello " + __var0__`
(expr: string)
| 348 | if (from === "image") return false; |
| 349 | if (to === "string") return true; |
| 350 | return false; |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Wrap bare text in a string-type expression into quoted string literals for jsep. |
| 355 | * Splits by variable placeholders (__varN__), quotes text segments, joins with +. |
| 356 | * E.g. `hello __var0__` → `"hello " + __var0__` |
| 357 | */ |
| 358 | function wrapStringTemplate(expr: string): string { |
| 359 | // Split by __varN__ placeholders but keep them as delimiters |
| 360 | const parts = expr.split(/(__var\d+__)/); |
| 361 | const segments: string[] = []; |
| 362 | |
| 363 | for (const part of parts) { |
| 364 | if (/^__var\d+__$/.test(part)) { |
| 365 | segments.push(part); |
| 366 | } else if (part !== "") { |
| 367 | const escaped = part.replace(/\\/g, "\\\\").replace(/"/g, '\\"'); |
| 368 | segments.push(`"${escaped}"`); |