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

Usage of forwardRef in NestJS decorator is not captured by SWC #6024

Closed
RobertMenke opened this issue Oct 2, 2022 · 2 comments
Closed

Usage of forwardRef in NestJS decorator is not captured by SWC #6024

RobertMenke opened this issue Oct 2, 2022 · 2 comments
Labels

Comments

@RobertMenke
Copy link

RobertMenke commented Oct 2, 2022

Describe the bug

NestJS has a strategy for dealing with circular dependencies, which is the use of a function called forwardRef.

Input code

// a.ts
@Injectable()
export class A {
    constructor(
          @Inject(forwardRef(() => B))
          private readonly b: B
    ) {}
}

// b.ts
@Injectable()
export class B {
    constructor(
          private readonly a: A
    ) {}
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true
    },
    "target": "es2020",
    "keepClassNames": true,
    "baseUrl": "."
  },
  "module": {
    "type": "commonjs",
    "strictMode": true
  }
}

Playground link

https://play.swc.rs/?version=1.3.4&code=H4sIAAAAAAAAA32OTQrCMBCF93OKWSYbuy8oaXZuvcEknYISkjIZrVJ6d6XdFETf8v3wPXfON45KIbGxwM%2BxiGJMVCt2OAN%2BFEuuKveoRcxqbHLb0gxFJpL%2BwoMxFo8n9NbuaqNcH6SMwtSXnF4YWvRrbnFeYAFoGgwHreB%2BX%2FH%2Fr3wxqMVux3gDB1vo%2BeUAAAA%3D&config=H4sIAAAAAAAAA02OMQ7CMAxF7%2BK5QlXHrrCWjQOYxFQtSR3ZrkRU9e4kggo26%2Bu%2F%2F7zBrA76DRKKktRL82L4gh4sJ1InUzJowJNjQWNR6E1W2hswwUUfLLFSgUZ0%2BXK0PqU%2FbCBDj4Y%2FGmUkKxrSru3aongSpXNA1StG0mPhjko3CaV4goJF9mugaqzvldRxjLzMWgbUZHI2sKevZX8D5J%2BHyd8AAAA%3D

Expected behavior

I would expect that the code compiles because tsc does not error

Actual behavior

ReferenceError: Cannot access 'MyClassName' before initialization

Version

1.3.4

Additional context

No response

@RobertMenke RobertMenke changed the title Usage of forwardRef if NestJS decorator is not captured by SWC Usage of forwardRef in NestJS decorator is not captured by SWC Oct 2, 2022
@kdy1
Copy link
Member

kdy1 commented Oct 2, 2022

Please search before filing an issue #5047

@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2022
@kdy1 kdy1 added invalid and removed C-bug labels Oct 2, 2022
@swc-bot
Copy link
Collaborator

swc-bot commented Nov 2, 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 Nov 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants