buxlabs / abstract-syntax-tree

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

Converting ArrayExpression into a BinaryExpression [docs] #90

Closed emilos closed 4 years ago

emilos commented 4 years ago

It would be nice to document how to transform:

{
  "type": "ArrayExpression",
  "elements": [
    {
      "type": "Literal",
      "value": "foo"
    },
    {
      "type": "Literal",
      "value": "bar"
    },
    {
      "type": "Literal",
      "value": "baz"
    }
  ]
}

to:

{
  "type": "BinaryExpression",
  "left": {
    "type": "BinaryExpression",
    "left": {
      "type": "Literal",
      "value": "foo"
    },
    "right": {
      "type": "Literal",
      "value": "bar"
    },
    "operator": "+"
  },
  "right": {
    "type": "Literal",
    "value": "baz"
  },
  "operator": "+"
}

Cases to consider:

emilos commented 4 years ago

toBinaryExpression was added