Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0effd92
commit 376555f
Showing
24 changed files
with
291 additions
and
147 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
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,76 @@ | ||
/* @minVersion 7.23.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 _usingCtx() { | ||
var empty = {}; | ||
return { | ||
s: [], // stack | ||
e: empty, // error | ||
using: function (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." | ||
); | ||
} | ||
// 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.`); | ||
} | ||
this.s.push({ v: value, d: dispose, a: isAwait }); | ||
return value; | ||
}, | ||
dispose: function () { | ||
var stack = this.s, | ||
error = this.e; | ||
|
||
function next() { | ||
while ((r = stack.pop())) { | ||
try { | ||
var r, | ||
p = r.d.call(r.v); | ||
if (r.a) return Promise.resolve(p).then(next, err); | ||
} catch (e) { | ||
return err(e); | ||
} | ||
} | ||
if (error != empty) throw error; | ||
} | ||
|
||
function err(e) { | ||
error = error != empty ? new dispose_SuppressedError(e, error) : e; | ||
|
||
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
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
13 changes: 6 additions & 7 deletions
13
...ugin-proposal-explicit-resource-management/test/fixtures/transform-await/mixed/output.mjs
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 |
---|---|---|
@@ -1,11 +1,10 @@ | ||
try { | ||
var _stack = []; | ||
const a = babelHelpers.using(_stack, 1); | ||
const b = babelHelpers.using(_stack, 2, true); | ||
const c = babelHelpers.using(_stack, 3); | ||
var _usingCtx = babelHelpers.usingCtx(); | ||
const a = _usingCtx.using(1); | ||
const b = _usingCtx.using(2, true); | ||
const c = _usingCtx.using(3); | ||
} catch (_) { | ||
var _error = _; | ||
var _hasError = true; | ||
_usingCtx.e = _; | ||
} finally { | ||
await babelHelpers.dispose(_stack, _error, _hasError); | ||
await _usingCtx.dispose(); | ||
} |
13 changes: 6 additions & 7 deletions
13
...al-explicit-resource-management/test/fixtures/transform-await/only-using-await/output.mjs
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 |
---|---|---|
@@ -1,13 +1,12 @@ | ||
try { | ||
var _stack = []; | ||
const x = babelHelpers.using(_stack, obj, true); | ||
var _usingCtx = babelHelpers.usingCtx(); | ||
const x = _usingCtx.using(obj, true); | ||
stmt; | ||
const y = babelHelpers.using(_stack, obj, true), | ||
z = babelHelpers.using(_stack, obj, true); | ||
const y = _usingCtx.using(obj, true), | ||
z = _usingCtx.using(obj, true); | ||
doSomethingWith(x, y); | ||
} catch (_) { | ||
var _error = _; | ||
var _hasError = true; | ||
_usingCtx.e = _; | ||
} finally { | ||
await babelHelpers.dispose(_stack, _error, _hasError); | ||
await _usingCtx.dispose(); | ||
} |
9 changes: 4 additions & 5 deletions
9
...n-proposal-explicit-resource-management/test/fixtures/transform-sync/bare-block/output.js
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 |
---|---|---|
@@ -1,10 +1,9 @@ | ||
try { | ||
var _stack = []; | ||
const x = babelHelpers.using(_stack, obj); | ||
var _usingCtx = babelHelpers.usingCtx(); | ||
const x = _usingCtx.using(obj); | ||
doSomethingWith(x); | ||
} catch (_) { | ||
var _error = _; | ||
var _hasError = true; | ||
_usingCtx.e = _; | ||
} finally { | ||
babelHelpers.dispose(_stack, _error, _hasError); | ||
_usingCtx.dispose(); | ||
} |
9 changes: 4 additions & 5 deletions
9
...posal-explicit-resource-management/test/fixtures/transform-sync/for-await-head/output.mjs
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 |
---|---|---|
@@ -1,10 +1,9 @@ | ||
for await (const _x of y) try { | ||
var _stack = []; | ||
const x = babelHelpers.using(_stack, _x); | ||
var _usingCtx = babelHelpers.usingCtx(); | ||
const x = _usingCtx.using(_x); | ||
doSomethingWith(x); | ||
} catch (_) { | ||
var _error = _; | ||
var _hasError = true; | ||
_usingCtx.e = _; | ||
} finally { | ||
babelHelpers.dispose(_stack, _error, _hasError); | ||
_usingCtx.dispose(); | ||
} |
9 changes: 4 additions & 5 deletions
9
...gin-proposal-explicit-resource-management/test/fixtures/transform-sync/for-head/output.js
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 |
---|---|---|
@@ -1,10 +1,9 @@ | ||
for (const _x of y) try { | ||
var _stack = []; | ||
const x = babelHelpers.using(_stack, _x); | ||
var _usingCtx = babelHelpers.usingCtx(); | ||
const x = _usingCtx.using(_x); | ||
doSomethingWith(x); | ||
} catch (_) { | ||
var _error = _; | ||
var _hasError = true; | ||
_usingCtx.e = _; | ||
} finally { | ||
babelHelpers.dispose(_stack, _error, _hasError); | ||
_usingCtx.dispose(); | ||
} |
9 changes: 4 additions & 5 deletions
9
...roposal-explicit-resource-management/test/fixtures/transform-sync/function-body/output.js
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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
function fn() { | ||
try { | ||
var _stack = []; | ||
const x = babelHelpers.using(_stack, obj); | ||
var _usingCtx = babelHelpers.usingCtx(); | ||
const x = _usingCtx.using(obj); | ||
return doSomethingWith(x); | ||
} catch (_) { | ||
var _error = _; | ||
var _hasError = true; | ||
_usingCtx.e = _; | ||
} finally { | ||
babelHelpers.dispose(_stack, _error, _hasError); | ||
_usingCtx.dispose(); | ||
} | ||
} |
9 changes: 4 additions & 5 deletions
9
...ugin-proposal-explicit-resource-management/test/fixtures/transform-sync/if-body/output.js
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 |
---|---|---|
@@ -1,10 +1,9 @@ | ||
if (test) try { | ||
var _stack = []; | ||
const x = babelHelpers.using(_stack, obj); | ||
var _usingCtx = babelHelpers.usingCtx(); | ||
const x = _usingCtx.using(obj); | ||
doSomethingWith(x); | ||
} catch (_) { | ||
var _error = _; | ||
var _hasError = true; | ||
_usingCtx.e = _; | ||
} finally { | ||
babelHelpers.dispose(_stack, _error, _hasError); | ||
_usingCtx.dispose(); | ||
} |
Oops, something went wrong.