babel-plugin-polyfill-corejs2 0.1.0 → 0.1.4
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 +11 -2
- package/lib/index.js +17 -7
- package/package.json +4 -4
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.StaticProperties = exports.InstanceProperties = exports.BuiltIns = exports.CommonIterators = void 0;
|
|
5
5
|
|
|
6
|
+
var _corejs2BuiltIns = _interopRequireDefault(require("@babel/compat-data/corejs2-built-ins"));
|
|
7
|
+
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
|
|
6
10
|
const define = (name, pure, global = [], meta) => {
|
|
7
11
|
return {
|
|
8
12
|
name,
|
|
@@ -91,7 +95,6 @@ const InstanceProperties = {
|
|
|
91
95
|
repeat: globalOnly(["es6.string.repeat"]),
|
|
92
96
|
replace: globalOnly(["es6.regexp.replace"]),
|
|
93
97
|
search: globalOnly(["es6.regexp.search"]),
|
|
94
|
-
slice: globalOnly(["es6.array.slice"]),
|
|
95
98
|
small: globalOnly(["es6.string.small"]),
|
|
96
99
|
some: globalOnly(["es6.array.some"]),
|
|
97
100
|
sort: globalOnly(["es6.array.sort"]),
|
|
@@ -109,8 +112,14 @@ const InstanceProperties = {
|
|
|
109
112
|
trimRight: globalOnly(["es7.string.trim-right"]),
|
|
110
113
|
trimStart: globalOnly(["es7.string.trim-left"]),
|
|
111
114
|
values: globalOnly(ArrayNatureIterators)
|
|
112
|
-
};
|
|
115
|
+
}; // This isn't present in older @babel/compat-data versions
|
|
116
|
+
|
|
113
117
|
exports.InstanceProperties = InstanceProperties;
|
|
118
|
+
|
|
119
|
+
if ("es6.array.slice" in _corejs2BuiltIns.default) {
|
|
120
|
+
InstanceProperties.slice = globalOnly(["es6.array.slice"]);
|
|
121
|
+
}
|
|
122
|
+
|
|
114
123
|
const StaticProperties = {
|
|
115
124
|
Array: {
|
|
116
125
|
from: pureAndGlobal("array/from", ["es6.symbol", "es6.array.from", ...CommonIterators]),
|
package/lib/index.js
CHANGED
|
@@ -17,14 +17,19 @@ var _core = require("@babel/core");
|
|
|
17
17
|
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
19
|
|
|
20
|
-
const presetEnvCompat = "#__secret_key__@babel/preset-env__compatibility";
|
|
20
|
+
const presetEnvCompat = "#__secret_key__@babel/preset-env__compatibility";
|
|
21
|
+
const runtimeCompat = "#__secret_key__@babel/runtime__compatibility"; // $FlowIgnore
|
|
21
22
|
|
|
22
23
|
const has = Function.call.bind(Object.hasOwnProperty);
|
|
23
24
|
|
|
24
25
|
var _default = (0, _helperDefinePolyfillProvider.default)(function (api, {
|
|
25
|
-
version: runtimeVersion = "7.0.0-beta.0",
|
|
26
26
|
[presetEnvCompat]: {
|
|
27
27
|
entryInjectRegenerator
|
|
28
|
+
} = {},
|
|
29
|
+
[runtimeCompat]: {
|
|
30
|
+
useBabelRuntime,
|
|
31
|
+
runtimeVersion,
|
|
32
|
+
ext = ".js"
|
|
28
33
|
} = {}
|
|
29
34
|
}) {
|
|
30
35
|
const resolve = api.createMetaResolver({
|
|
@@ -38,7 +43,7 @@ var _default = (0, _helperDefinePolyfillProvider.default)(function (api, {
|
|
|
38
43
|
method
|
|
39
44
|
} = api;
|
|
40
45
|
const polyfills = (0, _addPlatformSpecificPolyfills.default)(api.targets, method, _corejs2BuiltIns.default);
|
|
41
|
-
const coreJSBase = method === "usage-pure" ? "core-js/library/fn" : "core-js/modules";
|
|
46
|
+
const coreJSBase = useBabelRuntime ? `${useBabelRuntime}/core-js` : method === "usage-pure" ? "core-js/library/fn" : "core-js/modules";
|
|
42
47
|
|
|
43
48
|
function inject(name, utils) {
|
|
44
49
|
if (typeof name === "string") {
|
|
@@ -65,12 +70,13 @@ var _default = (0, _helperDefinePolyfillProvider.default)(function (api, {
|
|
|
65
70
|
meta,
|
|
66
71
|
name
|
|
67
72
|
} = desc;
|
|
73
|
+
if (!pure || !shouldInjectPolyfill(name)) return;
|
|
68
74
|
|
|
69
|
-
if (
|
|
75
|
+
if (runtimeVersion && meta && meta.minRuntimeVersion && !(0, _helpers.hasMinVersion)(meta && meta.minRuntimeVersion, runtimeVersion)) {
|
|
70
76
|
return;
|
|
71
77
|
}
|
|
72
78
|
|
|
73
|
-
return utils.injectDefaultImport(`${coreJSBase}/${pure}
|
|
79
|
+
return utils.injectDefaultImport(`${coreJSBase}/${pure}${ext}`, hint);
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
return {
|
|
@@ -106,12 +112,16 @@ var _default = (0, _helperDefinePolyfillProvider.default)(function (api, {
|
|
|
106
112
|
usagePure(meta, utils, path) {
|
|
107
113
|
if (meta.kind === "in") {
|
|
108
114
|
if (meta.key === "Symbol.iterator") {
|
|
109
|
-
path.replaceWith(_core.types.callExpression(utils.injectDefaultImport(`${coreJSBase}/is-iterable
|
|
115
|
+
path.replaceWith(_core.types.callExpression(utils.injectDefaultImport(`${coreJSBase}/is-iterable${ext}`, "isIterable"), [path.node.right]));
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
return;
|
|
113
119
|
}
|
|
114
120
|
|
|
121
|
+
if (path.parentPath.isUnaryExpression({
|
|
122
|
+
operator: "delete"
|
|
123
|
+
})) return;
|
|
124
|
+
|
|
115
125
|
if (meta.kind === "property") {
|
|
116
126
|
// We can't compile destructuring.
|
|
117
127
|
if (!path.isMemberExpression()) return;
|
|
@@ -120,7 +130,7 @@ var _default = (0, _helperDefinePolyfillProvider.default)(function (api, {
|
|
|
120
130
|
if (meta.key === "Symbol.iterator" && shouldInjectPolyfill("es6.symbol") && path.parentPath.isCallExpression({
|
|
121
131
|
callee: path.node
|
|
122
132
|
}) && path.parent.arguments.length === 0) {
|
|
123
|
-
path.parentPath.replaceWith(_core.types.callExpression(utils.injectDefaultImport(`${coreJSBase}/get-iterator
|
|
133
|
+
path.parentPath.replaceWith(_core.types.callExpression(utils.injectDefaultImport(`${coreJSBase}/get-iterator${ext}`, "getIterator"), [path.node.object]));
|
|
124
134
|
path.skip();
|
|
125
135
|
return;
|
|
126
136
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-polyfill-corejs2",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "A Babel plugin to inject imports to core-js@2 polyfills",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@babel/compat-data": "^7.11.0",
|
|
20
|
-
"@babel/helper-define-polyfill-provider": "^0.1.
|
|
20
|
+
"@babel/helper-define-polyfill-provider": "^0.1.1",
|
|
21
21
|
"semver": "^6.1.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@babel/core": "^7.
|
|
24
|
+
"@babel/core": "^7.13.0",
|
|
25
25
|
"@babel/helper-plugin-test-runner": "^7.10.4",
|
|
26
26
|
"@babel/plugin-transform-for-of": "^7.10.4",
|
|
27
27
|
"@babel/plugin-transform-modules-commonjs": "^7.10.4"
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@babel/core": "^7.0.0-0"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "8a59cefc151aa2104f4e4f921ec9c743a9d4eb72"
|
|
33
33
|
}
|