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

Decorator transform puts variables in incorrect scope #8551

Closed
0f-0b opened this issue Jan 24, 2024 · 1 comment · Fixed by #8556
Closed

Decorator transform puts variables in incorrect scope #8551

0f-0b opened this issue Jan 24, 2024 · 1 comment · Fixed by #8556
Assignees
Labels
Milestone

Comments

@0f-0b
Copy link

0f-0b commented Jan 24, 2024

Describe the bug

If a class is followed by a TypeScript namespace, the decorator transform places variables generated for the class in the namespace.

Input code

class C {
  [Symbol.iterator]() {}
}

namespace NS {
  export function f() {}
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true
    },
    "transform": {
      "decoratorVersion": "2022-03"
    },
    "target": "es2022"
  },
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.3.105&code=H4sIAAAAAAAAA0vOSSwuVnBWqOZSUIgOrsxNys%2FRyyxJLUosyS%2BK1dBUqK7lquXiykvMTS0uSExOVfALBitNrSjILypRSCvNSy7JzM9TSIMpBQBdEy1bUAAAAA%3D%3D&config=H4sIAAAAAAAAA1WNwQrCQAxE7%2F2KJWeFst78B6%2FewzbKim6WJAVL6b%2BbrbToLTNvZjJ3IcBDE5zD7KeLiqIku3ZHp2L4dgdsqqRJcjU4bHSgxILGop4wGWkFy5eDCRa9sbx%2BB%2FfKlUQzlzYd%2BxiP%2FQn%2B2yh3soZJW6DRlUHWCw%2Fjk7afS%2FcBWAWB98oAAAA%3D

SWC Info output

No response

Expected behavior

_computedKey is declared in the same scope as C.

var _computedKey;
_computedKey = Symbol.iterator;
class C {
    [_computedKey]() {}
}
var NS;
(function(NS) {
    function f() {}
    NS.f = f;
})(NS || (NS = {}));

Actual behavior

_computedKey is declared in the namespace.

_computedKey = Symbol.iterator;
class C {
    [_computedKey]() {}
}
var NS;
(function(NS) {
    var _computedKey;
    function f() {}
    NS.f = f;
})(NS || (NS = {}));

Version

1.3.105

Additional context

No response

@swc-bot
Copy link
Collaborator

swc-bot commented Feb 28, 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 Feb 28, 2024
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.

4 participants