Skip to content

Commit

Permalink
fix(es/proposal): Use tsc version of explicit resource management (#…
Browse files Browse the repository at this point in the history
…9585)

**Related issue:**

 - Closes #9576
  • Loading branch information
kdy1 authored Oct 17, 2024
1 parent b2d40a7 commit f735108
Show file tree
Hide file tree
Showing 443 changed files with 12,894 additions and 6,704 deletions.
6 changes: 6 additions & 0 deletions .changeset/dull-shirts-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_ecma_transforms_proposal: patch
swc_core: patch
---

fix(es/proposal): Call `asyncDispose` correctly
18 changes: 12 additions & 6 deletions crates/swc/tests/fixture/issues-8xxx/8020/output/1.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
var _using_ctx = require("@swc/helpers/_/_using_ctx");
var _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource");
var _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources");
const env = {
stack: [],
error: void 0,
hasError: false
};
try {
var _usingCtx = _using_ctx._();
const foo = _usingCtx.u(null);
const foo = _ts_add_disposable_resource._(env, null, false);
const bar = 1;
console.log(baz());
function baz() {
return bar;
}
} catch (_) {
_usingCtx.e = _;
} catch (e) {
env.error = e;
env.hasError = true;
} finally{
_usingCtx.d();
_ts_dispose_resources._(env);
}
31 changes: 17 additions & 14 deletions crates/swc/tests/fixture/issues-8xxx/8629/output/1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx";
var _Disposable;
import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource";
import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources";
const env = {
stack: [],
error: void 0,
hasError: false
};
try {
var _usingCtx = _using_ctx();
var _computedKey;
_computedKey = Symbol.dispose;
class Disposable {
[_computedKey]() {
console.log('dispose');
}
}
_Disposable = Disposable;
var _disposable = _usingCtx.u(new Disposable());
const _disposable = _ts_add_disposable_resource(env, new Disposable(), false);
console.log('ok');
} catch (_) {
_usingCtx.e = _;
} catch (e) {
env.error = e;
env.hasError = true;
} finally{
_usingCtx.d();
_ts_dispose_resources(env);
}
export class Disposable {
[_computedKey]() {
console.log('dispose');
}
}
export { _Disposable as Disposable };
23 changes: 13 additions & 10 deletions crates/swc/tests/fixture/issues-8xxx/8629/output/2.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx";
var _Disposable;
import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource";
import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources";
const env = {
stack: [],
error: void 0,
hasError: false
};
try {
var _usingCtx = _using_ctx();
var Disposable = 1334;
_Disposable = Disposable;
var _disposable = _usingCtx.u(new Disposable());
const _disposable = _ts_add_disposable_resource(env, new Disposable(), false);
console.log('ok');
} catch (_) {
_usingCtx.e = _;
} catch (e) {
env.error = e;
env.hasError = true;
} finally{
_usingCtx.d();
_ts_dispose_resources(env);
}
export { _Disposable as Disposable };
export var Disposable = 1334;
56 changes: 39 additions & 17 deletions crates/swc/tests/fixture/issues-8xxx/8774/output/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var _using_ctx = require("@swc/helpers/_/_using_ctx");
var _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource");
var _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources");
const logClean = function() {
return {
[Symbol.dispose] () {
Expand All @@ -10,40 +11,61 @@ const logClean = function() {
};
};
async function foo() {
const env = {
stack: [],
error: void 0,
hasError: false
};
try {
var _usingCtx = _using_ctx._();
const a = _usingCtx.u(logClean());
const b = _usingCtx.a(logClean());
for (const a of [
const a = _ts_add_disposable_resource._(env, logClean(), false);
;
const b = _ts_add_disposable_resource._(env, logClean(), true);
;
for (const _ of [
logClean(),
logClean()
]){
const env = {
stack: [],
error: void 0,
hasError: false
};
try {
var _usingCtx1 = _using_ctx._();
const a = _ts_add_disposable_resource._(env, _, false);
{}
} catch (_) {
_usingCtx1.e = _;
} catch (e) {
env.error = e;
env.hasError = true;
} finally{
_usingCtx1.d();
_ts_dispose_resources._(env);
}
}
for (const a of [
for (const _ of [
logClean(),
logClean()
]){
const env = {
stack: [],
error: void 0,
hasError: false
};
try {
var _usingCtx2 = _using_ctx._();
const a = _ts_add_disposable_resource._(env, _, true);
{}
} catch (_) {
_usingCtx2.e = _;
} catch (e) {
env.error = e;
env.hasError = true;
} finally{
_usingCtx2.d();
const result = _ts_dispose_resources._(env);
if (result) await result;
}
}
} catch (_) {
_usingCtx.e = _;
} catch (e) {
env.error = e;
env.hasError = true;
} finally{
await _usingCtx.d();
const result = _ts_dispose_resources._(env);
if (result) await result;
}
}
foo();
19 changes: 13 additions & 6 deletions crates/swc/tests/fixture/issues-8xxx/8895/output/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var _using_ctx = require("@swc/helpers/_/_using_ctx");
var _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource");
var _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources");
class File {
read() {
return 'content';
Expand All @@ -8,16 +9,22 @@ class File {
}
}
function main() {
const env = {
stack: [],
error: void 0,
hasError: false
};
try {
var _usingCtx = _using_ctx._();
const file = _usingCtx.u(new File());
const file = _ts_add_disposable_resource._(env, new File(), false);
;
function readFile() {
file.read();
}
readFile();
} catch (_) {
_usingCtx.e = _;
} catch (e) {
env.error = e;
env.hasError = true;
} finally{
_usingCtx.d();
_ts_dispose_resources._(env);
}
}
Loading

0 comments on commit f735108

Please sign in to comment.