"use strict";

exports.__esModule = true;
exports.default = _default;

var _regexpuCore = _interopRequireDefault(require("regexpu-core"));

var regex = _interopRequireWildcard(require("@babel/helper-regex"));

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _default(api, options) {
  var _options$useUnicodeFl = options.useUnicodeFlag,
      useUnicodeFlag = _options$useUnicodeFl === void 0 ? true : _options$useUnicodeFl;

  if (typeof useUnicodeFlag !== "boolean") {
    throw new Error(".useUnicodeFlag must be a boolean, or undefined");
  }

  return {
    visitor: {
      RegExpLiteral: function RegExpLiteral(path) {
        var node = path.node;

        if (!regex.is(node, "u")) {
          return;
        }

        node.pattern = (0, _regexpuCore.default)(node.pattern, node.flags, {
          unicodePropertyEscape: true,
          useUnicodeFlag: useUnicodeFlag
        });

        if (!useUnicodeFlag) {
          regex.pullFlag(node, "u");
        }
      }
    }
  };
}