buxlabs/abstract-syntax-tree

Add a serialize method

emilos opened this issue · 0 comments

Context

Sometimes it's useful to serialize an abstract syntax tree node to a value/object.

For example:

{
  type: 'ArrayExpression',
  elements: [
    { type: 'Literal', value: 1 },
    { type: 'Literal', value: 2 },
    { type: 'Literal', value: 3 },
    { type: 'Literal', value: 4 },
    { type: 'Literal', value: 5 }
  ]
}

can be serialized to:

[1, 2, 3, 4, 5]

Acceptance criteria