This package has been deprecated

Author message:

This is supported natively in Vite with esbuild.target: 'es2022'

vite-plugin-using
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

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.

99% test coverage

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

pnpm add vite-plugin-using

Add to your vite.config.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:

Symbol.dispose ??= Symbol('@@dispose');
Symbol.asyncDispose ??= Symbol('@@asyncDispose');

Usage

Just start using!!

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!

Package Sidebar

Install

npm i vite-plugin-using

Weekly Downloads

131

Version

0.0.4

License

MIT

Unpacked Size

22.6 kB

Total Files

8

Last publish

Collaborators

  • ekwoka