mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
chore(es): Add helpers (#9586)
Some checks failed
CI / Cargo fmt (push) Has been cancelled
CI / Cargo clippy (push) Has been cancelled
CI / Check license of dependencies (push) Has been cancelled
CI / Check (macos-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / Test wasm (binding_core_wasm) (push) Has been cancelled
CI / Test wasm (binding_minifier_wasm) (push) Has been cancelled
CI / Test wasm (binding_typescript_wasm) (push) Has been cancelled
CI / List crates (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Has been cancelled
CI / Test with @swc/cli (push) Has been cancelled
CI / Miri (better_scoped_tls) (push) Has been cancelled
CI / Miri (string_enum) (push) Has been cancelled
CI / Miri (swc) (push) Has been cancelled
CI / Miri (swc_bundler) (push) Has been cancelled
CI / Miri (swc_ecma_codegen) (push) Has been cancelled
CI / Miri (swc_ecma_minifier) (push) Has been cancelled
Benchmark / Bench everything (push) Has been cancelled
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Has been cancelled
CI / Done (push) Has been cancelled
Some checks failed
CI / Cargo fmt (push) Has been cancelled
CI / Cargo clippy (push) Has been cancelled
CI / Check license of dependencies (push) Has been cancelled
CI / Check (macos-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / Test wasm (binding_core_wasm) (push) Has been cancelled
CI / Test wasm (binding_minifier_wasm) (push) Has been cancelled
CI / Test wasm (binding_typescript_wasm) (push) Has been cancelled
CI / List crates (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Has been cancelled
CI / Test with @swc/cli (push) Has been cancelled
CI / Miri (better_scoped_tls) (push) Has been cancelled
CI / Miri (string_enum) (push) Has been cancelled
CI / Miri (swc) (push) Has been cancelled
CI / Miri (swc_bundler) (push) Has been cancelled
CI / Miri (swc_ecma_codegen) (push) Has been cancelled
CI / Miri (swc_ecma_minifier) (push) Has been cancelled
Benchmark / Bench everything (push) Has been cancelled
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Has been cancelled
CI / Done (push) Has been cancelled
**Description:** This is a part of https://github.com/swc-project/swc/pull/9585. I extracted this as a separate PR to make WIP small.
This commit is contained in:
parent
0a5a2d44cb
commit
b94a0e1fd2
@ -0,0 +1,33 @@
|
|||||||
|
function _ts_add_disposable_resource(env, value, async) {
|
||||||
|
if (value !== null && value !== void 0) {
|
||||||
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
||||||
|
var dispose, inner;
|
||||||
|
if (async) {
|
||||||
|
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
||||||
|
dispose = value[Symbol.asyncDispose];
|
||||||
|
}
|
||||||
|
if (dispose === void 0) {
|
||||||
|
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
||||||
|
dispose = value[Symbol.dispose];
|
||||||
|
if (async) inner = dispose;
|
||||||
|
}
|
||||||
|
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
||||||
|
if (inner) dispose = function () {
|
||||||
|
try {
|
||||||
|
inner.call(this);
|
||||||
|
} catch (e) {
|
||||||
|
return Promise.reject(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
env.stack.push({
|
||||||
|
value: value,
|
||||||
|
dispose: dispose,
|
||||||
|
async: async
|
||||||
|
});
|
||||||
|
} else if (async) {
|
||||||
|
env.stack.push({
|
||||||
|
async: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
function _ts_dispose_resources(SuppressedError) {
|
||||||
|
return function (env) {
|
||||||
|
function fail(e) {
|
||||||
|
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
||||||
|
env.hasError = true;
|
||||||
|
}
|
||||||
|
var r,
|
||||||
|
s = 0;
|
||||||
|
function next() {
|
||||||
|
while (r = env.stack.pop()) {
|
||||||
|
try {
|
||||||
|
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
||||||
|
if (r.dispose) {
|
||||||
|
var result = r.dispose.call(r.value);
|
||||||
|
if (r.async) return s |= 2, Promise.resolve(result).then(next, function (e) {
|
||||||
|
fail(e);
|
||||||
|
return next();
|
||||||
|
});
|
||||||
|
} else s |= 1;
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
||||||
|
if (env.hasError) throw env.error;
|
||||||
|
}
|
||||||
|
return next();
|
||||||
|
};
|
||||||
|
} (typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
||||||
|
var e = new Error(message);
|
||||||
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
||||||
|
});
|
@ -410,6 +410,8 @@ define_helpers!(Helpers {
|
|||||||
ts_metadata: (),
|
ts_metadata: (),
|
||||||
ts_param: (),
|
ts_param: (),
|
||||||
ts_values: (),
|
ts_values: (),
|
||||||
|
ts_add_disposable_resource: (),
|
||||||
|
ts_dispose_resources: (),
|
||||||
|
|
||||||
apply_decs_2203_r: (),
|
apply_decs_2203_r: (),
|
||||||
identity: (),
|
identity: (),
|
||||||
|
1
packages/helpers/esm/_ts_add_disposable_resource.js
Normal file
1
packages/helpers/esm/_ts_add_disposable_resource.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { __addDisposableResource as _ } from "tslib";
|
1
packages/helpers/esm/_ts_dispose_resources.js
Normal file
1
packages/helpers/esm/_ts_dispose_resources.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { __disposeResources as _ } from "tslib";
|
@ -89,7 +89,9 @@ export { _ as _to_array } from "./_to_array.js";
|
|||||||
export { _ as _to_consumable_array } from "./_to_consumable_array.js";
|
export { _ as _to_consumable_array } from "./_to_consumable_array.js";
|
||||||
export { _ as _to_primitive } from "./_to_primitive.js";
|
export { _ as _to_primitive } from "./_to_primitive.js";
|
||||||
export { _ as _to_property_key } from "./_to_property_key.js";
|
export { _ as _to_property_key } from "./_to_property_key.js";
|
||||||
|
export { _ as _ts_add_disposable_resource } from "./_ts_add_disposable_resource.js";
|
||||||
export { _ as _ts_decorate } from "./_ts_decorate.js";
|
export { _ as _ts_decorate } from "./_ts_decorate.js";
|
||||||
|
export { _ as _ts_dispose_resources } from "./_ts_dispose_resources.js";
|
||||||
export { _ as _ts_generator } from "./_ts_generator.js";
|
export { _ as _ts_generator } from "./_ts_generator.js";
|
||||||
export { _ as _ts_metadata } from "./_ts_metadata.js";
|
export { _ as _ts_metadata } from "./_ts_metadata.js";
|
||||||
export { _ as _ts_param } from "./_ts_param.js";
|
export { _ as _ts_param } from "./_ts_param.js";
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
"zx": "^7.2.1"
|
"zx": "^7.2.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.4.0"
|
"tslib": "^2.7.0"
|
||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
"./package.json": "./package.json",
|
"./package.json": "./package.json",
|
||||||
@ -403,10 +403,18 @@
|
|||||||
"import": "./esm/_to_property_key.js",
|
"import": "./esm/_to_property_key.js",
|
||||||
"default": "./cjs/_to_property_key.cjs"
|
"default": "./cjs/_to_property_key.cjs"
|
||||||
},
|
},
|
||||||
|
"./_/_ts_add_disposable_resource": {
|
||||||
|
"import": "./esm/_ts_add_disposable_resource.js",
|
||||||
|
"default": "./cjs/_ts_add_disposable_resource.cjs"
|
||||||
|
},
|
||||||
"./_/_ts_decorate": {
|
"./_/_ts_decorate": {
|
||||||
"import": "./esm/_ts_decorate.js",
|
"import": "./esm/_ts_decorate.js",
|
||||||
"default": "./cjs/_ts_decorate.cjs"
|
"default": "./cjs/_ts_decorate.cjs"
|
||||||
},
|
},
|
||||||
|
"./_/_ts_dispose_resources": {
|
||||||
|
"import": "./esm/_ts_dispose_resources.js",
|
||||||
|
"default": "./cjs/_ts_dispose_resources.cjs"
|
||||||
|
},
|
||||||
"./_/_ts_generator": {
|
"./_/_ts_generator": {
|
||||||
"import": "./esm/_ts_generator.js",
|
"import": "./esm/_ts_generator.js",
|
||||||
"default": "./cjs/_ts_generator.cjs"
|
"default": "./cjs/_ts_generator.cjs"
|
||||||
|
@ -4639,7 +4639,7 @@ __metadata:
|
|||||||
"@ast-grep/napi": "npm:^0.3.1"
|
"@ast-grep/napi": "npm:^0.3.1"
|
||||||
dprint: "npm:^0.35.3"
|
dprint: "npm:^0.35.3"
|
||||||
magic-string: "npm:^0.30.0"
|
magic-string: "npm:^0.30.0"
|
||||||
tslib: "npm:^2.4.0"
|
tslib: "npm:^2.7.0"
|
||||||
zx: "npm:^7.2.1"
|
zx: "npm:^7.2.1"
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
@ -16822,6 +16822,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"tslib@npm:^2.7.0":
|
||||||
|
version: 2.7.0
|
||||||
|
resolution: "tslib@npm:2.7.0"
|
||||||
|
checksum: 9a5b47ddac65874fa011c20ff76db69f97cf90c78cff5934799ab8894a5342db2d17b4e7613a087046bc1d133d21547ddff87ac558abeec31ffa929c88b7fce6
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"tsx@npm:^3.13.0":
|
"tsx@npm:^3.13.0":
|
||||||
version: 3.14.0
|
version: 3.14.0
|
||||||
resolution: "tsx@npm:3.14.0"
|
resolution: "tsx@npm:3.14.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user