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

asyncToGenerator function unrolls secondary parameter if it is an array #5951

Closed
finnboeger opened this issue Sep 26, 2022 · 1 comment · Fixed by #5965
Closed

asyncToGenerator function unrolls secondary parameter if it is an array #5951

finnboeger opened this issue Sep 26, 2022 · 1 comment · Fixed by #5965
Assignees
Milestone

Comments

@finnboeger
Copy link
Contributor

Calling an async function with the result of two async functions that both return an array leads to the second array being unrolled and each member of it being passed as a seperate parameter to the function.

With a and b being

async function a(): Promise<string[]> {
    return [1,2];
}

async function b(x: string[], y: string[]): Promise<void> {
    console.log(x, y);
    console.log(...x, ...y);
}

the following code is being transpiled incorrectly:

(
    async () => b(await a(), await a())
)().then();

into

_asyncToGenerator(function() {
    var _tmp;
    return __generator(this, function(_state) {
        switch(_state.label){
            case 0:
                return [
                    4,
                    a()
                ];
            case 1:
                _tmp = [
                    _state.sent()
                ];
                return [
                    4,
                    a()
                ];
            case 2:
                return [
                    2,
                    b.apply(void 0, _tmp.concat(_state.sent()))
                ];
        }
    });
})().then();

whereas the line b.apply(void 0, _tmp.concat(_state.sent())) should be instead b.apply(void 0, _tmp.push(_state.sent()))

The issue is reproduced here: https://github.com/finnboeger/swc-loader-async-bug

@kdy1 kdy1 transferred this issue from swc-project/swc-loader Sep 26, 2022
@kdy1 kdy1 added this to the Planned milestone Sep 26, 2022
@kdy1 kdy1 self-assigned this Sep 26, 2022
kdy1 pushed a commit that referenced this issue Sep 27, 2022
@kdy1 kdy1 modified the milestones: Planned, v1.3.4 Sep 30, 2022
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 30, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants