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