1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = _default;
|
7 |
|
8 | var _corejs2BuiltIns = _interopRequireDefault(require("../../../data/corejs2-built-ins.json"));
|
9 |
|
10 | var _getPlatformSpecificDefault = _interopRequireDefault(require("./get-platform-specific-default"));
|
11 |
|
12 | var _filterItems = _interopRequireDefault(require("../../filter-items"));
|
13 |
|
14 | var _utils = require("../../utils");
|
15 |
|
16 | var _debug = require("../../debug");
|
17 |
|
18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19 |
|
20 | function _default(_, {
|
21 | include,
|
22 | exclude,
|
23 | polyfillTargets,
|
24 | regenerator,
|
25 | debug
|
26 | }) {
|
27 | const polyfills = (0, _filterItems.default)(_corejs2BuiltIns.default, include, exclude, polyfillTargets, (0, _getPlatformSpecificDefault.default)(polyfillTargets));
|
28 | const isPolyfillImport = {
|
29 | ImportDeclaration(path) {
|
30 | if ((0, _utils.isPolyfillSource)((0, _utils.getImportSource)(path))) {
|
31 | this.replaceBySeparateModulesImport(path);
|
32 | }
|
33 | },
|
34 |
|
35 | Program(path) {
|
36 | path.get("body").forEach(bodyPath => {
|
37 | if ((0, _utils.isPolyfillSource)((0, _utils.getRequireSource)(bodyPath))) {
|
38 | this.replaceBySeparateModulesImport(bodyPath);
|
39 | }
|
40 | });
|
41 | }
|
42 |
|
43 | };
|
44 | return {
|
45 | name: "corejs2-entry",
|
46 | visitor: isPolyfillImport,
|
47 |
|
48 | pre() {
|
49 | this.importPolyfillIncluded = false;
|
50 |
|
51 | this.replaceBySeparateModulesImport = function (path) {
|
52 | this.importPolyfillIncluded = true;
|
53 |
|
54 | if (regenerator) {
|
55 | (0, _utils.createImport)(path, "regenerator-runtime");
|
56 | }
|
57 |
|
58 | const modules = Array.from(polyfills).reverse();
|
59 |
|
60 | for (const module of modules) {
|
61 | (0, _utils.createImport)(path, module);
|
62 | }
|
63 |
|
64 | path.remove();
|
65 | };
|
66 | },
|
67 |
|
68 | post() {
|
69 | if (debug) {
|
70 | (0, _debug.logEntryPolyfills)("@babel/polyfill", this.importPolyfillIncluded, polyfills, this.file.opts.filename, polyfillTargets, _corejs2BuiltIns.default);
|
71 | }
|
72 | }
|
73 |
|
74 | };
|
75 | } |
\ | No newline at end of file |