text: "use strict";
  
  exports.__esModule = true;
  exports.default = _default;
  
  var _pluginSyntaxObjectRestSpread = _interopRequireDefault(require("@babel/plugin-syntax-object-rest-spread"));
  
  var _core = require("@babel/core");
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function _default(api, opts) {
    var _opts$useBuiltIns = opts.useBuiltIns,
        useBuiltIns = _opts$useBuiltIns === void 0 ? false : _opts$useBuiltIns;
  
    if (typeof useBuiltIns !== "boolean") {
      throw new Error(".useBuiltIns must be a boolean, or undefined");
    }
  
    function hasRestElement(path) {
      var foundRestElement = false;
      path.traverse({
        RestElement: function RestElement() {
          foundRestElement = true;
          path.stop();
        }
      });
      return foundRestElement;
    }
  
    function hasSpread(node) {
      for (var _iterator = node.properties, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
        var _ref;
  
        if (_isArray) {
          if (_i >= _iterator.length) break;
          _ref = _iterator[_i++];
        } else {
          _i = _iterator.next();
          if (_i.done) break;
          _ref = _i.value;
        }
  
        var _prop = _ref;
  
        if (_core.types.isSpreadElement(_prop)) {
          return true;
        }
      }
  
      return false;
    }
  
    function extractNormalizedKeys(path) {
      var props = path.node.properties;
      var keys = [];
      var allLiteral = true;
  
      for (var _iterator2 = props, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
        var _ref2;
  
        if (_isArray2) {
          if (_i2 >= _iterator2.length) break;
          _ref2 = _iterator2[_i2++];
        } else {
          _i2 = _iterator2.next();
          if (_i2.done) break;
          _ref2 = _i2.value;
        }
  
        var _prop2 = _ref2;
  
        if (_core.types.isIdentifier(_prop2.key) && !_prop2.computed) {
          keys.push(_core.types.stringLiteral(_prop2.key.name));
        } else if (_core.types.isLiteral(_prop2.key)) {
          keys.push(_core.types.stringLiteral(String(_prop2.key.value)));
        } else {
          keys.push(_core.types.cloneNode(_prop2.key));
          allLiteral = false;
        }
      }
  
      return {
        keys: keys,
        allLiteral: allLiteral
      };
    }
  
    function replaceImpureComputedKeys(path) {
      var impureComputedPropertyDeclarators = [];
  
      for (var _iterator3 = path.get("properties"), _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
        var _ref3;
  
        if (_isArray3) {
          if (_i3 >= _iterator3.length) break;
          _ref3 = _iterator3[_i3++];
        } else {
          _i3 = _iterator3.next();
          if (_i3.done) break;
          _ref3 = _i3.value;
        }
  
        var _propPath = _ref3;
  
        var key = _propPath.get("key");
  
        if (_propPath.node.computed && !key.isPure()) {
          var name = path.scope.generateUidBasedOnNode(key.node);
  
          var declarator = _core.types.variableDeclarator(_core.types.identifier(name), key.node);
  
          impureComputedPropertyDeclarators.push(declarator);
          key.replaceWith(_core.types.identifier(name));
        }
      }
  
      return impureComputedPropertyDeclarators;
    }
  
    function createObjectSpread(path, file, objRef) {
      var props = path.get("properties");
      var last = props[props.length - 1];
  
      _core.types.assertRestElement(last.node);
  
      var restElement = _core.types.cloneNode(last.node);
  
      last.remove();
      var impureComputedPropertyDeclarators = replaceImpureComputedKeys(path);
  
      var _extractNormalizedKey = extractNormalizedKeys(path),
          keys = _extractNormalizedKey.keys,
          allLiteral = _extractNormalizedKey.allLiteral;
  
      var keyExpression;
  
      if (!allLiteral) {
        keyExpression = _core.types.callExpression(_core.types.memberExpression(_core.types.arrayExpression(keys), _core.types.identifier("map")), [file.addHelper("toPropertyKey")]);
      } else {
        keyExpression = _core.types.arrayExpression(keys);
      }
  
      return [impureComputedPropertyDeclarators, restElement.argument, _core.types.callExpression(file.addHelper("objectWithoutProperties"), [_core.types.cloneNode(objRef), keyExpression])];
    }
  
    function replaceRestElement(parentPath, paramPath, i, numParams) {
      if (paramPath.isAssignmentPattern()) {
        replaceRestElement(parentPath, paramPath.get("left"), i, numParams);
        return;
      }
  
      if (paramPath.isArrayPattern() && hasRestElement(paramPath)) {
        var elements = paramPath.get("elements");
  
        for (var _i4 = 0; _i4 < elements.length; _i4++) {
          replaceRestElement(parentPath, elements[_i4], _i4, elements.length);
        }
      }
  
      if (paramPath.isObjectPattern() && hasRestElement(paramPath)) {
        var uid = parentPath.scope.generateUidIdentifier("ref");
  
        var declar = _core.types.variableDeclaration("let", [_core.types.variableDeclarator(paramPath.node, uid)]);
  
        parentPath.ensureBlock();
        parentPath.get("body").unshiftContainer("body", declar);
        paramPath.replaceWith(_core.types.cloneNode(uid));
      }
    }
  
    return {
      inherits: _pluginSyntaxObjectRestSpread.default,
      visitor: {
        Function: function Function(path) {
          var params = path.get("params");
  
          for (var i = params.length - 1; i >= 0; i--) {
            replaceRestElement(params[i].parentPath, params[i], i, params.length);
          }
        },
        VariableDeclarator: function VariableDeclarator(path, file) {
          if (!path.get("id").isObjectPattern()) {
            return;
          }
  
          var insertionPath = path;
          path.get("id").traverse({
            RestElement: function RestElement(path) {
              if (!path.parentPath.isObjectPattern()) {
                return;
              }
  
              if (this.originalPath.node.id.properties.length > 1 && !_core.types.isIdentifier(this.originalPath.node.init)) {
                var initRef = path.scope.generateUidIdentifierBasedOnNode(this.originalPath.node.init, "ref");
                this.originalPath.insertBefore(_core.types.variableDeclarator(initRef, this.originalPath.node.init));
                this.originalPath.replaceWith(_core.types.variableDeclarator(this.originalPath.node.id, _core.types.cloneNode(initRef)));
                return;
              }
  
              var ref = this.originalPath.node.init;
              var refPropertyPath = [];
              var kind;
              path.findParent(function (path) {
                if (path.isObjectProperty()) {
                  refPropertyPath.unshift(path.node.key.name);
                } else if (path.isVariableDeclarator()) {
                  kind = path.parentPath.node.kind;
                  return true;
                }
              });
  
              if (refPropertyPath.length) {
                refPropertyPath.forEach(function (prop) {
                  ref = _core.types.memberExpression(ref, _core.types.identifier(prop));
                });
              }
  
              var objectPatternPath = path.findParent(function (path) {
                return path.isObjectPattern();
              });
  
              var _createObjectSpread = createObjectSpread(objectPatternPath, file, ref),
                  impureComputedPropertyDeclarators = _createObjectSpread[0],
                  argument = _createObjectSpread[1],
                  callExpression = _createObjectSpread[2];
  
              _core.types.assertIdentifier(argument);
  
              insertionPath.insertBefore(impureComputedPropertyDeclarators);
              insertionPath.insertAfter(_core.types.variableDeclarator(argument, callExpression));
              insertionPath = insertionPath.getSibling(insertionPath.key + 1);
              path.scope.registerBinding(kind, insertionPath);
  
              if (objectPatternPath.node.properties.length === 0) {
                objectPatternPath.findParent(function (path) {
                  return path.isObjectProperty() || path.isVariableDeclarator();
                }).remove();
              }
            }
          }, {
            originalPath: path
          });
        },
        ExportNamedDeclaration: function ExportNamedDeclaration(path) {
          var declaration = path.get("declaration");
          if (!declaration.isVariableDeclaration()) return;
          if (!hasRestElement(declaration)) return;
          var specifiers = [];
  
          for (var name in path.getOuterBindingIdentifiers(path)) {
            specifiers.push(_core.types.exportSpecifier(_core.types.identifier(name), _core.types.identifier(name)));
          }
  
          path.replaceWith(declaration.node);
          path.insertAfter(_core.types.exportNamedDeclaration(null, specifiers));
        },
        CatchClause: function CatchClause(path) {
          var paramPath = path.get("param");
          replaceRestElement(paramPath.parentPath, paramPath);
        },
        AssignmentExpression: function AssignmentExpression(path, file) {
          var leftPath = path.get("left");
  
          if (leftPath.isObjectPattern() && hasRestElement(leftPath)) {
            var nodes = [];
            var refName = path.scope.generateUidBasedOnNode(path.node.right, "ref");
            nodes.push(_core.types.variableDeclaration("var", [_core.types.variableDeclarator(_core.types.identifier(refName), path.node.right)]));
  
            var _createObjectSpread2 = createObjectSpread(leftPath, file, _core.types.identifier(refName)),
                impureComputedPropertyDeclarators = _createObjectSpread2[0],
                argument = _createObjectSpread2[1],
                callExpression = _createObjectSpread2[2];
  
            if (impureComputedPropertyDeclarators.length > 0) {
              nodes.push(_core.types.variableDeclaration("var", impureComputedPropertyDeclarators));
            }
  
            var nodeWithoutSpread = _core.types.cloneNode(path.node);
  
            nodeWithoutSpread.right = _core.types.identifier(refName);
            nodes.push(_core.types.expressionStatement(nodeWithoutSpread));
            nodes.push(_core.types.toStatement(_core.types.assignmentExpression("=", argument, callExpression)));
            nodes.push(_core.types.expressionStatement(_core.types.identifier(refName)));
            path.replaceWithMultiple(nodes);
          }
        },
        ForXStatement: function ForXStatement(path) {
          var node = path.node,
              scope = path.scope;
          var leftPath = path.get("left");
          var left = node.left;
  
          if (_core.types.isObjectPattern(left) && hasRestElement(leftPath)) {
            var temp = scope.generateUidIdentifier("ref");
            node.left = _core.types.variableDeclaration("var", [_core.types.variableDeclarator(temp)]);
            path.ensureBlock();
            node.body.body.unshift(_core.types.variableDeclaration("var", [_core.types.variableDeclarator(left, _core.types.cloneNode(temp))]));
            return;
          }
  
          if (!_core.types.isVariableDeclaration(left)) return;
          var pattern = left.declarations[0].id;
          if (!_core.types.isObjectPattern(pattern)) return;
          var key = scope.generateUidIdentifier("ref");
          node.left = _core.types.variableDeclaration(left.kind, [_core.types.variableDeclarator(key, null)]);
          path.ensureBlock();
          node.body.body.unshift(_core.types.variableDeclaration(node.left.kind, [_core.types.variableDeclarator(pattern, _core.types.cloneNode(key))]));
        },
        ObjectExpression: function ObjectExpression(path, file) {
          if (!hasSpread(path.node)) return;
          var args = [];
          var props = [];
  
          function push() {
            if (!props.length) return;
            args.push(_core.types.objectExpression(props));
            props = [];
          }
  
          var _arr = path.node.properties;
  
          for (var _i5 = 0; _i5 < _arr.length; _i5++) {
            var prop = _arr[_i5];
  
            if (_core.types.isSpreadElement(prop)) {
              push();
              args.push(prop.argument);
            } else {
              props.push(prop);
            }
          }
  
          push();
  
          if (!_core.types.isObjectExpression(args[0])) {
            args.unshift(_core.types.objectExpression([]));
          }
  
          var helper = useBuiltIns ? _core.types.memberExpression(_core.types.identifier("Object"), _core.types.identifier("assign")) : file.addHelper("extends");
          path.replaceWith(_core.types.callExpression(helper, args));
        }
      }
    };
  }