purescript/purescript — pull request #189 by garyb (2014-02-11 12:14:38+00:00)
Title: Fix for the Math module (and others)

The generated JS no longer declares variables for each module, instead it attaches them to the object passed in by the export wrapper, now named `_ps` instead of `exports` so it will never collide with a Purescript declaration.

Each module exports its members by attaching them to an object named `module` rather than using the module name (so that in the case of `Math` it's not being hidden locally), which is then returned at the end of the module function so it can be assigned directly to `_ps`. `module` is a reserved word in Purescript so there should be no issue with collisions there.

So for example, the code generated for `Errors` now looks like this:
``` js
_ps.Errors = (function (module) {
function throwError(e) { return function() { throw e; };};
module.throwError = throwError;
function catchError(c) { return function(t) { return function() { try { return t(); } catch(e) { return c(e)(); } }; };};
module.catchError = catchError;
return module;
})({});
```

The main impact this has outside of generated code is the JS in foreign imports now needs to access Purescript declarations through `_ps`, e.g:
```
foreign import nowt "function nowt() {\
\ return _ps.Maybe.Nothing;
\}" :: forall a. {} -> Maybe a
```
Also floats parse correctly now, the Math module has constants like Math.PI, and the generated code is a little cleaner when exporting operators as a bonus.