That's pretty neat. Clearly some level of parsing needs to happen before run time, or else it couldn't even balance braces to know where the function body ends. So it must be that it parses the function body just enough to figure out where it starts and ends, then does a complete parse at runtime (probably building off the results from the first stage).
Re:Plan to throw one away
by munificent on Wednesday December 16, 2015 @01:45PM
(#10746276)
> or else it couldn't even balance braces to know where the function body ends
That's literally all it does. It tokenizes and counts braces.
Fun fact: most modern JavaScript engines in browsers work this way today, though at a different level of granularity. Parsing slows down application startup, so many JS engines don't parse a function body until it's first called. This means you can have a syntax error in a function body and won't know if it's never used.