buxlabs / abstract-syntax-tree

A library for working with abstract syntax trees.
MIT License
110 stars 13 forks source link

Add a serialize method #82

Closed emilos closed 4 years ago

emilos commented 4 years ago

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