mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 09:38:16 +03:00
fix(es/proposals): Support using using
keyword with functions (#8574)
**Related issue:** - Closes #8570 - https://github.com/babel/babel/pull/16150
This commit is contained in:
parent
f5ee6d1d7f
commit
d81596cd2b
@ -1,9 +1,7 @@
|
||||
function _using(stack, value, isAwait) {
|
||||
if (value === null || value === void 0) return value;
|
||||
if (typeof value !== "object") {
|
||||
throw new TypeError(
|
||||
"using declarations can only be used with objects, null, or undefined."
|
||||
);
|
||||
if (Object(value) !== value) {
|
||||
throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
||||
}
|
||||
// core-js-pure uses Symbol.for for polyfilling well-known symbols
|
||||
if (isAwait) {
|
||||
|
@ -0,0 +1,15 @@
|
||||
return async function () {
|
||||
let log = [];
|
||||
async function getDisposable() {
|
||||
function disposable() { log.push('call') }
|
||||
disposable[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")] = () => { log.push('dispose') };
|
||||
return disposable;
|
||||
}
|
||||
|
||||
{
|
||||
await using x = getDisposable();
|
||||
x();
|
||||
}
|
||||
|
||||
expect(log).toEqual(['call', 'dispose']);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
let log = [];
|
||||
function disposable() { log.push('call') }
|
||||
disposable[Symbol.dispose || Symbol.for("Symbol.dispose")] = () => { log.push('dispose') };
|
||||
|
||||
{
|
||||
using x = disposable;
|
||||
x();
|
||||
}
|
||||
|
||||
expect(log).toEqual(['call', 'dispose']);
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@swc/counter",
|
||||
"packageManager": "yarn@3.5.0",
|
||||
"packageManager": "yarn@4.0.2",
|
||||
"main": "index.js",
|
||||
"version": "0.1.2",
|
||||
"description": "Downloade counter for the swc project",
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
export function _using(stack, value, isAwait) {
|
||||
if (value === null || value === void 0) return value;
|
||||
if (typeof value !== "object") {
|
||||
throw new TypeError("using declarations can only be used with objects, null, or undefined.");
|
||||
if (Object(value) !== value) {
|
||||
throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
||||
}
|
||||
// core-js-pure uses Symbol.for for polyfilling well-known symbols
|
||||
if (isAwait) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@swc/helpers",
|
||||
"packageManager": "yarn@3.5.0",
|
||||
"version": "0.5.3",
|
||||
"packageManager": "yarn@4.0.2",
|
||||
"version": "0.5.4",
|
||||
"description": "External helpers for the swc project.",
|
||||
"module": "esm/index.js",
|
||||
"main": "cjs/index.cjs",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "swc-info",
|
||||
"packageManager": "yarn@3.5.0",
|
||||
"packageManager": "yarn@4.0.2",
|
||||
"version": "0.1.15",
|
||||
"description": "CLI tool to help issue reporting for swc",
|
||||
"sideEffects": false,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@swc/types",
|
||||
"packageManager": "yarn@3.5.0",
|
||||
"packageManager": "yarn@4.0.2",
|
||||
"version": "0.1.5",
|
||||
"description": "Typings for the swc project.",
|
||||
"sideEffects": false,
|
||||
|
Loading…
Reference in New Issue
Block a user