You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A reference error will be emitted when executing the code generated by swc that references a variable declared using using from closures. (See the sample input code below)
This issue can be re-produced in both of Typescript and JavaScript. The main part of a sample generated code looks like:
classFile{read(){return'content';}[Symbol.dispose](){console.log(`closing the file ...`);}}functionmain(){usingfile=newFile();functionreadFile(){file.read();// ...}readFile();}
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.
Describe the bug
A reference error will be emitted when executing the code generated by
swc
that references a variable declared usingusing
from closures. (See the sample input code below)This issue can be re-produced in both of Typescript and JavaScript. The main part of a sample generated code looks like:
Executing this code can emit an reference error:
file is not defined
.Moreover, here is the main part of the generated code from the official TypeScript transpiler (
tsc
), without this issue:The link to this code on typescriptlang.org.
Input code
Config
Playground link (or link to the minimal reproduction)
https://play.swc.rs/?version=1.5.0&code=H4sIAAAAAAAAA0WOMQrDMAxFd59CW5zFOYDp2gt0LIW4jpIaHKnEDqGU3L22Y9JBIH2e%2Fv%2FWmxDg6jzCVwAsaAbZljUfcV0IGssUkWKjk7qnud8%2B85O9Glx4c8DH%2BZDAwB6V50n21nNwNEF8IYzZXynVt4fHLsaVbHRMMBtH1WAtfGEvQLiVWrK8nHgueMg1M%2BPqqK2L0HU5qVb941rsP5Y8dYDsAAAA&config=H4sIAAAAAAAAA2VPOw6DMAzdOQXy3KFi7B1YegMrNSgoP8VGAiHu3iRA2qqb38fv2VvTtjCxgke7pTGBgJEpVpwYXp3gkhggZZFV1EHgdqkTZ2lAw1Q5WoLRSsuT2M9RUY8OR7LkJFklzlSM%2B%2BEHwTiSlHzu7l13ZoPxnuk3G6x2eli%2Fr1PehkjMf0dYdKOp%2B0djc7aC9a%2B5iOfXsoaMcpr1bmL4OK%2FGmg6a%2B2u9PLO%2FAcfgY45GAQAA
SWC Info output
No response
Expected behavior
The expected behavior is for the code to be generated in a correct way like what
tsc
does that it runs without emitting reference errorsActual behavior
No response
Version
1.5.0
Additional context
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management
The text was updated successfully, but these errors were encountered: