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

this initialised are before super() when with async function #9432

Closed
9aoy opened this issue Aug 15, 2024 · 1 comment · Fixed by #9446 or web-infra-dev/swc-plugins#212
Closed

this initialised are before super() when with async function #9432

9aoy opened this issue Aug 15, 2024 · 1 comment · Fixed by #9446 or web-infra-dev/swc-plugins#212
Assignees
Labels
Milestone

Comments

@9aoy
Copy link

9aoy commented Aug 15, 2024

Describe the bug

An error will be reported when the super parameter contains an async function:
ReferenceError: this hasn't been initialised - super() hasn't been called

Input code

class Foo extends Bar {
  constructor(options) {
    super(
      {
        callA: async () => {
          this.callA();
        },
      }
    );
  }
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "env": {
    "targets": [
        "chrome >= 51",
        "edge >= 15",
        "firefox >= 54",
        "safari >= 10",
        "ios_saf >= 10"
      ],
      "bugfixes": true,
  },
  "minify": false,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.11&code=H4sIAAAAAAAAA02KTQrCMBCF9znFWyYgPUBFQRfeI0wDBkKmZKbQUnJ3dSjFt3k%2F36MSRfBiRlo11UnwjA27A4iraFtIuXmeNX9rMADIMqfmLeKYfqJYymNElK0SfMDt%2FgcBfWcZ7OPD9dz75Yjd3Eh33X0A8SqckZkAAAA%3D&config=H4sIAAAAAAAAA1WQQQ7CIBBF9z0FYe1CE%2BvCRG%2FgCYwx2A4VU0ozQ02bpncXkBK6Y%2F77zMyfuWCMf6jiZza7pyt6gQSYaqfQ1FkxOoVDpQVVqHrLdyv9kEdStARBWv6Et8YQrCRqWnVKTnnvyugegWhr9FbRNS1sOxexO9emHgKMO9uph7AfnXgyQffNHAIbsH7MPU7ww99oNLDrhZWHFMj%2FrJugHspclQpBmjHYjzkgIQWq8GGf68rQ07EIov5ICV9DI9UIfieLQ0ge061XShfhim5rZO8tlh%2BMdDPEuAEAAA%3D%3D

SWC Info output

No response

Expected behavior

this should be accessed after super() call

Actual behavior

class Foo extends Bar {
    constructor(options){
        var _this = this;
        super({
            callA: _async_to_generator(function*() {
                _this.callA();
            })
        });
    }
}

Version

1.7.11

Additional context

No response

@swc-bot
Copy link
Collaborator

swc-bot commented Sep 18, 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 Sep 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.