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

Support the using keyword for functions #8570

Closed
KyleJune opened this issue Jan 29, 2024 · 2 comments · Fixed by #8574
Closed

Support the using keyword for functions #8570

KyleJune opened this issue Jan 29, 2024 · 2 comments · Fixed by #8574
Assignees
Milestone

Comments

@KyleJune
Copy link

KyleJune commented Jan 29, 2024

Describe the feature

The following check for the using keyword currently only allows it for objects. These lines will prevent the using keyword from being used on functions which is allowed in tsc.

if (typeof value !== "object") {
throw new TypeError("using declarations can only be used with objects, null, or undefined.");
}

A function can have the Symbol.dispose or Symbol.asyncDispose added to them to make them disposable just like how an object can. Here is the implementation in TypeScript, showing that it should allow the using keyword for functions.

https://github.com/microsoft/TypeScript/blob/36f9e9e037a8bf715d96c8270732d5830719d7c8/tests/baselines/reference/usingDeclarations.11.js#L57

if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");

Babel plugin or link to the feature description

No response

Additional context

This is based on a discussion about making spies and stubs disposable so that the originals will automatically be restored after they are no longer needed. This is needed to implement the feature.

denoland/deno_std#3966

@Austaras
Copy link
Member

babel/babel#16150

@kdy1 kdy1 added this to the Planned milestone Jan 30, 2024
@kdy1 kdy1 assigned kdy1 and unassigned kdy1 Jan 30, 2024
kdy1 added a commit that referenced this issue Jan 30, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.4.0 Feb 5, 2024
@swc-bot
Copy link
Collaborator

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

Successfully merging a pull request may close this issue.

4 participants