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

Incorrect transpile spread syntax in async function when specify env targets "Chrome >= 46" #8397

Closed
leemars opened this issue Dec 7, 2023 · 2 comments · Fixed by #8401
Closed
Assignees
Labels
Milestone

Comments

@leemars
Copy link

leemars commented Dec 7, 2023

Describe the bug

Refs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#spread_in_array_literals

Input code

function f() {
  const a = [1, 2, 3];
  const b = [...a, 4, 5];
}

async function af() {
  const a = [1, 2, 3];
  const b = [...a, 4, 5];
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    },
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true,
  "env": {
    "targets": "Chrome >= 46"
  }
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.3.100&code=H4sIAAAAAAAAA0srzUsuyczPU0jT0FSo5lJQSM7PKy5RSFSwVYg21FEw0lEwjrWGCyeBhPX09BJ1FEx0FEyBMrVcXInFlXnJCmkwgxLJNQkAvaCSE4sAAAA%3D&config=H4sIAAAAAAAAA2WOvQ7CMAyE9z5F5JkRMSDBwsxDRMEtQc2P7BQRVX33JmlTilis%2BLvz5cZGCHixgrMY0zMtXhIjbXsiHG2Qn0QgRI%2BsSPsAh6oGzlIre8aCpkWB3jnGqqzMaKvbuM9WznhC5l9jtkrb9fifXAYY9xiKupbOxXJB5BN8TfW3LRk03%2BtloGFhaN%2B7IEkdhlwHbk9yBsX1Io5LaDPNmovHqi4BAAA%3D

SWC Info output

No response

Expected behavior

See comment in actual behavior

Actual behavior

...
function f() {
    var a = [
        1,
        2,
        3
    ];
    var b = [
        ...a,
        4,
        5
    ];
}
function af() {
    return _af.apply(this, arguments);
}
function _af() {
    _af = _async_to_generator(function() {
        var a, b;
        return _ts_generator(this, function(_state) {
            a = [
                1,
                2,
                3
            ];
            b = [
                a,    # <---- Incorrect. should be "...a"
                4,
                5
            ];
            return [
                2
            ];
        });
    });
    return _af.apply(this, arguments);
}

Version

1.3.100

Additional context

No response

@leemars leemars added the C-bug label Dec 7, 2023
@kdy1
Copy link
Member

kdy1 commented Dec 7, 2023

My guess is that this is a bug of a pass asumming ExprOrSpread.spread is None and using ExprOrSpread.expr.as_arg()

@kdy1 kdy1 added this to the Planned milestone Dec 7, 2023
@kdy1 kdy1 self-assigned this Dec 7, 2023
@kdy1 kdy1 closed this as completed in #8401 Dec 8, 2023
kdy1 pushed a commit that referenced this issue Dec 8, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.101 Dec 18, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Jan 17, 2024

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 Jan 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants