UNPKG

babel-preset-playlyfe

Version:
73 lines (47 loc) 3.67 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.Opts = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _es = _interopRequireWildcard(require("./presets/es")); var _react = _interopRequireWildcard(require("./presets/react")); var _pick2 = _interopRequireDefault(require("lodash/pick")); var _pluginTransformRuntime = _interopRequireDefault(require("@babel/plugin-transform-runtime")); var _flowRuntime = _interopRequireWildcard(require("flow-runtime")); function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } const Type = _flowRuntime.default.tdz(() => _flowRuntime.Type); const PresetReactOpts = _flowRuntime.default.tdz(() => _react.Opts); const PresetESOpts = _flowRuntime.default.tdz(() => _es.Opts); const DEFAULT_OPTS = Object.freeze(_objectSpread({}, _es.DEFAULT_OPTS, {}, _react.DEFAULT_OPTS, { react: true, babelRuntime: true })); const Opts = _flowRuntime.default.type("Opts", _flowRuntime.default.intersection(_flowRuntime.default.ref(PresetESOpts), _flowRuntime.default.ref(PresetReactOpts), _flowRuntime.default.object(_flowRuntime.default.property("react", _flowRuntime.default.boolean()), _flowRuntime.default.property("babelRuntime", _flowRuntime.default.boolean())))); exports.Opts = Opts; var _default = _flowRuntime.default.annotate((context, opts) => { let _contextType = _flowRuntime.default.any(); let _optsType = _flowRuntime.default.nullable(_flowRuntime.default.$shape(Opts)); _flowRuntime.default.param("context", _contextType).assert(context); _flowRuntime.default.param("opts", _optsType, true).assert(opts); // eslint-disable-next-line no-use-before-define const options = _objectSpread({}, DEFAULT_OPTS, {}, opts); validateOpts(options); const presetESOpts = (0, _pick2.default)(options, Object.keys(_es.DEFAULT_OPTS)); const presetReactOpts = (0, _pick2.default)(options, Object.keys(_react.DEFAULT_OPTS)); return { presets: [[_es.default, presetESOpts], options.react ? [_react.default, presetReactOpts] : null].filter(Boolean), plugins: [// to avoid duplicate babel helpers code options.babelRuntime ? [_pluginTransformRuntime.default, { useESModules: options.modules === false }] : null].filter(Boolean) }; }, _flowRuntime.default.function(_flowRuntime.default.param("context", _flowRuntime.default.any()), _flowRuntime.default.param("opts", _flowRuntime.default.nullable(_flowRuntime.default.$shape(Opts))))); exports.default = _default; function validateOpts(opts) { const OptsType = _flowRuntime.default.$exact(Opts); OptsType.assert(opts); }