Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ekwoka/vite-plugin-using
Vite Plugin to transpile the using keyword
https://github.com/ekwoka/vite-plugin-using
Last synced: 27 days ago
JSON representation
Vite Plugin to transpile the using keyword
- Host: GitHub
- URL: https://github.com/ekwoka/vite-plugin-using
- Owner: ekwoka
- License: mit
- Created: 2023-08-28T18:03:36.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-31T13:33:54.000Z (9 months ago)
- Last Synced: 2024-05-02T01:12:42.627Z (8 months ago)
- Language: TypeScript
- Size: 92.8 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A quick and easy way to start using USING today!
> Note: This project is deprecated! The behavior is easily accessible inside of VITE using `esbuild.target: 'es2022' which will be a lot better than this dirty package anyway.
[](https://www.npmjs.com/package/vite-plugin-using)
[](https://bundlephobia.com/package/vite-plugin-using)This plugin allows using the upcoming JS keyword `using` in your code today! It transpiles `using` and `await using` to `try/finally` blocks to get the same effect more easily!
## Installation
```bash
pnpm add vite-plugin-using
```Add to your `vite.config.ts`
```ts
import ViteUsing from 'vite-plugin-using';export default defineConfig({
plugins: [ViteUsing()],
});
```You will need to polyfill the new `@@dispose` and `@@asyncDispose` symbols as such somewhere in your runtime:
```ts
Symbol.dispose ??= Symbol('@@dispose');
Symbol.asyncDispose ??= Symbol('@@asyncDispose');
```## Usage
Just start `using`!!
```ts
class disposable {
constructor() {}
[Symbol.dispose]() {
console.log('disposing')
}
[Symbol.asyncDispose]() {
console.log('async disposing')
}
}{
using obj = new disposable();
console.log('made one obj');
await using obj2 = new disposable();
console.log('made two obj');
console.log(obj, obj2)
}
```## Dang That's Cool!