fix(es/compat): Fix scoping of explicit-resource-management (#8044)

**Related issue:**

 - Closes #8020
This commit is contained in:
Donny/강동윤 2023-10-02 15:16:08 +09:00 committed by GitHub
parent 77b8591d86
commit 96a7a4d045
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 64 additions and 16 deletions

View File

@ -0,0 +1,19 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false
},
"loose": false,
"minify": {
"compress": false,
"mangle": false
},
"target": "es2022",
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true,
}

View File

@ -0,0 +1,9 @@
using foo = null
const bar = 1
console.log(baz())
function baz() {
return bar
}

View File

@ -0,0 +1,16 @@
import { _ as _dispose } from "@swc/helpers/_/_dispose";
import { _ as _using } from "@swc/helpers/_/_using";
function baz() {
return bar;
}
try {
var _stack = [];
var foo = _using(_stack, null);
var bar = 1;
console.log(baz());
} catch (_) {
var _error = _;
var _hasError = true;
} finally{
_dispose(_stack, _error, _hasError);
}

View File

@ -87,6 +87,10 @@ impl ExplicitResourceManagement {
Ok(stmt @ Stmt::Decl(Decl::Fn(..))) => {
new.push(T::from_stmt(stmt));
}
Ok(Stmt::Decl(Decl::Var(mut var))) => {
var.kind = VarDeclKind::Var;
try_body.push(Stmt::Decl(Decl::Var(var)));
}
Ok(stmt) => try_body.push(stmt),
Err(stmt) => match stmt.try_into_module_decl() {
Ok(ModuleDecl::ExportDefaultDecl(decl)) => {

View File

@ -1,9 +1,9 @@
{
try {
var _stack = [];
const a = _using(_stack, 1);
const b = _using(_stack, 2, true);
const c = _using(_stack, 3);
var a = _using(_stack, 1);
var b = _using(_stack, 2, true);
var c = _using(_stack, 3);
} catch (_) {
var _error = _;
var _hasError = true;

View File

@ -1,9 +1,9 @@
{
try {
var _stack = [];
const x = _using(_stack, obj, true);
var x = _using(_stack, obj, true);
stmt;
const y = _using(_stack, obj, true), z = _using(_stack, obj, true);
var y = _using(_stack, obj, true), z = _using(_stack, obj, true);
doSomethingWith(x, y);
} catch (_) {
var _error = _;

View File

@ -1,7 +1,7 @@
{
try {
var _stack = [];
const x = _using(_stack, obj);
var x = _using(_stack, obj);
doSomethingWith(x);
} catch (_) {
var _error = _;

View File

@ -1,7 +1,7 @@
function fn() {
try {
var _stack = [];
const x = _using(_stack, obj);
var x = _using(_stack, obj);
return doSomethingWith(x);
} catch (_) {
var _error = _;

View File

@ -1,7 +1,7 @@
if (test) {
try {
var _stack = [];
const x = _using(_stack, obj);
var x = _using(_stack, obj);
doSomethingWith(x);
} catch (_) {
var _error = _;

View File

@ -1,14 +1,14 @@
{
try {
var _stack = [];
const x = _using(_stack, obj);
var x = _using(_stack, obj);
{
try {
var _stack1 = [];
const y = _using(_stack1, call(()=>{
var y = _using(_stack1, call(()=>{
try {
var _stack = [];
const z = _using(_stack, obj);
var z = _using(_stack, obj);
return z;
} catch (_) {
var _error = _;

View File

@ -2,11 +2,11 @@
try {
var _stack = [];
stmt;
const x = _using(_stack, obj);
var x = _using(_stack, obj);
stmt;
const y = _using(_stack, obj), z = _using(_stack, obj);
var y = _using(_stack, obj), z = _using(_stack, obj);
stmt;
const w = _using(_stack, obj);
var w = _using(_stack, obj);
doSomethingWith(x, z);
} catch (_) {
var _error = _;

View File

@ -2,7 +2,7 @@ class A {
static{
try {
var _stack = [];
const x = _using(_stack, y);
var x = _using(_stack, y);
doSomethingWith(x);
} catch (_) {
var _error = _;

View File

@ -19,7 +19,7 @@ export class B {
try {
var _stack = [];
doSomething();
let c = 2;
var c = 2;
class A {
}
var x = _using(_stack, null);