mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
splatted constructors returning null
should produce the new instance
This commit is contained in:
parent
ef0cb46b9b
commit
abb11c80d1
3 changed files with 8 additions and 2 deletions
|
@ -813,7 +813,7 @@
|
|||
}
|
||||
if (this.isNew) {
|
||||
idt = this.tab + TAB;
|
||||
return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return typeof result === \"object\" ? result : child;\n" + this.tab + "})(" + (this.variable.compile(o, LEVEL_LIST)) + ", " + splatArgs + ", function() {})";
|
||||
return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return typeof result === \"object\" && result !== null ? result : child;\n" + this.tab + "})(" + (this.variable.compile(o, LEVEL_LIST)) + ", " + splatArgs + ", function() {})";
|
||||
}
|
||||
base = new Value(this.variable);
|
||||
if ((name = base.properties.pop()) && base.isComplex()) {
|
||||
|
|
|
@ -587,7 +587,7 @@ exports.Call = class Call extends Base
|
|||
(function(func, args, ctor) {
|
||||
#{idt}ctor.prototype = func.prototype;
|
||||
#{idt}var child = new ctor, result = func.apply(child, args);
|
||||
#{idt}return typeof result === "object" ? result : child;
|
||||
#{idt}return typeof result === "object" && result !== null ? result : child;
|
||||
#{@tab}})(#{ @variable.compile o, LEVEL_LIST }, #{splatArgs}, function() {})
|
||||
"""
|
||||
base = new Value @variable
|
||||
|
|
|
@ -392,6 +392,12 @@ test "#1011: passing a splat to a method of a number", ->
|
|||
eq '1011', (131.0).toString [5]...
|
||||
|
||||
|
||||
test "splats and the `new` operator: functions that return `null` should produce their instance", ->
|
||||
args = []
|
||||
child = new (constructor = -> null) args...
|
||||
ok child instanceof constructor
|
||||
|
||||
|
||||
test "implicit return", ->
|
||||
|
||||
eq ok, new ->
|
||||
|
|
Loading…
Reference in a new issue