Skip to content

Commit

Permalink
rename enums
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Apr 5, 2024
1 parent 202b59d commit 0f4e40a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/babel-helpers/src/helpers/usingCtx.ts
Expand Up @@ -2,17 +2,17 @@

const enum DisposeFlag {
// set when the dispose function is a [Symbol.asyncDispose] method
ASYNC_FLAG = 1,
// alias of AWAIT_FLAG: set when the resource is an `await using` disposable
ASYNC_MASK = 2,
ASYNC_DISPOSE = 1,
// alias of AWAIT_USING: set when the resource is an `await using` disposable
ASYNC_DISPOSE_MASK = 2,
}

const enum DisposeKind {
SYNC = 0,
USING_DISPOSE = 0,
// AWAIT_FLAG
AWAIT_SYNC = 2,
// AWAIT_FLAG | ASYNC_FLAG
AWAIT_ASYNC = 3,
AWAIT_USING_DISPOSE = 2,
// Flag.AWAIT_USING | Flag.ASYNC_DISPOSE
AWAIT_USING_ASYNC_DISPOSE = 3,
}

type Stack = {
Expand Down Expand Up @@ -46,19 +46,19 @@ export default function _usingCtx() {
if (isAwait) {
var dispose =
value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")],
kind = DisposeKind.AWAIT_ASYNC;
kind = DisposeKind.AWAIT_USING_ASYNC_DISPOSE;
}
if (dispose === undefined) {
dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
kind &= DisposeFlag.ASYNC_MASK;
kind &= DisposeFlag.ASYNC_DISPOSE_MASK;
}
if (typeof dispose !== "function") {
throw new TypeError("Object is not disposable.");
}
stack.push({ v: value, d: dispose, k: kind });
} else if (isAwait) {
// provide the nullish `value` as `d` for minification gain
stack.push({ d: value, k: DisposeKind.AWAIT_SYNC });
stack.push({ d: value, k: DisposeKind.AWAIT_USING_DISPOSE });
}
return value;
}
Expand All @@ -82,7 +82,7 @@ export default function _usingCtx() {
if (resource.k) {
return Promise.resolve(
// do not await the promise returned from the sync @@dispose
resource.k & DisposeFlag.ASYNC_FLAG && disposalResult,
resource.k & DisposeFlag.ASYNC_DISPOSE && disposalResult,
).then(next, err);
}
} catch (e) {
Expand Down

0 comments on commit 0f4e40a

Please sign in to comment.