Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8020/input/.swcrc
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8020/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using foo = null

const bar = 1

console.log(baz())

function baz() {
return bar
}
16 changes: 16 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8020/output/1.js
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)) => {
Expand Down
Loading