Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow rest/spread on polyfilled or builtin iterables when
Symbol
un…
…supported Currently, when `Symbol` is not supported, we allow using rest/spread with: - arrays - strings - arguments With this PR, it will be also possible to use it with - maps - sets - binary arrays While in old browsers es6 builtins would still need to be polyfilled, it's way easier to polyfill them because `Symbol` cannot be reliably polyfilled. I didn't use `instanceof` becase: - it doesn't work with polyfills not attatched to the global scope - when using Babel to load polyfills, it would force the inclusion of `Map` and `Set` polyfills even if they are not used Downside: the current approach of relying on `toString || construcor.name` doesn't work with subclasses.
- Loading branch information
1 parent
a3f5bbb
commit b2db406
Showing
12 changed files
with
72 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
...ages/babel-preset-env/test/fixtures/preset-options/browserslist-defaults-not-ie/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
packages/babel-preset-env/test/fixtures/sanity/block-scoping-for-of/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import arrayWithHoles from "./arrayWithHoles"; | ||
import iterableToArray from "./iterableToArray"; | ||
import unsupportedIterableToArray from "./unsupportedIterableToArray"; | ||
import nonIterableRest from "./nonIterableRest"; | ||
export default function _toArray(arr) { | ||
return arrayWithHoles(arr) || iterableToArray(arr) || nonIterableRest(); | ||
return arrayWithHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableRest(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export default function _iterableToArray(iter) { | ||
if (typeof iter === 'string' || Object.prototype.toString.call(iter) === "[object Arguments]" || typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import arrayWithHoles from "./arrayWithHoles"; | ||
import iterableToArray from "./iterableToArray"; | ||
import unsupportedIterableToArray from "./unsupportedIterableToArray"; | ||
import nonIterableRest from "./nonIterableRest"; | ||
export default function _toArray(arr) { | ||
return arrayWithHoles(arr) || iterableToArray(arr) || nonIterableRest(); | ||
return arrayWithHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableRest(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
function _iterableToArray(iter) { | ||
if (typeof iter === 'string' || Object.prototype.toString.call(iter) === "[object Arguments]" || typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
} | ||
|
||
module.exports = _iterableToArray; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters