JParser now with Automatic Semicolon Insertion

I finally found a spare few hours to implement Automatic Semicolon Insertion into my JavaScript Parser.
Check out the test interface here.

Section 7.9 of the ECMAScript language specification details the circumstances under which you are permitted to omit a semicolon in a statement which otherwise requires it. In short, there are situations where this lazy practice is not the end of the world; it is fairly clear what the programmer is trying to do, so it lets you off.

I’ve managed to implement most of these conditions, but not all. I still have some work to do on the more peculiar conditions, but the ones that are relevant to most common practice should be covered. Give it a bash, and let me know if you can break it!

If you don’t know what I’m talking about, consider this:

a = b
c = d

Most JavaScript programmers would be disciplined enough write:

a = b;
c = d;

However, there are some conditions that probably catch us all out.
What is the difference between this:

function xfunc(){
}

and this?:

var xfunc = function(){
}

The former is a Function Declaration, and does not require termination, but the latter is a Function Expression, which in this case forms an Expression Statement and so it requires a semicolon to terminate it. A very common ‘mistake’, but solved quite comfortably by the rules of Automatic Semicolon Insertion, which transform it into:

var xfunc = function(){
};

There are plenty more cases I could discuss, but if you’re really interested, I suggest reading the ECMA-262 specification yourself.