diff --git a/react-packager/src/BundlesLayout/__tests__/BundlesLayoutIntegration-test.js b/react-packager/src/BundlesLayout/__tests__/BundlesLayoutIntegration-test.js index 6fab15da..93164ed1 100644 --- a/react-packager/src/BundlesLayout/__tests__/BundlesLayoutIntegration-test.js +++ b/react-packager/src/BundlesLayout/__tests__/BundlesLayoutIntegration-test.js @@ -35,6 +35,7 @@ describe('BundlesLayout', () => { 'polyfills/error-guard.js', 'polyfills/String.prototype.es6.js', 'polyfills/Array.prototype.es6.js', + 'polyfills/Array.es6.js', ]; const baseFs = getBaseFs(); diff --git a/react-packager/src/Resolver/__tests__/Resolver-test.js b/react-packager/src/Resolver/__tests__/Resolver-test.js index 715c0459..9687fb04 100644 --- a/react-packager/src/Resolver/__tests__/Resolver-test.js +++ b/react-packager/src/Resolver/__tests__/Resolver-test.js @@ -135,6 +135,19 @@ describe('Resolver', function() { 'polyfills/String.prototype.es6.js', ], }, + { id: 'polyfills/Array.es6.js', + isPolyfill: true, + path: 'polyfills/Array.es6.js', + dependencies: [ + 'polyfills/prelude.js', + 'polyfills/require.js', + 'polyfills/polyfills.js', + 'polyfills/console.js', + 'polyfills/error-guard.js', + 'polyfills/String.prototype.es6.js', + 'polyfills/Array.prototype.es6.js', + ], + } ]); }); }); @@ -196,7 +209,8 @@ describe('Resolver', function() { 'polyfills/console.js', 'polyfills/error-guard.js', 'polyfills/String.prototype.es6.js', - 'polyfills/Array.prototype.es6.js' + 'polyfills/Array.prototype.es6.js', + 'polyfills/Array.es6.js', ] }, ]); diff --git a/react-packager/src/Resolver/index.js b/react-packager/src/Resolver/index.js index 13c2ee46..d2c25e09 100644 --- a/react-packager/src/Resolver/index.js +++ b/react-packager/src/Resolver/index.js @@ -105,6 +105,7 @@ class Resolver { path.join(__dirname, 'polyfills/error-guard.js'), path.join(__dirname, 'polyfills/String.prototype.es6.js'), path.join(__dirname, 'polyfills/Array.prototype.es6.js'), + path.join(__dirname, 'polyfills/Array.es6.js'), ].concat(this._polyfillModuleNames); return polyfillModuleNames.map( diff --git a/react-packager/src/Resolver/polyfills/Array.es6.js b/react-packager/src/Resolver/polyfills/Array.es6.js new file mode 100644 index 00000000..ae3ac25e --- /dev/null +++ b/react-packager/src/Resolver/polyfills/Array.es6.js @@ -0,0 +1,81 @@ +/** + * Copyright 2013-2014 Facebook, Inc. + * @provides Array.es6 + * @polyfill + */ + +/*eslint-disable */ + +/** + * Creates an array from array like objects. + * + * https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from + */ +if (!Array.from) { + Array.from = function(arrayLike /*, mapFn, thisArg */) { + if (arrayLike == null) { + throw new TypeError('Object is null or undefined'); + } + + // Optional args. + var mapFn = arguments[1]; + var thisArg = arguments[2]; + + var C = this; + var items = Object(arrayLike); + var symbolIterator = typeof Symbol === 'function' + ? Symbol.iterator + : '@@iterator'; + var mapping = typeof mapFn === 'function'; + var usingIterator = typeof items[symbolIterator] === 'function'; + var key = 0; + var ret; + var value; + + if (usingIterator) { + ret = typeof C === 'function' + ? new C() + : []; + var it = items[symbolIterator](); + var next; + + while (!(next = it.next()).done) { + value = next.value; + + if (mapping) { + value = mapFn.call(thisArg, value, key); + } + + ret[key] = value; + key += 1; + } + + ret.length = key; + return ret; + } + + var len = items.length; + if (isNaN(len) || len < 0) { + len = 0; + } + + ret = typeof C === 'function' + ? new C(len) + : new Array(len); + + while (key < len) { + value = items[key]; + + if (mapping) { + value = mapFn.call(thisArg, value, key); + } + + ret[key] = value; + + key += 1; + } + + ret.length = key; + return ret; + }; +} diff --git a/react-packager/src/Resolver/polyfills/Array.prototype.es6.js b/react-packager/src/Resolver/polyfills/Array.prototype.es6.js index 34a38645..80e62f05 100644 --- a/react-packager/src/Resolver/polyfills/Array.prototype.es6.js +++ b/react-packager/src/Resolver/polyfills/Array.prototype.es6.js @@ -55,78 +55,4 @@ } }); } - - /** - * Creates an array from array like objects. - * - * https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from - */ - if (!Array.from) { - Array.from = function(arrayLike /*, mapFn, thisArg */) { - if (arrayLike == null) { - throw new TypeError('Object is null or undefined'); - } - - // Optional args. - var mapFn = arguments[1]; - var thisArg = arguments[2]; - - var C = this; - var items = Object(arrayLike); - var symbolIterator = typeof Symbol === 'function' - ? Symbol.iterator - : '@@iterator'; - var mapping = typeof mapFn === 'function'; - var usingIterator = typeof items[symbolIterator] === 'function'; - var key = 0; - var ret; - var value; - - if (usingIterator) { - ret = typeof C === 'function' - ? new C() - : []; - var it = items[symbolIterator](); - var next; - - while (!(next = it.next()).done) { - value = next.value; - - if (mapping) { - value = mapFn.call(thisArg, value, key); - } - - ret[key] = value; - key += 1; - } - - ret.length = key; - return ret; - } - - var len = items.length; - if (isNaN(len) || len < 0) { - len = 0; - } - - ret = typeof C === 'function' - ? new C(len) - : new Array(len); - - while (key < len) { - value = items[key]; - - if (mapping) { - value = mapFn.call(thisArg, value, key); - } - - ret[key] = value; - - key += 1; - } - - ret.length = key; - return ret; - }; - } })();