Skip to content

Commit

Permalink
fix(es/proposal): Fix scoping of explicit resource management pass (#…
Browse files Browse the repository at this point in the history
…8903)

**Related issue:**

 - Closes #8895
  • Loading branch information
kdy1 authored May 5, 2024
1 parent 225d25a commit 762b0d4
Show file tree
Hide file tree
Showing 21 changed files with 669 additions and 606 deletions.
6 changes: 3 additions & 3 deletions crates/swc/tests/fixture/issues-8xxx/8020/output/1.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx";
function baz() {
return bar;
}
try {
var _usingCtx = _using_ctx();
var foo = _usingCtx.u(null);
const bar = 1;
console.log(baz());
function baz() {
return bar;
}
} catch (_) {
_usingCtx.e = _;
} finally{
Expand Down
20 changes: 20 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8895/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false,
"explicitResourceManagement": true
},
"target": "es2022",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "commonjs"
},
"minify": false,
"isModule": true
}
16 changes: 16 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8895/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class File {
read() {
return 'content';
}
[Symbol.dispose]() {
console.log(`closing the file ...`);
}
}
function main() {
using file = new File();
function readFile() {
file.read();
// ...
}
readFile();
}
27 changes: 27 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8895/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const _using_ctx = require("@swc/helpers/_/_using_ctx");
class File {
read() {
return 'content';
}
[Symbol.dispose]() {
console.log(`closing the file ...`);
}
}
function main() {
try {
var _usingCtx = _using_ctx._();
const file = _usingCtx.u(new File());
function readFile() {
file.read();
}
readFile();
} catch (_) {
_usingCtx.e = _;
} finally{
_usingCtx.d();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,56 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _await_async_generator } from "@swc/helpers/_/_await_async_generator";
import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator";
import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx";
function af() {
return _af.apply(this, arguments);
}
function _af() {
_af = _async_to_generator(function*() {
try {
var _usingCtx = _using_ctx();
const d3 = _usingCtx.a({
[Symbol.asyncDispose] () {
return _async_to_generator(function*() {})();
}
});
yield null;
} catch (_) {
_usingCtx.e = _;
} finally{
yield _usingCtx.d();
}
});
return _af.apply(this, arguments);
}
function ag() {
return _ag.apply(this, arguments);
}
function _ag() {
_ag = _wrap_async_generator(function*() {
try {
var _usingCtx = _using_ctx();
const d5 = _usingCtx.a({
[Symbol.asyncDispose] () {
return _async_to_generator(function*() {})();
}
});
yield;
yield _await_async_generator(null);
} catch (_) {
_usingCtx.e = _;
} finally{
yield _await_async_generator(_usingCtx.d());
}
});
return _ag.apply(this, arguments);
}
try {
var _usingCtx = _using_ctx();
var d1 = _usingCtx.a({
[Symbol.asyncDispose] () {
return _async_to_generator(function*() {})();
}
});
function af() {
return _af.apply(this, arguments);
}
function _af() {
_af = _async_to_generator(function*() {
try {
var _usingCtx = _using_ctx();
const d3 = _usingCtx.a({
[Symbol.asyncDispose] () {
return _async_to_generator(function*() {})();
}
});
yield null;
} catch (_) {
_usingCtx.e = _;
} finally{
yield _usingCtx.d();
}
});
return _af.apply(this, arguments);
}
function ag() {
return _ag.apply(this, arguments);
}
function _ag() {
_ag = _wrap_async_generator(function*() {
try {
var _usingCtx = _using_ctx();
const d5 = _usingCtx.a({
[Symbol.asyncDispose] () {
return _async_to_generator(function*() {})();
}
});
yield;
yield _await_async_generator(null);
} catch (_) {
_usingCtx.e = _;
} finally{
yield _await_async_generator(_usingCtx.d());
}
});
return _ag.apply(this, arguments);
}
const a = function() {
var _ref = _async_to_generator(function*() {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
//// [awaitUsingDeclarations.1.ts]
import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx";
async function af() {
try {
var _usingCtx = _using_ctx();
const d3 = _usingCtx.a({
async [Symbol.asyncDispose] () {}
});
await null;
} catch (_) {
_usingCtx.e = _;
} finally{
await _usingCtx.d();
}
}
async function* ag() {
try {
var _usingCtx = _using_ctx();
const d5 = _usingCtx.a({
async [Symbol.asyncDispose] () {}
});
yield;
await null;
} catch (_) {
_usingCtx.e = _;
} finally{
await _usingCtx.d();
}
}
try {
var _usingCtx = _using_ctx();
var d1 = _usingCtx.a({
async [Symbol.asyncDispose] () {}
});
async function af() {
try {
var _usingCtx = _using_ctx();
const d3 = _usingCtx.a({
async [Symbol.asyncDispose] () {}
});
await null;
} catch (_) {
_usingCtx.e = _;
} finally{
await _usingCtx.d();
}
}
async function* ag() {
try {
var _usingCtx = _using_ctx();
const d5 = _usingCtx.a({
async [Symbol.asyncDispose] () {}
});
yield;
await null;
} catch (_) {
_usingCtx.e = _;
} finally{
await _usingCtx.d();
}
}
const a = async ()=>{
try {
var _usingCtx = _using_ctx();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
//// [awaitUsingDeclarations.1.ts]
import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx";
async function af() {
try {
var _usingCtx = _using_ctx();
const d3 = _usingCtx.a({
async [Symbol.asyncDispose] () {}
});
await null;
} catch (_) {
_usingCtx.e = _;
} finally{
await _usingCtx.d();
}
}
async function* ag() {
try {
var _usingCtx = _using_ctx();
const d5 = _usingCtx.a({
async [Symbol.asyncDispose] () {}
});
yield;
await null;
} catch (_) {
_usingCtx.e = _;
} finally{
await _usingCtx.d();
}
}
try {
var _usingCtx = _using_ctx();
var d1 = _usingCtx.a({
async [Symbol.asyncDispose] () {}
});
async function af() {
try {
var _usingCtx = _using_ctx();
const d3 = _usingCtx.a({
async [Symbol.asyncDispose] () {}
});
await null;
} catch (_) {
_usingCtx.e = _;
} finally{
await _usingCtx.d();
}
}
async function* ag() {
try {
var _usingCtx = _using_ctx();
const d5 = _usingCtx.a({
async [Symbol.asyncDispose] () {}
});
yield;
await null;
} catch (_) {
_usingCtx.e = _;
} finally{
await _usingCtx.d();
}
}
const a = async ()=>{
try {
var _usingCtx = _using_ctx();
Expand Down
Loading

0 comments on commit 762b0d4

Please sign in to comment.