Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/proposals): Support using using keyword with functions #8574

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions crates/swc_ecma_transforms_base/src/helpers/_using.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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']);
}
Original file line number Diff line number Diff line change
@@ -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']);
2 changes: 1 addition & 1 deletion packages/counter/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/helpers/esm/_using.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/helpers/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/swc-info/package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading