transformAST

API / publicodes / transformAST

function transformAST(fn, stopOnUpdate): ASTTransformer

This function creates a transormation of the AST from on a simpler callback function fn

fn will be called with the nodes of the ASTTree during the exploration

The outcome of the callback function has an influence on the exploration of the AST :

  • false, the node is not updated and the exploration does not continue further down this branch
  • undefined, the node is not updated but the exploration continues and its children will be transformed
  • ASTNode, the node is transformed to the new value and the exploration does not continue further down the branch

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

Parameters

ParameterTypeDefault value
fn(node, transform) => undefined | false | ASTNodeundefined
stopOnUpdatebooleantrue

Returns

ASTTransformer

Defined in

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