CoffeeScriptRedux
CoffeeScriptRedux copied to clipboard
compiled extends$ function filled with garbage declarations?
This is what I get after compiling one of my classes. It doesn't look right? Compiled on CoffeeScript 2.0.0-beta3
function extends$(child, parent) {
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
for (key in parent)
if (isOwn$(parent, key))
child[key] = parent[key];
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor;
child.__super__ = parent.prototype;
return child;
}
Wow, when did that happen? git bisect
ing now...
I can't reproduce this. Please provide a test case.
Hehehe. It's funny. It happens to me too in the on line demo. But only if i'm typing the code. If i type class Foo extends Bar
it starts adding var key;
lines on the compiled output for each new character i type after the "B" of Bar. If i refresh the page the code is shown without extra var key;
lines.
Reproduced in both Firefox and Chrome in Ubuntu.
Confirmed that this is currently happening in the online demo with the steps @epidemian noted.
This happened when I was compiling my code using require('coffee-script-redux')
and going the more manual route (in a grunt task). The CLI does not generate that extra noise. I couldn't really see what the CLI was doing that I wasn't, but...
Wow, this is an insane bug. I must have accidental state somewhere in the declaration-emitting code. Re-opening.
Yeah, it's quite a fun bug :smile_cat:. Good luck git bisect
ing it (BTW, thanks for mentioning that command; i didn't know about it!).
@epidemian: It's very useful, especially when you can easily write a script that fails when it detects the bug.
Huh, I still can't reproduce this on current master
.
$ bin/coffee --js --cli 'a extends b'
// Generated by CoffeeScript 2.0.0-beta3
extends$(a, b);
function isOwn$(o, p) {
return {}.hasOwnProperty.call(o, p);
}
function extends$(child, parent) {
var key;
for (key in parent)
if (isOwn$(parent, key))
child[key] = parent[key];
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor;
child.__super__ = parent.prototype;
return child;
}
Can anyone give me a reproducible case?
That's why i said good luck git bissect
ing it hehe. The bug looks to be easily triggered in the on line demo, but not so much in the command line compiler.
Here's a script that reproduces this (intended to run at the root of Redux project):
#! /usr/bin/env coffee
CS = require './lib/coffee-script/module'
compileFail = ->
CS.cs2js 'class Foo extends Bar'
# Call a couple of times...
compileFail()
compileFail()
# And voila!
console.log compileFail()
Output:
// Generated by CoffeeScript 2.0.0-beta3
void function () {
var Foo;
Foo = function (super$) {
extends$(Foo, super$);
function Foo() {
}
void 0;
return Foo;
}(Bar);
function isOwn$(o, p) {
return {}.hasOwnProperty.call(o, p);
}
function extends$(child, parent) {
var key;
var key;
var key;
for (key in parent)
if (isOwn$(parent, key))
child[key] = parent[key];
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor;
child.__super__ = parent.prototype;
return child;
}
}.call(this);
The amount of var key;
declarations in the output is directly proportional to the times compileFail
is called xD
A simpler script to test it:
$ coffee --eval "console.log ((require './lib/coffee-script/module').cs2js 'a extends b' for i in [1..10])[9]"
// Generated by CoffeeScript 2.0.0-beta3
extends$(a, b);
function isOwn$(o, p) {
return {}.hasOwnProperty.call(o, p);
}
function extends$(child, parent) {
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
var key;
for (key in parent)
if (isOwn$(parent, key))
child[key] = parent[key];
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor;
child.__super__ = parent.prototype;
return child;
}
One funny (or not so funny...) thing about this script is that the CS code needs to be compiled with the old CS compiler, as Redux will raise an error. I'm gonna open an issue for that now, but i wanted to leave this code here just as an evidence of this not being a very esoteric use-case.