Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__spread does not work in IE11 #74

Open
nvirth opened this issue Aug 14, 2019 · 6 comments
Open

__spread does not work in IE11 #74

nvirth opened this issue Aug 14, 2019 · 6 comments
Assignees

Comments

@nvirth
Copy link

nvirth commented Aug 14, 2019

This TypeScript code (a Jasmine test):

describe("array spread operator", function() {
    it('should be able to spread arguments', function() {
        let argumentsArray;
        function testFunction() {
            argumentsArray = [...arguments];
        }
        (testFunction as any)(1, 2, 3);
        expect(argumentsArray).toEqual([1, 2, 3]);
    });
});

runs successfully in browsers but IE.
In IE11, it fails with:

Expected $.length = 1 to equal 3.
Expected $[0] = [object Arguments] to equal 1.
Expected $[1] = undefined to equal 2.
Expected $[2] = undefined to equal 3.

I can see the ... array spread operator gets built into a call for helper __spread, thus submitting the issue here.

Browsers I tried:

  • Chrome 76.0.3809.100 64bit
  • Opera 62.0.3331.116
  • Firefox Quantum 68.0.1 64-bit
  • Internet Explorer 11.309.16299.0
  • Microsoft Edge 41.16299.248.0
@RyanCavanaugh
Copy link
Member

@rbuckton any idea what's up?

@imasalygin
Copy link

imasalygin commented Sep 2, 2019

@RyanCavanaugh

IE doesn't support Symbol.Iterator
therefore function __read return arguments
therefore ar = [].concat(arguments) equals [arguments]
e.g., function function f() { return [...arguments] }; f(1); returns [{0: 1}]

@rbuckton
Copy link
Member

rbuckton commented Feb 26, 2020

We can possibly just change __read to do this:

    __read = function (o, n) {
        var m = typeof Symbol === "function" && o[Symbol.iterator];
        if (!m) return Array.prototype.slice.call(o, 0, n);
        ...

@rbuckton
Copy link
Member

Previously we didn't care about the n argument here since its purpose was to limit how many times we step through the iterator in cases like [a, b] = [1, 2, 3]. It didn't matter when we were just passing through the input object, but if we end up copying it using slice then we should limit the size of the output to cut down on memory usage.

@anton-bot
Copy link

The solution is to polyfill the Symbol.

import 'core-js/features/symbol';

Source: https://www.leereamsnyder.com/blog/new-skool-uniq-in-internet-explorer

@nvirth
Copy link
Author

nvirth commented Nov 9, 2021

We recently updated TSC from 4.1.2 to 4.4.4, where we could see diffing the built JS before and after the TSC upgrade, that lot of __spread usages have been replaced with __spreadArray.
After the upgrade, the above initial test case successfully runs in IE11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants