CloudMade/Leaflet — Issue #447: Build omits trailing semicolon from compressed leaflet.js
Author: chosak
Created: 2012-01-26 18:52:46+00:00
State: open

The new jake-based build process relies on uglifyjs to combine the multiple JS files into a single compressed file. The combined file (generated at ```/dist/leaflet-src.js```) includes a trailing semicolon, which is in the last source file to be included (```/src/map/ext/Map.Geolocation.js```). Unfortunately, the uglifyjs compression process removes this trailing semicolon (generated at ```/dist/leaflet.src```).

This can cause problems if you try to combine the compressed Leaflet JS file along with other JS files, for example if you want to serve a single aggregated file for all JS on your site. If your aggregation tool of choice doesn't automatically add semicolons between files, you'll get an error since the compressed Leaflet library doesn't end in one. While this might not be a common case, and it might be fair to say the burden should be on the aggregator, I ran into this and it took me a while to figure out what was going on. I notice that many common minimized JS libraries (like [jQuery](https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js) and [jQuery UI](https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js)) include trailing semicolons which prevent this problem.

There's a huge discussion on [issue 126](https://github.com/mishoo/UglifyJS/issues/126) of the uglifyjs project about whether it should include trailing semicolons or not. In the end, they decided to do so ([see commit](https://github.com/mishoo/UglifyJS/commit/7805e1d039ec641977615c4ec35f04a799eb6267)), but only when calling ```uglifyjs``` directly, not via ```uglifyjs.parser.parse``` as the Leaflet build script does in ```/build/build.js```, line 45.

An easy way to fix this (if you think it's worth doing), is just to modify the build script, line 50 to something like:

```js
return pro.gen_code(ast) + ';';
```