mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
Rename proposal explicit resource management (#17340)
* rename proposal-explicit-resource-management to transform-explicit-resource-management * update library description * bump Babel/core version requirements to ^7.23.9 * add deprecation reminder * remove outdated reminders * update reminder date
This commit is contained in:
committed by
GitHub
parent
c8a70fb65f
commit
577b41b198
@@ -1,7 +1,7 @@
|
||||
name: Open issue to remind doing something
|
||||
on:
|
||||
schedule:
|
||||
- cron: 0 0 30 11 *
|
||||
- cron: 0 0 15 07 *
|
||||
|
||||
permissions:
|
||||
issues: write
|
||||
@@ -19,7 +19,5 @@ jobs:
|
||||
body: |-
|
||||
Please run these commands:
|
||||
```
|
||||
npm deprecate @babel/plugin-proposal-duplicate-named-capturing-groups-regex "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-duplicate-named-capturing-groups-regex instead."
|
||||
npm deprecate @babel/plugin-proposal-regexp-modifiers "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-regexp-modifiers instead."
|
||||
npm deprecate @babel/plugin-proposal-json-modules "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-json-modules instead."
|
||||
npm deprecate @babel/plugin-proposal-explicit-resource-management "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-explicit-resource-management instead."
|
||||
```
|
||||
|
||||
@@ -12,6 +12,6 @@ module.exports = {
|
||||
["@babel/plugin-proposal-decorators", { version: "2023-05" }],
|
||||
"@babel/plugin-transform-private-methods",
|
||||
"@babel/plugin-proposal-do-expressions",
|
||||
"@babel/plugin-proposal-explicit-resource-management",
|
||||
"@babel/plugin-transform-explicit-resource-management",
|
||||
],
|
||||
};
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
"@babel/eslint-parser": "workspace:^",
|
||||
"@babel/plugin-proposal-decorators": "workspace:^",
|
||||
"@babel/plugin-proposal-do-expressions": "workspace:^",
|
||||
"@babel/plugin-proposal-explicit-resource-management": "workspace:^",
|
||||
"@babel/plugin-proposal-pipeline-operator": "workspace:^",
|
||||
"@babel/plugin-syntax-export-default-from": "workspace:^",
|
||||
"@babel/plugin-transform-class-properties": "workspace:^",
|
||||
"@babel/plugin-transform-explicit-resource-management": "workspace:^",
|
||||
"@babel/plugin-transform-private-methods": "workspace:^",
|
||||
"@babel/preset-env": "workspace:^",
|
||||
"@babel/preset-flow": "workspace:^",
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# @babel/plugin-proposal-explicit-resource-management
|
||||
|
||||
> Compile `using` declarations to ES2015
|
||||
|
||||
See our website [@babel/plugin-proposal-explicit-resource-management](https://babeljs.io/docs/babel-plugin-proposal-explicit-resource-management) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/plugin-proposal-explicit-resource-management
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/plugin-proposal-explicit-resource-management --dev
|
||||
```
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["proposal-explicit-resource-management"]
|
||||
}
|
||||
Vendored
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"sourceMaps": true,
|
||||
"plugins": ["proposal-explicit-resource-management"]
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": ["proposal-explicit-resource-management"]
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": ["transform-modules-commonjs", "proposal-explicit-resource-management"]
|
||||
}
|
||||
@@ -262,7 +262,7 @@ function isBlockScoped(
|
||||
const { kind } = node;
|
||||
if (kind === "using" || kind === "await using") {
|
||||
throw path.buildCodeFrameError(
|
||||
`The ${kind} declaration should be first transformed by \`@babel/plugin-proposal-explicit-resource-management\`.`,
|
||||
`The ${kind} declaration should be first transformed by \`@babel/plugin-transform-explicit-resource-management\`.`,
|
||||
);
|
||||
} else if (!isLetOrConst(kind)) {
|
||||
return false;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": ["transform-block-scoping", "syntax-explicit-resource-management"],
|
||||
"throws": "The await using declaration should be first transformed by `@babel/plugin-proposal-explicit-resource-management`."
|
||||
"throws": "The await using declaration should be first transformed by `@babel/plugin-transform-explicit-resource-management`."
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"plugins": ["transform-block-scoping", "syntax-explicit-resource-management"],
|
||||
"throws": "The using declaration should be first transformed by `@babel/plugin-proposal-explicit-resource-management`."
|
||||
"throws": "The using declaration should be first transformed by `@babel/plugin-transform-explicit-resource-management`."
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# @babel/plugin-transform-explicit-resource-management
|
||||
|
||||
> Compile `using` and `await using` declarations to ES2015
|
||||
|
||||
See our website [@babel/plugin-transform-explicit-resource-management](https://babeljs.io/docs/babel-plugin-transform-explicit-resource-management) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/plugin-transform-explicit-resource-management
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/plugin-transform-explicit-resource-management --dev
|
||||
```
|
||||
+4
-4
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "@babel/plugin-proposal-explicit-resource-management",
|
||||
"name": "@babel/plugin-transform-explicit-resource-management",
|
||||
"version": "7.27.4",
|
||||
"description": "Compile `using` declarations to ES2015",
|
||||
"description": "Compile `using` and `await using` declarations to ES2015",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-plugin-proposal-explicit-resource-management"
|
||||
"directory": "packages/babel-plugin-transform-explicit-resource-management"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-plugin-proposal-explicit-resource-management",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-explicit-resource-management",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
+48
-107
@@ -28,7 +28,8 @@ function emitSetFunctionNameCall(
|
||||
}
|
||||
|
||||
export default declare(api => {
|
||||
api.assertVersion(REQUIRED_VERSION("^7.22.0"));
|
||||
// The first Babel 7 version with usingCtx helper support.
|
||||
api.assertVersion(REQUIRED_VERSION("^7.23.9"));
|
||||
|
||||
const TOP_LEVEL_USING = new Map<t.Node, USING_KIND>();
|
||||
|
||||
@@ -62,46 +63,45 @@ export default declare(api => {
|
||||
path: NodePath<t.BlockStatement | t.StaticBlock>,
|
||||
state,
|
||||
) {
|
||||
if (process.env.BABEL_8_BREAKING || state.availableHelper("usingCtx")) {
|
||||
let ctx: t.Identifier | null = null;
|
||||
let needsAwait = false;
|
||||
const scope = path.scope;
|
||||
let ctx: t.Identifier | null = null;
|
||||
let needsAwait = false;
|
||||
const scope = path.scope;
|
||||
|
||||
for (const node of path.node.body) {
|
||||
if (!isUsingDeclaration(node)) continue;
|
||||
ctx ??= scope.generateUidIdentifier("usingCtx");
|
||||
const isAwaitUsing =
|
||||
node.kind === "await using" ||
|
||||
TOP_LEVEL_USING.get(node) === USING_KIND.AWAIT;
|
||||
needsAwait ||= isAwaitUsing;
|
||||
for (const node of path.node.body) {
|
||||
if (!isUsingDeclaration(node)) continue;
|
||||
ctx ??= scope.generateUidIdentifier("usingCtx");
|
||||
const isAwaitUsing =
|
||||
node.kind === "await using" ||
|
||||
TOP_LEVEL_USING.get(node) === USING_KIND.AWAIT;
|
||||
needsAwait ||= isAwaitUsing;
|
||||
|
||||
if (!TOP_LEVEL_USING.delete(node)) {
|
||||
node.kind = "const";
|
||||
}
|
||||
for (const decl of node.declarations) {
|
||||
const currentInit = decl.init;
|
||||
decl.init = t.callExpression(
|
||||
t.memberExpression(
|
||||
t.cloneNode(ctx),
|
||||
isAwaitUsing ? t.identifier("a") : t.identifier("u"),
|
||||
),
|
||||
[
|
||||
isAnonymousFunctionDefinition(currentInit) &&
|
||||
t.isIdentifier(decl.id)
|
||||
? emitSetFunctionNameCall(state, currentInit, decl.id.name)
|
||||
: currentInit,
|
||||
],
|
||||
);
|
||||
}
|
||||
if (!TOP_LEVEL_USING.delete(node)) {
|
||||
node.kind = "const";
|
||||
}
|
||||
if (!ctx) return;
|
||||
for (const decl of node.declarations) {
|
||||
const currentInit = decl.init;
|
||||
decl.init = t.callExpression(
|
||||
t.memberExpression(
|
||||
t.cloneNode(ctx),
|
||||
isAwaitUsing ? t.identifier("a") : t.identifier("u"),
|
||||
),
|
||||
[
|
||||
isAnonymousFunctionDefinition(currentInit) &&
|
||||
t.isIdentifier(decl.id)
|
||||
? emitSetFunctionNameCall(state, currentInit, decl.id.name)
|
||||
: currentInit,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!ctx) return;
|
||||
|
||||
const disposeCall = t.callExpression(
|
||||
t.memberExpression(t.cloneNode(ctx), t.identifier("d")),
|
||||
[],
|
||||
);
|
||||
const disposeCall = t.callExpression(
|
||||
t.memberExpression(t.cloneNode(ctx), t.identifier("d")),
|
||||
[],
|
||||
);
|
||||
|
||||
const replacement = template.statement.ast`
|
||||
const replacement = template.statement.ast`
|
||||
try {
|
||||
var ${t.cloneNode(ctx)} = ${state.addHelper("usingCtx")}();
|
||||
${path.node.body}
|
||||
@@ -112,78 +112,19 @@ export default declare(api => {
|
||||
}
|
||||
` as t.TryStatement;
|
||||
|
||||
t.inherits(replacement, path.node);
|
||||
t.inherits(replacement, path.node);
|
||||
|
||||
const { parentPath } = path;
|
||||
if (
|
||||
parentPath.isFunction() ||
|
||||
parentPath.isTryStatement() ||
|
||||
parentPath.isCatchClause()
|
||||
) {
|
||||
path.replaceWith(t.blockStatement([replacement]));
|
||||
} else if (path.isStaticBlock()) {
|
||||
path.node.body = [replacement];
|
||||
} else {
|
||||
path.replaceWith(replacement);
|
||||
}
|
||||
const { parentPath } = path;
|
||||
if (
|
||||
parentPath.isFunction() ||
|
||||
parentPath.isTryStatement() ||
|
||||
parentPath.isCatchClause()
|
||||
) {
|
||||
path.replaceWith(t.blockStatement([replacement]));
|
||||
} else if (path.isStaticBlock()) {
|
||||
path.node.body = [replacement];
|
||||
} else {
|
||||
let stackId: t.Identifier | null = null;
|
||||
let needsAwait = false;
|
||||
|
||||
for (const node of path.node.body) {
|
||||
if (!isUsingDeclaration(node)) continue;
|
||||
stackId ??= path.scope.generateUidIdentifier("stack");
|
||||
const isAwaitUsing =
|
||||
node.kind === "await using" ||
|
||||
TOP_LEVEL_USING.get(node) === USING_KIND.AWAIT;
|
||||
needsAwait ||= isAwaitUsing;
|
||||
|
||||
if (!TOP_LEVEL_USING.delete(node)) {
|
||||
node.kind = "const";
|
||||
}
|
||||
node.declarations.forEach(decl => {
|
||||
const args = [t.cloneNode(stackId), decl.init];
|
||||
if (isAwaitUsing) args.push(t.booleanLiteral(true));
|
||||
decl.init = t.callExpression(state.addHelper("using"), args);
|
||||
});
|
||||
}
|
||||
if (!stackId) return;
|
||||
|
||||
const errorId = path.scope.generateUidIdentifier("error");
|
||||
const hasErrorId = path.scope.generateUidIdentifier("hasError");
|
||||
|
||||
let disposeCall: t.Expression = t.callExpression(
|
||||
state.addHelper("dispose"),
|
||||
[t.cloneNode(stackId), t.cloneNode(errorId), t.cloneNode(hasErrorId)],
|
||||
);
|
||||
if (needsAwait) disposeCall = t.awaitExpression(disposeCall);
|
||||
|
||||
const replacement = template.statement.ast`
|
||||
try {
|
||||
var ${stackId} = [];
|
||||
${path.node.body}
|
||||
} catch (_) {
|
||||
var ${errorId} = _;
|
||||
var ${hasErrorId} = true;
|
||||
} finally {
|
||||
${disposeCall}
|
||||
}
|
||||
` as t.TryStatement;
|
||||
|
||||
t.inherits(replacement.block, path.node);
|
||||
|
||||
const { parentPath } = path;
|
||||
if (
|
||||
parentPath.isFunction() ||
|
||||
parentPath.isTryStatement() ||
|
||||
parentPath.isCatchClause()
|
||||
) {
|
||||
path.replaceWith(t.blockStatement([replacement]));
|
||||
} else if (path.isStaticBlock()) {
|
||||
path.node.body = [replacement];
|
||||
} else {
|
||||
path.replaceWith(replacement);
|
||||
}
|
||||
path.replaceWith(replacement);
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -199,7 +140,7 @@ export default declare(api => {
|
||||
]);
|
||||
|
||||
return {
|
||||
name: "proposal-explicit-resource-management",
|
||||
name: "transform-explicit-resource-management",
|
||||
manipulateOptions: (_, p) => p.plugins.push("explicitResourceManagement"),
|
||||
|
||||
visitor: traverse.visitors.merge([
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"proposal-explicit-resource-management",
|
||||
"transform-explicit-resource-management",
|
||||
"transform-optional-catch-binding",
|
||||
"transform-async-to-generator"
|
||||
],
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"proposal-explicit-resource-management",
|
||||
"transform-explicit-resource-management",
|
||||
"transform-optional-catch-binding",
|
||||
"transform-async-to-generator"
|
||||
],
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"proposal-explicit-resource-management"
|
||||
"transform-explicit-resource-management"
|
||||
],
|
||||
"minNodeVersion": "12.0.0"
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"proposal-explicit-resource-management",
|
||||
"transform-explicit-resource-management",
|
||||
"transform-optional-catch-binding"
|
||||
]
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"proposal-explicit-resource-management",
|
||||
"transform-explicit-resource-management",
|
||||
"transform-async-to-generator"
|
||||
]
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": ["transform-modules-commonjs", "transform-export-namespace-from", "proposal-explicit-resource-management"]
|
||||
"plugins": ["transform-modules-commonjs", "transform-export-namespace-from", "transform-explicit-resource-management"]
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["transform-explicit-resource-management"]
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sourceMaps": true,
|
||||
"plugins": ["transform-explicit-resource-management"]
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": ["transform-explicit-resource-management"]
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user