@babel/plugin-transform-explicit-resource-management
Traduction Bêta Non Officielle
Cette page a été traduite par PageTurner AI (bêta). Non approuvée officiellement par le projet. Vous avez trouvé une erreur ? Signaler un problème →
info
Ce plugin est inclus dans @babel/preset-env, dans ES2026.
Ce plugin permet à Babel de transformer les déclarations using handler = await read();.
Exemple
input.js
using handlerSync = openSync();
await using handlerAsync = await openAsync();
sera transformé en
output.js
try {
var _usingCtx = babelHelpers.usingCtx();
var handlerSync = _usingCtx.u(openSync());
var handlerAsync = _usingCtx.a(await openAsync());
} catch (_) {
_usingCtx.e = _;
} finally {
await _usingCtx.d();
}
Installation
- npm
- Yarn
- pnpm
- Bun
npm install --save-dev @babel/plugin-transform-explicit-resource-management
yarn add --dev @babel/plugin-transform-explicit-resource-management
pnpm add --save-dev @babel/plugin-transform-explicit-resource-management
bun add --dev @babel/plugin-transform-explicit-resource-management
Utilisation
Avec un fichier de configuration (Recommandé)
babel.config.json
{
"plugins": ["@babel/plugin-transform-explicit-resource-management"]
}
Via CLI
Shell
babel --plugins @babel/plugin-transform-explicit-resource-management script.js
Via l'API Node
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-transform-explicit-resource-management"]
});