ASI Scanning Test Grounds

This is a test for ASI certification.

Your job is to add all the semi-colons where ASI would put them.

That means that no ASI should occur after you're done.

These are the three rules to Automatic Semi-colon Insertion (ASI):

  1. When unable to parse the next token and the previous token was seperated by at least one line terminator
  2. When the end of input is reached and the current script cannot be parsed as Ecmascript
  3. When a closing curly brace (}) is encountered

There are a few cases where no ASI is applied, even when the rules above would apply:

  1. The resulting semi-colon may not cause an empty statement
  2. The resulting semi-colon may not become one of the two semi-colons of a for-header
  3. When the next line starts with a regular expression

There are also a few hidden cases, which you'll have to discover on your own ;)

You can only insert semi-colons.

The script was hacked together quickly so del and backspace screw your cursor position (just don't make mistakes! ;)

The cursor position is also the reason this test fails in IE. It has a very annoyingly complex way of getting the cursor position.

Press the next button when you think you've finished.

Results and explanation are presented at the end. Good luck!

The test is supposed to prove the point that you can't predict ASI well enough to rely on it.

By Peter van der Zee, September 2010