Skip to content

Commit f727b1d

Browse files
committed
Check in a forked version of object-assign
This one uses ES modules so that we can inline it into UMD builds. We could wait for object-assign to make an ESM export but we're going to remove this dependency and assume global polyfills in the next version anyway. However, we'd have to figure out how to keep the copyright header and it'll get counted in terms of byte size (even if other tooling removes it). A lot of headache when we have our own implementation anyway. So I'll just use that. Ours is not resilient to checking certain browser bugs but those browsers are mostly unused anyway. (Even FB breaks on them presumably.) We also don't need to be resilient to Symbols since the way React uses it we shouldn't need to copy symbols
1 parent 4ee592e commit f727b1d

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright 2004-present Facebook. All Rights Reserved.
3+
*/
4+
5+
const hasOwnProperty = Object.prototype.hasOwnProperty;
6+
7+
const _assign = function(to, from) {
8+
for (var key in from) {
9+
if (hasOwnProperty.call(from, key)) {
10+
to[key] = from[key];
11+
}
12+
}
13+
};
14+
15+
export default Object.assign ||
16+
function(target, sources) {
17+
if (target == null) {
18+
throw new TypeError('Object.assign target cannot be null or undefined');
19+
}
20+
21+
const to = Object(target);
22+
23+
for (let nextIndex = 1; nextIndex < arguments.length; nextIndex++) {
24+
const nextSource = arguments[nextIndex];
25+
if (nextSource != null) {
26+
_assign(to, Object(nextSource));
27+
}
28+
}
29+
30+
return to;
31+
};

scripts/rollup/forks.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const {RENDERER, RECONCILER} = moduleTypes;
2222
// If you need to replace a file with another file for a specific environment,
2323
// add it to this list with the logic for choosing the right replacement.
2424
const forks = Object.freeze({
25-
// Optimization: for UMDs, use object-assign polyfill that is already a part
26-
// of the React package instead of bundling it again.
25+
// Optimization: for UMDs, use a version that we can inline into the React bundle.
26+
// Use that from all other bundles.
2727
'object-assign': (bundleType, entry, dependencies) => {
2828
if (
2929
bundleType !== UMD_DEV &&
@@ -34,12 +34,16 @@ const forks = Object.freeze({
3434
// happens. Other bundles just require('object-assign') anyway.
3535
return null;
3636
}
37+
if (entry === 'react') {
38+
// Use the forked version that uses ES modules instead of CommonJS.
39+
return 'shared/forks/object-assign.inline-umd.js';
40+
}
3741
if (dependencies.indexOf('react') === -1) {
3842
// We can only apply the optimizations to bundle that depend on React
3943
// because we read assign() from an object exposed on React internals.
4044
return null;
4145
}
42-
// We can use the fork!
46+
// We can use the fork that reads the secret export!
4347
return 'shared/forks/object-assign.umd.js';
4448
},
4549

0 commit comments

Comments
 (0)