Pass system for Astral
Pass system for Astral.
There are two kinds of passes:
Info passes operate on a copy of the AST,
but are allowed to modify the
info object passed into the function as a parameter.
myPassinfoinfofoo = 'bar'; // persistschunkfoo = 'bar'; // does not persist;
Transforms, on the other hand, allow you to modify the structure of the part of the AST that the pass matches,
but prevents you from making changes to the
myPassinfoinfofoo = 'bar'; // does not persistchunkfoo = 'bar'; // persists;
Below is a simple example.
var myPass = require'astral-pass';myPassname = 'myPass';myPassprereqs = /* other pass names here */ ;myPasswhen// ... AST chunkwhen// return true or falsetransform;
You can introduce more complicated behavior by composing passes.
This is done by modifying a pass's
var astralPass = require'astral-pass';// p1 needs some info to do its transformationsvar p1 = astralPass;p1name = 'myPass';p1prereqs = 'p2' ;p1whentransform ;// p2 gathers the info for p1var p2 = astralPass;p2name = 'myPass';p2wheninfo ;
I recommend namespacing passes with