Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Sep 12, 2023
1 parent 376555f commit 1f5f6f2
Show file tree
Hide file tree
Showing 21 changed files with 102 additions and 100 deletions.
2 changes: 1 addition & 1 deletion packages/babel-helpers/src/helpers-generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default Object.freeze({
),
usingCtx: helper(
"7.23.0",
'function dispose_SuppressedError(r,e){return"undefined"!=typeof SuppressedError?dispose_SuppressedError=SuppressedError:(dispose_SuppressedError=function(r,e){this.suppressed=r,this.error=e,this.stack=(new Error).stack},dispose_SuppressedError.prototype=Object.create(Error.prototype,{constructor:{value:dispose_SuppressedError,writable:!0,configurable:!0}})),new dispose_SuppressedError(r,e)}export default function _usingCtx(){var r={};return{s:[],e:r,using:function(r,e){if(null==r)return r;if("object"!=typeof r)throw new TypeError("using declarations can only be used with objects, null, or undefined.");if(e)var s=r[Symbol.asyncDispose||Symbol.for("Symbol.asyncDispose")];if(null==s&&(s=r[Symbol.dispose||Symbol.for("Symbol.dispose")]),"function"!=typeof s)throw new TypeError("Property [Symbol.dispose] is not a function.");return this.s.push({v:r,d:s,a:e}),r},dispose:function(){var e=this.s,s=this.e;function next(){for(;o=e.pop();)try{var o,t=o.d.call(o.v);if(o.a)return Promise.resolve(t).then(next,err)}catch(r){return err(r)}if(s!=r)throw s}function err(e){return s=s!=r?new dispose_SuppressedError(e,s):e,next()}return next()}}}',
'export default function _usingCtxFactory(){var r;return"undefined"!=typeof SuppressedError?r=SuppressedError:(r=function(r,e){this.suppressed=r,this.error=e,this.stack=(new Error).stack}).prototype=Object.create(Error.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),(_usingCtxFactory=function(){var e={},o=[];return{e:e,u:function(r,e){if(null==r)return r;if("object"!=typeof r)throw new TypeError("using declarations can only be used with objects, null, or undefined.");if(e)var t=r[Symbol.asyncDispose||Symbol.for("Symbol.asyncDispose")];if(null==t&&(t=r[Symbol.dispose||Symbol.for("Symbol.dispose")]),"function"!=typeof t)throw new TypeError("Property [Symbol.dispose] is not a function.");return o.push({v:r,d:t,a:e}),r},d:function(){var t=this.e;function next(){for(;r=o.pop();)try{var r,n=r.d.call(r.v);if(r.a)return Promise.resolve(n).then(next,err)}catch(r){return err(r)}if(t!=e)throw t}function err(o){return t=t!=e?new r(o,t):o,next()}return next()}}})()}',
),
wrapRegExp: helper(
"7.19.0",
Expand Down
100 changes: 51 additions & 49 deletions packages/babel-helpers/src/helpers/usingCtx.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* @minVersion 7.23.0 */

function dispose_SuppressedError(suppressed, error) {
export default function _usingCtxFactory() {
var dispose_SuppressedError;
if (typeof SuppressedError !== "undefined") {
// eslint-disable-next-line no-undef
dispose_SuppressedError = SuppressedError;
Expand All @@ -18,59 +19,60 @@ function dispose_SuppressedError(suppressed, error) {
},
});
}
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;
return (_usingCtxFactory = function _usingCtx() {
var empty = {},
stack = [];
return {
// error
e: empty,
// using
u: 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.`);
}
stack.push({ v: value, d: dispose, a: isAwait });
return value;
},
// dispose
d: function () {
var 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);
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;
}
if (error != empty) throw error;
}

function err(e) {
error = error != empty ? new dispose_SuppressedError(e, error) : e;
function err(e) {
error = error != empty ? new dispose_SuppressedError(e, error) : e;

return next();
}
return next();
}

return next();
},
};
return next();
},
};
})();
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ export default declare(api => {
const args = [decl.init];
if (isAwaitUsing) args.push(t.booleanLiteral(true));
decl.init = t.callExpression(
t.memberExpression(t.cloneNode(ctx), t.identifier("using")),
t.memberExpression(t.cloneNode(ctx), t.identifier("u")),
args,
);
});
}
if (!ctx) return;

let disposeCall: t.Expression = t.callExpression(
t.memberExpression(t.cloneNode(ctx), t.identifier("dispose")),
t.memberExpression(t.cloneNode(ctx), t.identifier("d")),
[],
);
if (needsAwait) disposeCall = t.awaitExpression(disposeCall);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ function fn() {
yield 0;
try {
var _usingCtx = babelHelpers.usingCtx();
const x = _usingCtx.using(y, true);
const x = _usingCtx.u(y, true);
yield 1;
} catch (_) {
_usingCtx.e = _;
} finally {
yield _usingCtx.dispose();
yield _usingCtx.d();
}
})).apply(this, arguments);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
try {
var _usingCtx = babelHelpers.usingCtx();
const a = _usingCtx.using(1);
const b = _usingCtx.using(2, true);
const c = _usingCtx.using(3);
const a = _usingCtx.u(1);
const b = _usingCtx.u(2, true);
const c = _usingCtx.u(3);
} catch (_) {
_usingCtx.e = _;
} finally {
await _usingCtx.dispose();
await _usingCtx.d();
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
try {
var _usingCtx = babelHelpers.usingCtx();
const x = _usingCtx.using(obj, true);
const x = _usingCtx.u(obj, true);
stmt;
const y = _usingCtx.using(obj, true),
z = _usingCtx.using(obj, true);
const y = _usingCtx.u(obj, true),
z = _usingCtx.u(obj, true);
doSomethingWith(x, y);
} catch (_) {
_usingCtx.e = _;
} finally {
await _usingCtx.dispose();
await _usingCtx.d();
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
try {
var _usingCtx = babelHelpers.usingCtx();
const x = _usingCtx.using(obj);
const x = _usingCtx.u(obj);
doSomethingWith(x);
} catch (_) {
_usingCtx.e = _;
} finally {
_usingCtx.dispose();
_usingCtx.d();
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
for await (const _x of y) try {
var _usingCtx = babelHelpers.usingCtx();
const x = _usingCtx.using(_x);
const x = _usingCtx.u(_x);
doSomethingWith(x);
} catch (_) {
_usingCtx.e = _;
} finally {
_usingCtx.dispose();
_usingCtx.d();
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
for (const _x of y) try {
var _usingCtx = babelHelpers.usingCtx();
const x = _usingCtx.using(_x);
const x = _usingCtx.u(_x);
doSomethingWith(x);
} catch (_) {
_usingCtx.e = _;
} finally {
_usingCtx.dispose();
_usingCtx.d();
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function fn() {
try {
var _usingCtx = babelHelpers.usingCtx();
const x = _usingCtx.using(obj);
const x = _usingCtx.u(obj);
return doSomethingWith(x);
} catch (_) {
_usingCtx.e = _;
} finally {
_usingCtx.dispose();
_usingCtx.d();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
if (test) try {
var _usingCtx = babelHelpers.usingCtx();
const x = _usingCtx.using(obj);
const x = _usingCtx.u(obj);
doSomethingWith(x);
} catch (_) {
_usingCtx.e = _;
} finally {
_usingCtx.dispose();
_usingCtx.d();
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
try {
var _usingCtx = babelHelpers.usingCtx();
const x = _usingCtx.using(obj);
const x = _usingCtx.u(obj);
try {
var _usingCtx2 = babelHelpers.usingCtx();
const y = _usingCtx2.using(call(() => {
const y = _usingCtx2.u(call(() => {
try {
var _usingCtx3 = babelHelpers.usingCtx();
const z = _usingCtx3.using(obj);
const z = _usingCtx3.u(obj);
return z;
} catch (_) {
_usingCtx3.e = _;
} finally {
_usingCtx3.dispose();
_usingCtx3.d();
}
}));
stmt;
} catch (_) {
_usingCtx2.e = _;
} finally {
_usingCtx2.dispose();
_usingCtx2.d();
}
stmt;
} catch (_) {
_usingCtx.e = _;
} finally {
_usingCtx.dispose();
_usingCtx.d();
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
try {
var _usingCtx = babelHelpers.usingCtx();
stmt;
const x = _usingCtx.using(obj);
const x = _usingCtx.u(obj);
stmt;
const y = _usingCtx.using(obj),
z = _usingCtx.using(obj);
const y = _usingCtx.u(obj),
z = _usingCtx.u(obj);
stmt;
const w = _usingCtx.using(obj);
const w = _usingCtx.u(obj);
doSomethingWith(x, z);
} catch (_) {
_usingCtx.e = _;
} finally {
_usingCtx.dispose();
_usingCtx.d();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ class A {
static {
try {
var _usingCtx = babelHelpers.usingCtx();
const x = _usingCtx.using(y);
const x = _usingCtx.u(y);
doSomethingWith(x);
} catch (_) {
_usingCtx.e = _;
} finally {
_usingCtx.dispose();
_usingCtx.d();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export { x, y };
try {
var _usingCtx = babelHelpers.usingCtx();
var x = _usingCtx.using(A);
var y = _usingCtx.using(B, true);
var x = _usingCtx.u(A);
var y = _usingCtx.u(B, true);
} catch (_) {
_usingCtx.e = _;
} finally {
await _usingCtx.dispose();
await _usingCtx.d();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export { _default as default };
try {
var _usingCtx = babelHelpers.usingCtx();
var x = _usingCtx.using(null);
var x = _usingCtx.u(null);
var _default = class {};
} catch (_) {
_usingCtx.e = _;
} finally {
_usingCtx.dispose();
_usingCtx.d();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export { C as default };
try {
var _usingCtx = babelHelpers.usingCtx();
var x = _usingCtx.using(null);
var x = _usingCtx.u(null);
var C = class {};
} catch (_) {
_usingCtx.e = _;
} finally {
_usingCtx.dispose();
_usingCtx.d();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export { _default as default };
try {
var _usingCtx = babelHelpers.usingCtx();
var x = _usingCtx.using(null);
var x = _usingCtx.u(null);
var _default = doSomething();
} catch (_) {
_usingCtx.e = _;
} finally {
_usingCtx.dispose();
_usingCtx.d();
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default function fn() {}
try {
var _usingCtx = babelHelpers.usingCtx();
var x = _usingCtx.using(null);
var x = _usingCtx.u(null);
} catch (_) {
_usingCtx.e = _;
} finally {
_usingCtx.dispose();
_usingCtx.d();
}

0 comments on commit 1f5f6f2

Please sign in to comment.