syntax error in javascript output when last function parameter is both a splat and a property
erisdev opened this issue · comments
That's quite a mouthful. Better to show you what I mean.
% node_modules/.bin/coffee -bj --cli 'its (@really, @bad...) =>'
// Generated by CoffeeScript 2.0.0-beta8
its(function (this$) {
return function (param$, ) {
this$.bad = 2 <= arguments.length ? [].slice.call(arguments, 1) : [];
this$.really = param$;
};
}(this));
I suspect it has something to do with the fact that a normal splat adds a parameter with the same name.
Lol :D. But I think this is a duplicate of some other one
@Nami-Doc ugh I wouldn't be surprised. It was a surprisingly difficult issue to actually search for.
Reducing it further, a = (@b...) =>
is enough to replicate the behavior. It produces an invalid parameter name, function (this$.b) { ... }
.
In contrast, CoffeeScript 1.8 doesn't even add arguments (function () { }
) for any function that has splats.
Found something similar: #288 — it actually refers to a different syntax oddity though (var ;
)
@rstacruz what exactly is your command and output for that? I can't duplicate it unless there is at least one parameter before the splat. obsoive:
% node_modules/.bin/coffee -bj --cli 'a = (@b...)->'
// Generated by CoffeeScript 2.0.0-beta8
var a;
a = function () {
this.b = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
};
I just tried it in the online site: http://michaelficarra.github.io/CoffeeScriptRedux/#try:a%20%3D%20%28%40b...%29%20-%3E
a = (@b...) ->
// Generated by CoffeeScript 2.0.0-beta8
void function () {
var a;
a = function (this.b) {
this.b = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
};
}.call(this);
@rstacruz what in the hell
The online demo might not be up-to-date. Always try things out by pulling the latest master and running bin/coffee
.
~/CoffeeScriptRedux [master|✔]
18:30 $ bin/coffee -bj --cli 'its (@really, @bad...) =>'
// Generated by CoffeeScript 2.0.0-beta9-dev
its(function (this$) {
return function (param$) {
this$.bad = arguments.length > 1 ? [].slice.call(arguments, 1) : [];
this$.really = param$;
};
}(this));
~/CoffeeScriptRedux [master|✔]
18:32 $ bin/coffee -bj --cli 'a = (@b...) =>'
// Generated by CoffeeScript 2.0.0-beta9-dev
var a;
a = function (this$) {
return function () {
this$.b = arguments.length > 0 ? [].slice.call(arguments, 0) : [];
};
}(this);
~/CoffeeScriptRedux [master|✔]
18:33 $ bin/coffee -bj --cli 'a = (@b...) ->'
// Generated by CoffeeScript 2.0.0-beta9-dev
var a;
a = function () {
this.b = arguments.length > 0 ? [].slice.call(arguments, 0) : [];
};
Seems to work.