Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Nicolò Ribaudo <hello@nicr.dev>
- Loading branch information
1 parent
1200542
commit 218faee
Showing
40 changed files
with
513 additions
and
428 deletions.
There are no files selected for viewing
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
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,81 @@ | ||
/* @minVersion 7.23.9 */ | ||
|
||
type Stack = { | ||
v: any; | ||
d: () => any; | ||
a: boolean; | ||
}; | ||
|
||
export default function _usingCtx() { | ||
var _disposeSuppressedError = | ||
typeof SuppressedError === "function" | ||
? // eslint-disable-next-line no-undef | ||
SuppressedError | ||
: (function (error: Error, suppressed: Error) { | ||
var err = new Error() as SuppressedError; | ||
err.name = "SuppressedError"; | ||
err.suppressed = suppressed; | ||
err.error = error; | ||
return err; | ||
} as SuppressedErrorConstructor), | ||
empty = {}, | ||
stack: Stack[] = []; | ||
function using(isAwait: boolean, value: any) { | ||
if (value != null) { | ||
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) { | ||
var dispose = | ||
value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]; | ||
} | ||
if (dispose == null) { | ||
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; | ||
} | ||
return { | ||
// error | ||
e: empty, | ||
// using | ||
u: using.bind(null, false), | ||
// await using | ||
a: using.bind(null, true), | ||
// dispose | ||
d: function () { | ||
var error = this.e; | ||
|
||
function next(): any { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
while ((resource = stack.pop())) { | ||
try { | ||
var resource, | ||
disposalResult = resource.d.call(resource.v); | ||
if (resource.a) { | ||
return Promise.resolve(disposalResult).then(next, err); | ||
} | ||
} catch (e) { | ||
return err(e); | ||
} | ||
} | ||
if (error !== empty) throw error; | ||
} | ||
|
||
function err(e: Error) { | ||
error = error !== empty ? new _disposeSuppressedError(error, e) : 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
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
9 changes: 4 additions & 5 deletions
9
...el-plugin-proposal-explicit-resource-management/test/fixtures/source-maps/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, fn()); | ||
var _usingCtx = babelHelpers.usingCtx(); | ||
const x = _usingCtx.u(fn()); | ||
doSomethingWith(x); | ||
} catch (_) { | ||
var _error = _; | ||
var _hasError = true; | ||
_usingCtx.e = _; | ||
} finally { | ||
babelHelpers.dispose(_stack, _error, _hasError); | ||
_usingCtx.d(); | ||
} |
Oops, something went wrong.