Thanks for trying out Shaper and posting your questions to the list.
[Assuming that you have the function node bound to var f, and that you
want to wrap the entire f body inside the while loop]
You can use the Shaper.insertBefore and Shaper.remove helpers if you
wish. This should get you started:
Shaper.insertBefore(new Ref(f.body, "children", 0),
Shaper.parse("while (true) { $; }"))
Ref's are used to provide another level of indirection, in essence a
pointer to the pointer. This is a consequence of Shaper not storing
up-pointers in each node (i.e. node.parent and node.parentProperty).
You can also manipulate the children and srcs arrays directly. srcs is
an array of children.length + 1 text fragments (leading, separating
and trailing) so it must be kept updated accordingly.
var w = Shaper.parse("while (true) { }");
w.body.children = f.body.children;
w.body.srcs = f.body.srcs;
f.body.children = [w];
f.body.srcs = ["{ ", " }"];
A third alternative is to go half-nuts and assign w.body = f.body as
long as you stay alert (further modifications and w.body is of BLOCK
type while f.body is a SCRIPT).
Having said all this, we should create a multiple-statement-wrapping
helper (and probably a few others too). Also, once Shaper.replace is
reworked the same way Shaper.match was it should be able to do most of
this.
/Olov