Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement transform support for
using
declarations (#15633)
Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
- Loading branch information
1 parent
6f59f92
commit 09aede9
Showing
86 changed files
with
1,213 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* @minVersion 7.0.0-beta.0 */ | ||
function dispose_SuppressedError(suppressed, error) { | ||
if (typeof SuppressedError !== "undefined") { | ||
// eslint-disable-next-line no-undef | ||
dispose_SuppressedError = SuppressedError; | ||
} else { | ||
dispose_SuppressedError = function SuppressedError(suppressed, error) { | ||
this.suppressed = suppressed; | ||
this.error = error; | ||
this.stack = new Error().stack; | ||
}; | ||
dispose_SuppressedError.prototype = Object.create(Error.prototype, { | ||
constructor: { | ||
value: dispose_SuppressedError, | ||
writable: true, | ||
configurable: true, | ||
}, | ||
}); | ||
} | ||
return new dispose_SuppressedError(suppressed, error); | ||
} | ||
|
||
export default function _dispose(stack, error, hasError) { | ||
function next() { | ||
if (stack.length === 0) { | ||
if (hasError) throw error; | ||
return; | ||
} | ||
|
||
var r = stack.pop(); | ||
if (r.a) { | ||
return Promise.resolve(r.d.call(r.v)).then(next, err); | ||
} | ||
try { | ||
r.d.call(r.v); | ||
} catch (e) { | ||
return err(e); | ||
} | ||
return next(); | ||
} | ||
|
||
function err(e) { | ||
error = hasError ? new dispose_SuppressedError(e, error) : e; | ||
hasError = true; | ||
|
||
return next(); | ||
} | ||
|
||
return next(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* @minVersion 7.0.0-beta.0 */ | ||
|
||
export default function _using(stack, value, isAwait) { | ||
if (value === null || value === void 0) return value; | ||
if (typeof value !== "object") { | ||
throw new TypeError( | ||
"using decarations can only be used with objects, null, or undefined." | ||
); | ||
} | ||
// core-js-pure uses Symbol.for for polyfilling well-known symbols | ||
if (isAwait) { | ||
var dispose = | ||
value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]; | ||
} | ||
if (dispose === null || dispose === void 0) { | ||
dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")]; | ||
} | ||
if (typeof dispose !== "function") { | ||
throw new TypeError(`Property [Symbol.dispose] is not a function.`); | ||
} | ||
stack.push({ v: value, d: dispose, a: isAwait }); | ||
return value; | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-proposal-explicit-resource-management/.npmignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src | ||
test | ||
*.log |
19 changes: 19 additions & 0 deletions
19
packages/babel-plugin-proposal-explicit-resource-management/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# @babel/plugin-proposal-explicit-resource-managements | ||
|
||
> Compile `using` declarations to ES2015 | ||
See our website [@babel/plugin-proposal-explicit-resource-managements](https://babeljs.io/docs/en/babel-plugin-proposal-explicit-resource-managements) for more information. | ||
|
||
## Install | ||
|
||
Using npm: | ||
|
||
```sh | ||
npm install --save-dev @babel/plugin-proposal-explicit-resource-managements | ||
``` | ||
|
||
or using yarn: | ||
|
||
```sh | ||
yarn add @babel/plugin-proposal-explicit-resource-managements --dev | ||
``` |
47 changes: 47 additions & 0 deletions
47
packages/babel-plugin-proposal-explicit-resource-management/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "@babel/plugin-proposal-explicit-resource-management", | ||
"version": "7.18.6", | ||
"description": "Compile `using` declarations to ES2015", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/babel/babel.git", | ||
"directory": "packages/babel-plugin-proposal-explicit-resource-management" | ||
}, | ||
"homepage": "https://babel.dev/docs/en/next/babel-plugin-proposal-explicit-resource-management", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "./lib/index.js", | ||
"keywords": [ | ||
"babel-plugin" | ||
], | ||
"dependencies": { | ||
"@babel/helper-plugin-utils": "workspace:^", | ||
"@babel/plugin-syntax-explicit-resource-management": "workspace:^" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "^7.0.0-0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "workspace:^", | ||
"@babel/helper-plugin-test-runner": "workspace:^" | ||
}, | ||
"engines": { | ||
"node": ">=6.9.0" | ||
}, | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
"conditions": { | ||
"USE_ESM": [ | ||
{ | ||
"type": "module" | ||
}, | ||
null | ||
] | ||
}, | ||
"exports": { | ||
".": "./lib/index.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"type": "commonjs" | ||
} |
Oops, something went wrong.