mirror of
https://github.com/swc-project/swc.git
synced 2024-11-24 02:06:08 +03:00
fix(es/compat): Fix scoping of explicit-resource-management
(#8044)
**Related issue:** - Closes #8020
This commit is contained in:
parent
77b8591d86
commit
96a7a4d045
19
crates/swc/tests/fixture/issues-8xxx/8020/input/.swcrc
Normal file
19
crates/swc/tests/fixture/issues-8xxx/8020/input/.swcrc
Normal 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,
|
||||
}
|
9
crates/swc/tests/fixture/issues-8xxx/8020/input/1.js
Normal file
9
crates/swc/tests/fixture/issues-8xxx/8020/input/1.js
Normal file
@ -0,0 +1,9 @@
|
||||
using foo = null
|
||||
|
||||
const bar = 1
|
||||
|
||||
console.log(baz())
|
||||
|
||||
function baz() {
|
||||
return bar
|
||||
}
|
16
crates/swc/tests/fixture/issues-8xxx/8020/output/1.js
Normal file
16
crates/swc/tests/fixture/issues-8xxx/8020/output/1.js
Normal 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);
|
||||
}
|
@ -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)) => {
|
||||
|
@ -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;
|
||||
|
@ -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 = _;
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
try {
|
||||
var _stack = [];
|
||||
const x = _using(_stack, obj);
|
||||
var x = _using(_stack, obj);
|
||||
doSomethingWith(x);
|
||||
} catch (_) {
|
||||
var _error = _;
|
||||
|
@ -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 = _;
|
||||
|
@ -1,7 +1,7 @@
|
||||
if (test) {
|
||||
try {
|
||||
var _stack = [];
|
||||
const x = _using(_stack, obj);
|
||||
var x = _using(_stack, obj);
|
||||
doSomethingWith(x);
|
||||
} catch (_) {
|
||||
var _error = _;
|
||||
|
@ -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 = _;
|
||||
|
@ -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 = _;
|
||||
|
@ -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 = _;
|
||||
|
@ -19,7 +19,7 @@ export class B {
|
||||
try {
|
||||
var _stack = [];
|
||||
doSomething();
|
||||
let c = 2;
|
||||
var c = 2;
|
||||
class A {
|
||||
}
|
||||
var x = _using(_stack, null);
|
||||
|
Loading…
Reference in New Issue
Block a user