Adding a toJSON or toString function to the TreeSitterNode class. I think the raw, internal representation is still useful to be able to inspect, so I only want to do the formatting on the DDSA_Console instead of globally.
What the reviewer should know
This PR also adds tests for console.log on various JavaScript types (superseding these tests, which will be replaced in the PR that switches over to ddsa)
The stella console.log for the same node as above is:
What problem are you trying to solve?
Currently, when calling
console.log
on aTreeSitterNode
, we get the raw, internal representation, which is a bunch of integers.Console logging is useful for debugging during the rule writing process, so it should output a more friendly helpful representation of a node.
What is your solution?
Implement a custom JSON.stringify replacer function to serialize the node with helpful information like the CST node type and text.
Before
After
Alternatives considered
toJSON
ortoString
function to theTreeSitterNode
class. I think the raw, internal representation is still useful to be able to inspect, so I only want to do the formatting on theDDSA_Console
instead of globally.What the reviewer should know
console.log
on various JavaScript types (superseding these tests, which will be replaced in the PR that switches over to ddsa)