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

Erroneous output when class name equals the base class name combined with transform-classes #7546

Closed
kvet opened this issue Jun 19, 2023 · 1 comment · Fixed by #7550
Closed
Assignees
Labels
Milestone

Comments

@kvet
Copy link

kvet commented Jun 19, 2023

Describe the bug

Hi. First, thank you for the great project.

I was adopting it into one of my projects and run into a bug. Please check the details below.

Input code

import { ClassName } from './some-file';

export default {
    field: class ClassName extends ClassName {
        constructor() {
            super();
        }
    }
}

Config

{
  "jsc": {
    "loose": true
  },
  "env": {
    "include": [
      "transform-classes"
    ]
  }
}

Playground link

https://play.swc.rs/?version=1.3.64&code=H4sIAAAAAAAAA02MMQrEIBREe0%2Fxu%2BwWm%2B2Tcvu9g%2BgIguYHv0Jg8e7RDQRfMcVjZnzcOWX60Sdoka%2BOoEoucaRpfgtHvJwPmFalcPybFk6X0BaKGs4j2IVMHw8XODI2O5qr3jG8SU7FZE6P5%2BA7UnY0u96yqivrCQGTcsCoAAAA&config=H4sIAAAAAAAAA1WPPQ7CMAxG956i8gwjDNyBEyAGK7hVqvzJThFV1buTpkkLW%2Fw928%2BZm7aFQRTc2jk9UxGQhXivUyKTi%2FhJCZCyKIp1iHCqdJAVdWiEcrRsBCJyTzFPyaW0g%2FFeKGWRRyqR1U53069PeRuYROraXWXR9Yb%2BbU0xgvWvMcPyjzgF2uxXOJqqbF8MWu51sl4F5N7HIu2UGV8rf9RDIqOTzrM9K4MiJJDJc%2FU0yxd9B63KVAEAAA%3D%3D

Expected behavior

It's hard for me to say what it should yield in such a case, but here is the babel output for reference (with transform-classes):

/* ... */
import { ClassName } from './some-file';
export default {
  field: /*#__PURE__*/function (_ClassName) {
    _inherits(ClassName, _ClassName);
    var _super = _createSuper(ClassName);
    function ClassName() {
      _classCallCheck(this, ClassName);
      return _super.call(this);
    }
    return _createClass(ClassName);
  }(ClassName)
};

Actual behavior

Here is the result I get from swc. The problem here is that I am getting TypeError:

/* ... */
import { ClassName } from "./some-file";
export default {
    field: /*#__PURE__*/ function(ClassName) {
        "use strict";
        _inherits(ClassName1, ClassName);
        function ClassName1() {
            return ClassName.call(this);
        }
        return ClassName1;
    }(ClassName1)
};

Take a close look at the invocation in the line before the last one. }(ClassName1) There is no such reference yet.

Version

1.3.65

Additional context

No response

@kvet kvet added the C-bug label Jun 19, 2023
@kdy1 kdy1 self-assigned this Jun 20, 2023
@kdy1 kdy1 added this to the Planned milestone Jun 20, 2023
kdy1 added a commit that referenced this issue Jun 20, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.66 Jun 20, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Jul 20, 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 Jul 20, 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