text: "use strict";
  // -------------------------------------------------------------
  // WARNING: this file is used by both the client and the server.
  // Do not use any browser or node-specific API!
  // -------------------------------------------------------------
  var __importDefault = (this && this.__importDefault) || function (mod) {
      return (mod && mod.__esModule) ? mod : { "default": mod };
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  const node_builder_1 = require("../node-builder");
  const esotope_hammerhead_1 = require("esotope-hammerhead");
  const replace_node_1 = __importDefault(require("./replace-node"));
  const temp_variables_1 = __importDefault(require("./temp-variables"));
  // Transform:
  // function x ({a, b}, [c, d]) {}
  // -->
  // function x (_hh$temp0, _hh$temp1) {
  //     var {a, b} = _hh$temp0,
  //         [c, d] = _hh$temp1;
  // }
  function create(type) {
      return {
          nodeReplacementRequireTransform: false,
          nodeTypes: type,
          condition: node => {
              for (let param of node.params) {
                  if (param.type === esotope_hammerhead_1.Syntax.AssignmentPattern)
                      param = param.left;
                  if (param.type === esotope_hammerhead_1.Syntax.ObjectPattern || param.type === esotope_hammerhead_1.Syntax.ArrayPattern)
                      return true;
              }
              return false;
          },
          run: (node) => {
              const declarations = [];
              for (let param of node.params) {
                  let tempVarParent = node;
                  let tempVarKey = 'params';
                  if (param.type === esotope_hammerhead_1.Syntax.AssignmentPattern) {
                      // @ts-ignore
                      tempVarParent = param;
                      param = param.left;
                      tempVarKey = 'left';
                  }
                  if (param.type === esotope_hammerhead_1.Syntax.ObjectPattern && param.properties.length ||
                      param.type === esotope_hammerhead_1.Syntax.ArrayPattern && param.elements.length) {
                      const tempVar = node_builder_1.createIdentifier(temp_variables_1.default.generateName());
                      // @ts-ignore
                      replace_node_1.default(param, tempVar, tempVarParent, tempVarKey);
                      declarations.push(node_builder_1.createVariableDeclarator(param, tempVar));
                  }
              }
              if (!declarations.length)
                  return null;
              const declaration = node_builder_1.createVariableDeclaration('var', declarations);
              if (node.body.type !== esotope_hammerhead_1.Syntax.BlockStatement) {
                  // @ts-ignore
                  const returnStmt = node_builder_1.createReturnStatement(node.body);
                  replace_node_1.default(node.body, node_builder_1.createBlockStatement([declaration, returnStmt]), node, 'body');
                  // @ts-ignore
                  node.expression = false;
                  return node;
              }
              else
                  replace_node_1.default(null, declaration, node.body, 'body');
              declaration.reTransform = true;
              return null;
          }
      };
  }
  exports.default = create;module.exports = exports.default;
  
  