creationix/mine — pull request #6 by glenjamin (2014-02-17 23:49:52+00:00)
Title: Whitespace and regex handling

This PR supersedes #5, as I needed those changes to get the tests passing in this branch.

This should also resolve #2 and #4.

I had to step outside the current parsing algorithm slightly, in order to handle the regex vs division case.

Rather than implement the full state machine to tell whether in a unary or binary expression context, I use the heuristic that a regular expression cannot contain a newline character. This means that if a newline is encountered before the closing `/`, and we know we have valid javascript, we can safely assume that it must have been division and backtrack, continuing with this new knowledge.

As noted in the testcase, this does still leave the case of
```javascript
var a = 1 / require('a') / 2;
```

However this is no worse than before the PR, and I do manage to cover a number of other common cases (#4 has some examples).