babel-plugin-polyfill-corejs3 0.0.10 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/built-in-definitions.js +2 -2
- package/lib/index.js +53 -14
- package/lib/utils.js +2 -2
- package/package.json +5 -5
|
@@ -63,7 +63,7 @@ const BuiltIns = {
|
|
|
63
63
|
compositeKey: define("composite-key", ["esnext.composite-key"]),
|
|
64
64
|
compositeSymbol: define("composite-symbol", ["esnext.composite-symbol"]),
|
|
65
65
|
fetch: define(null, PromiseDependencies),
|
|
66
|
-
globalThis: define("global-this", ["
|
|
66
|
+
globalThis: define("global-this", ["es.global-this"]),
|
|
67
67
|
parseFloat: define("parse-float", ["es.parse-float"]),
|
|
68
68
|
parseInt: define("parse-int", ["es.parse-int"]),
|
|
69
69
|
queueMicrotask: define("queue-microtask", ["web.queue-microtask"]),
|
|
@@ -276,7 +276,7 @@ const InstanceProperties = {
|
|
|
276
276
|
link: define(null, ["es.string.link"]),
|
|
277
277
|
map: define("instance/map", ["es.array.map"]),
|
|
278
278
|
match: define(null, ["es.string.match", "es.regexp.exec"]),
|
|
279
|
-
matchAll: define("instance/match-all", ["
|
|
279
|
+
matchAll: define("instance/match-all", ["es.string.match-all"]),
|
|
280
280
|
name: define(null, ["es.function.name"]),
|
|
281
281
|
padEnd: define("instance/pad-end", ["es.string.pad-end"]),
|
|
282
282
|
padStart: define("instance/pad-start", ["es.string.pad-start"]),
|
package/lib/index.js
CHANGED
|
@@ -19,6 +19,18 @@ var _helperDefinePolyfillProvider = _interopRequireDefault(require("@babel/helpe
|
|
|
19
19
|
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
21
|
|
|
22
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
23
|
+
|
|
24
|
+
const runtimeCompat = "#__secret_key__@babel/runtime__compatibility";
|
|
25
|
+
|
|
26
|
+
const esnextFallback = (name, cb) => {
|
|
27
|
+
if (cb(name)) return true;
|
|
28
|
+
if (!name.startsWith("es.")) return false;
|
|
29
|
+
const fallback = `esnext.${name.slice(3)}`;
|
|
30
|
+
if (!_data.default[fallback]) return false;
|
|
31
|
+
return cb(fallback);
|
|
32
|
+
};
|
|
33
|
+
|
|
22
34
|
var _default = (0, _helperDefinePolyfillProvider.default)(function ({
|
|
23
35
|
getUtils,
|
|
24
36
|
method,
|
|
@@ -29,7 +41,11 @@ var _default = (0, _helperDefinePolyfillProvider.default)(function ({
|
|
|
29
41
|
}, {
|
|
30
42
|
version = 3,
|
|
31
43
|
proposals,
|
|
32
|
-
shippedProposals
|
|
44
|
+
shippedProposals,
|
|
45
|
+
[runtimeCompat]: {
|
|
46
|
+
useBabelRuntime,
|
|
47
|
+
ext = ".js"
|
|
48
|
+
} = {}
|
|
33
49
|
}) {
|
|
34
50
|
const isWebpack = babel.caller(caller => (caller == null ? void 0 : caller.name) === "babel-loader");
|
|
35
51
|
const resolve = createMetaResolver({
|
|
@@ -38,20 +54,31 @@ var _default = (0, _helperDefinePolyfillProvider.default)(function ({
|
|
|
38
54
|
instance: _builtInDefinitions.InstanceProperties
|
|
39
55
|
});
|
|
40
56
|
const available = new Set((0, _getModulesListForTargetVersion.default)(version));
|
|
41
|
-
const coreJSPureBase = proposals ? "core-js-pure/features" : "core-js-pure/stable";
|
|
57
|
+
const coreJSPureBase = useBabelRuntime ? proposals ? `${useBabelRuntime}/core-js` : `${useBabelRuntime}/core-js-stable` : proposals ? "core-js-pure/features" : "core-js-pure/stable";
|
|
42
58
|
|
|
43
|
-
function
|
|
59
|
+
function maybeInjectGlobalImpl(name, utils) {
|
|
60
|
+
if (shouldInjectPolyfill(name)) {
|
|
61
|
+
debug(name);
|
|
62
|
+
utils.injectGlobalImport((0, _utils.coreJSModule)(name));
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function maybeInjectGlobal(names, utils, fallback = true) {
|
|
44
70
|
for (const name of names) {
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
71
|
+
if (fallback) {
|
|
72
|
+
esnextFallback(name, name => maybeInjectGlobalImpl(name, utils));
|
|
73
|
+
} else {
|
|
74
|
+
maybeInjectGlobalImpl(name, utils);
|
|
48
75
|
}
|
|
49
76
|
}
|
|
50
77
|
}
|
|
51
78
|
|
|
52
79
|
function maybeInjectPure(desc, hint, utils, object) {
|
|
53
|
-
if (desc.pure && !(object && desc.exclude && desc.exclude.includes(object)) &&
|
|
54
|
-
return utils.injectDefaultImport(`${coreJSPureBase}/${desc.pure}
|
|
80
|
+
if (desc.pure && !(object && desc.exclude && desc.exclude.includes(object)) && esnextFallback(desc.name, shouldInjectPolyfill)) {
|
|
81
|
+
return utils.injectDefaultImport(`${coreJSPureBase}/${desc.pure}${ext}`, hint);
|
|
55
82
|
}
|
|
56
83
|
}
|
|
57
84
|
|
|
@@ -82,7 +109,7 @@ var _default = (0, _helperDefinePolyfillProvider.default)(function ({
|
|
|
82
109
|
return;
|
|
83
110
|
}
|
|
84
111
|
|
|
85
|
-
maybeInjectGlobal(modules, utils);
|
|
112
|
+
maybeInjectGlobal(modules, utils, false);
|
|
86
113
|
path.remove();
|
|
87
114
|
},
|
|
88
115
|
|
|
@@ -102,12 +129,15 @@ var _default = (0, _helperDefinePolyfillProvider.default)(function ({
|
|
|
102
129
|
usagePure(meta, utils, path) {
|
|
103
130
|
if (meta.kind === "in") {
|
|
104
131
|
if (meta.key === "Symbol.iterator") {
|
|
105
|
-
path.replaceWith(_core.types.callExpression(utils.injectDefaultImport((0, _utils.coreJSPureHelper)("is-iterable"), "isIterable"), [path.node.right]));
|
|
132
|
+
path.replaceWith(_core.types.callExpression(utils.injectDefaultImport((0, _utils.coreJSPureHelper)("is-iterable", useBabelRuntime, ext), "isIterable"), [path.node.right]));
|
|
106
133
|
}
|
|
107
134
|
|
|
108
135
|
return;
|
|
109
136
|
}
|
|
110
137
|
|
|
138
|
+
if (path.parentPath.isUnaryExpression({
|
|
139
|
+
operator: "delete"
|
|
140
|
+
})) return;
|
|
111
141
|
let isCall;
|
|
112
142
|
|
|
113
143
|
if (meta.kind === "property") {
|
|
@@ -123,22 +153,31 @@ var _default = (0, _helperDefinePolyfillProvider.default)(function ({
|
|
|
123
153
|
|
|
124
154
|
if (isCall) {
|
|
125
155
|
if (path.parent.arguments.length === 0) {
|
|
126
|
-
path.parentPath.replaceWith(_core.types.callExpression(utils.injectDefaultImport((0, _utils.coreJSPureHelper)("get-iterator"), "getIterator"), [path.node.object]));
|
|
156
|
+
path.parentPath.replaceWith(_core.types.callExpression(utils.injectDefaultImport((0, _utils.coreJSPureHelper)("get-iterator", useBabelRuntime, ext), "getIterator"), [path.node.object]));
|
|
127
157
|
path.skip();
|
|
128
158
|
} else {
|
|
129
|
-
(0, _utils.callMethod)(path, utils.injectDefaultImport((0, _utils.coreJSPureHelper)("get-iterator-method"), "getIteratorMethod"));
|
|
159
|
+
(0, _utils.callMethod)(path, utils.injectDefaultImport((0, _utils.coreJSPureHelper)("get-iterator-method", useBabelRuntime, ext), "getIteratorMethod"));
|
|
130
160
|
}
|
|
131
161
|
} else {
|
|
132
|
-
path.replaceWith(_core.types.callExpression(utils.injectDefaultImport((0, _utils.coreJSPureHelper)("get-iterator-method"), "getIteratorMethod"), [path.node.object]));
|
|
162
|
+
path.replaceWith(_core.types.callExpression(utils.injectDefaultImport((0, _utils.coreJSPureHelper)("get-iterator-method", useBabelRuntime, ext), "getIteratorMethod"), [path.node.object]));
|
|
133
163
|
}
|
|
134
164
|
|
|
135
165
|
return;
|
|
136
166
|
}
|
|
137
167
|
}
|
|
138
168
|
|
|
139
|
-
|
|
169
|
+
let resolved = resolve(meta);
|
|
140
170
|
if (!resolved) return;
|
|
141
171
|
|
|
172
|
+
if (useBabelRuntime && resolved.desc.pure && resolved.desc.pure.slice(-6) === "/index") {
|
|
173
|
+
// Remove /index, since it doesn't exist in @babel/runtime-corejs3s
|
|
174
|
+
resolved = _extends({}, resolved, {
|
|
175
|
+
desc: _extends({}, resolved.desc, {
|
|
176
|
+
pure: resolved.desc.pure.slice(0, -6)
|
|
177
|
+
})
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
142
181
|
if (resolved.kind === "global") {
|
|
143
182
|
const id = maybeInjectPure(resolved.desc, resolved.name, utils);
|
|
144
183
|
if (id) path.replaceWith(id);
|
package/lib/utils.js
CHANGED
|
@@ -42,6 +42,6 @@ function coreJSModule(name) {
|
|
|
42
42
|
return `core-js/modules/${name}.js`;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
function coreJSPureHelper(name) {
|
|
46
|
-
return `core-js-pure/features/${name}.js`;
|
|
45
|
+
function coreJSPureHelper(name, useBabelRuntime, ext) {
|
|
46
|
+
return useBabelRuntime ? `${useBabelRuntime}/core-js/${name}${ext}` : `core-js-pure/features/${name}.js`;
|
|
47
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-polyfill-corejs3",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A Babel plugin to inject imports to core-js@3 polyfills",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"babel-plugin"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@babel/helper-define-polyfill-provider": "^0.0
|
|
20
|
-
"core-js-compat": "^3.
|
|
19
|
+
"@babel/helper-define-polyfill-provider": "^0.1.0",
|
|
20
|
+
"core-js-compat": "^3.8.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@babel/core": "^7.11.5",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
26
26
|
"@babel/plugin-transform-for-of": "^7.10.4",
|
|
27
27
|
"@babel/plugin-transform-modules-commonjs": "^7.10.4",
|
|
28
|
-
"core-js-pure": "^3.
|
|
28
|
+
"core-js-pure": "^3.8.1"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@babel/core": "^7.0.0-0"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "b1a6b262d1de56486a2ab662ecc25834be6d2ad5"
|
|
34
34
|
}
|