Replies: 2 comments
-
I think I found the solution I need by running const tokenizer = new Tokenizer(text);
const tokens = tokenizer.readTopLevelTokens(); Does this seem like the best method to reproduce the input liquid code from the source liquid code? |
Beta Was this translation helpful? Give feedback.
-
Yes, it is. And the result for tokenization is lexical AST (means there's no structural infomation). Calling
It's quite straightforward to reproduce the input, see the following code: const tokenizer = new Tokenizer(html)
const tokens = tokenizer.readTopLevelTokens()
const output = tokens.map(x => x.getText()).join('')
console.log(output === html) // true Note that not all subtypes of |
Beta Was this translation helpful? Give feedback.
-
I would like to use the AST generated by liquidjs to create a liquid formatter.
However, I am having trouble traversing the generated AST.
A block like the above gets generated and I get an array of Nodes. However, I can't figure out how to get the tokens nested in the if statement.
My generated output from looping through each Node and reducing getContent() or getText() to a string gives output like:
Are there any suggestions or places in the code base you could point me to helping me traverse the AST better?
Beta Was this translation helpful? Give feedback.
All reactions