babel-plugin-polyfill-corejs2 0.0.8 → 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.
Files changed (2) hide show
  1. package/lib/index.js +17 -7
  2. package/package.json +3 -3
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"; // $FlowIgnore
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 (!pure || !(0, _helpers.hasMinVersion)(meta && meta.minRuntimeVersion, runtimeVersion) || !shouldInjectPolyfill(name)) {
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}.js`, hint);
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.js`, "isIterable"), [path.node.right]));
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.js`, "getIterator"), [path.node.object]));
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.0.8",
3
+ "version": "0.1.2",
4
4
  "description": "A Babel plugin to inject imports to core-js@2 polyfills",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "dependencies": {
19
19
  "@babel/compat-data": "^7.11.0",
20
- "@babel/helper-define-polyfill-provider": "^0.0.6",
20
+ "@babel/helper-define-polyfill-provider": "^0.1.0",
21
21
  "semver": "^6.1.1"
22
22
  },
23
23
  "devDependencies": {
@@ -29,5 +29,5 @@
29
29
  "peerDependencies": {
30
30
  "@babel/core": "^7.0.0-0"
31
31
  },
32
- "gitHead": "762a528b570a87fad72ebc24e7565b354b4bfbba"
32
+ "gitHead": "b1a6b262d1de56486a2ab662ecc25834be6d2ad5"
33
33
  }