babel-plugin-goto
v0.0.1
Published
Support GOTO in JavaScript
Downloads
3
Readme
Goto in JavaScript
A Babel transformer which implements goto (within function scope) for JavaScript.
Example
function loop() {
var i = 0;
start:
i = i + 1;
console.log(i);
if (i == 10) goto(end);
goto(start);
end:
console.log("all done");
}
loop();
How does this work?
Blocks that include labels are rewritten as labeled infinite loops
containing a switch statement; labels become cases, and goto
sets
the appropriate case of the switch statement and then jumps using a
labeled continue. Such a technique might be termed a
trampoline
since control jumps back to the beginning (via the labeled continue)
and then to the appropriate labeled position (via the switch
statement).
There are limitations: it isn't possible to goto
a label in a deeper
block. On the other hand, it is possible to jump both forward and
backward.
Credits
Inspired by Alex Sexton's Summer of Goto.