fix native type constructor spread - closes #373

This commit is contained in:
Sebastian McKenzie
2015-01-05 10:20:36 +11:00
parent b0c9d3daa4
commit 45d0eea842
3 changed files with 21 additions and 1 deletions

View File

@@ -29,6 +29,7 @@ File.helpers = [
"object-without-properties",
"has-own",
"slice",
"bind",
"define-property",
"async-to-generator",
"interop-require-wildcard",

View File

@@ -0,0 +1 @@
Function.prototype.bind

View File

@@ -1,4 +1,5 @@
var t = require("../../types");
var _ = require("lodash");
var getSpreadLiteral = function (spread, file) {
return file.toArray(spread.argument);
@@ -98,7 +99,14 @@ exports.NewExpression = function (node, parent, file) {
var args = node.arguments;
if (!hasSpread(args)) return;
var nativeType = t.isIdentifier(node.callee) && _.contains(t.NATIVE_TYPES_NAMES, node.callee.name);
var nodes = build(args, file);
if (nativeType) {
nodes.unshift(t.arrayExpression([t.literal(null)]));
}
var first = nodes.shift();
if (nodes.length) {
@@ -107,5 +115,15 @@ exports.NewExpression = function (node, parent, file) {
args = first;
}
return t.callExpression(file.addHelper("apply-constructor"), [node.callee, args]);
if (nativeType) {
return t.newExpression(
t.callExpression(
t.memberExpression(file.addHelper("bind"), t.identifier("apply")),
[node.callee, args]
),
[]
);
} else {
return t.callExpression(file.addHelper("apply-constructor"), [node.callee, args]);
}
};