fixed Text parsing issue

This commit is contained in:
kree 2026-08-06 10:29:11 -04:00
parent b81ac470c5
commit 10003a1167

View file

@ -74,7 +74,11 @@ function _parse(text: string, root: Node): Node {
if (text.substring(i, i+2) == '}}') { if (text.substring(i, i+2) == '}}') {
textNode.parent = scope; textNode.parent = scope;
const j = open.pop()!;
textNode.endIndex = j;
textNode.text = text.substring(textNode.startIndex!, textNode.endIndex!) textNode.text = text.substring(textNode.startIndex!, textNode.endIndex!)
switch (scope.type) { switch (scope.type) {
case 'Container': case 'Container':
scope.placeholders!.push(textNode) scope.placeholders!.push(textNode)
@ -84,14 +88,13 @@ function _parse(text: string, root: Node): Node {
placeholders.push(textNode); placeholders.push(textNode);
} }
const j = open.pop()!;
textNode = { textNode = {
type: 'Text', type: 'Text',
startIndex: j+2, startIndex: i+2,
endIndex: i endIndex: i
}; };
const command = parseCommand(text, j+2, i); const command = parseCommand(text, j+2, i);
command.parent = scope; command.parent = scope;
@ -242,6 +245,7 @@ function printNode(node: Node, offset='') {
break; break;
case 'Text': case 'Text':
console.log(`${offset}${node.type} [text=${JSON.stringify(node.text)}]`); console.log(`${offset}${node.type} [text=${JSON.stringify(node.text)}]`);
break;
default: default:
console.log(`${offset}${node.type}`); console.log(`${offset}${node.type}`);
} }