Permalink
Browse files

splatted constructors returning `null` should produce the new instance

  • Loading branch information...
1 parent ef0cb46 commit abb11c80d1c8cbb1484a4f68c715ea44fd34a164 @michaelficarra michaelficarra committed Mar 7, 2012
Showing with 8 additions and 2 deletions.
  1. +1 −1 lib/coffee-script/nodes.js
  2. +1 −1 src/nodes.coffee
  3. +6 −0 test/function_invocation.coffee
Oops, something went wrong.
View
@@ -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 ->

0 comments on commit abb11c8

Please sign in to comment.