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 transpilation of inherited classes #6506

Closed
raon0211 opened this issue Nov 24, 2022 · 1 comment · Fixed by #6796
Closed

Incorrect transpilation of inherited classes #6506

raon0211 opened this issue Nov 24, 2022 · 1 comment · Fixed by #6796
Assignees
Labels
Milestone

Comments

@raon0211
Copy link

raon0211 commented Nov 24, 2022

Describe the bug

The following input code should log 1 in stdout, but when transpiled with SWC it logs the instance of Bar.

It seems that _possibleConstructorReturn only returns when the value's type is object or function, which is incorrect.

Input code

class Foo {}

class Bar extends Foo {
    constructor() {
        super();
        this.node = 1;
        const self = this;
        this.root = {
            get node() {
                return self.node;
            }
        };
    }
}

console.log((new Bar()).root.node);

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.3.19&code=H4sIAAAAAAAAA11PMQ7CMAzc8wqPyVKJOWJh4B9VagpSFKPEEUgofyd2S6ty293Zd3aIYylwJYJPMyYou4wZ8M2YptUx0BEoFc41MGXrVk1Q6hO74jeB748yJJoQznDaZd2HgvHWdZn528hE3J09WDAjg0QdGn%2FIyDUnjdQ%2Bf5hoG2uL0Yx82K%2BgiEOk2dqEL3nWOqftGuL8F4aikMcTAQAA&config=H4sIAAAAAAAAA0WMTQrEIAxG75K1286id5hDBCctFv9IUhgR714tlu7C915ehUMsrBUyshCPS0pU%2FMMKZAOKZZcVTNf6tKEXagYUeScdiiyd%2BZSEJjUQXHRbGSWbQmYSeRHG3T9m66GQfucYKmjJdAc%2F0N7G%2FHPynaLySe0Cj9ke9LUAAAA%3D

Expected behavior

Logs 1.

Actual behavior

Logs the instance of Bar.

Version

1.3.19

Additional context

No response

@raon0211 raon0211 added the C-bug label Nov 24, 2022
@kdy1 kdy1 added this to the Planned milestone Nov 24, 2022
@kdy1 kdy1 self-assigned this Dec 22, 2022
kdy1 added a commit that referenced this issue Jan 12, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.27 Jan 17, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Feb 16, 2023

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 Feb 16, 2023
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