fix(rest-spread): Do not require Symbol.iterator for strings (#9794)

This commit is contained in:
Carlos Lopez 2020-03-15 09:54:44 -04:00 committed by GitHub
parent 661ffbd830
commit 7b9bc7c28b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 6 deletions

View File

@ -934,8 +934,9 @@ helpers.arrayWithHoles = helper("7.0.0-beta.0")`
helpers.iterableToArray = helper("7.0.0-beta.0")` helpers.iterableToArray = helper("7.0.0-beta.0")`
export default function _iterableToArray(iter) { export default function _iterableToArray(iter) {
if ( if (
Symbol.iterator in Object(iter) || typeof iter === 'string'
Object.prototype.toString.call(iter) === "[object Arguments]" || Object.prototype.toString.call(iter) === "[object Arguments]"
|| Symbol.iterator in Object(iter)
) return Array.from(iter); ) return Array.from(iter);
} }
`; `;

View File

@ -0,0 +1,9 @@
function sum(x, y, z) {
return x + y + z;
}
function test() {
var args = arguments;
return sum(...args);
}
expect(test(1, 2, 3)).toBe(6);

View File

@ -0,0 +1,3 @@
{
"plugins": ["proposal-object-rest-spread"]
}

View File

@ -0,0 +1,3 @@
expect([...'']).toHaveLength(0);
expect([...'abc']).toHaveLength(3);
expect([...'def']).toMatchObject(['d','e','f']);

View File

@ -1,5 +1,5 @@
import _Array$from from "../../core-js/array/from"; import _Array$from from "../../core-js/array/from";
import _isIterable from "../../core-js/is-iterable"; import _isIterable from "../../core-js/is-iterable";
export default function _iterableToArray(iter) { export default function _iterableToArray(iter) {
if (_isIterable(Object(iter)) || Object.prototype.toString.call(iter) === "[object Arguments]") return _Array$from(iter); if (typeof iter === 'string' || Object.prototype.toString.call(iter) === "[object Arguments]" || _isIterable(Object(iter))) return _Array$from(iter);
} }

View File

@ -3,7 +3,7 @@ var _Array$from = require("../core-js/array/from");
var _isIterable = require("../core-js/is-iterable"); var _isIterable = require("../core-js/is-iterable");
function _iterableToArray(iter) { function _iterableToArray(iter) {
if (_isIterable(Object(iter)) || Object.prototype.toString.call(iter) === "[object Arguments]") return _Array$from(iter); if (typeof iter === 'string' || Object.prototype.toString.call(iter) === "[object Arguments]" || _isIterable(Object(iter))) return _Array$from(iter);
} }
module.exports = _iterableToArray; module.exports = _iterableToArray;

View File

@ -1,3 +1,3 @@
export default function _iterableToArray(iter) { export default function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); if (typeof iter === 'string' || Object.prototype.toString.call(iter) === "[object Arguments]" || Symbol.iterator in Object(iter)) return Array.from(iter);
} }

View File

@ -1,5 +1,5 @@
function _iterableToArray(iter) { function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); if (typeof iter === 'string' || Object.prototype.toString.call(iter) === "[object Arguments]" || Symbol.iterator in Object(iter)) return Array.from(iter);
} }
module.exports = _iterableToArray; module.exports = _iterableToArray;