Skip to content

Commit 0e6199b

Browse files
Make "object without properties" helpers ES6-compatible (#17086)
* change `includes` to `indexOf` and rebuild * turn off lint rule * update fixtures
1 parent c9ffe77 commit 0e6199b

7 files changed

Lines changed: 15 additions & 15 deletions

File tree

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ export default [
351351
"prefer-spread": "off",
352352
"import/no-extraneous-dependencies": "off",
353353
"import/no-unresolved": "off",
354+
"@typescript-eslint/prefer-includes": "off",
354355
"@typescript-eslint/prefer-optional-chain": "off",
355356
"unicorn/prefer-includes": "off",
356357
},

packages/babel-helpers/src/helpers-generated.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -959,10 +959,10 @@ const helpers: Record<string, Helper> = {
959959
},
960960
},
961961
),
962-
// size: 275, gzip size: 198
962+
// size: 279, gzip size: 205
963963
objectWithoutProperties: helper(
964964
"7.0.0-beta.0",
965-
"function _objectWithoutProperties(e,t){if(null==e)return{};var o,r,i=objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(r=0;r<s.length;r++)o=s[r],t.includes(o)||{}.propertyIsEnumerable.call(e,o)&&(i[o]=e[o])}return i}",
965+
"function _objectWithoutProperties(e,t){if(null==e)return{};var o,r,i=objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(r=0;r<n.length;r++)o=n[r],-1===t.indexOf(o)&&{}.propertyIsEnumerable.call(e,o)&&(i[o]=e[o])}return i}",
966966
{
967967
globals: ["Object"],
968968
locals: { _objectWithoutProperties: ["body.0.id"] },
@@ -975,10 +975,10 @@ const helpers: Record<string, Helper> = {
975975
},
976976
},
977977
),
978-
// size: 165, gzip size: 151
978+
// size: 169, gzip size: 156
979979
objectWithoutPropertiesLoose: helper(
980980
"7.0.0-beta.0",
981-
"function _objectWithoutPropertiesLoose(r,e){if(null==r)return{};var t={};for(var n in r)if({}.hasOwnProperty.call(r,n)){if(e.includes(n))continue;t[n]=r[n]}return t}",
981+
"function _objectWithoutPropertiesLoose(r,e){if(null==r)return{};var t={};for(var n in r)if({}.hasOwnProperty.call(r,n)){if(-1!==e.indexOf(n))continue;t[n]=r[n]}return t}",
982982
{
983983
globals: [],
984984
locals: { _objectWithoutPropertiesLoose: ["body.0.id"] },

packages/babel-helpers/src/helpers/objectWithoutProperties.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function _objectWithoutProperties<
2929
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
3030
for (i = 0; i < sourceSymbolKeys.length; i++) {
3131
key = sourceSymbolKeys[i] as keyof typeof source & keyof typeof target;
32-
if (excluded.includes(key)) continue;
32+
if (excluded.indexOf(key) !== -1) continue;
3333
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
3434
target[key] = source[key];
3535
}

packages/babel-helpers/src/helpers/objectWithoutPropertiesLoose.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function _objectWithoutPropertiesLoose<T extends object>(
2121

2222
for (var key in source) {
2323
if (Object.prototype.hasOwnProperty.call(source, key)) {
24-
if (excluded.includes(key)) continue;
24+
if (excluded.indexOf(key) !== -1) continue;
2525
target[key] = source[key];
2626
}
2727
}

packages/babel-preset-env/test/fixtures/corejs2-babel-7/usage-shippedProposals/output.js

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/babel-runtime-corejs3/helpers/esm/objectWithoutProperties.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import _Object$getOwnPropertySymbols from "core-js-pure/features/object/get-own-property-symbols.js";
2-
import _includesInstanceProperty from "core-js-pure/features/instance/includes.js";
2+
import _indexOfInstanceProperty from "core-js-pure/features/instance/index-of.js";
33
import objectWithoutPropertiesLoose from "./objectWithoutPropertiesLoose.js";
44
function _objectWithoutProperties(e, t) {
55
if (null == e) return {};
66
var o,
77
r,
88
i = objectWithoutPropertiesLoose(e, t);
99
if (_Object$getOwnPropertySymbols) {
10-
var s = _Object$getOwnPropertySymbols(e);
11-
for (r = 0; r < s.length; r++) o = s[r], _includesInstanceProperty(t).call(t, o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
10+
var n = _Object$getOwnPropertySymbols(e);
11+
for (r = 0; r < n.length; r++) o = n[r], -1 === _indexOfInstanceProperty(t).call(t, o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
1212
}
1313
return i;
1414
}

packages/babel-runtime-corejs3/helpers/esm/objectWithoutPropertiesLoose.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import _includesInstanceProperty from "core-js-pure/features/instance/includes.js";
1+
import _indexOfInstanceProperty from "core-js-pure/features/instance/index-of.js";
22
function _objectWithoutPropertiesLoose(r, e) {
33
if (null == r) return {};
44
var t = {};
55
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
6-
if (_includesInstanceProperty(e).call(e, n)) continue;
6+
if (-1 !== _indexOfInstanceProperty(e).call(e, n)) continue;
77
t[n] = r[n];
88
}
99
return t;

0 commit comments

Comments
 (0)