CarlosNZ / fig-tree-evaluator

A highly configurable custom expression tree evaluator
MIT License
16 stars 3 forks source link

Aliases that reference other aliases at the same level don't get evaluated properly #77

Closed CarlosNZ closed 1 year ago

CarlosNZ commented 1 year ago

For example:

{
  $alias1: 10,
  $alias2: 20,
  $aliasTotal: {
    operator: "+",
    values: [
      "$alias1",
      "$alias2"
    ]
  },
  operator: "pass",
  value: "$aliasTotal"
}

Returns "$alias1$alias2" but should be 30

CarlosNZ commented 1 year ago

Not sure if we should change this. Aliases can currently only reference other aliases at a higher level. For now can work around with something like this:

{
  $alias1: 10,
  $alias2: 20,
  operator: "pass",
  value: {
    $aliasTotal: {
      operator: "+",
      values: [
        "$alias1",
        "$alias2"
      ]
    },
    operator: "pass",
    value: "$aliasTotal"
  }
}

// => 30
CarlosNZ commented 1 year ago

This is not really possible if we want to evaluate all the alias nodes in parallel (like they do currently), as there's no reasonable way to get them to wait for each other if they reference each other.

For now the above workaround will have to do.