| 13447 | } |
| 13448 | |
| 13449 | function visitCallSpread(traverse, node, path, state) { |
| 13450 | utils.catchup(node.range[0], state); |
| 13451 | |
| 13452 | if (node.type === Syntax.NewExpression) { |
| 13453 | // Input = new Set(1, 2, ...list) |
| 13454 | // Output = new (Function.prototype.bind.apply(Set, [null, 1, 2].concat(list))) |
| 13455 | utils.append('new (Function.prototype.bind.apply(', state); |
| 13456 | process(traverse, node.callee, path, state); |
| 13457 | } else if (node.callee.type === Syntax.MemberExpression) { |
| 13458 | // Input = get().fn(1, 2, ...more) |
| 13459 | // Output = (_ = get()).fn.apply(_, [1, 2].apply(more)) |
| 13460 | var tempVar = utils.injectTempVar(state); |
| 13461 | utils.append('(' + tempVar + ' = ', state); |
| 13462 | process(traverse, node.callee.object, path, state); |
| 13463 | utils.append(')', state); |
| 13464 | if (node.callee.property.type === Syntax.Identifier) { |
| 13465 | utils.append('.', state); |
| 13466 | process(traverse, node.callee.property, path, state); |
| 13467 | } else { |
| 13468 | utils.append('[', state); |
| 13469 | process(traverse, node.callee.property, path, state); |
| 13470 | utils.append(']', state); |
| 13471 | } |
| 13472 | utils.append('.apply(' + tempVar, state); |
| 13473 | } else { |
| 13474 | // Input = max(1, 2, ...list) |
| 13475 | // Output = max.apply(null, [1, 2].concat(list)) |
| 13476 | var needsToBeWrappedInParenthesis = |
| 13477 | node.callee.type === Syntax.FunctionDeclaration || |
| 13478 | node.callee.type === Syntax.FunctionExpression; |
| 13479 | if (needsToBeWrappedInParenthesis) { |
| 13480 | utils.append('(', state); |
| 13481 | } |
| 13482 | process(traverse, node.callee, path, state); |
| 13483 | if (needsToBeWrappedInParenthesis) { |
| 13484 | utils.append(')', state); |
| 13485 | } |
| 13486 | utils.append('.apply(null', state); |
| 13487 | } |
| 13488 | utils.append(', ', state); |
| 13489 | |
| 13490 | var args = node.arguments.slice(); |
| 13491 | var spread = args.pop(); |
| 13492 | if (args.length || node.type === Syntax.NewExpression) { |
| 13493 | utils.append('[', state); |
| 13494 | if (node.type === Syntax.NewExpression) { |
| 13495 | utils.append('null' + (args.length ? ', ' : ''), state); |
| 13496 | } |
| 13497 | while (args.length) { |
| 13498 | var arg = args.shift(); |
| 13499 | utils.move(arg.range[0], state); |
| 13500 | traverse(arg, path, state); |
| 13501 | if (args.length) { |
| 13502 | utils.catchup(args[0].range[0], state); |
| 13503 | } else { |
| 13504 | utils.catchup(arg.range[1], state); |
| 13505 | } |
| 13506 | } |