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

bug: "this" context are not passed properly if the function is async #1455

Closed
noaione opened this issue Mar 7, 2021 · 1 comment · Fixed by #1529
Closed

bug: "this" context are not passed properly if the function is async #1455

noaione opened this issue Mar 7, 2021 · 1 comment · Fixed by #1529
Assignees
Labels
Milestone

Comments

@noaione
Copy link

noaione commented Mar 7, 2021

Describe the bug

this context are not passed properly to statics while using ts-mongoose.
ts-mongoose passed the Model (as this) object to the statics arguments/parameters, but the compiled code doesn't pass the Model object making it undefined.

This only happens if the function is asynchronous.

Input code

const SampleData = typedModel("SampleVideo", VideosSchema, undefined, undefined, {
    byPlatform: async function (platform: string) {
        const result = await this.find({ platform: { $eq: platform } });
        return result;
    },
});

SampleData.byPlatform("youtube").then((res) => {
    console.info(res);
});

Config

{
    "exclude": [".*.js$", ".*.map$", ".*.test.ts$"],
    "jsc": {
        "target": "es2016",
        "parser": {
            "syntax": "typescript",
            "tsx": false,
            "decorators": true
        }
    },
    "minify": false,
    "module": {
        "type": "commonjs"
    }
}

Expected behavior
this is passed properly and not undefined.

Version
The version of @swc/core: 1.2.50
Node version: v14.15.1 (deployment server) and v12.13.0 (personal)

@noaione noaione added the C-bug label Mar 7, 2021
@kdy1 kdy1 added this to the v1.2.52 milestone Mar 28, 2021
@kdy1 kdy1 self-assigned this Apr 1, 2021
@kdy1 kdy1 mentioned this issue Apr 1, 2021
4 tasks
kdy1 added a commit to kdy1/swc that referenced this issue Apr 1, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 1, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 1, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 1, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 1, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 1, 2021
@kdy1 kdy1 closed this as completed in #1529 Apr 2, 2021
kdy1 added a commit that referenced this issue Apr 2, 2021
swc_ecma_parser:
 - Fix comment positions. (#1530)

swc_ecam_transforms_compat:
 - Handle default in destructuring binding patterns. (#1477, #1449)
 - `async_to_generator`: Handle `this` correctly for async function in key-value properties. (#1455)

swc_ecam_transforms_typescript:
 - Handle import defaults. (#1448)
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 25, 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 25, 2022
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