Description
google's closure javascript compiler (https://developers.google.com/closure/compiler/) detects some extra trailing commas in the javascript generated by gopherjs.
I tried closure out on Dmitri's live-refreshing markdown code; http://dmitri.shuralyov.com/projects/live-markdown/markdown.go. (Btw this is a very cool project.)
After generating markdown.js from gopherjs, then I run the closure compiler on it. There are a bunch of warnings about unreachable code which I ignored, but 2 errors look like they could be problematic, and result in closure compiler not producing output.
Aside: it looks like closure -O ADVANCED will compress a 3MB gopherjs generated javascript file down to 1.6MB (minified and dead-code elimination done); once I manually removed the commas--nice to know.
run:
bash-3.2$ java -jar ./build/compiler.jar < markdown.js > markdown-minified.js
The compiler is waiting for input via stdin.
stdin:320: ERROR - Parse error. IE8 (and below) will parse trailing commas in array and object literals incorrectly. If you are targeting newer versions of JS, set the appropriate language_in option.
set: function(value) { obj[fieldProp] = value; },
^
stdin:1528: ERROR - Parse error. IE8 (and below) will parse trailing commas in array and object literals incorrectly. If you are targeting newer versions of JS, set the appropriate language_in option.
},
^
2 error(s), 0 warning(s)
bash-3.2$
the errors detected are here:
var $pointerOfStructConversion = function(obj, type) {
if(obj.$proxies === undefined) {
obj.$proxies = {};
obj.$proxies[obj.constructor.string] = obj;
}
var proxy = obj.$proxies[type.string];
if (proxy === undefined) {
var properties = {};
for (var i = 0; i < type.elem.fields.length; i++) {
(function(fieldProp) {
properties[fieldProp] = {
get: function() { return obj[fieldProp]; },
set: function(value) { obj[fieldProp] = value; }, /////<<< line 320, has extra comma at end
};
})(type.elem.fields[i].prop);
}
proxy = Object.create(type.prototype, properties);
proxy.$val = proxy;
obj.$proxies[type.string] = proxy;
proxy.$proxies = obj.$proxies;
}
return proxy;
};
var $send = function(chan, value) {
if (chan.$closed) {
$throwRuntimeError("send on closed channel");
}
var queuedRecv = chan.$recvQueue.shift();
if (queuedRecv !== undefined) {
queuedRecv([value, true]);
return;
}
if (chan.$buffer.length < chan.$capacity) {
chan.$buffer.push(value);
return;
}
var thisGoroutine = $curGoroutine;
chan.$sendQueue.push(function() {
$schedule(thisGoroutine);
return value;
});
$block();
return {
$blk: function() {
if (chan.$closed) {
$throwRuntimeError("send on closed channel");
}
}, /////<<<< line 1528, extra comma at end
};
};