(name: string)
| 7 | * {{VALUE:name}} grammar. |
| 8 | */ |
| 9 | export function assertAssignableVariableName(name: string): void { |
| 10 | const trimmed = name.trim(); |
| 11 | if (!trimmed) throw new Error("assignToVariable cannot be empty."); |
| 12 | // `value` (the programmatic {{VALUE}} slot) and `title` (file-name title) are |
| 13 | // formatter-reserved; assigning them would silently hijack those tokens. |
| 14 | // Matched case-INSENSITIVELY because the formatter resolves {{VALUE:name}} |
| 15 | // that way (resolveExistingVariableKey -> findCaseInsensitiveMatch), so a |
| 16 | // `Value`/`TITLE` variant would otherwise slip the guard and still hijack the |
| 17 | // built-in token - consistent with isReservedVariableKey below. |
| 18 | if (new Set(["value", "title", "text", "meta"]).has(trimmed.toLowerCase())) { |
| 19 | throw new Error( |
| 20 | `assignToVariable "${trimmed}" is reserved (it would hijack a built-in formatter token).`, |
| 21 | ); |
| 22 | } |
| 23 | // Case-insensitive for the same reason as the reserved-name set above: the |
| 24 | // formatter resolves {{VALUE:name}} case-insensitively, so `summary-Quoted` |
| 25 | // would still collide with the auto-generated `${key}-quoted` companion. |
| 26 | if (trimmed.toLowerCase().endsWith("-quoted")) { |
| 27 | throw new Error( |
| 28 | `assignToVariable "${trimmed}" cannot end with "-quoted" (collides with the quoted output variable).`, |
| 29 | ); |
| 30 | } |
| 31 | // Reserved internal namespace (shared with the URI/CLI boundaries) and the |
| 32 | // pipe/comma characters the {{VALUE:name}} grammar cannot reference. |
| 33 | if (isReservedVariableKey(trimmed)) { |
| 34 | throw new Error( |
| 35 | `assignToVariable "${trimmed}" uses the reserved "__qa." prefix for QuickAdd internal variables.`, |
| 36 | ); |
| 37 | } |
| 38 | if (/[|,]/.test(trimmed)) { |
| 39 | throw new Error( |
| 40 | `assignToVariable "${trimmed}" contains characters unreachable by {{VALUE:name}}.`, |
| 41 | ); |
| 42 | } |
| 43 | } |
no test coverage detected