reduceAST

API / publicodes / reduceAST

function reduceAST<T>(
   fn, 
   start, 
   node): T

This function allows to construct a specific value while exploring the AST with a simple reducing function as argument.

fn will be called with the currently reduced value acc and the current node of the AST

If the callback function returns:

  • undefined, the exploration continues further down and all the children are reduced successively to a single value
  • T, the reduced value is returned

reduceFn : It is possible to specifically use the reduced value of a child by using the function passed as second argument. The returned value will be the reduced version of the node

Type Parameters

Type Parameter
T

Parameters

ParameterType
fn(acc, n, reduceFn) => undefined | T
startT
nodeASTNode

Returns

T

Defined in

packages/core/src/AST/index.ts:93