babel-preset-playlyfe
Version:
Babel preset for playlyfe
73 lines (58 loc) • 3.03 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.DEFAULT_OPTS = exports.Opts = void 0;
var _presetEnv = _interopRequireDefault(require("@babel/preset-env"));
var _presetFlow = _interopRequireDefault(require("@babel/preset-flow"));
var _pluginProposalClassProperties = _interopRequireDefault(require("@babel/plugin-proposal-class-properties"));
var _pluginProposalObjectRestSpread = _interopRequireDefault(require("@babel/plugin-proposal-object-rest-spread"));
var _flowRuntime = _interopRequireDefault(require("flow-runtime"));
const Opts = _flowRuntime.default.type("Opts", _flowRuntime.default.exactObject(_flowRuntime.default.property("flow", _flowRuntime.default.boolean()), _flowRuntime.default.property("asyncAwait", _flowRuntime.default.boolean()), _flowRuntime.default.property("modules", _flowRuntime.default.union(_flowRuntime.default.string("amd"), _flowRuntime.default.string("umd"), _flowRuntime.default.string("systemjs"), _flowRuntime.default.string("commonjs"), _flowRuntime.default.boolean(false))), _flowRuntime.default.property("targets", _flowRuntime.default.object()), _flowRuntime.default.property("useBuiltIns", _flowRuntime.default.boolean()), _flowRuntime.default.property("debug", _flowRuntime.default.boolean())));
exports.Opts = Opts;
const DEFAULT_OPTS = Opts.assert(Object.freeze({
flow: true,
asyncAwait: false,
modules: 'commonjs',
targets: {},
useBuiltIns: true,
debug: false
}));
exports.DEFAULT_OPTS = DEFAULT_OPTS;
var _default = _flowRuntime.default.annotate((context, opts) => {
let _contextType = _flowRuntime.default.any();
let _optsType = Opts;
_flowRuntime.default.param("context", _contextType).assert(context);
_flowRuntime.default.param("opts", _optsType).assert(opts);
const {
targets,
modules,
debug,
useBuiltIns,
asyncAwait
} = opts;
return {
presets: [[_presetEnv.default, {
targets,
modules,
debug,
useBuiltIns: useBuiltIns ? 'entry' : false,
corejs: 3,
// only enable generator when asyncAwait enabled
exclude: !asyncAwait // eslint-disable-line no-negated-condition
? ['transform-regenerator', 'transform-async-to-generator'] : []
}], opts.flow ? _presetFlow.default : null],
plugins: [// add class properties support
// NOTE: keeping loose: true see issue: https://github.com/facebook/create-react-app/issues/4263
[_pluginProposalClassProperties.default, {
loose: true
}], // add object rest spread support
// keeping useBuiltIns: true & loose: false to use Object.assign which is fine for our use case
[_pluginProposalObjectRestSpread.default, {
useBuiltIns: true,
loose: true
}]].filter(Boolean)
};
}, _flowRuntime.default.function(_flowRuntime.default.param("context", _flowRuntime.default.any()), _flowRuntime.default.param("opts", Opts)));
exports.default = _default;