From d1d637d0cacfd8ab9f62d51f9670f684ef7e5209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Wed, 25 Sep 2024 15:37:59 +0900 Subject: [PATCH 01/28] Add a test --- .../exec-async/issue-9576.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/issue-9576.js diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/issue-9576.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/issue-9576.js new file mode 100644 index 000000000000..6b9d9f938af9 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/issue-9576.js @@ -0,0 +1,31 @@ +class Disposable { + disposed = false; + + [Symbol.dispose]() { + this.disposed = true + } +} + +const disposables = [new Disposable()] + +for (using _ of disposables) {/* ... */ } + +if (disposables[0].disposed) { + console.log("✅ dispose ok") +} else { + console.error("💥 failed to dispose") +} + +class AsyncDisposable { + disposed = false; + + [Symbol.asyncDispose]() { + this.disposed = true + } +} + +const asyncDisposables = [new AsyncDisposable()] + +for (await using _ of asyncDisposables) {/* ... */ } + +expect(asyncDisposables[0].disposed).toBe(true); \ No newline at end of file From c463305c7a4b4519bee56efd6b18e7f9fd5cd11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Wed, 25 Sep 2024 15:41:04 +0900 Subject: [PATCH 02/28] fiup --- .../explicit-resource-management/exec-async/issue-9576.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/issue-9576.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/issue-9576.js index 6b9d9f938af9..2ddc268f333f 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/issue-9576.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/issue-9576.js @@ -10,11 +10,7 @@ const disposables = [new Disposable()] for (using _ of disposables) {/* ... */ } -if (disposables[0].disposed) { - console.log("✅ dispose ok") -} else { - console.error("💥 failed to dispose") -} +expect(disposables[0].disposed).toBe(true); class AsyncDisposable { disposed = false; From 091197f6b5b434062d9ffcea70389266d4ddf076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Wed, 25 Sep 2024 16:13:53 +0900 Subject: [PATCH 03/28] disposable --- .../src/explicit_resource_management.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index 73515461b119..bf958a7bc8b3 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -52,7 +52,7 @@ impl ExplicitResourceManagement { self.state = old_state; } - fn wrap_with_try(&mut self, state: State, stmts: &mut Vec) + fn wrap_with_try(&mut self, state: State, disposable: Box, stmts: &mut Vec) where T: StmtLike + ModuleItemLike, { From 814c5e4dc8c57c37ceec0e60f80dd8868b1be53f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Wed, 25 Sep 2024 16:32:35 +0900 Subject: [PATCH 04/28] WIP: wrap_with_try --- .../src/explicit_resource_management.rs | 352 +----------------- 1 file changed, 19 insertions(+), 333 deletions(-) diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index bf958a7bc8b3..97571c8483b0 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -19,10 +19,7 @@ struct ExplicitResourceManagement { } struct State { - using_ctx: Ident, - catch_var: Ident, - - has_await: bool, + env: Ident, } impl Default for State { @@ -60,346 +57,35 @@ impl ExplicitResourceManagement { let mut extras = Vec::new(); let mut try_body = Vec::new(); - let using_ctx_var = VarDeclarator { + let env = private_ident!("env"); + let catch_e = private_ident!("e"); + + let try_block = BlockStmt {}; + + let catch_clause = CatchClause { span: DUMMY_SP, - name: state.using_ctx.clone().into(), - init: Some( - CallExpr { - callee: helper!(using_ctx), + param: Some(Pat::Ident(catch_e.clone())), + body: Box::new( + BlockStmt { span: DUMMY_SP, - args: Default::default(), + stmts: vec![], ..Default::default() } .into(), ), - definite: Default::default(), }; - try_body.push( - VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - declare: false, - decls: vec![using_ctx_var], - ..Default::default() - } - .into(), - ); - - for stmt in stmts.take() { - match stmt.try_into_stmt() { - Ok(stmt @ Stmt::Decl(Decl::Fn(..))) => { - try_body.push(stmt); - } - Ok(Stmt::Decl(Decl::Var(var))) => { - // var.kind = VarDeclKind::Var; - try_body.push(var.into()); - } - Ok(stmt) => try_body.push(stmt), - Err(stmt) => match stmt.try_into_module_decl() { - Ok(ModuleDecl::ExportDefaultDecl(decl)) => { - let ident = match &decl.decl { - DefaultDecl::Class(c) => c.ident.clone(), - DefaultDecl::Fn(f) => f.ident.clone(), - DefaultDecl::TsInterfaceDecl(_) => unreachable!(), - }; - - let ident = ident.unwrap_or_else(|| private_ident!("_default")); - - // export { C as default } - new.push( - T::try_from_module_decl( - NamedExport { - span: DUMMY_SP, - specifiers: vec![ExportSpecifier::Named( - ExportNamedSpecifier { - span: DUMMY_SP, - orig: ModuleExportName::Ident(ident.clone()), - exported: Some(ModuleExportName::Ident( - Ident::new_no_ctxt("default".into(), DUMMY_SP), - )), - is_type_only: Default::default(), - }, - )], - src: None, - type_only: Default::default(), - with: None, - } - .into(), - ) - .unwrap(), - ); - try_body.push( - VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: vec![VarDeclarator { - span: DUMMY_SP, - name: ident.into(), - init: Some(match decl.decl { - DefaultDecl::Class(c) => Box::new(Expr::Class(c)), - DefaultDecl::Fn(f) => Box::new(Expr::Fn(f)), - DefaultDecl::TsInterfaceDecl(_) => unreachable!(), - }), - definite: Default::default(), - }], - ..Default::default() - } - .into(), - ); - } - - Ok(ModuleDecl::ExportDefaultExpr(decl)) => { - let ident = private_ident!("_default"); - - // export { _default as default } - new.push( - T::try_from_module_decl( - NamedExport { - span: DUMMY_SP, - specifiers: vec![ExportSpecifier::Named( - ExportNamedSpecifier { - span: DUMMY_SP, - orig: ModuleExportName::Ident(ident.clone()), - exported: Some(ModuleExportName::Ident( - Ident::new_no_ctxt("default".into(), DUMMY_SP), - )), - is_type_only: Default::default(), - }, - )], - src: None, - type_only: Default::default(), - with: None, - } - .into(), - ) - .unwrap(), - ); - try_body.push( - VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - declare: Default::default(), - decls: vec![VarDeclarator { - span: DUMMY_SP, - name: ident.into(), - init: Some(decl.expr), - definite: Default::default(), - }], - ..Default::default() - } - .into(), - ); - } - - Ok(ModuleDecl::ExportDecl(e)) => { - match &e.decl { - Decl::Class(ClassDecl { ident, .. }) - | Decl::Fn(FnDecl { ident, .. }) => { - let ident = ident.clone(); - let var_name = private_ident!(format!("_{}", ident.sym)); - let var = VarDeclarator { - span: DUMMY_SP, - name: var_name.clone().into(), - init: None, - definite: Default::default(), - }; - - new.push(T::from( - VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - declare: false, - decls: vec![var], - ..Default::default() - } - .into(), - )); - - try_body.push(e.decl.into()); - try_body.push( - ExprStmt { - span: DUMMY_SP, - expr: AssignExpr { - span: DUMMY_SP, - op: op!("="), - left: var_name.clone().into(), - right: ident.clone().into(), - } - .into(), - } - .into(), - ); - - let specifier = ExportSpecifier::Named(ExportNamedSpecifier { - span: DUMMY_SP, - orig: ModuleExportName::Ident(var_name), - exported: Some(ModuleExportName::Ident(ident.clone())), - is_type_only: false, - }); - - extras.push( - T::try_from_module_decl( - NamedExport { - span: DUMMY_SP, - specifiers: vec![specifier], - src: None, - type_only: false, - with: None, - } - .into(), - ) - .unwrap(), - ); - } - Decl::Var(d) => { - let orig_var_names: Vec = find_pat_ids(&d.decls); - - let var_names = orig_var_names - .iter() - .map(|ident| private_ident!(format!("_{}", ident.sym))) - .collect::>(); - - let var_decls = var_names - .iter() - .cloned() - .map(|var_name| VarDeclarator { - span: DUMMY_SP, - name: var_name.into(), - init: None, - definite: Default::default(), - }) - .collect(); - - new.push(T::from( - VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - declare: false, - decls: var_decls, - ..Default::default() - } - .into(), - )); - - try_body.push(e.decl.into()); - try_body.push( - ExprStmt { - span: DUMMY_SP, - expr: Expr::from_exprs( - orig_var_names - .iter() - .zip(var_names.iter()) - .map(|(orig, var_name)| { - AssignExpr { - span: DUMMY_SP, - op: op!("="), - left: var_name.clone().into(), - right: orig.clone().into(), - } - .into() - }) - .collect(), - ), - } - .into(), - ); - let specifiers = orig_var_names - .iter() - .zip(var_names.iter()) - .map(|(orig, var)| { - ExportSpecifier::Named(ExportNamedSpecifier { - span: DUMMY_SP, - orig: ModuleExportName::Ident(var.clone()), - exported: Some(ModuleExportName::Ident(orig.clone())), - is_type_only: false, - }) - }) - .collect(); - - extras.push( - T::try_from_module_decl( - NamedExport { - span: DUMMY_SP, - specifiers, - src: None, - type_only: false, - with: None, - } - .into(), - ) - .unwrap(), - ); - } - _ => { - new.push(T::try_from_module_decl(e.into()).unwrap()); - } - }; - } - - Ok(stmt) => new.push(T::try_from_module_decl(stmt).unwrap()), - Err(stmt) => new.push(stmt), - }, - } - } - - // Drop `;` - try_body.retain(|stmt| !matches!(stmt, Stmt::Empty(..))); - - // usingCtx.e = $catch_var - let assign_error = AssignExpr { - span: DUMMY_SP, - op: op!("="), - left: state - .using_ctx - .clone() - .make_member(quote_ident!("e")) - .into(), - right: state.catch_var.clone().into(), - } - .into_stmt(); - - // _usingCtx.d() - let dispose_expr = CallExpr { - span: DUMMY_SP, - callee: state - .using_ctx - .clone() - .make_member(quote_ident!("d")) - .as_callee(), - args: Vec::new(), - ..Default::default() - }; - let dispose_stmt = if state.has_await { - AwaitExpr { - span: DUMMY_SP, - arg: Box::new(dispose_expr.into()), - } - .into() - } else { - Expr::from(dispose_expr) - } - .into_stmt(); - let try_stmt = TryStmt { span: DUMMY_SP, - block: BlockStmt { - span: DUMMY_SP, - stmts: try_body, - ..Default::default() - }, - handler: Some(CatchClause { - span: DUMMY_SP, - param: Some(state.catch_var.into()), - body: BlockStmt { - span: DUMMY_SP, - stmts: vec![assign_error], - ..Default::default() - }, - }), + block: try_block, + handler: Some(catch_clause), finalizer: Some(BlockStmt { - span: DUMMY_SP, - stmts: vec![dispose_stmt], + stmts: vec![CallExpr { + callee: helper!(ts, ts_dispose_resources), + args: vec![env.clone().as_arg()], + ..Default::default() + } + .into_stmt()], ..Default::default() }), }; From 986d8becfdc1bff8718b3db16a798b20f96a5df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Wed, 25 Sep 2024 16:34:25 +0900 Subject: [PATCH 05/28] more fix --- .../src/explicit_resource_management.rs | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index 97571c8483b0..c62c631ef031 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -64,15 +64,43 @@ impl ExplicitResourceManagement { let catch_clause = CatchClause { span: DUMMY_SP, - param: Some(Pat::Ident(catch_e.clone())), - body: Box::new( - BlockStmt { - span: DUMMY_SP, - stmts: vec![], - ..Default::default() - } - .into(), - ), + param: Some(Pat::Ident(catch_e.clone().into())), + body: BlockStmt { + span: DUMMY_SP, + stmts: vec![ + // env.e = e; + AssignExpr { + span: DUMMY_SP, + left: MemberExpr { + span: DUMMY_SP, + obj: Box::new(env.clone().into()), + prop: MemberProp::Ident(quote_ident!("e")), + } + .into(), + op: op!("="), + right: Box::new(catch_e.clone().into()), + } + .into_stmt(), + // env.hasError = true; + AssignExpr { + span: DUMMY_SP, + left: MemberExpr { + span: DUMMY_SP, + obj: Box::new(env.clone().into()), + prop: MemberProp::Ident(quote_ident!("hasError")), + } + .into(), + op: op!("="), + right: Box::new(Expr::Lit(Lit::Bool(Bool { + span: DUMMY_SP, + value: true, + }))), + } + .into_stmt(), + ], + ..Default::default() + } + .into(), }; let try_stmt = TryStmt { From 06f6e57ca51a1f9100bb2dea5a4e11115ea2c7f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Wed, 25 Sep 2024 16:39:11 +0900 Subject: [PATCH 06/28] env --- .../src/explicit_resource_management.rs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index c62c631ef031..aa0614bfd795 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -60,6 +60,42 @@ impl ExplicitResourceManagement { let env = private_ident!("env"); let catch_e = private_ident!("e"); + // const env_1 = { stack: [], error: void 0, hasError: false }; + new.push(T::from(Stmt::Decl(Decl::Var(Box::new(VarDecl { + span: DUMMY_SP, + kind: VarDeclKind::Const, + declare: false, + decls: vec![VarDeclarator { + span: DUMMY_SP, + name: Pat::Ident(env.clone().into()), + init: Some(Box::new(Expr::Object(ObjectLit { + span: DUMMY_SP, + props: vec![ + PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { + key: PropName::Ident(quote_ident!("stack")), + value: Box::new(Expr::Array(ArrayLit { + span: DUMMY_SP, + elems: vec![], + })), + }))), + PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { + key: PropName::Ident(quote_ident!("error")), + value: Expr::undefined(DUMMY_SP), + }))), + PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { + key: PropName::Ident(quote_ident!("hasError")), + value: Box::new(Expr::Lit(Lit::Bool(Bool { + span: DUMMY_SP, + value: false, + }))), + }))), + ], + }))), + definite: false, + }], + ..Default::default() + }))))); + let try_block = BlockStmt {}; let catch_clause = CatchClause { From 2f67cef8490a885d532177eee707a11f26a7d476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 26 Sep 2024 11:44:09 +0900 Subject: [PATCH 07/28] wrap_with_try --- .../src/explicit_resource_management.rs | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index aa0614bfd795..5c98929c30ce 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -49,8 +49,14 @@ impl ExplicitResourceManagement { self.state = old_state; } - fn wrap_with_try(&mut self, state: State, disposable: Box, stmts: &mut Vec) - where + fn wrap_with_try( + &mut self, + state: State, + name: Ident, + disposable: Box, + is_async: bool, + stmts: &mut Vec, + ) where T: StmtLike + ModuleItemLike, { let mut new = Vec::new(); @@ -96,7 +102,37 @@ impl ExplicitResourceManagement { ..Default::default() }))))); - let try_block = BlockStmt {}; + let init_var_decl = Stmt::Decl(Decl::Var(Box::new(VarDecl { + span: DUMMY_SP, + kind: VarDeclKind::Const, + declare: false, + decls: vec![VarDeclarator { + span: DUMMY_SP, + name: Pat::Ident(name.clone().into()), + init: Some( + CallExpr { + callee: helper!(ts, ts_add_disposable_resource), + args: vec![env.clone().as_arg(), disposable.as_arg(), is_async.as_arg()], + ..Default::default() + } + .into(), + ), + definite: false, + }], + ..Default::default() + }))); + + let mut try_block = BlockStmt { + stmts: vec![init_var_decl], + ..Default::default() + }; + + for stmt in stmts.take() { + match stmt.try_into_stmt() { + Ok(stmt) => try_block.stmts.push(stmt), + Err(t) => extras.push(t), + } + } let catch_clause = CatchClause { span: DUMMY_SP, From 16ad620605eab6df58bbac3fc54d5245fc272f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 27 Sep 2024 19:46:54 +0900 Subject: [PATCH 08/28] Fix build issues --- .../src/explicit_resource_management.rs | 105 +++++++----------- 1 file changed, 41 insertions(+), 64 deletions(-) diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index 5c98929c30ce..60b2e8b39840 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -2,8 +2,8 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::helper; use swc_ecma_utils::{ - find_pat_ids, private_ident, quote_ident, stack_size::maybe_grow_default, ExprFactory, - ModuleItemLike, StmtLike, + private_ident, quote_ident, stack_size::maybe_grow_default, ExprFactory, ModuleItemLike, + StmtLike, }; use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; @@ -20,14 +20,17 @@ struct ExplicitResourceManagement { struct State { env: Ident, + has_await: bool, + + vars: Vec<(Pat, Box)>, } impl Default for State { fn default() -> Self { Self { - using_ctx: private_ident!("_usingCtx"), - catch_var: private_ident!("_"), + env: private_ident!("env"), has_await: false, + vars: Vec::new(), } } } @@ -49,23 +52,20 @@ impl ExplicitResourceManagement { self.state = old_state; } - fn wrap_with_try( - &mut self, - state: State, - name: Ident, - disposable: Box, - is_async: bool, - stmts: &mut Vec, - ) where + fn wrap_with_try(&mut self, state: State, stmts: &mut Vec) + where T: StmtLike + ModuleItemLike, { let mut new = Vec::new(); let mut extras = Vec::new(); - let mut try_body = Vec::new(); - let env = private_ident!("env"); + let env = state.env; let catch_e = private_ident!("e"); + let name = state.vars[0].0.clone(); + let disposable = state.vars[0].1.clone(); + let is_async = state.has_await; + // const env_1 = { stack: [], error: void 0, hasError: false }; new.push(T::from(Stmt::Decl(Decl::Var(Box::new(VarDecl { span: DUMMY_SP, @@ -108,7 +108,7 @@ impl ExplicitResourceManagement { declare: false, decls: vec![VarDeclarator { span: DUMMY_SP, - name: Pat::Ident(name.clone().into()), + name, init: Some( CallExpr { callee: helper!(ts, ts_add_disposable_resource), @@ -171,8 +171,7 @@ impl ExplicitResourceManagement { .into_stmt(), ], ..Default::default() - } - .into(), + }, }; let try_stmt = TryStmt { @@ -208,18 +207,14 @@ impl VisitMut for ExplicitResourceManagement { n.visit_mut_children_with(self); if let ForHead::UsingDecl(decl) = &mut n.left { - let state = State::default(); + let mut state = State::default(); - n.left = ForHead::VarDecl(Box::new(VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Const, - declare: false, - decls: decl.decls.take(), - ..Default::default() - })); + let var_decl = handle_using_decl(decl, &mut state); let mut body = vec![*n.body.take()]; self.wrap_with_try(state, &mut body); + + n.left = ForHead::VarDecl(var_decl); n.body = Box::new( BlockStmt { span: DUMMY_SP, @@ -238,48 +233,12 @@ impl VisitMut for ExplicitResourceManagement { fn visit_mut_stmt(&mut self, s: &mut Stmt) { maybe_grow_default(|| s.visit_mut_children_with(self)); - if let Stmt::Decl(Decl::Using(decl)) = s { + if let Stmt::Decl(Decl::Using(using)) = s { let state = self.state.get_or_insert_with(Default::default); - state.has_await |= decl.is_await; + let decl = handle_using_decl(using, state); - *s = VarDecl { - span: DUMMY_SP, - kind: if self.is_not_top_level { - VarDeclKind::Const - } else { - VarDeclKind::Var - }, - declare: Default::default(), - decls: decl - .decls - .take() - .into_iter() - .map(|d| { - let init = CallExpr { - span: decl.span, - callee: state - .using_ctx - .clone() - .make_member(if decl.is_await { - quote_ident!("a") - } else { - quote_ident!("u") - }) - .as_callee(), - args: vec![d.init.unwrap().as_arg()], - ..Default::default() - }; - - VarDeclarator { - init: Some(init.into()), - ..d - } - }) - .collect(), - ..Default::default() - } - .into(); + *s = Stmt::Decl(Decl::Var(decl)); } } @@ -290,3 +249,21 @@ impl VisitMut for ExplicitResourceManagement { self.is_not_top_level = old_is_not_top_level; } } + +fn handle_using_decl(using: &mut UsingDecl, state: &mut State) -> Box { + state.has_await |= using.is_await; + + for decl in &mut using.decls { + state + .vars + .push((decl.name.clone(), decl.init.take().unwrap())); + } + + Box::new(VarDecl { + span: DUMMY_SP, + kind: VarDeclKind::Const, + declare: false, + decls: vec![], + ..Default::default() + }) +} From 6bd1dec37d6c0d54f7e7a1ef03cfc55a2c28e996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 27 Sep 2024 19:52:09 +0900 Subject: [PATCH 09/28] Init --- .../src/explicit_resource_management.rs | 64 ++++++++++--------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index 60b2e8b39840..17125b009402 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -62,8 +62,6 @@ impl ExplicitResourceManagement { let env = state.env; let catch_e = private_ident!("e"); - let name = state.vars[0].0.clone(); - let disposable = state.vars[0].1.clone(); let is_async = state.has_await; // const env_1 = { stack: [], error: void 0, hasError: false }; @@ -102,31 +100,39 @@ impl ExplicitResourceManagement { ..Default::default() }))))); - let init_var_decl = Stmt::Decl(Decl::Var(Box::new(VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Const, - declare: false, - decls: vec![VarDeclarator { - span: DUMMY_SP, - name, - init: Some( - CallExpr { - callee: helper!(ts, ts_add_disposable_resource), - args: vec![env.clone().as_arg(), disposable.as_arg(), is_async.as_arg()], - ..Default::default() - } - .into(), - ), - definite: false, - }], - ..Default::default() - }))); - let mut try_block = BlockStmt { - stmts: vec![init_var_decl], + stmts: vec![], ..Default::default() }; + for (name, disposable) in state.vars { + let init_var_decl = Stmt::Decl(Decl::Var(Box::new(VarDecl { + span: DUMMY_SP, + kind: VarDeclKind::Const, + declare: false, + decls: vec![VarDeclarator { + span: DUMMY_SP, + name, + init: Some( + CallExpr { + callee: helper!(ts, ts_add_disposable_resource), + args: vec![ + env.clone().as_arg(), + disposable.as_arg(), + is_async.as_arg(), + ], + ..Default::default() + } + .into(), + ), + definite: false, + }], + ..Default::default() + }))); + + try_block.stmts.push(init_var_decl); + } + for stmt in stmts.take() { match stmt.try_into_stmt() { Ok(stmt) => try_block.stmts.push(stmt), @@ -237,6 +243,10 @@ impl VisitMut for ExplicitResourceManagement { let state = self.state.get_or_insert_with(Default::default); let decl = handle_using_decl(using, state); + if decl.decls.is_empty() { + s.take(); + return; + } *s = Stmt::Decl(Decl::Var(decl)); } @@ -253,17 +263,11 @@ impl VisitMut for ExplicitResourceManagement { fn handle_using_decl(using: &mut UsingDecl, state: &mut State) -> Box { state.has_await |= using.is_await; - for decl in &mut using.decls { - state - .vars - .push((decl.name.clone(), decl.init.take().unwrap())); - } - Box::new(VarDecl { span: DUMMY_SP, kind: VarDeclKind::Const, declare: false, - decls: vec![], + decls: using.decls.take(), ..Default::default() }) } From 90d59f612b28e0bcae3e4967bd69336e2b5ed5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 27 Sep 2024 20:11:03 +0900 Subject: [PATCH 10/28] Sync test suite --- .../exec-async-node-10/options.json | 9 + .../using-null-multiple-collapse.js | 345 ++++++++++++++++++ .../async-dispose-throws-synchronously.js | 10 +- .../exec-async/completion-throw.js | 12 +- .../exec-async/invalid-not-a-function.js | 27 +- .../exec-async/sync-fallback-error.js | 26 ++ .../exec-async/sync-fallback-promise.js | 35 ++ .../exec-async/using-function.js | 24 +- .../exec-async/using-null-multiple.js | 25 ++ .../exec-async/using-undefined-multiple.js | 25 ++ .../exec-sync/completion-throw.js | 8 +- .../exec-sync/using-function.js | 6 +- .../input.js | 0 .../options.json | 0 .../integration/async-to-generator/output.js | 18 + .../source-maps/block/input.js | 4 + .../source-maps/block/output.js | 9 + .../source-maps/block/source-map-visual.txt | 116 ++++++ .../source-maps/block/source-map.json | 23 ++ .../source-maps/for-of/input.js | 3 + .../source-maps/for-of/output.js | 9 + .../source-maps/for-of/source-map-visual.txt | 128 +++++++ .../source-maps/for-of/source-map.json | 24 ++ .../source-maps/options.json | 4 + .../source-maps/switch/input.js | 10 + .../source-maps/switch/output.js | 18 + .../source-maps/switch/source-map-visual.txt | 173 +++++++++ .../source-maps/switch/source-map.json | 24 ++ .../source-maps/top-level/input.mjs | 4 + .../source-maps/top-level/output.mjs | 11 + .../top-level/source-map-visual.txt | 104 ++++++ .../source-maps/top-level/source-map.json | 23 ++ .../transform-await/issue-8853/input.mjs | 32 -- .../transform-await/issue-8853/output.mjs | 49 --- .../mixed/{input.mjs => input.js} | 0 .../transform-await/mixed/output.mjs | 20 +- .../only-using-await/{input.mjs => input.js} | 0 .../only-using-await/output.mjs | 23 +- .../transform-await/switch/input.js | 10 + .../transform-await/switch/output.mjs | 17 + .../transform-sync/bare-block/output.js | 18 +- .../for-await-head/{input.mjs => input.js} | 0 .../transform-sync/for-await-head/output.mjs | 19 +- .../transform-sync/for-head/output.js | 19 +- .../transform-sync/function-body/output.js | 18 +- .../transform-sync/if-body/output.js | 18 +- .../transform-sync/issue-8629/input.js | 10 - .../transform-sync/issue-8629/output.js | 18 - .../transform-sync/multiple-nested/output.js | 58 ++- .../multiple-same-level/output.js | 29 +- .../transform-sync/static-block/output.js | 20 +- .../transform-sync/switch/input.js | 10 + .../transform-sync/switch/output.js | 18 + .../await-or-not-preserved/output.mjs | 12 +- .../hoisting-default-clas-anon/output.mjs | 13 +- .../hoisting-default-class/output.mjs | 13 +- .../hoisting-default-expr/output.mjs | 12 +- .../hoisting-default-fn-anon/output.mjs | 13 +- .../hoisting-default-fn/output.mjs | 13 +- .../transform-top-level/hoisting/output.mjs | 57 ++- 60 files changed, 1456 insertions(+), 340 deletions(-) create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async-node-10/options.json create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async-node-10/using-null-multiple-collapse.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/sync-fallback-error.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/sync-fallback-promise.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/using-null-multiple.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/using-undefined-multiple.js rename crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/{.async-to-generator => async-to-generator}/input.js (100%) rename crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/{.async-to-generator => async-to-generator}/options.json (100%) create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/output.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/input.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/output.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/source-map-visual.txt create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/source-map.json create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/input.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/output.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/source-map-visual.txt create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/source-map.json create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/options.json create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/input.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/output.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/source-map-visual.txt create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/source-map.json create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/input.mjs create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/output.mjs create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/source-map-visual.txt create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/source-map.json delete mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/issue-8853/input.mjs delete mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/issue-8853/output.mjs rename crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/{input.mjs => input.js} (100%) rename crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/{input.mjs => input.js} (100%) create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/input.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/output.mjs rename crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-await-head/{input.mjs => input.js} (100%) delete mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/issue-8629/input.js delete mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/issue-8629/output.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/input.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/output.js diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async-node-10/options.json b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async-node-10/options.json new file mode 100644 index 000000000000..b477d01d8d13 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async-node-10/options.json @@ -0,0 +1,9 @@ +{ + "plugins": [ + "proposal-explicit-resource-management", + "transform-optional-catch-binding", + "transform-async-to-generator" + ], + "parserOpts": { "allowReturnOutsideFunction": true }, + "minNodeVersion": "10.0.0" +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async-node-10/using-null-multiple-collapse.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async-node-10/using-null-multiple-collapse.js new file mode 100644 index 000000000000..2020f8880128 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async-node-10/using-null-multiple-collapse.js @@ -0,0 +1,345 @@ +return (async function () { + // async_null + { + const log = []; + + let asyncId = 0, + pending = Promise.resolve(); + for (let i = 0; i < 10; i++) { + pending = pending.then(() => asyncId++); + } + + { + await using async_null_1 = null, + async_null_2 = null, + async_null_3 = null, + async_null_4 = null; + log.push(asyncId); + } + + log.push(asyncId); + + await pending; + + expect(log).toEqual([0, 1]); + } + // async_null, async_null + { + const log = []; + + let asyncId = 0, + pending = Promise.resolve(); + for (let i = 0; i < 10; i++) { + pending = pending.then(() => asyncId++); + } + + { + await using async_null_1 = null, + async_null_2 = null; + await using async_null_3 = null, + async_null_4 = null; + log.push(asyncId); + } + + log.push(asyncId); + + await pending; + + expect(log).toEqual([0, 1]); + } + // async_null, async_from_async + { + const log = []; + + let asyncId = 0, + pending = Promise.resolve(); + for (let i = 0; i < 10; i++) { + pending = pending.then(() => asyncId++); + } + + { + await using async_null_1 = null, + async_null_2 = null; + await using async1 = { + [Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]() { + log.push(asyncId); + }, + }; + log.push(asyncId); + } + + log.push(asyncId); + + await pending; + + expect(log).toEqual([0, 0, 2]); + } + // async_null, async_from_sync + { + const log = []; + + let asyncId = 0, + pending = Promise.resolve(); + for (let i = 0; i < 10; i++) { + pending = pending.then(() => asyncId++); + } + + { + await using async_null_1 = null, + async_null_2 = null; + await using async1 = { + [Symbol.dispose || Symbol.for("Symbol.dispose")]() { + log.push(asyncId); + }, + }; + log.push(asyncId); + } + + log.push(asyncId); + + await pending; + + expect(log).toEqual([0, 0, 2]); + } + // async_null, async_from_sync_throw + { + const log = []; + + let asyncId = 0, + pending = Promise.resolve(); + for (let i = 0; i < 10; i++) { + pending = pending.then(() => asyncId++); + } + + try { + await using async_null_1 = null, + async_null_2 = null; + await using async1 = { + [Symbol.dispose || Symbol.for("Symbol.dispose")]() { + log.push(asyncId); + throw new Error(); + }, + }; + log.push(asyncId); + } catch {} + + log.push(asyncId); + + await pending; + + expect(log).toEqual([0, 0, 2]); + } + // async_null, sync + { + const log = []; + + let asyncId = 0, + pending = Promise.resolve(); + for (let i = 0; i < 10; i++) { + pending = pending.then(() => asyncId++); + } + + { + await using async_null_1 = null, + async_null_2 = null; + using sync1 = { + [Symbol.dispose || Symbol.for("Symbol.dispose")]() { + log.push(asyncId); + }, + }; + log.push(asyncId); + } + + log.push(asyncId); + + await pending; + + expect(log).toEqual([0, 0, 1]); + } + // async_null, async_from_async, async_null + { + const log = []; + + let asyncId = 0, + pending = Promise.resolve(); + for (let i = 0; i < 10; i++) { + pending = pending.then(() => asyncId++); + } + + { + await using async_null_1 = null, + async_null_2 = null; + await using async1 = { + [Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]() { + log.push(asyncId); + }, + }; + await using async_null_3 = null, + async_null_4 = null; + log.push(asyncId); + } + + log.push(asyncId); + + await pending; + + expect(log).toEqual([0, 0, 2]); + } + // async_null, async_from_sync, async_null + { + const log = []; + + let asyncId = 0, + pending = Promise.resolve(); + for (let i = 0; i < 10; i++) { + pending = pending.then(() => asyncId++); + } + + { + await using async_null_1 = null, + async_null_2 = null; + await using async1 = { + [Symbol.dispose || Symbol.for("Symbol.dispose")]() { + log.push(asyncId); + }, + }; + await using async_null_3 = null, + async_null_4 = null; + log.push(asyncId); + } + + log.push(asyncId); + + await pending; + + expect(log).toEqual([0, 0, 2]); + } + // async_null, async_from_sync_throw, async_null + { + const log = []; + + let asyncId = 0, + pending = Promise.resolve(); + for (let i = 0; i < 10; i++) { + pending = pending.then(() => asyncId++); + } + + try { + await using async_null_1 = null, + async_null_2 = null; + await using async1 = { + [Symbol.dispose || Symbol.for("Symbol.dispose")]() { + log.push(asyncId); + throw new Error(); + }, + }; + await using async_null_3 = null, + async_null_4 = null; + log.push(asyncId); + } catch {} + + log.push(asyncId); + + await pending; + + expect(log).toEqual([0, 0, 2]); + } + // async_null, sync, async_null + { + const log = []; + + let asyncId = 0, + pending = Promise.resolve(); + for (let i = 0; i < 10; i++) { + pending = pending.then(() => asyncId++); + } + + { + await using async_null_1 = null, + async_null_2 = null; + using sync1 = { + [Symbol.dispose || Symbol.for("Symbol.dispose")]() { + log.push(asyncId); + }, + }; + await using async_null_3 = null, + async_null_4 = null; + log.push(asyncId); + } + + log.push(asyncId); + + await pending; + + expect(log).toEqual([0, 1, 4]); + } + // sync, async_null, sync, async_null + { + const log = []; + + let asyncId = 0, + pending = Promise.resolve(); + for (let i = 0; i < 10; i++) { + pending = pending.then(() => asyncId++); + } + + { + using sync1 = { + [Symbol.dispose || Symbol.for("Symbol.dispose")]() { + log.push(asyncId); + }, + }; // asyncId: 2 + await using async_null_1 = null, + async_null_2 = null; + using sync2 = { + [Symbol.dispose || Symbol.for("Symbol.dispose")]() { + log.push(asyncId); + }, + }; // asyncId: 1 + await using async_null_3 = null, + async_null_4 = null; + log.push(asyncId); + } + + log.push(asyncId); + + await pending; + + expect(log).toEqual([0, 1, 2, 4]); + } + // sync_throw, async_null, sync, async_null + { + const log = []; + + let asyncId = 0, + pending = Promise.resolve(); + for (let i = 0; i < 10; i++) { + pending = pending.then(() => asyncId++); + } + + try { + using sync1 = { + [Symbol.dispose || Symbol.for("Symbol.dispose")]() { + log.push(asyncId); + throw new Error(); + }, + }; // asyncId: 2 + await using async_null_1 = null, + async_null_2 = null; + using sync2 = { + [Symbol.dispose || Symbol.for("Symbol.dispose")]() { + log.push(asyncId); + }, + }; // asyncId: 1 + await using async_null_3 = null, + async_null_4 = null; + log.push(asyncId); + } catch {} + + log.push(asyncId); + + await pending; + + expect(log).toEqual([0, 1, 2, 4]); + } +})(); diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/async-dispose-throws-synchronously.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/async-dispose-throws-synchronously.js index 07b1bfcb3de0..9d40308bd27c 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/async-dispose-throws-synchronously.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/async-dispose-throws-synchronously.js @@ -1,4 +1,4 @@ -return async function () { +return (async function () { let disposed = false; let beforeEnd; @@ -10,13 +10,13 @@ return async function () { await using x = { [Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]() { throw err1; - } + }, }; throw err2; } catch (e) { thrown = e; } - expect(thrown.suppressed).toBe(err1); - expect(thrown.error).toBe(err2); -}(); \ No newline at end of file + expect(thrown.suppressed).toBe(err2); + expect(thrown.error).toBe(err1); +})(); diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/completion-throw.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/completion-throw.js index 358bd54730d5..540b2add9e5e 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/completion-throw.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/completion-throw.js @@ -1,4 +1,4 @@ -return async function () { +return (async function () { let disposed = false; let beforeReturn; let inCatch; @@ -8,15 +8,19 @@ return async function () { await using x = { async [Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]() { disposed = true; - } + throw 1; + }, }; beforeReturn = disposed; throw 0; - } catch { + } catch (e) { inCatch = disposed; + expect(e.name).toBe("SuppressedError"); + expect(e.suppressed).toBe(0); + expect(e.error).toBe(1); } expect(beforeReturn).toBe(false); expect(inCatch).toBe(true); expect(disposed).toBe(true); -}(); \ No newline at end of file +})(); diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/invalid-not-a-function.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/invalid-not-a-function.js index 0877dd37be3f..bff4ca8c2968 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/invalid-not-a-function.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/invalid-not-a-function.js @@ -1,3 +1,24 @@ -return expect(async function () { - await using foo = { [Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]: 3 }; -}()).rejects.toThrow(TypeError); +expect( + (async function () { + await using foo = { + [Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]: 3, + }; + })() +).rejects.toThrow(TypeError); + +expect( + (async function () { + await using foo = { + [Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]: 3, + }; + })() +).rejects.toThrow("Object is not disposable."); + +expect( + (async function () { + await using foo = { + [Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]: null, + [Symbol.dispose || Symbol.for("Symbol.dispose")]() {}, + }; + })() +).rejects.toThrow("Object is not disposable."); diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/sync-fallback-error.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/sync-fallback-error.js new file mode 100644 index 000000000000..8b6d797eeb74 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/sync-fallback-error.js @@ -0,0 +1,26 @@ +return (async () => { + const log = []; + + async function main() { + const promiseDispose = Promise.resolve().then(() => { + log.push("interleave"); + }); + + try { + await using x = { + [Symbol.dispose || Symbol.for("Symbol.dispose")]() { + log.push("dispose"); + throw null; + }, + }; + } catch (e) { + log.push("catch"); + } + + await promiseDispose; + } + + await main(); + + expect(log).toEqual(["dispose", "interleave", "catch"]); +})(); diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/sync-fallback-promise.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/sync-fallback-promise.js new file mode 100644 index 000000000000..fac7a9dcaf6e --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/sync-fallback-promise.js @@ -0,0 +1,35 @@ +return (async () => { + const log = []; + + const promiseDispose = new Promise((resolve, _) => { + setTimeout(() => { + log.push("y dispose promise body"); + resolve(); + }, 0); + }); + + { + await using x = { + [Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]() { + log.push("x asyncDispose body"); + }, + }; + await using y = { + [Symbol.dispose || Symbol.for("Symbol.dispose")]() { + log.push("y dispose body"); + return promiseDispose; + }, + }; + } + + log.push("body"); + + await promiseDispose; + + expect(log).toEqual([ + "y dispose body", + "x asyncDispose body", + "body", + "y dispose promise body", + ]); +})(); diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/using-function.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/using-function.js index bf5eacc0a2ca..75a8be647881 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/using-function.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/using-function.js @@ -1,15 +1,15 @@ return async function () { - let log = []; - async function getDisposable() { - function disposable() { log.push('call') } - disposable[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")] = () => { log.push('dispose') }; - return disposable; - } + let log = []; + async function getDisposable() { + function disposable() { log.push('call') } + disposable[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")] = () => { log.push('dispose') }; + return disposable; + } - { - await using x = getDisposable(); - x(); - } + { + await using x = getDisposable(); + x(); + } - expect(log).toEqual(['call', 'dispose']); -} \ No newline at end of file + expect(log).toEqual(['call', 'dispose']); +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/using-null-multiple.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/using-null-multiple.js new file mode 100644 index 000000000000..258d2708cae0 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/using-null-multiple.js @@ -0,0 +1,25 @@ +return (async function () { + const log = []; + + function disposable(name) { + return { + async [Symbol.dispose || Symbol.for("Symbol.dispose")]() { + log.push(name); + }, + }; + } + + async function f() { + using y = disposable("y"); + await using x = null; + log.push("f body"); + } + + const promise = f(); + + log.push("body"); + + await promise; + + expect(log).toEqual(["f body", "body", "y"]); +})(); diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/using-undefined-multiple.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/using-undefined-multiple.js new file mode 100644 index 000000000000..a355c425df2f --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/using-undefined-multiple.js @@ -0,0 +1,25 @@ +return (async function () { + const log = []; + + function disposable(name) { + return { + async [Symbol.dispose || Symbol.for("Symbol.dispose")]() { + log.push(name); + }, + }; + } + + async function f() { + using y = disposable("y"); + await using x = undefined; + log.push("f body"); + } + + const promise = f(); + + log.push("body"); + + await promise; + + expect(log).toEqual(["f body", "body", "y"]); +})(); diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-sync/completion-throw.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-sync/completion-throw.js index 659c82703310..167b7ed096c4 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-sync/completion-throw.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-sync/completion-throw.js @@ -7,12 +7,16 @@ try { using x = { [Symbol.dispose || Symbol.for("Symbol.dispose")]() { disposed = true; - } + throw 1; + }, }; beforeReturn = disposed; throw 0; -} catch { +} catch (e) { inCatch = disposed; + expect(e.name).toBe("SuppressedError"); + expect(e.suppressed).toBe(0); + expect(e.error).toBe(1); } expect(beforeReturn).toBe(false); diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-sync/using-function.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-sync/using-function.js index 0c47497ca4b7..70bf43ec5117 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-sync/using-function.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-sync/using-function.js @@ -3,8 +3,8 @@ function disposable() { log.push('call') } disposable[Symbol.dispose || Symbol.for("Symbol.dispose")] = () => { log.push('dispose') }; { - using x = disposable; - x(); + using x = disposable; + x(); } -expect(log).toEqual(['call', 'dispose']); \ No newline at end of file +expect(log).toEqual(['call', 'dispose']); diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/.async-to-generator/input.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/input.js similarity index 100% rename from crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/.async-to-generator/input.js rename to crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/input.js diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/.async-to-generator/options.json b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/options.json similarity index 100% rename from crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/.async-to-generator/options.json rename to crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/options.json diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/output.js new file mode 100644 index 000000000000..1848ab20f14f --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/output.js @@ -0,0 +1,18 @@ +function fn() { + return _fn.apply(this, arguments); +} +function _fn() { + _fn = babelHelpers.asyncToGenerator(function* () { + yield 0; + try { + var _usingCtx = babelHelpers.usingCtx(); + const x = _usingCtx.a(y); + yield 1; + } catch (_) { + _usingCtx.e = _; + } finally { + yield _usingCtx.d(); + } + }); + return _fn.apply(this, arguments); +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/input.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/input.js new file mode 100644 index 000000000000..5bb5632a9d34 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/input.js @@ -0,0 +1,4 @@ +{ + using x = fn(); + doSomethingWith(x); +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/output.js new file mode 100644 index 000000000000..2baa347eda5b --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/output.js @@ -0,0 +1,9 @@ +try { + var _usingCtx = babelHelpers.usingCtx(); + const x = _usingCtx.u(fn()); + doSomethingWith(x); +} catch (_) { + _usingCtx.e = _; +} finally { + _usingCtx.d(); +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/source-map-visual.txt b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/source-map-visual.txt new file mode 100644 index 000000000000..249d0f28510b --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/source-map-visual.txt @@ -0,0 +1,116 @@ + (1:0-1) { <-- (1:0-5) try { + ^ ^^^^^ + + (1:0-1) { <-- (2:2-6) var _usi + ^ ^^^^ + + (1:0-1) { <-- (2:6-15) var _usingCtx = b + ^ ^^^^^^^^^ + + (1:0-1) { <-- (2:15-18) gCtx = babe + ^ ^^^ + + (1:0-1) { <-- (2:18-30) x = babelHelpers.usi + ^ ^^^^^^^^^^^^ + + (1:0-1) { <-- (2:30-31) pers.usin + ^ ^ + + (1:0-1) { <-- (2:31-39) ers.usingCtx(); + ^ ^^^^^^^^ + + (1:0-1) { <-- (2:39-42) gCtx(); + ^ ^^^ + + (2:2-8) using x = <-- (3:2-8) const x = + ^^^^^^ ^^^^^^ + + (2:8-9) ing x = f <-- (3:8-9) nst x = _ + ^ ^ + + (2:9-12) ng x = fn() <-- (3:9-12) st x = _usi + ^^^ ^^^ + + (2:9-12) ng x = fn() <-- (3:12-21) x = _usingCtx.u(f + ^^^ ^^^^^^^^^ + + (2:9-12) ng x = fn() <-- (3:21-22) gCtx.u(fn + ^^^ ^ + + (2:9-12) ng x = fn() <-- (3:22-23) Ctx.u(fn( + ^^^ ^ + + (2:9-12) ng x = fn() <-- (3:23-24) tx.u(fn() + ^^^ ^ + +(2:12-14) x = fn(); <-- (3:24-26) x.u(fn()); + ^^ ^^ + +(2:14-15) = fn(); <-- (3:26-27) u(fn()); + ^ ^ + +(2:15-16) fn(); <-- (3:27-28) (fn()); + ^ ^ + +(2:16-17) fn(); <-- (3:28-30) fn()); + ^ ^^ + + (3:2-17) doSomethingWith(x); <-- (4:2-17) doSomethingWith(x); + ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ + +(3:17-18) With(x); <-- (4:17-18) With(x); + ^ ^ + +(3:18-19) ith(x); <-- (4:18-19) ith(x); + ^ ^ + +(3:19-20) th(x); <-- (4:19-20) th(x); + ^ ^ + +(3:20-21) h(x); <-- (4:20-21) h(x); + ^ ^ + +(3:21-21) (x); <-- (5:0-9) } catch (_) { + >< ^^^^^^^^^ + +(3:21-21) (x); <-- (5:9-10) ch (_) { + >< ^ + +(3:21-21) (x); <-- (5:10-13) h (_) { + >< ^^^ + +(3:21-21) (x); <-- (6:2-11) _usingCtx.e = + >< ^^^^^^^^^ + +(3:21-21) (x); <-- (6:11-12) gCtx.e = + >< ^ + +(3:21-21) (x); <-- (6:12-13) Ctx.e = _ + >< ^ + +(3:21-21) (x); <-- (6:13-16) tx.e = _; + >< ^^^ + +(3:21-21) (x); <-- (6:16-17) e = _; + >< ^ + +(3:21-21) (x); <-- (6:17-18) = _; + >< ^ + +(3:21-21) (x); <-- (7:0-11) } finally { + >< ^^^^^^^^^^^ + +(3:21-21) (x); <-- (8:2-11) _usingCtx.d() + >< ^^^^^^^^^ + +(3:21-21) (x); <-- (8:11-12) gCtx.d(); + >< ^ + +(3:21-21) (x); <-- (8:12-13) Ctx.d(); + >< ^ + +(3:21-21) (x); <-- (8:13-16) tx.d(); + >< ^^^ + +(3:21-21) (x); <-- (9:0-1) } + >< ^ diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/source-map.json b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/source-map.json new file mode 100644 index 000000000000..3071796a2bcc --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/source-map.json @@ -0,0 +1,23 @@ +{ + "version": 3, + "names": [ + "_usingCtx", + "babelHelpers", + "usingCtx", + "x", + "u", + "fn", + "doSomethingWith", + "_", + "e", + "d" + ], + "sources": [ + "source-maps/block/input.js" + ], + "sourcesContent": [ + "{\n using x = fn();\n doSomethingWith(x);\n}" + ], + "mappings": "AAAA;EAAA,IAAAA,SAAA,GAAAC,YAAA,CAAAC,QAAA;EACE,MAAMC,CAAC,GAAAH,SAAA,CAAAI,CAAA,CAAGC,EAAE,CAAC,CAAC;EACdC,eAAe,CAACH,CAAC,CAAC;AAAC,SAAAI,CAAA;EAAAP,SAAA,CAAAQ,CAAA,GAAAD,CAAA;AAAA;EAAAP,SAAA,CAAAS,CAAA;AAAA", + "ignoreList": [] +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/input.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/input.js new file mode 100644 index 000000000000..24343c97f1df --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/input.js @@ -0,0 +1,3 @@ +for (using x of it) { + doSomethingWith(x); +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/output.js new file mode 100644 index 000000000000..007a76d4d375 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/output.js @@ -0,0 +1,9 @@ +for (const _x of it) try { + var _usingCtx = babelHelpers.usingCtx(); + const x = _usingCtx.u(_x); + doSomethingWith(x); +} catch (_) { + _usingCtx.e = _; +} finally { + _usingCtx.d(); +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/source-map-visual.txt b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/source-map-visual.txt new file mode 100644 index 000000000000..4ef5da1d22ad --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/source-map-visual.txt @@ -0,0 +1,128 @@ + (1:0-5) for (usin <-- (1:0-5) for (cons + ^^^^^ ^^^^^ + + (1:5-11) or (using x of <-- (1:5-11) or (const _x o + ^^^^^^ ^^^^^^ + +(1:11-12) ing x of <-- (1:11-13) nst _x of + ^ ^^ + +(1:12-16) ng x of it) <-- (1:13-17) t _x of it) + ^^^^ ^^^^ + +(1:16-18) of it) { <-- (1:17-19) of it) tr + ^^ ^^ + +(1:18-20) f it) { <-- (1:19-21) f it) try + ^^ ^^ + +(1:20-20) it) { <-- (1:21-26) it) try { + >< ^^^^^ + +(1:20-20) it) { <-- (2:2-6) var _usi + >< ^^^^ + +(1:20-20) it) { <-- (2:6-15) var _usingCtx = b + >< ^^^^^^^^^ + +(1:20-20) it) { <-- (2:15-18) gCtx = babe + >< ^^^ + +(1:20-20) it) { <-- (2:18-30) x = babelHelpers.usi + >< ^^^^^^^^^^^^ + +(1:20-20) it) { <-- (2:30-31) pers.usin + >< ^ + +(1:20-20) it) { <-- (2:31-39) ers.usingCtx(); + >< ^^^^^^^^ + +(1:20-20) it) { <-- (2:39-42) gCtx(); + >< ^^^ + +(1:20-20) it) { <-- (3:2-8) const x = + >< ^^^^^^ + +(1:11-12) ing x of <-- (3:8-9) nst x = _ + ^ ^ + +(1:12-21) ng x of it) { <-- (3:9-12) st x = _usi + ^^^^^^^^^ ^^^ + +(1:12-21) ng x of it) { <-- (3:12-21) x = _usingCtx.u(_ + ^^^^^^^^^ ^^^^^^^^^ + +(1:12-21) ng x of it) { <-- (3:21-22) gCtx.u(_x + ^^^^^^^^^ ^ + +(1:12-21) ng x of it) { <-- (3:22-23) Ctx.u(_x) + ^^^^^^^^^ ^ + +(1:12-21) ng x of it) { <-- (3:23-24) tx.u(_x); + ^^^^^^^^^ ^ + +(1:12-21) ng x of it) { <-- (3:24-26) x.u(_x); + ^^^^^^^^^ ^^ + +(1:12-21) ng x of it) { <-- (3:26-28) u(_x); + ^^^^^^^^^ ^^ + + (2:2-17) doSomethingWith(x); <-- (4:2-17) doSomethingWith(x); + ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ + +(2:17-18) With(x); <-- (4:17-18) With(x); + ^ ^ + +(2:18-19) ith(x); <-- (4:18-19) ith(x); + ^ ^ + +(2:19-20) th(x); <-- (4:19-20) th(x); + ^ ^ + +(2:20-21) h(x); <-- (4:20-21) h(x); + ^ ^ + +(2:21-21) (x); <-- (5:0-9) } catch (_) { + >< ^^^^^^^^^ + +(2:21-21) (x); <-- (5:9-10) ch (_) { + >< ^ + +(2:21-21) (x); <-- (5:10-13) h (_) { + >< ^^^ + +(2:21-21) (x); <-- (6:2-11) _usingCtx.e = + >< ^^^^^^^^^ + +(2:21-21) (x); <-- (6:11-12) gCtx.e = + >< ^ + +(2:21-21) (x); <-- (6:12-13) Ctx.e = _ + >< ^ + +(2:21-21) (x); <-- (6:13-16) tx.e = _; + >< ^^^ + +(2:21-21) (x); <-- (6:16-17) e = _; + >< ^ + +(2:21-21) (x); <-- (6:17-18) = _; + >< ^ + +(2:21-21) (x); <-- (7:0-11) } finally { + >< ^^^^^^^^^^^ + +(2:21-21) (x); <-- (8:2-11) _usingCtx.d() + >< ^^^^^^^^^ + +(2:21-21) (x); <-- (8:11-12) gCtx.d(); + >< ^ + +(2:21-21) (x); <-- (8:12-13) Ctx.d(); + >< ^ + +(2:21-21) (x); <-- (8:13-16) tx.d(); + >< ^^^ + +(2:21-21) (x); <-- (9:0-1) } + >< ^ diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/source-map.json b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/source-map.json new file mode 100644 index 000000000000..ce84da078f54 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/source-map.json @@ -0,0 +1,24 @@ +{ + "version": 3, + "names": [ + "_x", + "it", + "_usingCtx", + "babelHelpers", + "usingCtx", + "x", + "u", + "doSomethingWith", + "_", + "e", + "d" + ], + "sources": [ + "source-maps/for-of/input.js" + ], + "sourcesContent": [ + "for (using x of it) {\n doSomethingWith(x);\n}" + ], + "mappings": "AAAA,KAAK,MAAMA,EAAC,IAAIC,EAAE,EAAE;EAAA,IAAAC,SAAA,GAAAC,YAAA,CAAAC,QAAA;EAAA,MAATC,CAAC,GAAAH,SAAA,CAAAI,CAAA,CAAAN,EAAA;EACVO,eAAe,CAACF,CAAC,CAAC;AAAC,SAAAG,CAAA;EAAAN,SAAA,CAAAO,CAAA,GAAAD,CAAA;AAAA;EAAAN,SAAA,CAAAQ,CAAA;AAAA", + "ignoreList": [] +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/options.json b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/options.json new file mode 100644 index 000000000000..77cc69ab3a21 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/options.json @@ -0,0 +1,4 @@ +{ + "sourceMaps": true, + "plugins": ["proposal-explicit-resource-management"] +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/input.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/input.js new file mode 100644 index 000000000000..8f4846a6dfb6 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/input.js @@ -0,0 +1,10 @@ +function f() { + switch (v) { + case 0: + using x = 0; + break; + default: + using y = 1; + break; + }; +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/output.js new file mode 100644 index 000000000000..17ccc0da5a6b --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/output.js @@ -0,0 +1,18 @@ +function f() { + try { + var _usingCtx = babelHelpers.usingCtx(); + switch (v) { + case 0: + const x = _usingCtx.u(0); + break; + default: + const y = _usingCtx.u(1); + break; + } + } catch (_) { + _usingCtx.e = _; + } finally { + _usingCtx.d(); + } + ; +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/source-map-visual.txt b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/source-map-visual.txt new file mode 100644 index 000000000000..def1b8c39fe0 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/source-map-visual.txt @@ -0,0 +1,173 @@ + (1:0-9) function f() <-- (1:0-9) function f() + ^^^^^^^^^ ^^^^^^^^^ + + (1:9-10) ion f() { <-- (1:9-10) ion f() { + ^ ^ + +(1:10-13) on f() { <-- (1:10-11) on f() { + ^^^ ^ + +(1:10-13) on f() { <-- (1:11-13) n f() { + ^^^ ^^ + +(1:13-14) f() { <-- (1:13-14) f() { + ^ ^ + + (2:2-10) switch (v) { <-- (2:2-7) try { + ^^^^^^^^ ^^^^^ + + (2:2-10) switch (v) { <-- (3:4-8) var _usi + ^^^^^^^^ ^^^^ + + (2:2-10) switch (v) { <-- (3:8-17) var _usingCtx = b + ^^^^^^^^ ^^^^^^^^^ + + (2:2-10) switch (v) { <-- (3:17-20) gCtx = babe + ^^^^^^^^ ^^^ + + (2:2-10) switch (v) { <-- (3:20-32) x = babelHelpers.usi + ^^^^^^^^ ^^^^^^^^^^^^ + + (2:2-10) switch (v) { <-- (3:32-33) pers.usin + ^^^^^^^^ ^ + + (2:2-10) switch (v) { <-- (3:33-41) ers.usingCtx(); + ^^^^^^^^ ^^^^^^^^ + + (2:2-10) switch (v) { <-- (3:41-44) gCtx(); + ^^^^^^^^ ^^^ + + (2:2-10) switch (v) { <-- (4:4-12) switch (v) { + ^^^^^^^^ ^^^^^^^^ + +(2:10-11) ch (v) { <-- (4:12-13) ch (v) { + ^ ^ + +(2:11-14) h (v) { <-- (4:13-16) h (v) { + ^^^ ^^^ + + (3:4-9) case 0: <-- (5:6-11) case 0: + ^^^^^ ^^^^^ + + (3:9-10) ase 0: <-- (5:11-12) ase 0: + ^ ^ + +(3:10-11) se 0: <-- (5:12-13) se 0: + ^ ^ + + (4:6-12) using x = <-- (6:8-14) const x = + ^^^^^^ ^^^^^^ + +(4:12-13) ing x = 0 <-- (6:14-15) nst x = _ + ^ ^ + +(4:13-16) ng x = 0; <-- (6:15-18) st x = _usi + ^^^ ^^^ + +(4:13-16) ng x = 0; <-- (6:18-27) x = _usingCtx.u(0 + ^^^ ^^^^^^^^^ + +(4:13-16) ng x = 0; <-- (6:27-28) gCtx.u(0) + ^^^ ^ + +(4:13-16) ng x = 0; <-- (6:28-29) Ctx.u(0); + ^^^ ^ + +(4:13-16) ng x = 0; <-- (6:29-30) tx.u(0); + ^^^ ^ + +(4:16-17) x = 0; <-- (6:30-31) x.u(0); + ^ ^ + +(4:17-18) = 0; <-- (6:31-33) .u(0); + ^ ^^ + + (5:6-12) break; <-- (7:8-14) break; + ^^^^^^ ^^^^^^ + + (6:4-12) default: <-- (8:6-14) default: + ^^^^^^^^ ^^^^^^^^ + + (7:6-12) using y = <-- (9:8-14) const y = + ^^^^^^ ^^^^^^ + +(7:12-13) ing y = 1 <-- (9:14-15) nst y = _ + ^ ^ + +(7:13-16) ng y = 1; <-- (9:15-18) st y = _usi + ^^^ ^^^ + +(7:13-16) ng y = 1; <-- (9:18-27) y = _usingCtx.u(1 + ^^^ ^^^^^^^^^ + +(7:13-16) ng y = 1; <-- (9:27-28) gCtx.u(1) + ^^^ ^ + +(7:13-16) ng y = 1; <-- (9:28-29) Ctx.u(1); + ^^^ ^ + +(7:13-16) ng y = 1; <-- (9:29-30) tx.u(1); + ^^^ ^ + +(7:16-17) y = 1; <-- (9:30-31) x.u(1); + ^ ^ + +(7:17-18) = 1; <-- (9:31-33) .u(1); + ^ ^^ + + (8:6-12) break; <-- (10:8-14) break; + ^^^^^^ ^^^^^^ + + (9:2-3) }; <-- (11:4-5) } + ^ ^ + + (9:3-4) }; <-- (12:2-11) } catch (_) { + ^ ^^^^^^^^^ + + (9:3-4) }; <-- (12:11-12) ch (_) { + ^ ^ + + (9:3-4) }; <-- (12:12-15) h (_) { + ^ ^^^ + + (9:3-4) }; <-- (13:4-13) _usingCtx.e = + ^ ^^^^^^^^^ + + (9:3-4) }; <-- (13:13-14) gCtx.e = + ^ ^ + + (9:3-4) }; <-- (13:14-15) Ctx.e = _ + ^ ^ + + (9:3-4) }; <-- (13:15-18) tx.e = _; + ^ ^^^ + + (9:3-4) }; <-- (13:18-19) e = _; + ^ ^ + + (9:3-4) }; <-- (13:19-20) = _; + ^ ^ + + (9:3-4) }; <-- (14:2-13) } finally { + ^ ^^^^^^^^^^^ + + (9:3-4) }; <-- (15:4-13) _usingCtx.d() + ^ ^^^^^^^^^ + + (9:3-4) }; <-- (15:13-14) gCtx.d(); + ^ ^ + + (9:3-4) }; <-- (15:14-15) Ctx.d(); + ^ ^ + + (9:3-4) }; <-- (15:15-18) tx.d(); + ^ ^^^ + + (9:3-4) }; <-- (16:2-3) } + ^ ^ + + (9:3-4) }; <-- (17:2-3) ; + ^ ^ + + (10:0-1) } <-- (18:0-1) } + ^ ^ diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/source-map.json b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/source-map.json new file mode 100644 index 000000000000..63de53e365c2 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/source-map.json @@ -0,0 +1,24 @@ +{ + "version": 3, + "names": [ + "f", + "_usingCtx", + "babelHelpers", + "usingCtx", + "v", + "x", + "u", + "y", + "_", + "e", + "d" + ], + "sources": [ + "source-maps/switch/input.js" + ], + "sourcesContent": [ + "function f() {\n switch (v) {\n case 0:\n using x = 0;\n break;\n default:\n using y = 1;\n break;\n };\n}" + ], + "mappings": "AAAA,SAASA,CAACA,CAAA,EAAG;EACX;IAAA,IAAAC,SAAA,GAAAC,YAAA,CAAAC,QAAA;IAAA,QAAQC,CAAC;MACP,KAAK,CAAC;QACJ,MAAMC,CAAC,GAAAJ,SAAA,CAAAK,CAAA,CAAG,CAAC;QACX;MACF;QACE,MAAMC,CAAC,GAAAN,SAAA,CAAAK,CAAA,CAAG,CAAC;QACX;IACJ;EAAC,SAAAE,CAAA;IAAAP,SAAA,CAAAQ,CAAA,GAAAD,CAAA;EAAA;IAAAP,SAAA,CAAAS,CAAA;EAAA;EAAA;AACH", + "ignoreList": [] +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/input.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/input.mjs new file mode 100644 index 000000000000..10f3afd9162d --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/input.mjs @@ -0,0 +1,4 @@ +before; +using x = fn(); +doSomethingWith(x); +after; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/output.mjs new file mode 100644 index 000000000000..55eb974d39b1 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/output.mjs @@ -0,0 +1,11 @@ +try { + var _usingCtx = babelHelpers.usingCtx(); + before; + var x = _usingCtx.u(fn()); + doSomethingWith(x); + after; +} catch (_) { + _usingCtx.e = _; +} finally { + _usingCtx.d(); +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/source-map-visual.txt b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/source-map-visual.txt new file mode 100644 index 000000000000..92af7c03eb3e --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/source-map-visual.txt @@ -0,0 +1,104 @@ + (1:0-6) before; <-- (3:2-8) before; + ^^^^^^ ^^^^^^ + + (1:6-7) fore; <-- (3:8-9) fore; + ^ ^ + + (2:0-6) using x = <-- (4:2-6) var x = + ^^^^^^ ^^^^ + + (2:6-7) ing x = f <-- (4:6-7) var x = _ + ^ ^ + + (2:7-10) ng x = fn() <-- (4:7-10) ar x = _usi + ^^^ ^^^ + + (2:7-10) ng x = fn() <-- (4:10-19) x = _usingCtx.u(f + ^^^ ^^^^^^^^^ + + (2:7-10) ng x = fn() <-- (4:19-20) gCtx.u(fn + ^^^ ^ + + (2:7-10) ng x = fn() <-- (4:20-21) Ctx.u(fn( + ^^^ ^ + + (2:7-10) ng x = fn() <-- (4:21-22) tx.u(fn() + ^^^ ^ + +(2:10-12) x = fn(); <-- (4:22-24) x.u(fn()); + ^^ ^^ + +(2:12-13) = fn(); <-- (4:24-25) u(fn()); + ^ ^ + +(2:13-14) fn(); <-- (4:25-26) (fn()); + ^ ^ + +(2:14-15) fn(); <-- (4:26-28) fn()); + ^ ^^ + + (3:0-15) doSomethingWith(x); <-- (5:2-17) doSomethingWith(x); + ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ + +(3:15-16) With(x); <-- (5:17-18) With(x); + ^ ^ + +(3:16-17) ith(x); <-- (5:18-19) ith(x); + ^ ^ + +(3:17-18) th(x); <-- (5:19-20) th(x); + ^ ^ + +(3:18-19) h(x); <-- (5:20-21) h(x); + ^ ^ + + (4:0-5) after; <-- (6:2-7) after; + ^^^^^ ^^^^^ + + (4:5-6) fter; <-- (6:7-8) fter; + ^ ^ + + (4:6-6) ter; <-- (7:0-9) } catch (_) { + >< ^^^^^^^^^ + + (4:6-6) ter; <-- (7:9-10) ch (_) { + >< ^ + + (4:6-6) ter; <-- (7:10-13) h (_) { + >< ^^^ + + (4:6-6) ter; <-- (8:2-11) _usingCtx.e = + >< ^^^^^^^^^ + + (4:6-6) ter; <-- (8:11-12) gCtx.e = + >< ^ + + (4:6-6) ter; <-- (8:12-13) Ctx.e = _ + >< ^ + + (4:6-6) ter; <-- (8:13-16) tx.e = _; + >< ^^^ + + (4:6-6) ter; <-- (8:16-17) e = _; + >< ^ + + (4:6-6) ter; <-- (8:17-18) = _; + >< ^ + + (4:6-6) ter; <-- (9:0-11) } finally { + >< ^^^^^^^^^^^ + + (4:6-6) ter; <-- (10:2-11) _usingCtx.d() + >< ^^^^^^^^^ + + (4:6-6) ter; <-- (10:11-12) gCtx.d(); + >< ^ + + (4:6-6) ter; <-- (10:12-13) Ctx.d(); + >< ^ + + (4:6-6) ter; <-- (10:13-16) tx.d(); + >< ^^^ + + (4:6-6) ter; <-- (11:0-1) } + >< ^ diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/source-map.json b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/source-map.json new file mode 100644 index 000000000000..f9b646edfe6e --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/source-map.json @@ -0,0 +1,23 @@ +{ + "version": 3, + "names": [ + "before", + "x", + "_usingCtx", + "u", + "fn", + "doSomethingWith", + "after", + "_", + "e", + "d" + ], + "sources": [ + "source-maps/top-level/input.mjs" + ], + "sourcesContent": [ + "before;\nusing x = fn();\ndoSomethingWith(x);\nafter;" + ], + "mappings": ";;EAAAA,MAAM;EACN,IAAMC,CAAC,GAAAC,SAAA,CAAAC,CAAA,CAAGC,EAAE,CAAC,CAAC;EACdC,eAAe,CAACJ,CAAC,CAAC;EAClBK,KAAK;AAAC,SAAAC,CAAA;EAAAL,SAAA,CAAAM,CAAA,GAAAD,CAAA;AAAA;EAAAL,SAAA,CAAAO,CAAA;AAAA", + "ignoreList": [] +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/issue-8853/input.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/issue-8853/input.mjs deleted file mode 100644 index 88d6474578a1..000000000000 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/issue-8853/input.mjs +++ /dev/null @@ -1,32 +0,0 @@ - -let i = 0 -let err -try { - await using _x1 = { - async [Symbol.asyncDispose]() { - throw [1, ++i] - } - } - - await using _x2 = { - async [Symbol.asyncDispose]() { - throw [2, ++i] - } - } - - await using _x3 = { - async [Symbol.asyncDispose]() { - throw [3, ++i] - } - } - - await using _x4 = { - async [Symbol.asyncDispose]() { - throw [4, ++i] - } - } - - throw [5, ++i] -} catch (e) { - err = e -} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/issue-8853/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/issue-8853/output.mjs deleted file mode 100644 index 7d8080129a94..000000000000 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/issue-8853/output.mjs +++ /dev/null @@ -1,49 +0,0 @@ -let i = 0; -let err; -try { - try { - var _usingCtx = _using_ctx(); - const _x1 = _usingCtx.a({ - async [Symbol.asyncDispose] () { - throw [ - 1, - ++i - ]; - } - }); - const _x2 = _usingCtx.a({ - async [Symbol.asyncDispose] () { - throw [ - 2, - ++i - ]; - } - }); - const _x3 = _usingCtx.a({ - async [Symbol.asyncDispose] () { - throw [ - 3, - ++i - ]; - } - }); - const _x4 = _usingCtx.a({ - async [Symbol.asyncDispose] () { - throw [ - 4, - ++i - ]; - } - }); - throw [ - 5, - ++i - ]; - } catch (_) { - _usingCtx.e = _; - } finally{ - await _usingCtx.d(); - } -} catch (e) { - err = e; -} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/input.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/input.js similarity index 100% rename from crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/input.mjs rename to crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/input.js diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/output.mjs index bc88967b14d5..697f4b8ec00b 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/output.mjs @@ -1,12 +1,10 @@ -{ - try { - var _usingCtx = _using_ctx(); - const a = _usingCtx.u(1); - const b = _usingCtx.a(2); - const c = _usingCtx.u(3); - } catch (_) { - _usingCtx.e = _; - } finally{ - await _usingCtx.d(); - } +try { + var _usingCtx = babelHelpers.usingCtx(); + const a = _usingCtx.u(1); + const b = _usingCtx.a(2); + const c = _usingCtx.u(3); +} catch (_) { + _usingCtx.e = _; +} finally { + await _usingCtx.d(); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/input.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/input.js similarity index 100% rename from crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/input.mjs rename to crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/input.js diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/output.mjs index ab8caf7f5d1e..3e14b0a5ec77 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/output.mjs @@ -1,13 +1,12 @@ -{ - try { - var _usingCtx = _using_ctx(); - const x = _usingCtx.a(obj); - stmt; - const y = _usingCtx.a(obj), z = _usingCtx.a(obj); - doSomethingWith(x, y); - } catch (_) { - _usingCtx.e = _; - } finally{ - await _usingCtx.d(); - } +try { + var _usingCtx = babelHelpers.usingCtx(); + const x = _usingCtx.a(obj); + stmt; + const y = _usingCtx.a(obj), + z = _usingCtx.a(obj); + doSomethingWith(x, y); +} catch (_) { + _usingCtx.e = _; +} finally { + await _usingCtx.d(); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/input.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/input.js new file mode 100644 index 000000000000..be673b00a88a --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/input.js @@ -0,0 +1,10 @@ +async function f() { + switch (v) { + case 0: + await using x = 0; + break; + default: + await using y = 1; + break; + } +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/output.mjs new file mode 100644 index 000000000000..5e4a482e28f9 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/output.mjs @@ -0,0 +1,17 @@ +async function f() { + try { + var _usingCtx = babelHelpers.usingCtx(); + switch (v) { + case 0: + const x = _usingCtx.a(0); + break; + default: + const y = _usingCtx.a(1); + break; + } + } catch (_) { + _usingCtx.e = _; + } finally { + await _usingCtx.d(); + } +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/bare-block/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/bare-block/output.js index ae57c226afa8..393c4ab1b128 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/bare-block/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/bare-block/output.js @@ -1,11 +1,9 @@ -{ - try { - var _usingCtx = _using_ctx(); - const x = _usingCtx.u(obj); - doSomethingWith(x); - } catch (_) { - _usingCtx.e = _; - } finally{ - _usingCtx.d(); - } +try { + var _usingCtx = babelHelpers.usingCtx(); + const x = _usingCtx.u(obj); + doSomethingWith(x); +} catch (_) { + _usingCtx.e = _; +} finally { + _usingCtx.d(); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-await-head/input.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-await-head/input.js similarity index 100% rename from crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-await-head/input.mjs rename to crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-await-head/input.js diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-await-head/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-await-head/output.mjs index 69d1662c66a6..10d665678cc4 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-await-head/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-await-head/output.mjs @@ -1,12 +1,9 @@ -for await (const x of y){ - try { - var _usingCtx = _using_ctx(); - { - doSomethingWith(x); - } - } catch (_) { - _usingCtx.e = _; - } finally{ - _usingCtx.d(); - } +for await (const _x of y) try { + var _usingCtx = babelHelpers.usingCtx(); + const x = _usingCtx.u(_x); + doSomethingWith(x); +} catch (_) { + _usingCtx.e = _; +} finally { + _usingCtx.d(); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-head/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-head/output.js index 664ad9129e5e..45feb156198f 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-head/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-head/output.js @@ -1,12 +1,9 @@ -for (const x of y){ - try { - var _usingCtx = _using_ctx(); - { - doSomethingWith(x); - } - } catch (_) { - _usingCtx.e = _; - } finally{ - _usingCtx.d(); - } +for (const _x of y) try { + var _usingCtx = babelHelpers.usingCtx(); + const x = _usingCtx.u(_x); + doSomethingWith(x); +} catch (_) { + _usingCtx.e = _; +} finally { + _usingCtx.d(); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/function-body/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/function-body/output.js index 73a4f9acebd4..feec5c626618 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/function-body/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/function-body/output.js @@ -1,11 +1,11 @@ function fn() { - try { - var _usingCtx = _using_ctx(); - const x = _usingCtx.u(obj); - return doSomethingWith(x); - } catch (_) { - _usingCtx.e = _; - } finally{ - _usingCtx.d(); - } + try { + var _usingCtx = babelHelpers.usingCtx(); + const x = _usingCtx.u(obj); + return doSomethingWith(x); + } catch (_) { + _usingCtx.e = _; + } finally { + _usingCtx.d(); + } } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/if-body/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/if-body/output.js index 37a67bf08873..bc9964c1f9f1 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/if-body/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/if-body/output.js @@ -1,11 +1,9 @@ -if (test) { - try { - var _usingCtx = _using_ctx(); - const x = _usingCtx.u(obj); - doSomethingWith(x); - } catch (_) { - _usingCtx.e = _; - } finally{ - _usingCtx.d(); - } +if (test) try { + var _usingCtx = babelHelpers.usingCtx(); + const x = _usingCtx.u(obj); + doSomethingWith(x); +} catch (_) { + _usingCtx.e = _; +} finally { + _usingCtx.d(); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/issue-8629/input.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/issue-8629/input.js deleted file mode 100644 index 4714506c2b8f..000000000000 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/issue-8629/input.js +++ /dev/null @@ -1,10 +0,0 @@ -// main.ts -export class Disposable { - [Symbol.dispose]() { - console.log('dispose') - } -} - -using _disposable = new Disposable() - -console.log('ok') \ No newline at end of file diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/issue-8629/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/issue-8629/output.js deleted file mode 100644 index f4bf134efc46..000000000000 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/issue-8629/output.js +++ /dev/null @@ -1,18 +0,0 @@ -// main.ts -var _Disposable; -try { - var _usingCtx = _using_ctx(); - class Disposable { - [Symbol.dispose]() { - console.log('dispose'); - } - } - _Disposable = Disposable; - var _disposable = _usingCtx.u(new Disposable()); - console.log('ok'); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); -} -export { _Disposable as Disposable }; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-nested/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-nested/output.js index a43a642ea82b..a95315682dc1 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-nested/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-nested/output.js @@ -1,32 +1,28 @@ -{ - try { - var _usingCtx = _using_ctx(); - const x = _usingCtx.u(obj); - { - try { - var _usingCtx1 = _using_ctx(); - const y = _usingCtx1.u(call(()=>{ - try { - var _usingCtx = _using_ctx(); - const z = _usingCtx.u(obj); - return z; - } catch (_) { - _usingCtx.e = _; - } finally{ - _usingCtx.d(); - } - })); - stmt; - } catch (_) { - _usingCtx1.e = _; - } finally{ - _usingCtx1.d(); - } - } - stmt; - } catch (_) { - _usingCtx.e = _; - } finally{ - _usingCtx.d(); - } +try { + var _usingCtx = babelHelpers.usingCtx(); + const x = _usingCtx.u(obj); + try { + var _usingCtx2 = babelHelpers.usingCtx(); + const y = _usingCtx2.u(call(() => { + try { + var _usingCtx3 = babelHelpers.usingCtx(); + const z = _usingCtx3.u(obj); + return z; + } catch (_) { + _usingCtx3.e = _; + } finally { + _usingCtx3.d(); + } + })); + stmt; + } catch (_) { + _usingCtx2.e = _; + } finally { + _usingCtx2.d(); + } + stmt; +} catch (_) { + _usingCtx.e = _; +} finally { + _usingCtx.d(); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-same-level/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-same-level/output.js index 74d1135cdc3f..98d674368c43 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-same-level/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-same-level/output.js @@ -1,16 +1,15 @@ -{ - try { - var _usingCtx = _using_ctx(); - stmt; - const x = _usingCtx.u(obj); - stmt; - const y = _usingCtx.u(obj), z = _usingCtx.u(obj); - stmt; - const w = _usingCtx.u(obj); - doSomethingWith(x, z); - } catch (_) { - _usingCtx.e = _; - } finally{ - _usingCtx.d(); - } +try { + var _usingCtx = babelHelpers.usingCtx(); + stmt; + const x = _usingCtx.u(obj); + stmt; + const y = _usingCtx.u(obj), + z = _usingCtx.u(obj); + stmt; + const w = _usingCtx.u(obj); + doSomethingWith(x, z); +} catch (_) { + _usingCtx.e = _; +} finally { + _usingCtx.d(); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/static-block/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/static-block/output.js index 40822b4ddd8f..ea4cdda72dbb 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/static-block/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/static-block/output.js @@ -1,13 +1,13 @@ class A { - static{ - try { - var _usingCtx = _using_ctx(); - const x = _usingCtx.u(y); - doSomethingWith(x); - } catch (_) { - _usingCtx.e = _; - } finally{ - _usingCtx.d(); - } + static { + try { + var _usingCtx = babelHelpers.usingCtx(); + const x = _usingCtx.u(y); + doSomethingWith(x); + } catch (_) { + _usingCtx.e = _; + } finally { + _usingCtx.d(); } + } } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/input.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/input.js new file mode 100644 index 000000000000..8f4846a6dfb6 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/input.js @@ -0,0 +1,10 @@ +function f() { + switch (v) { + case 0: + using x = 0; + break; + default: + using y = 1; + break; + }; +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/output.js new file mode 100644 index 000000000000..17ccc0da5a6b --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/output.js @@ -0,0 +1,18 @@ +function f() { + try { + var _usingCtx = babelHelpers.usingCtx(); + switch (v) { + case 0: + const x = _usingCtx.u(0); + break; + default: + const y = _usingCtx.u(1); + break; + } + } catch (_) { + _usingCtx.e = _; + } finally { + _usingCtx.d(); + } + ; +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/await-or-not-preserved/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/await-or-not-preserved/output.mjs index 95ff79d27880..465458a41c9d 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/await-or-not-preserved/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/await-or-not-preserved/output.mjs @@ -1,10 +1,10 @@ export { x, y }; try { - var _usingCtx = _using_ctx(); - var x = _usingCtx.u(A); - var y = _usingCtx.a(B); + var _usingCtx = babelHelpers.usingCtx(); + var x = _usingCtx.u(A); + var y = _usingCtx.a(B); } catch (_) { - _usingCtx.e = _; -} finally{ - await _usingCtx.d(); + _usingCtx.e = _; +} finally { + await _usingCtx.d(); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-clas-anon/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-clas-anon/output.mjs index 92818dd6f95f..d3d22236cc69 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-clas-anon/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-clas-anon/output.mjs @@ -1,11 +1,10 @@ export { _default as default }; try { - var _usingCtx = _using_ctx(); - var x = _usingCtx.u(null); - var _default = class { - }; + var _usingCtx = babelHelpers.usingCtx(); + var x = _usingCtx.u(null); + var _default = class {}; } catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); + _usingCtx.e = _; +} finally { + _usingCtx.d(); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-class/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-class/output.mjs index 34ad7a56f1df..201fea1665e8 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-class/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-class/output.mjs @@ -1,11 +1,10 @@ export { C as default }; try { - var _usingCtx = _using_ctx(); - var x = _usingCtx.u(null); - var C = class C { - }; + var _usingCtx = babelHelpers.usingCtx(); + var x = _usingCtx.u(null); + var C = class {}; } catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); + _usingCtx.e = _; +} finally { + _usingCtx.d(); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-expr/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-expr/output.mjs index 682561df4403..82344af039bd 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-expr/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-expr/output.mjs @@ -1,10 +1,10 @@ export { _default as default }; try { - var _usingCtx = _using_ctx(); - var x = _usingCtx.u(null); - var _default = doSomething(); + var _usingCtx = babelHelpers.usingCtx(); + var x = _usingCtx.u(null); + var _default = doSomething(); } catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); + _usingCtx.e = _; +} finally { + _usingCtx.d(); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn-anon/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn-anon/output.mjs index 7357daba7ddf..0225d7d45c50 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn-anon/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn-anon/output.mjs @@ -1,10 +1,9 @@ -export { fn as default }; +export default function fn() {} try { - var _usingCtx = _using_ctx(); - var x = _usingCtx.u(null); - var fn = function fn() {}; + var _usingCtx = babelHelpers.usingCtx(); + var x = _usingCtx.u(null); } catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); + _usingCtx.e = _; +} finally { + _usingCtx.d(); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn/output.mjs index 7357daba7ddf..0225d7d45c50 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn/output.mjs @@ -1,10 +1,9 @@ -export { fn as default }; +export default function fn() {} try { - var _usingCtx = _using_ctx(); - var x = _usingCtx.u(null); - var fn = function fn() {}; + var _usingCtx = babelHelpers.usingCtx(); + var x = _usingCtx.u(null); } catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); + _usingCtx.e = _; +} finally { + _usingCtx.d(); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting/output.mjs index e09f3d2ca214..50b3e4ee1bd8 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting/output.mjs @@ -1,39 +1,32 @@ import { doSomething } from "somewhere"; export * from "somewhere else"; export * as ns from "somewhere else"; -var _g; +function f() { + a; + B; +} +function h() { + b; + A; +} +export function g() { + c; +} export { f }; -var _b; -var _B; +export { b }; +export { B }; try { - var _usingCtx = _using_ctx(); - function f() { - a; - B; - } - function h() { - b; - A; - } - function g() { - c; - } - _g = g; - doSomething(); - let { b } = {}; - _b = b; - let c = 2; - class A { - } - class B { - } - _B = B; - var x = _usingCtx.u(null); + var _usingCtx = babelHelpers.usingCtx(); + doSomething(); + var { + b + } = {}; + var c = 2; + var A = class {}; + var B = class {}; + var x = _usingCtx.u(null); } catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); + _usingCtx.e = _; +} finally { + _usingCtx.d(); } -export { _g as g }; -export { _b as b }; -export { _B as B }; From 42e076fa3665e9dedb85693c0fcc4b05e3ce276e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 27 Sep 2024 20:14:20 +0900 Subject: [PATCH 11/28] Update helpers --- .../helpers/_ts_add_disposable_resource.js | 23 ++----- .../src/helpers/_ts_dispose_resources.js | 61 ++++++++++--------- .../src/explicit_resource_management.rs | 15 +++++ 3 files changed, 52 insertions(+), 47 deletions(-) diff --git a/crates/swc_ecma_transforms_base/src/helpers/_ts_add_disposable_resource.js b/crates/swc_ecma_transforms_base/src/helpers/_ts_add_disposable_resource.js index 992a8587d9c9..0b39b9f9aa98 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/_ts_add_disposable_resource.js +++ b/crates/swc_ecma_transforms_base/src/helpers/_ts_add_disposable_resource.js @@ -12,22 +12,11 @@ function _ts_add_disposable_resource(env, value, async) { if (async) inner = dispose; } if (typeof dispose !== "function") throw new TypeError("Object not disposable."); - if (inner) dispose = function () { - try { - inner.call(this); - } catch (e) { - return Promise.reject(e); - } - }; - env.stack.push({ - value: value, - dispose: dispose, - async: async - }); - } else if (async) { - env.stack.push({ - async: true - }); + if (inner) dispose = function () { try { inner.call(this); } catch (e) { return Promise.reject(e); } }; + env.stack.push({ value: value, dispose: dispose, async: async }); + } + else if (async) { + env.stack.push({ async: true }); } return value; -} \ No newline at end of file +}; \ No newline at end of file diff --git a/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js b/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js index 685b40e2985f..5d82ab6da025 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js +++ b/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js @@ -1,32 +1,33 @@ -function _ts_dispose_resources(SuppressedError) { - return function (env) { - function fail(e) { - env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; - env.hasError = true; - } - var r, - s = 0; - function next() { - while (r = env.stack.pop()) { - try { - if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); - if (r.dispose) { - var result = r.dispose.call(r.value); - if (r.async) return s |= 2, Promise.resolve(result).then(next, function (e) { - fail(e); - return next(); - }); - } else s |= 1; - } catch (e) { - fail(e); +function _ts_dispose_resources(env) { + _ts_dispose_resources = (function (SuppressedError) { + return function (env) { + function fail(e) { + env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; + env.hasError = true; + } + var r, s = 0; + function next() { + while (r = env.stack.pop()) { + try { + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function (e) { fail(e); return next(); }); + } + else s |= 1; + } + catch (e) { + fail(e); + } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); + if (env.hasError) throw env.error; } - if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); - if (env.hasError) throw env.error; - } - return next(); - }; -} (typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { - var e = new Error(message); - return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; -}); \ No newline at end of file + return next(); + }; + })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { + var e = new Error(message); + return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; + }); + return _ts_dispose_resources(env); +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index 17125b009402..2e4181c51fe0 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -263,6 +263,21 @@ impl VisitMut for ExplicitResourceManagement { fn handle_using_decl(using: &mut UsingDecl, state: &mut State) -> Box { state.has_await |= using.is_await; + for decl in &mut using.decls { + decl.init = Some( + CallExpr { + callee: helper!(ts, ts_add_disposable_resource), + args: vec![ + state.env.clone().as_arg(), + decl.init.take().unwrap().as_arg(), + using.is_await.as_arg(), + ], + ..Default::default() + } + .into(), + ); + } + Box::new(VarDecl { span: DUMMY_SP, kind: VarDeclKind::Const, From e0a3563fe8a6668b05035a04a83c2cfe03b9bdb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 12:03:23 +0900 Subject: [PATCH 12/28] _ts_dispose_resources --- .../src/helpers/_ts_dispose_resources.js | 53 +++++++++---------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js b/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js index 5d82ab6da025..2f4995322cda 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js +++ b/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js @@ -1,33 +1,28 @@ function _ts_dispose_resources(env) { - _ts_dispose_resources = (function (SuppressedError) { - return function (env) { - function fail(e) { - env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; - env.hasError = true; - } - var r, s = 0; - function next() { - while (r = env.stack.pop()) { - try { - if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); - if (r.dispose) { - var result = r.dispose.call(r.value); - if (r.async) return s |= 2, Promise.resolve(result).then(next, function (e) { fail(e); return next(); }); - } - else s |= 1; - } - catch (e) { - fail(e); - } - } - if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); - if (env.hasError) throw env.error; - } - return next(); - }; - })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { + var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { var e = new Error(message); return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; - }); - return _ts_dispose_resources(env); + }; + + + return (_ts_dispose_resources = function _ts_dispose_resources(env) { + function fail(e) { + env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; + env.hasError = true; + } + function next() { + while (env.stack.length) { + var rec = env.stack.pop(); + try { + var result = rec.dispose && rec.dispose.call(rec.value); + if (rec.async) return Promise.resolve(result).then(next, function (e) { fail(e); return next(); }); + } + catch (e) { + fail(e); + } + } + if (env.hasError) throw env.error; + } + return next(); + })(env); } \ No newline at end of file From a1c6d13fe1d5881edc78e01d0882e25ba7764686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 12:03:32 +0900 Subject: [PATCH 13/28] Improve helper --- .../src/helpers/_ts_add_disposable_resource.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/swc_ecma_transforms_base/src/helpers/_ts_add_disposable_resource.js b/crates/swc_ecma_transforms_base/src/helpers/_ts_add_disposable_resource.js index 0b39b9f9aa98..cf7e92b1c775 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/_ts_add_disposable_resource.js +++ b/crates/swc_ecma_transforms_base/src/helpers/_ts_add_disposable_resource.js @@ -1,7 +1,7 @@ function _ts_add_disposable_resource(env, value, async) { if (value !== null && value !== void 0) { if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected."); - var dispose, inner; + var dispose; if (async) { if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); dispose = value[Symbol.asyncDispose]; @@ -9,14 +9,12 @@ function _ts_add_disposable_resource(env, value, async) { if (dispose === void 0) { if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); dispose = value[Symbol.dispose]; - if (async) inner = dispose; } if (typeof dispose !== "function") throw new TypeError("Object not disposable."); - if (inner) dispose = function () { try { inner.call(this); } catch (e) { return Promise.reject(e); } }; env.stack.push({ value: value, dispose: dispose, async: async }); } else if (async) { env.stack.push({ async: true }); } return value; -}; \ No newline at end of file +} \ No newline at end of file From 19a4eaea625abfa1fb128167404ce0aaa2ab074b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 12:06:33 +0900 Subject: [PATCH 14/28] fix fielkd name --- .../src/explicit_resource_management.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index 2e4181c51fe0..659be4934110 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -152,7 +152,7 @@ impl ExplicitResourceManagement { left: MemberExpr { span: DUMMY_SP, obj: Box::new(env.clone().into()), - prop: MemberProp::Ident(quote_ident!("e")), + prop: MemberProp::Ident(quote_ident!("error")), } .into(), op: op!("="), @@ -215,6 +215,10 @@ impl VisitMut for ExplicitResourceManagement { if let ForHead::UsingDecl(decl) = &mut n.left { let mut state = State::default(); + for decl in &mut decl.decls { + let new_var = private_ident!("_value"); + decl.init = Some(new_var.clone().into()) + } let var_decl = handle_using_decl(decl, &mut state); let mut body = vec![*n.body.take()]; From 5cc3f98a2940ed0015e813c15d4107974720f9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 12:21:14 +0900 Subject: [PATCH 15/28] await result if required --- .../src/explicit_resource_management.rs | 63 +++++++++++++++++-- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index 659be4934110..3b885f4df231 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -180,17 +180,68 @@ impl ExplicitResourceManagement { }, }; + let finally_block = if is_async { + // Code: + // const result_1 = _ts_dispose_resources(env_1); + // if (result_1) + // await result_1; + + let result = private_ident!("result"); + + let var_decl = Stmt::Decl(Decl::Var(Box::new(VarDecl { + kind: VarDeclKind::Const, + decls: vec![VarDeclarator { + span: DUMMY_SP, + name: Pat::Ident(result.clone().into()), + init: Some(Box::new( + Expr::Call(CallExpr { + callee: helper!(ts, ts_dispose_resources), + args: vec![env.clone().as_arg()], + ..Default::default() + }) + .into(), + )), + definite: false, + }], + ..Default::default() + }))); + let if_stmt = Stmt::If(IfStmt { + span: DUMMY_SP, + test: Box::new(Expr::Lit(Lit::Bool(Bool { + span: DUMMY_SP, + value: true, + }))), + // Code: + // await result_1; + cons: Stmt::Expr(ExprStmt { + expr: Box::new(Expr::Await(AwaitExpr { + arg: result.clone().into(), + ..Default::default() + })), + ..Default::default() + }) + .into(), + ..Default::default() + }); + + vec![var_decl, if_stmt] + } else { + // Code: + // _ts_dispose_resources(env_1); + vec![CallExpr { + callee: helper!(ts, ts_dispose_resources), + args: vec![env.clone().as_arg()], + ..Default::default() + } + .into_stmt()] + }; + let try_stmt = TryStmt { span: DUMMY_SP, block: try_block, handler: Some(catch_clause), finalizer: Some(BlockStmt { - stmts: vec![CallExpr { - callee: helper!(ts, ts_dispose_resources), - args: vec![env.clone().as_arg()], - ..Default::default() - } - .into_stmt()], + stmts: finally_block, ..Default::default() }), }; From 2bd2267e528a6b9e83fdfc535cc9e942d233f980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 12:23:26 +0900 Subject: [PATCH 16/28] cleanup --- .../src/explicit_resource_management.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index 3b885f4df231..e9c93df57173 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -193,14 +193,14 @@ impl ExplicitResourceManagement { decls: vec![VarDeclarator { span: DUMMY_SP, name: Pat::Ident(result.clone().into()), - init: Some(Box::new( - Expr::Call(CallExpr { + init: Some( + CallExpr { callee: helper!(ts, ts_dispose_resources), args: vec![env.clone().as_arg()], ..Default::default() - }) + } .into(), - )), + ), definite: false, }], ..Default::default() From 1aae5dce0514b949828ea95edb2916ea902a9f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 12:27:52 +0900 Subject: [PATCH 17/28] result --- .../src/explicit_resource_management.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index e9c93df57173..f6633532dc18 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -207,10 +207,7 @@ impl ExplicitResourceManagement { }))); let if_stmt = Stmt::If(IfStmt { span: DUMMY_SP, - test: Box::new(Expr::Lit(Lit::Bool(Bool { - span: DUMMY_SP, - value: true, - }))), + test: result.clone().into(), // Code: // await result_1; cons: Stmt::Expr(ExprStmt { From 86dd46185940ff6c52a6fe297b26c0bc4ce8c801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 12:29:50 +0900 Subject: [PATCH 18/28] remove init for loops --- .../src/explicit_resource_management.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index f6633532dc18..67767024a914 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -263,10 +263,6 @@ impl VisitMut for ExplicitResourceManagement { if let ForHead::UsingDecl(decl) = &mut n.left { let mut state = State::default(); - for decl in &mut decl.decls { - let new_var = private_ident!("_value"); - decl.init = Some(new_var.clone().into()) - } let var_decl = handle_using_decl(decl, &mut state); let mut body = vec![*n.body.take()]; From f29400dc3936c2e977abcf2b037c5c04de385163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 12:53:14 +0900 Subject: [PATCH 19/28] update tslib --- packages/helpers/package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/helpers/package.json b/packages/helpers/package.json index bc7f7a9cf37c..1f8eb8139848 100644 --- a/packages/helpers/package.json +++ b/packages/helpers/package.json @@ -36,7 +36,7 @@ "zx": "^7.2.1" }, "dependencies": { - "tslib": "^2.7.0" + "tslib": "^2.8.0" }, "exports": { "./package.json": "./package.json", diff --git a/yarn.lock b/yarn.lock index b8dc25921e69..8fb068914a76 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4639,7 +4639,7 @@ __metadata: "@ast-grep/napi": "npm:^0.3.1" dprint: "npm:^0.35.3" magic-string: "npm:^0.30.0" - tslib: "npm:^2.7.0" + tslib: "npm:^2.8.0" zx: "npm:^7.2.1" languageName: unknown linkType: soft @@ -16822,10 +16822,10 @@ __metadata: languageName: node linkType: hard -"tslib@npm:^2.7.0": - version: 2.7.0 - resolution: "tslib@npm:2.7.0" - checksum: 9a5b47ddac65874fa011c20ff76db69f97cf90c78cff5934799ab8894a5342db2d17b4e7613a087046bc1d133d21547ddff87ac558abeec31ffa929c88b7fce6 +"tslib@npm:^2.8.0": + version: 2.8.0 + resolution: "tslib@npm:2.8.0" + checksum: 1bc7c43937477059b4d26f2dbde7e49ef0fb4f38f3014e0603eaea76d6a885742c8b1762af45949145e5e7408a736d20ded949da99dabc8ccba1fc5531d2d927 languageName: node linkType: hard From 91c72d3e43af1c989107e7de9daebf49900d69a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 12:53:34 +0900 Subject: [PATCH 20/28] bump --- packages/helpers/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/helpers/package.json b/packages/helpers/package.json index 1f8eb8139848..720cd69ae603 100644 --- a/packages/helpers/package.json +++ b/packages/helpers/package.json @@ -1,7 +1,7 @@ { "name": "@swc/helpers", "packageManager": "yarn@4.0.2", - "version": "0.5.13", + "version": "0.5.14", "description": "External helpers for the swc project.", "module": "esm/index.js", "main": "cjs/index.cjs", From 1671474bb3237fb40531b7257bf9ee2a5454efd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 12:55:30 +0900 Subject: [PATCH 21/28] Fix helpers --- .../src/helpers/_ts_add_disposable_resource.js | 4 +++- .../src/helpers/_ts_dispose_resources.js | 15 ++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/swc_ecma_transforms_base/src/helpers/_ts_add_disposable_resource.js b/crates/swc_ecma_transforms_base/src/helpers/_ts_add_disposable_resource.js index cf7e92b1c775..2ecbaaa888d5 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/_ts_add_disposable_resource.js +++ b/crates/swc_ecma_transforms_base/src/helpers/_ts_add_disposable_resource.js @@ -1,7 +1,7 @@ function _ts_add_disposable_resource(env, value, async) { if (value !== null && value !== void 0) { if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected."); - var dispose; + var dispose, inner; if (async) { if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); dispose = value[Symbol.asyncDispose]; @@ -9,8 +9,10 @@ function _ts_add_disposable_resource(env, value, async) { if (dispose === void 0) { if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); dispose = value[Symbol.dispose]; + if (async) inner = dispose; } if (typeof dispose !== "function") throw new TypeError("Object not disposable."); + if (inner) dispose = function () { try { inner.call(this); } catch (e) { return Promise.reject(e); } }; env.stack.push({ value: value, dispose: dispose, async: async }); } else if (async) { diff --git a/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js b/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js index 2f4995322cda..9ad97b032504 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js +++ b/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js @@ -7,20 +7,25 @@ function _ts_dispose_resources(env) { return (_ts_dispose_resources = function _ts_dispose_resources(env) { function fail(e) { - env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; + env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function (e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function (e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); From fefe5c06dbd10e3f42029a66905b793f545f0b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 13:01:20 +0900 Subject: [PATCH 22/28] fix helper --- .../src/helpers/_ts_dispose_resources.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js b/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js index 9ad97b032504..8865a070cbcf 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js +++ b/crates/swc_ecma_transforms_base/src/helpers/_ts_dispose_resources.js @@ -7,7 +7,7 @@ function _ts_dispose_resources(env) { return (_ts_dispose_resources = function _ts_dispose_resources(env) { function fail(e) { - env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; + env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } var r, s = 0; From a4bd7de5be0d744c4a568401ffaa61369a624382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 13:16:46 +0900 Subject: [PATCH 23/28] for loop --- .../src/explicit_resource_management.rs | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index 67767024a914..db84b979c064 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -260,12 +260,51 @@ impl VisitMut for ExplicitResourceManagement { fn visit_mut_for_of_stmt(&mut self, n: &mut ForOfStmt) { n.visit_mut_children_with(self); - if let ForHead::UsingDecl(decl) = &mut n.left { + if let ForHead::UsingDecl(using) = &mut n.left { let mut state = State::default(); + state.has_await |= using.is_await; - let var_decl = handle_using_decl(decl, &mut state); + let mut inner_var_decl = VarDecl { + kind: VarDeclKind::Const, + ..Default::default() + }; + + for decl in &mut using.decls { + let new_var = private_ident!("_"); + + inner_var_decl.decls.push(VarDeclarator { + span: DUMMY_SP, + name: decl.name.take(), + init: Some( + CallExpr { + callee: helper!(ts, ts_add_disposable_resource), + args: vec![ + state.env.clone().as_arg(), + new_var.clone().as_arg(), + using.is_await.as_arg(), + ], + ..Default::default() + } + .into(), + ), + definite: false, + }); + + decl.name = Pat::Ident(new_var.clone().into()); + } + + let var_decl = Box::new(VarDecl { + span: DUMMY_SP, + kind: VarDeclKind::Const, + declare: false, + decls: using.decls.take(), + ..Default::default() + }); - let mut body = vec![*n.body.take()]; + let mut body = vec![ + Stmt::Decl(Decl::Var(Box::new(inner_var_decl))), + *n.body.take(), + ]; self.wrap_with_try(state, &mut body); n.left = ForHead::VarDecl(var_decl); From 6137d6f0367d60eb743871caa4c9b17e42657b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 13:18:59 +0900 Subject: [PATCH 24/28] Remove wrong test --- .../exec-async/issue-8853.js | 40 ------------------- 1 file changed, 40 deletions(-) delete mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/issue-8853.js diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/issue-8853.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/issue-8853.js deleted file mode 100644 index 5876957eb2f1..000000000000 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/exec-async/issue-8853.js +++ /dev/null @@ -1,40 +0,0 @@ -const { deepStrictEqual } = require('node:assert') - -let i = 0 -let err -try { - await using _x1 = { - async [Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]() { - throw [1, ++i] - } - } - - await using _x2 = { - async [Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]() { - throw [2, ++i] - } - } - - await using _x3 = { - async [Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]() { - throw [3, ++i] - } - } - - await using _x4 = { - async [Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]() { - throw [4, ++i] - } - } - - throw [5, ++i] -} catch (e) { - err = e -} - -console.log(err) -deepStrictEqual(err.suppressed, [1, 5]) -deepStrictEqual(err.error.suppressed, [2, 4]) -deepStrictEqual(err.error.error.suppressed, [3, 3]) -deepStrictEqual(err.error.error.error.suppressed, [4, 2]) -deepStrictEqual(err.error.error.error.error, [5, 1]) \ No newline at end of file From e66aa1f6ac5001b167a283941391fd7b7043af73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 13:19:04 +0900 Subject: [PATCH 25/28] Update test refs --- .../integration/async-to-generator/output.js | 35 +++++---- .../source-maps/block/output.js | 24 ++++-- .../source-maps/for-of/output.js | 25 ++++-- .../source-maps/switch/output.js | 49 ++++++++---- .../source-maps/top-level/output.mjs | 24 +++--- .../transform-await/mixed/output.js | 21 +++++ .../only-using-await/output.js | 21 +++++ .../transform-await/switch/output.js | 38 ++++++++++ .../transform-sync/bare-block/output.js | 24 ++++-- .../transform-sync/for-await-head/output.js | 18 +++++ .../transform-sync/for-head/output.js | 25 ++++-- .../transform-sync/function-body/output.js | 24 +++--- .../transform-sync/if-body/output.js | 24 ++++-- .../transform-sync/multiple-nested/output.js | 76 ++++++++++++------- .../multiple-same-level/output.js | 37 +++++---- .../transform-sync/static-block/output.js | 26 ++++--- .../transform-sync/switch/output.js | 49 ++++++++---- .../await-or-not-preserved/output.mjs | 24 ++++-- .../hoisting-default-clas-anon/output.mjs | 22 ++++-- .../hoisting-default-class/output.mjs | 22 ++++-- .../hoisting-default-expr/output.mjs | 21 +++-- .../hoisting-default-fn-anon/output.mjs | 20 +++-- .../hoisting-default-fn/output.mjs | 20 +++-- .../transform-top-level/hoisting/output.mjs | 54 +++++++------ 24 files changed, 497 insertions(+), 226 deletions(-) create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/output.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/output.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/output.js create mode 100644 crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-await-head/output.js diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/output.js index 1848ab20f14f..7ea4e7afe729 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/output.js @@ -1,18 +1,21 @@ -function fn() { - return _fn.apply(this, arguments); -} -function _fn() { - _fn = babelHelpers.asyncToGenerator(function* () { - yield 0; - try { - var _usingCtx = babelHelpers.usingCtx(); - const x = _usingCtx.a(y); - yield 1; - } catch (_) { - _usingCtx.e = _; - } finally { - yield _usingCtx.d(); +async function fn() { + await 0; + { + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const x = _ts_add_disposable_resource(env, y, true); + ; + await 1; + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + const result = _ts_dispose_resources(env); + if (result) await result; + } } - }); - return _fn.apply(this, arguments); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/output.js index 2baa347eda5b..a2524db313bb 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/output.js @@ -1,9 +1,17 @@ -try { - var _usingCtx = babelHelpers.usingCtx(); - const x = _usingCtx.u(fn()); - doSomethingWith(x); -} catch (_) { - _usingCtx.e = _; -} finally { - _usingCtx.d(); +{ + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const x = _ts_add_disposable_resource(env, fn(), false); + ; + doSomethingWith(x); + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/output.js index 007a76d4d375..56e0c3940fb1 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/for-of/output.js @@ -1,9 +1,18 @@ -for (const _x of it) try { - var _usingCtx = babelHelpers.usingCtx(); - const x = _usingCtx.u(_x); - doSomethingWith(x); -} catch (_) { - _usingCtx.e = _; -} finally { - _usingCtx.d(); +for (const _ of it){ + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const x = _ts_add_disposable_resource(env, _, false); + { + doSomethingWith(x); + } + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/output.js index 17ccc0da5a6b..8129924e0ee2 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/output.js @@ -1,18 +1,37 @@ function f() { - try { - var _usingCtx = babelHelpers.usingCtx(); - switch (v) { - case 0: - const x = _usingCtx.u(0); - break; - default: - const y = _usingCtx.u(1); - break; + switch(v){ + case 0: + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const x = _ts_add_disposable_resource(env, 0, false); + ; + break; + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + _ts_dispose_resources(env); + } + default: + const env1 = { + stack: [], + error: void 0, + hasError: false + }; + try { + const y = _ts_add_disposable_resource(env1, 1, false); + ; + break; + } catch (e) { + env1.error = e; + env1.hasError = true; + } finally{ + _ts_dispose_resources(env1); + } } - } catch (_) { - _usingCtx.e = _; - } finally { - _usingCtx.d(); - } - ; + ; } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/output.mjs index 55eb974d39b1..605b85deb577 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/output.mjs @@ -1,11 +1,17 @@ +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = babelHelpers.usingCtx(); - before; - var x = _usingCtx.u(fn()); - doSomethingWith(x); - after; -} catch (_) { - _usingCtx.e = _; -} finally { - _usingCtx.d(); + before; + const x = _ts_add_disposable_resource(env, fn(), false); + ; + doSomethingWith(x); + after; +} catch (e) { + env.error = e; + env.hasError = true; +} finally{ + _ts_dispose_resources(env); } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/output.js new file mode 100644 index 000000000000..afbfd33fd0bf --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/output.js @@ -0,0 +1,21 @@ +{ + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const a = _ts_add_disposable_resource(env, 1, false); + ; + const b = _ts_add_disposable_resource(env, 2, true); + ; + const c = _ts_add_disposable_resource(env, 3, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + const result = _ts_dispose_resources(env); + if (result) await result; + } +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/output.js new file mode 100644 index 000000000000..2f5441a4e83a --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/output.js @@ -0,0 +1,21 @@ +{ + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const x = _ts_add_disposable_resource(env, obj, true); + ; + stmt; + const y = _ts_add_disposable_resource(env, obj, true), z = _ts_add_disposable_resource(env, obj, true); + ; + doSomethingWith(x, y); + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + const result = _ts_dispose_resources(env); + if (result) await result; + } +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/output.js new file mode 100644 index 000000000000..b9d99eae1372 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/output.js @@ -0,0 +1,38 @@ +async function f() { + switch(v){ + case 0: + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const x = _ts_add_disposable_resource(env, 0, true); + ; + break; + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + const result = _ts_dispose_resources(env); + if (result) await result; + } + default: + const env1 = { + stack: [], + error: void 0, + hasError: false + }; + try { + const y = _ts_add_disposable_resource(env1, 1, true); + ; + break; + } catch (e) { + env1.error = e; + env1.hasError = true; + } finally{ + const result = _ts_dispose_resources(env1); + if (result) await result; + } + } +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/bare-block/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/bare-block/output.js index 393c4ab1b128..cf9feb07ec12 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/bare-block/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/bare-block/output.js @@ -1,9 +1,17 @@ -try { - var _usingCtx = babelHelpers.usingCtx(); - const x = _usingCtx.u(obj); - doSomethingWith(x); -} catch (_) { - _usingCtx.e = _; -} finally { - _usingCtx.d(); +{ + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const x = _ts_add_disposable_resource(env, obj, false); + ; + doSomethingWith(x); + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-await-head/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-await-head/output.js new file mode 100644 index 000000000000..632232797195 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-await-head/output.js @@ -0,0 +1,18 @@ +for await (const _ of y){ + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const x = _ts_add_disposable_resource(env, _, false); + { + doSomethingWith(x); + } + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + _ts_dispose_resources(env); + } +} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-head/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-head/output.js index 45feb156198f..b26ea9acf511 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-head/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/for-head/output.js @@ -1,9 +1,18 @@ -for (const _x of y) try { - var _usingCtx = babelHelpers.usingCtx(); - const x = _usingCtx.u(_x); - doSomethingWith(x); -} catch (_) { - _usingCtx.e = _; -} finally { - _usingCtx.d(); +for (const _ of y){ + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const x = _ts_add_disposable_resource(env, _, false); + { + doSomethingWith(x); + } + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/function-body/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/function-body/output.js index feec5c626618..6f0533a0174c 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/function-body/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/function-body/output.js @@ -1,11 +1,17 @@ function fn() { - try { - var _usingCtx = babelHelpers.usingCtx(); - const x = _usingCtx.u(obj); - return doSomethingWith(x); - } catch (_) { - _usingCtx.e = _; - } finally { - _usingCtx.d(); - } + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const x = _ts_add_disposable_resource(env, obj, false); + ; + return doSomethingWith(x); + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/if-body/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/if-body/output.js index bc9964c1f9f1..0cc69839bee6 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/if-body/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/if-body/output.js @@ -1,9 +1,17 @@ -if (test) try { - var _usingCtx = babelHelpers.usingCtx(); - const x = _usingCtx.u(obj); - doSomethingWith(x); -} catch (_) { - _usingCtx.e = _; -} finally { - _usingCtx.d(); +if (test) { + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const x = _ts_add_disposable_resource(env, obj, false); + ; + doSomethingWith(x); + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-nested/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-nested/output.js index a95315682dc1..6d0283026a4d 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-nested/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-nested/output.js @@ -1,28 +1,50 @@ -try { - var _usingCtx = babelHelpers.usingCtx(); - const x = _usingCtx.u(obj); - try { - var _usingCtx2 = babelHelpers.usingCtx(); - const y = _usingCtx2.u(call(() => { - try { - var _usingCtx3 = babelHelpers.usingCtx(); - const z = _usingCtx3.u(obj); - return z; - } catch (_) { - _usingCtx3.e = _; - } finally { - _usingCtx3.d(); - } - })); - stmt; - } catch (_) { - _usingCtx2.e = _; - } finally { - _usingCtx2.d(); - } - stmt; -} catch (_) { - _usingCtx.e = _; -} finally { - _usingCtx.d(); +{ + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const x = _ts_add_disposable_resource(env, obj, false); + ; + { + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const y = _ts_add_disposable_resource(env, call(()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const z = _ts_add_disposable_resource(env, obj, false); + ; + return z; + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + _ts_dispose_resources(env); + } + }), false); + ; + stmt; + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + _ts_dispose_resources(env); + } + } + stmt; + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-same-level/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-same-level/output.js index 98d674368c43..b665392b9b36 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-same-level/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-same-level/output.js @@ -1,15 +1,24 @@ -try { - var _usingCtx = babelHelpers.usingCtx(); - stmt; - const x = _usingCtx.u(obj); - stmt; - const y = _usingCtx.u(obj), - z = _usingCtx.u(obj); - stmt; - const w = _usingCtx.u(obj); - doSomethingWith(x, z); -} catch (_) { - _usingCtx.e = _; -} finally { - _usingCtx.d(); +{ + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + stmt; + const x = _ts_add_disposable_resource(env, obj, false); + ; + stmt; + const y = _ts_add_disposable_resource(env, obj, false), z = _ts_add_disposable_resource(env, obj, false); + ; + stmt; + const w = _ts_add_disposable_resource(env, obj, false); + ; + doSomethingWith(x, z); + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/static-block/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/static-block/output.js index ea4cdda72dbb..c36e33bfe7b7 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/static-block/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/static-block/output.js @@ -1,13 +1,19 @@ class A { - static { - try { - var _usingCtx = babelHelpers.usingCtx(); - const x = _usingCtx.u(y); - doSomethingWith(x); - } catch (_) { - _usingCtx.e = _; - } finally { - _usingCtx.d(); + static{ + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const x = _ts_add_disposable_resource(env, y, false); + ; + doSomethingWith(x); + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + _ts_dispose_resources(env); + } } - } } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/output.js index 17ccc0da5a6b..8129924e0ee2 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/output.js @@ -1,18 +1,37 @@ function f() { - try { - var _usingCtx = babelHelpers.usingCtx(); - switch (v) { - case 0: - const x = _usingCtx.u(0); - break; - default: - const y = _usingCtx.u(1); - break; + switch(v){ + case 0: + const env = { + stack: [], + error: void 0, + hasError: false + }; + try { + const x = _ts_add_disposable_resource(env, 0, false); + ; + break; + } catch (e) { + env.error = e; + env.hasError = true; + } finally{ + _ts_dispose_resources(env); + } + default: + const env1 = { + stack: [], + error: void 0, + hasError: false + }; + try { + const y = _ts_add_disposable_resource(env1, 1, false); + ; + break; + } catch (e) { + env1.error = e; + env1.hasError = true; + } finally{ + _ts_dispose_resources(env1); + } } - } catch (_) { - _usingCtx.e = _; - } finally { - _usingCtx.d(); - } - ; + ; } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/await-or-not-preserved/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/await-or-not-preserved/output.mjs index 465458a41c9d..e020f64d1ad7 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/await-or-not-preserved/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/await-or-not-preserved/output.mjs @@ -1,10 +1,18 @@ -export { x, y }; +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = babelHelpers.usingCtx(); - var x = _usingCtx.u(A); - var y = _usingCtx.a(B); -} catch (_) { - _usingCtx.e = _; -} finally { - await _usingCtx.d(); + const x = _ts_add_disposable_resource(env, A, false); + ; + const y = _ts_add_disposable_resource(env, B, true); + ; +} catch (e) { + env.error = e; + env.hasError = true; +} finally{ + const result = _ts_dispose_resources(env); + if (result) await result; } +export { x, y }; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-clas-anon/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-clas-anon/output.mjs index d3d22236cc69..38ecd583ef88 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-clas-anon/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-clas-anon/output.mjs @@ -1,10 +1,16 @@ -export { _default as default }; +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = babelHelpers.usingCtx(); - var x = _usingCtx.u(null); - var _default = class {}; -} catch (_) { - _usingCtx.e = _; -} finally { - _usingCtx.d(); + const x = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; +} finally{ + _ts_dispose_resources(env); +} +export default class { } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-class/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-class/output.mjs index 201fea1665e8..b50ee59781f7 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-class/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-class/output.mjs @@ -1,10 +1,16 @@ -export { C as default }; +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = babelHelpers.usingCtx(); - var x = _usingCtx.u(null); - var C = class {}; -} catch (_) { - _usingCtx.e = _; -} finally { - _usingCtx.d(); + const x = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; +} finally{ + _ts_dispose_resources(env); +} +export default class C { } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-expr/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-expr/output.mjs index 82344af039bd..80815fe04151 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-expr/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-expr/output.mjs @@ -1,10 +1,15 @@ -export { _default as default }; +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = babelHelpers.usingCtx(); - var x = _usingCtx.u(null); - var _default = doSomething(); -} catch (_) { - _usingCtx.e = _; -} finally { - _usingCtx.d(); + const x = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; +} finally{ + _ts_dispose_resources(env); } +export default doSomething(); diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn-anon/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn-anon/output.mjs index 0225d7d45c50..1bac2b983899 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn-anon/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn-anon/output.mjs @@ -1,9 +1,15 @@ -export default function fn() {} +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = babelHelpers.usingCtx(); - var x = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; -} finally { - _usingCtx.d(); + const x = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; +} finally{ + _ts_dispose_resources(env); } +export default function fn() {} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn/output.mjs index 0225d7d45c50..1bac2b983899 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn/output.mjs @@ -1,9 +1,15 @@ -export default function fn() {} +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = babelHelpers.usingCtx(); - var x = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; -} finally { - _usingCtx.d(); + const x = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; +} finally{ + _ts_dispose_resources(env); } +export default function fn() {} diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting/output.mjs index 50b3e4ee1bd8..e3878d4f3ccf 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting/output.mjs @@ -1,32 +1,36 @@ +const env = { + stack: [], + error: void 0, + hasError: false +}; +try { + function f() { + a; + B; + } + function h() { + b; + A; + } + doSomething(); + let c = 2; + class A { + } + const x = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; +} finally{ + _ts_dispose_resources(env); +} import { doSomething } from "somewhere"; export * from "somewhere else"; export * as ns from "somewhere else"; -function f() { - a; - B; -} -function h() { - b; - A; -} export function g() { - c; + c; } export { f }; -export { b }; -export { B }; -try { - var _usingCtx = babelHelpers.usingCtx(); - doSomething(); - var { - b - } = {}; - var c = 2; - var A = class {}; - var B = class {}; - var x = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; -} finally { - _usingCtx.d(); +export let { b } = {}; +export class B { } From 4a258b44b37cc4be27222386ef284360e89a5532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Thu, 17 Oct 2024 13:20:13 +0900 Subject: [PATCH 26/28] Create dull-shirts-judge.md --- .changeset/dull-shirts-judge.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/dull-shirts-judge.md diff --git a/.changeset/dull-shirts-judge.md b/.changeset/dull-shirts-judge.md new file mode 100644 index 000000000000..c7b7e71e310f --- /dev/null +++ b/.changeset/dull-shirts-judge.md @@ -0,0 +1,6 @@ +--- +swc_ecma_transforms_proposal: patch +swc_core: patch +--- + +fix(es/proposal): Call `asyncDispose` correctly From d5c79c83dc7e2ef6b098c020392facc0cccce36f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 14:20:50 +0900 Subject: [PATCH 27/28] Update test refs --- .../fixture/issues-8xxx/8020/output/1.js | 18 +- .../fixture/issues-8xxx/8629/output/1.js | 31 +- .../fixture/issues-8xxx/8629/output/2.js | 23 +- .../fixture/issues-8xxx/8774/output/index.js | 56 +- .../fixture/issues-8xxx/8895/output/1.js | 19 +- ...gDeclarations.1(target=es2015).1.normal.js | 402 +++++++---- ...eclarations.1(target=es2015).2.minified.js | 311 ++++++--- ...gDeclarations.1(target=es2017).1.normal.js | 402 +++++++---- ...eclarations.1(target=es2017).2.minified.js | 311 ++++++--- ...gDeclarations.1(target=es2022).1.normal.js | 402 +++++++---- ...eclarations.1(target=es2022).2.minified.js | 311 ++++++--- ...singDeclarations.1(target=es5).1.normal.js | 572 ++++++++++------ ...ngDeclarations.1(target=es5).2.minified.js | 327 +++++---- ...gDeclarations.1(target=esnext).1.normal.js | 402 +++++++---- ...eclarations.1(target=esnext).2.minified.js | 311 ++++++--- .../awaitUsingDeclarations.12.1.normal.js | 20 +- .../awaitUsingDeclarations.12.2.minified.js | 3 +- .../awaitUsingDeclarations.13.1.normal.js | 37 +- .../awaitUsingDeclarations.13.2.minified.js | 18 +- .../awaitUsingDeclarations.15.1.normal.js | 22 +- .../awaitUsingDeclarations.15.2.minified.js | 3 +- ...gDeclarations.2(target=es2015).1.normal.js | 24 +- ...eclarations.2(target=es2015).2.minified.js | 32 +- ...gDeclarations.2(target=es2017).1.normal.js | 24 +- ...eclarations.2(target=es2017).2.minified.js | 32 +- ...gDeclarations.2(target=es2022).1.normal.js | 24 +- ...eclarations.2(target=es2022).2.minified.js | 32 +- ...singDeclarations.2(target=es5).1.normal.js | 24 +- ...ngDeclarations.2(target=es5).2.minified.js | 22 +- ...gDeclarations.2(target=esnext).1.normal.js | 24 +- ...eclarations.2(target=esnext).2.minified.js | 32 +- ...gDeclarations.3(target=es2015).1.normal.js | 24 +- ...eclarations.3(target=es2015).2.minified.js | 32 +- ...gDeclarations.3(target=es2017).1.normal.js | 24 +- ...eclarations.3(target=es2017).2.minified.js | 32 +- ...gDeclarations.3(target=es2022).1.normal.js | 24 +- ...eclarations.3(target=es2022).2.minified.js | 32 +- ...singDeclarations.3(target=es5).1.normal.js | 22 +- ...ngDeclarations.3(target=es5).2.minified.js | 20 +- ...gDeclarations.3(target=esnext).1.normal.js | 24 +- ...eclarations.3(target=esnext).2.minified.js | 32 +- .../awaitUsingDeclarations.9.1.normal.js | 20 +- .../awaitUsingDeclarations.9.2.minified.js | 24 +- ...onsInForAwaitOf(target=es2015).1.normal.js | 20 +- ...sInForAwaitOf(target=es2015).2.minified.js | 3 +- ...onsInForAwaitOf(target=es2017).1.normal.js | 20 +- ...sInForAwaitOf(target=es2017).2.minified.js | 3 +- ...onsInForAwaitOf(target=es2022).1.normal.js | 20 +- ...sInForAwaitOf(target=es2022).2.minified.js | 3 +- ...ationsInForAwaitOf(target=es5).1.normal.js | 98 ++- ...ionsInForAwaitOf(target=es5).2.minified.js | 3 +- ...onsInForAwaitOf(target=esnext).1.normal.js | 20 +- ...sInForAwaitOf(target=esnext).2.minified.js | 3 +- ...ationsInForOf.1(target=es2015).1.normal.js | 20 +- ...ionsInForOf.1(target=es2015).2.minified.js | 3 +- ...ationsInForOf.1(target=es2017).1.normal.js | 20 +- ...ionsInForOf.1(target=es2017).2.minified.js | 3 +- ...ationsInForOf.1(target=es2022).1.normal.js | 20 +- ...ionsInForOf.1(target=es2022).2.minified.js | 3 +- ...larationsInForOf.1(target=es5).1.normal.js | 106 ++- ...rationsInForOf.1(target=es5).2.minified.js | 3 +- ...ationsInForOf.1(target=esnext).1.normal.js | 20 +- ...ionsInForOf.1(target=esnext).2.minified.js | 3 +- ...TopLevelOfModule.1(module=es6).1.normal.js | 37 +- ...pLevelOfModule.1(module=es6).2.minified.js | 30 +- ...LevelOfModule.1(module=system).1.normal.js | 43 +- ...velOfModule.1(module=system).2.minified.js | 38 +- ...gDeclarationsWithImportHelpers.1.normal.js | 20 +- ...eclarationsWithImportHelpers.2.minified.js | 3 +- ...gDeclarations.1(target=es2015).1.normal.js | 576 ++++++++++------ ...eclarations.1(target=es2015).2.minified.js | 330 +++++---- ...gDeclarations.1(target=es2017).1.normal.js | 576 ++++++++++------ ...eclarations.1(target=es2017).2.minified.js | 330 +++++---- ...gDeclarations.1(target=es2022).1.normal.js | 576 ++++++++++------ ...eclarations.1(target=es2022).2.minified.js | 458 ++++++++----- ...singDeclarations.1(target=es5).1.normal.js | 642 ++++++++++++------ ...ngDeclarations.1(target=es5).2.minified.js | 257 ++++--- ...gDeclarations.1(target=esnext).1.normal.js | 576 ++++++++++------ ...eclarations.1(target=esnext).2.minified.js | 458 ++++++++----- .../usingDeclarations.11.1.normal.js | 83 ++- .../usingDeclarations.11.2.minified.js | 3 +- .../usingDeclarations.12.1.normal.js | 21 +- .../usingDeclarations.12.2.minified.js | 3 +- .../usingDeclarations.14.1.normal.js | 19 +- .../usingDeclarations.14.2.minified.js | 17 +- .../usingDeclarations.15.1.normal.js | 21 +- .../usingDeclarations.15.2.minified.js | 19 +- ...gDeclarations.2(target=es2015).1.normal.js | 23 +- ...eclarations.2(target=es2015).2.minified.js | 31 +- ...gDeclarations.2(target=es2017).1.normal.js | 23 +- ...eclarations.2(target=es2017).2.minified.js | 31 +- ...gDeclarations.2(target=es2022).1.normal.js | 23 +- ...eclarations.2(target=es2022).2.minified.js | 31 +- ...singDeclarations.2(target=es5).1.normal.js | 19 +- ...ngDeclarations.2(target=es5).2.minified.js | 17 +- ...gDeclarations.2(target=esnext).1.normal.js | 23 +- ...eclarations.2(target=esnext).2.minified.js | 31 +- ...gDeclarations.3(target=es2015).1.normal.js | 23 +- ...eclarations.3(target=es2015).2.minified.js | 31 +- ...gDeclarations.3(target=es2017).1.normal.js | 23 +- ...eclarations.3(target=es2017).2.minified.js | 31 +- ...gDeclarations.3(target=es2022).1.normal.js | 23 +- ...eclarations.3(target=es2022).2.minified.js | 31 +- ...singDeclarations.3(target=es5).1.normal.js | 19 +- ...ngDeclarations.3(target=es5).2.minified.js | 17 +- ...gDeclarations.3(target=esnext).1.normal.js | 23 +- ...eclarations.3(target=esnext).2.minified.js | 31 +- .../usingDeclarations.9.1.normal.js | 19 +- .../usingDeclarations.9.2.minified.js | 23 +- ...gDeclarationsDeclarationEmit.1.1.normal.js | 31 +- ...eclarationsDeclarationEmit.1.2.minified.js | 21 +- ...gDeclarationsDeclarationEmit.2.1.normal.js | 27 +- ...eclarationsDeclarationEmit.2.2.minified.js | 22 +- ...onsInForAwaitOf(target=es2015).1.normal.js | 19 +- ...sInForAwaitOf(target=es2015).2.minified.js | 3 +- ...onsInForAwaitOf(target=es2017).1.normal.js | 19 +- ...sInForAwaitOf(target=es2017).2.minified.js | 3 +- ...onsInForAwaitOf(target=es2022).1.normal.js | 19 +- ...sInForAwaitOf(target=es2022).2.minified.js | 3 +- ...ationsInForAwaitOf(target=es5).1.normal.js | 21 +- ...ionsInForAwaitOf(target=es5).2.minified.js | 3 +- ...onsInForAwaitOf(target=esnext).1.normal.js | 19 +- ...sInForAwaitOf(target=esnext).2.minified.js | 3 +- ...ationsInForOf.1(target=es2015).1.normal.js | 19 +- ...ionsInForOf.1(target=es2015).2.minified.js | 24 +- ...ationsInForOf.1(target=es2017).1.normal.js | 19 +- ...ionsInForOf.1(target=es2017).2.minified.js | 24 +- ...ationsInForOf.1(target=es2022).1.normal.js | 19 +- ...ionsInForOf.1(target=es2022).2.minified.js | 24 +- ...larationsInForOf.1(target=es5).1.normal.js | 19 +- ...rationsInForOf.1(target=es5).2.minified.js | 17 +- ...ationsInForOf.1(target=esnext).1.normal.js | 19 +- ...ionsInForOf.1(target=esnext).2.minified.js | 24 +- ...TopLevelOfModule.1(module=amd).1.normal.js | 37 +- ...pLevelOfModule.1(module=amd).2.minified.js | 31 +- ...velOfModule.1(module=commonjs).1.normal.js | 35 +- ...lOfModule.1(module=commonjs).2.minified.js | 27 +- ...TopLevelOfModule.1(module=es6).1.normal.js | 36 +- ...pLevelOfModule.1(module=es6).2.minified.js | 29 +- ...LevelOfModule.1(module=system).1.normal.js | 42 +- ...velOfModule.1(module=system).2.minified.js | 37 +- ...TopLevelOfModule.2(module=amd).1.normal.js | 23 +- ...pLevelOfModule.2(module=amd).2.minified.js | 20 +- ...velOfModule.2(module=commonjs).1.normal.js | 21 +- ...lOfModule.2(module=commonjs).2.minified.js | 16 +- ...TopLevelOfModule.3(module=amd).1.normal.js | 23 +- ...pLevelOfModule.3(module=amd).2.minified.js | 22 +- ...velOfModule.3(module=commonjs).1.normal.js | 21 +- ...lOfModule.3(module=commonjs).2.minified.js | 18 +- ...TopLevelOfModule.3(module=es6).1.normal.js | 23 +- ...pLevelOfModule.3(module=es6).2.minified.js | 20 +- ...LevelOfModule.3(module=system).1.normal.js | 30 +- ...velOfModule.3(module=system).2.minified.js | 28 +- ...gDeclarationsWithImportHelpers.1.normal.js | 19 +- ...eclarationsWithImportHelpers.2.minified.js | 23 +- ...module=commonjs,target=es2015).1.normal.js | 19 +- ...dule=commonjs,target=es2015).2.minified.js | 15 +- ....1(module=commonjs,target=es5).1.normal.js | 19 +- ...(module=commonjs,target=es5).2.minified.js | 15 +- ...module=commonjs,target=esnext).1.normal.js | 19 +- ...dule=commonjs,target=esnext).2.minified.js | 15 +- ...rs.1(module=es6,target=es2015).1.normal.js | 19 +- ....1(module=es6,target=es2015).2.minified.js | 17 +- ...ators.1(module=es6,target=es5).1.normal.js | 19 +- ...ors.1(module=es6,target=es5).2.minified.js | 17 +- ...rs.1(module=es6,target=esnext).1.normal.js | 19 +- ....1(module=es6,target=esnext).2.minified.js | 17 +- ...1(module=system,target=es2015).1.normal.js | 28 +- ...module=system,target=es2015).2.minified.js | 26 +- ...rs.1(module=system,target=es5).1.normal.js | 28 +- ....1(module=system,target=es5).2.minified.js | 26 +- ...1(module=system,target=esnext).1.normal.js | 28 +- ...module=system,target=esnext).2.minified.js | 26 +- ...module=commonjs,target=es2015).1.normal.js | 23 +- ...dule=commonjs,target=es2015).2.minified.js | 18 +- ...10(module=commonjs,target=es5).1.normal.js | 27 +- ...(module=commonjs,target=es5).2.minified.js | 20 +- ...module=commonjs,target=esnext).1.normal.js | 23 +- ...dule=commonjs,target=esnext).2.minified.js | 18 +- ...s.10(module=es6,target=es2015).1.normal.js | 24 +- ...10(module=es6,target=es2015).2.minified.js | 21 +- ...tors.10(module=es6,target=es5).1.normal.js | 29 +- ...rs.10(module=es6,target=es5).2.minified.js | 22 +- ...s.10(module=es6,target=esnext).1.normal.js | 24 +- ...10(module=es6,target=esnext).2.minified.js | 21 +- ...0(module=system,target=es2015).1.normal.js | 33 +- ...module=system,target=es2015).2.minified.js | 31 +- ...s.10(module=system,target=es5).1.normal.js | 36 +- ...10(module=system,target=es5).2.minified.js | 31 +- ...0(module=system,target=esnext).1.normal.js | 33 +- ...module=system,target=esnext).2.minified.js | 31 +- ...module=commonjs,target=es2015).1.normal.js | 19 +- ...dule=commonjs,target=es2015).2.minified.js | 15 +- ...11(module=commonjs,target=es5).1.normal.js | 19 +- ...(module=commonjs,target=es5).2.minified.js | 16 +- ...module=commonjs,target=esnext).1.normal.js | 19 +- ...dule=commonjs,target=esnext).2.minified.js | 15 +- ...s.11(module=es6,target=es2015).1.normal.js | 21 +- ...11(module=es6,target=es2015).2.minified.js | 17 +- ...tors.11(module=es6,target=es5).1.normal.js | 21 +- ...rs.11(module=es6,target=es5).2.minified.js | 18 +- ...s.11(module=es6,target=esnext).1.normal.js | 21 +- ...11(module=es6,target=esnext).2.minified.js | 17 +- ...1(module=system,target=es2015).1.normal.js | 28 +- ...module=system,target=es2015).2.minified.js | 26 +- ...s.11(module=system,target=es5).1.normal.js | 28 +- ...11(module=system,target=es5).2.minified.js | 27 +- ...1(module=system,target=esnext).1.normal.js | 28 +- ...module=system,target=esnext).2.minified.js | 26 +- ...module=commonjs,target=es2015).1.normal.js | 19 +- ...dule=commonjs,target=es2015).2.minified.js | 15 +- ...12(module=commonjs,target=es5).1.normal.js | 19 +- ...(module=commonjs,target=es5).2.minified.js | 16 +- ...module=commonjs,target=esnext).1.normal.js | 19 +- ...dule=commonjs,target=esnext).2.minified.js | 15 +- ...s.12(module=es6,target=es2015).1.normal.js | 21 +- ...12(module=es6,target=es2015).2.minified.js | 17 +- ...tors.12(module=es6,target=es5).1.normal.js | 21 +- ...rs.12(module=es6,target=es5).2.minified.js | 18 +- ...s.12(module=es6,target=esnext).1.normal.js | 21 +- ...12(module=es6,target=esnext).2.minified.js | 17 +- ...2(module=system,target=es2015).1.normal.js | 28 +- ...module=system,target=es2015).2.minified.js | 26 +- ...s.12(module=system,target=es5).1.normal.js | 28 +- ...12(module=system,target=es5).2.minified.js | 27 +- ...2(module=system,target=esnext).1.normal.js | 28 +- ...module=system,target=esnext).2.minified.js | 26 +- ...module=commonjs,target=es2015).1.normal.js | 27 +- ...dule=commonjs,target=es2015).2.minified.js | 22 +- ....2(module=commonjs,target=es5).1.normal.js | 31 +- ...(module=commonjs,target=es5).2.minified.js | 24 +- ...module=commonjs,target=esnext).1.normal.js | 27 +- ...dule=commonjs,target=esnext).2.minified.js | 22 +- ...rs.2(module=es6,target=es2015).1.normal.js | 26 +- ....2(module=es6,target=es2015).2.minified.js | 23 +- ...ators.2(module=es6,target=es5).1.normal.js | 30 +- ...ors.2(module=es6,target=es5).2.minified.js | 25 +- ...rs.2(module=es6,target=esnext).1.normal.js | 26 +- ....2(module=es6,target=esnext).2.minified.js | 23 +- ...2(module=system,target=es2015).1.normal.js | 37 +- ...module=system,target=es2015).2.minified.js | 33 +- ...rs.2(module=system,target=es5).1.normal.js | 42 +- ....2(module=system,target=es5).2.minified.js | 37 +- ...2(module=system,target=esnext).1.normal.js | 37 +- ...module=system,target=esnext).2.minified.js | 33 +- ...module=commonjs,target=es2015).1.normal.js | 23 +- ...dule=commonjs,target=es2015).2.minified.js | 20 +- ....3(module=commonjs,target=es5).1.normal.js | 27 +- ...(module=commonjs,target=es5).2.minified.js | 22 +- ...module=commonjs,target=esnext).1.normal.js | 23 +- ...dule=commonjs,target=esnext).2.minified.js | 20 +- ...rs.3(module=es6,target=es2015).1.normal.js | 24 +- ....3(module=es6,target=es2015).2.minified.js | 23 +- ...ators.3(module=es6,target=es5).1.normal.js | 29 +- ...ors.3(module=es6,target=es5).2.minified.js | 24 +- ...rs.3(module=es6,target=esnext).1.normal.js | 24 +- ....3(module=es6,target=esnext).2.minified.js | 23 +- ...3(module=system,target=es2015).1.normal.js | 33 +- ...module=system,target=es2015).2.minified.js | 33 +- ...rs.3(module=system,target=es5).1.normal.js | 36 +- ....3(module=system,target=es5).2.minified.js | 33 +- ...3(module=system,target=esnext).1.normal.js | 33 +- ...module=system,target=esnext).2.minified.js | 33 +- ...module=commonjs,target=es2015).1.normal.js | 23 +- ...dule=commonjs,target=es2015).2.minified.js | 20 +- ....4(module=commonjs,target=es5).1.normal.js | 27 +- ...(module=commonjs,target=es5).2.minified.js | 22 +- ...module=commonjs,target=esnext).1.normal.js | 23 +- ...dule=commonjs,target=esnext).2.minified.js | 20 +- ...rs.4(module=es6,target=es2015).1.normal.js | 24 +- ....4(module=es6,target=es2015).2.minified.js | 23 +- ...ators.4(module=es6,target=es5).1.normal.js | 29 +- ...ors.4(module=es6,target=es5).2.minified.js | 24 +- ...rs.4(module=es6,target=esnext).1.normal.js | 24 +- ....4(module=es6,target=esnext).2.minified.js | 23 +- ...4(module=system,target=es2015).1.normal.js | 33 +- ...module=system,target=es2015).2.minified.js | 33 +- ...rs.4(module=system,target=es5).1.normal.js | 36 +- ....4(module=system,target=es5).2.minified.js | 33 +- ...4(module=system,target=esnext).1.normal.js | 33 +- ...module=system,target=esnext).2.minified.js | 33 +- ...module=commonjs,target=es2015).1.normal.js | 19 +- ...dule=commonjs,target=es2015).2.minified.js | 15 +- ....5(module=commonjs,target=es5).1.normal.js | 19 +- ...(module=commonjs,target=es5).2.minified.js | 15 +- ...module=commonjs,target=esnext).1.normal.js | 19 +- ...dule=commonjs,target=esnext).2.minified.js | 15 +- ...rs.5(module=es6,target=es2015).1.normal.js | 21 +- ....5(module=es6,target=es2015).2.minified.js | 17 +- ...ators.5(module=es6,target=es5).1.normal.js | 21 +- ...ors.5(module=es6,target=es5).2.minified.js | 17 +- ...rs.5(module=es6,target=esnext).1.normal.js | 21 +- ....5(module=es6,target=esnext).2.minified.js | 17 +- ...5(module=system,target=es2015).1.normal.js | 28 +- ...module=system,target=es2015).2.minified.js | 26 +- ...rs.5(module=system,target=es5).1.normal.js | 28 +- ....5(module=system,target=es5).2.minified.js | 26 +- ...5(module=system,target=esnext).1.normal.js | 28 +- ...module=system,target=esnext).2.minified.js | 26 +- ...module=commonjs,target=es2015).1.normal.js | 19 +- ...dule=commonjs,target=es2015).2.minified.js | 15 +- ....6(module=commonjs,target=es5).1.normal.js | 19 +- ...(module=commonjs,target=es5).2.minified.js | 15 +- ...module=commonjs,target=esnext).1.normal.js | 19 +- ...dule=commonjs,target=esnext).2.minified.js | 15 +- ...rs.6(module=es6,target=es2015).1.normal.js | 21 +- ....6(module=es6,target=es2015).2.minified.js | 17 +- ...ators.6(module=es6,target=es5).1.normal.js | 21 +- ...ors.6(module=es6,target=es5).2.minified.js | 17 +- ...rs.6(module=es6,target=esnext).1.normal.js | 21 +- ....6(module=es6,target=esnext).2.minified.js | 17 +- ...6(module=system,target=es2015).1.normal.js | 28 +- ...module=system,target=es2015).2.minified.js | 26 +- ...rs.6(module=system,target=es5).1.normal.js | 28 +- ....6(module=system,target=es5).2.minified.js | 26 +- ...6(module=system,target=esnext).1.normal.js | 28 +- ...module=system,target=esnext).2.minified.js | 26 +- ...module=commonjs,target=es2015).1.normal.js | 19 +- ...dule=commonjs,target=es2015).2.minified.js | 15 +- ....7(module=commonjs,target=es5).1.normal.js | 19 +- ...(module=commonjs,target=es5).2.minified.js | 16 +- ...module=commonjs,target=esnext).1.normal.js | 19 +- ...dule=commonjs,target=esnext).2.minified.js | 15 +- ...rs.7(module=es6,target=es2015).1.normal.js | 19 +- ....7(module=es6,target=es2015).2.minified.js | 17 +- ...ators.7(module=es6,target=es5).1.normal.js | 19 +- ...ors.7(module=es6,target=es5).2.minified.js | 18 +- ...rs.7(module=es6,target=esnext).1.normal.js | 19 +- ....7(module=es6,target=esnext).2.minified.js | 17 +- ...7(module=system,target=es2015).1.normal.js | 28 +- ...module=system,target=es2015).2.minified.js | 26 +- ...rs.7(module=system,target=es5).1.normal.js | 28 +- ....7(module=system,target=es5).2.minified.js | 27 +- ...7(module=system,target=esnext).1.normal.js | 28 +- ...module=system,target=esnext).2.minified.js | 26 +- ...module=commonjs,target=es2015).1.normal.js | 27 +- ...dule=commonjs,target=es2015).2.minified.js | 23 +- ....8(module=commonjs,target=es5).1.normal.js | 31 +- ...(module=commonjs,target=es5).2.minified.js | 24 +- ...module=commonjs,target=esnext).1.normal.js | 27 +- ...dule=commonjs,target=esnext).2.minified.js | 23 +- ...rs.8(module=es6,target=es2015).1.normal.js | 26 +- ....8(module=es6,target=es2015).2.minified.js | 24 +- ...ators.8(module=es6,target=es5).1.normal.js | 30 +- ...ors.8(module=es6,target=es5).2.minified.js | 25 +- ...rs.8(module=es6,target=esnext).1.normal.js | 26 +- ....8(module=es6,target=esnext).2.minified.js | 24 +- ...8(module=system,target=es2015).1.normal.js | 37 +- ...module=system,target=es2015).2.minified.js | 32 +- ...rs.8(module=system,target=es5).1.normal.js | 42 +- ....8(module=system,target=es5).2.minified.js | 35 +- ...8(module=system,target=esnext).1.normal.js | 37 +- ...module=system,target=esnext).2.minified.js | 32 +- ...module=commonjs,target=es2015).1.normal.js | 23 +- ...dule=commonjs,target=es2015).2.minified.js | 18 +- ....9(module=commonjs,target=es5).1.normal.js | 27 +- ...(module=commonjs,target=es5).2.minified.js | 20 +- ...module=commonjs,target=esnext).1.normal.js | 23 +- ...dule=commonjs,target=esnext).2.minified.js | 18 +- ...rs.9(module=es6,target=es2015).1.normal.js | 24 +- ....9(module=es6,target=es2015).2.minified.js | 21 +- ...ators.9(module=es6,target=es5).1.normal.js | 29 +- ...ors.9(module=es6,target=es5).2.minified.js | 22 +- ...rs.9(module=es6,target=esnext).1.normal.js | 24 +- ....9(module=es6,target=esnext).2.minified.js | 21 +- ...9(module=system,target=es2015).1.normal.js | 33 +- ...module=system,target=es2015).2.minified.js | 31 +- ...rs.9(module=system,target=es5).1.normal.js | 36 +- ....9(module=system,target=es5).2.minified.js | 31 +- ...9(module=system,target=esnext).1.normal.js | 33 +- ...module=system,target=esnext).2.minified.js | 31 +- 371 files changed, 10913 insertions(+), 5957 deletions(-) diff --git a/crates/swc/tests/fixture/issues-8xxx/8020/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8020/output/1.js index fcc30418386a..e36a754a6633 100644 --- a/crates/swc/tests/fixture/issues-8xxx/8020/output/1.js +++ b/crates/swc/tests/fixture/issues-8xxx/8020/output/1.js @@ -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); } diff --git a/crates/swc/tests/fixture/issues-8xxx/8629/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8629/output/1.js index 65041b92b814..a73d3fd8bd2e 100644 --- a/crates/swc/tests/fixture/issues-8xxx/8629/output/1.js +++ b/crates/swc/tests/fixture/issues-8xxx/8629/output/1.js @@ -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 }; diff --git a/crates/swc/tests/fixture/issues-8xxx/8629/output/2.js b/crates/swc/tests/fixture/issues-8xxx/8629/output/2.js index 3eb77110e5a1..ed8c2d9df92c 100644 --- a/crates/swc/tests/fixture/issues-8xxx/8629/output/2.js +++ b/crates/swc/tests/fixture/issues-8xxx/8629/output/2.js @@ -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; diff --git a/crates/swc/tests/fixture/issues-8xxx/8774/output/index.js b/crates/swc/tests/fixture/issues-8xxx/8774/output/index.js index 4f58057923ec..466a4c70680a 100644 --- a/crates/swc/tests/fixture/issues-8xxx/8774/output/index.js +++ b/crates/swc/tests/fixture/issues-8xxx/8774/output/index.js @@ -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] () { @@ -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(); diff --git a/crates/swc/tests/fixture/issues-8xxx/8895/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8895/output/1.js index 498171479403..59bcd3da5aba 100644 --- a/crates/swc/tests/fixture/issues-8xxx/8895/output/1.js +++ b/crates/swc/tests/fixture/issues-8xxx/8895/output/1.js @@ -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'; @@ -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); } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2015).1.normal.js index d6cdfc7f1eda..91a893267356 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2015).1.normal.js @@ -2,31 +2,44 @@ 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"; +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 d1 = _usingCtx.a({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); + }, true); + ; function af() { return _af.apply(this, arguments); } function _af() { _af = _async_to_generator(function*() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d3 = _usingCtx.a({ + const d3 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); + }, true); + ; yield null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - yield _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) yield result; } }); return _af.apply(this, arguments); @@ -36,36 +49,50 @@ try { } function _ag() { _ag = _wrap_async_generator(function*() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d5 = _usingCtx.a({ + const d5 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); + }, true); + ; yield; yield _await_async_generator(null); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - yield _await_async_generator(_usingCtx.d()); + const result = _ts_dispose_resources(env); + if (result) yield _await_async_generator(result); } }); return _ag.apply(this, arguments); } const a = /*#__PURE__*/ function() { var _ref = _async_to_generator(function*() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d6 = _usingCtx.a({ + const d6 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - yield _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) yield result; } }); return function a() { @@ -75,259 +102,380 @@ try { class C1 { am() { return _async_to_generator(function*() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d13 = _usingCtx.a({ + const d13 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); + }, true); + ; yield null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - yield _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) yield result; } })(); } ag() { return _wrap_async_generator(function*() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d15 = _usingCtx.a({ + const d15 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); + }, true); + ; yield; yield _await_async_generator(null); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - yield _await_async_generator(_usingCtx.d()); + const result = _ts_dispose_resources(env); + if (result) yield _await_async_generator(result); } })(); } constructor(){ this.a = /*#__PURE__*/ _async_to_generator(function*() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d7 = _usingCtx.a({ + const d7 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - yield _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) yield result; } }); } } { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx1 = _using_ctx(); - const d19 = _usingCtx1.a({ + const d19 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); - } catch (_) { - _usingCtx1.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx1.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } switch(Math.random()){ case 0: + const env1 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx2 = _using_ctx(); - const d20 = _usingCtx2.a({ + const d20 = _ts_add_disposable_resource(env1, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); + }, true); + ; break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e; + env1.hasError = true; } finally{ - await _usingCtx2.d(); + const result = _ts_dispose_resources(env1); + if (result) await result; } case 1: + const env2 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx3 = _using_ctx(); - const d21 = _usingCtx3.a({ + const d21 = _ts_add_disposable_resource(env2, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); + }, true); + ; break; - } catch (_) { - _usingCtx3.e = _; + } catch (e) { + env2.error = e; + env2.hasError = true; } finally{ - await _usingCtx3.d(); + const result = _ts_dispose_resources(env2); + if (result) await result; } } if (true) switch(0){ case 0: + const env3 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx4 = _using_ctx(); - const d22 = _usingCtx4.a({ + const d22 = _ts_add_disposable_resource(env3, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); + }, true); + ; break; - } catch (_) { - _usingCtx4.e = _; + } catch (e) { + env3.error = e; + env3.hasError = true; } finally{ - await _usingCtx4.d(); + const result = _ts_dispose_resources(env3); + if (result) await result; } } try { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx5 = _using_ctx(); - const d23 = _usingCtx5.a({ + const d23 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); - } catch (_) { - _usingCtx5.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx5.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } catch (e) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx6 = _using_ctx(); - const d24 = _usingCtx6.a({ + const d24 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); - } catch (_) { - _usingCtx6.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx6.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } finally{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx7 = _using_ctx(); - const d25 = _usingCtx7.a({ + const d25 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); - } catch (_) { - _usingCtx7.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx7.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } if (true) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx8 = _using_ctx(); - const d26 = _usingCtx8.a({ + const d26 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); - } catch (_) { - _usingCtx8.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx8.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } else { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx9 = _using_ctx(); - const d27 = _usingCtx9.a({ + const d27 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); - } catch (_) { - _usingCtx9.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx9.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } while(true){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx10 = _using_ctx(); - const d28 = _usingCtx10.a({ + const d28 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); + }, true); + ; break; - } catch (_) { - _usingCtx10.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx10.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } do { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx11 = _using_ctx(); - const d29 = _usingCtx11.a({ + const d29 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); + }, true); + ; break; - } catch (_) { - _usingCtx11.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx11.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }while (true) for(;;){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx12 = _using_ctx(); - const d30 = _usingCtx12.a({ + const d30 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); + }, true); + ; break; - } catch (_) { - _usingCtx12.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx12.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } for(const x in {}){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx13 = _using_ctx(); - const d31 = _usingCtx13.a({ + const d31 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); - } catch (_) { - _usingCtx13.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx13.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } for (const x of []){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx14 = _using_ctx(); - const d32 = _usingCtx14.a({ + const d32 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); - } catch (_) { - _usingCtx14.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx14.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; } export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2015).2.minified.js index e927492a1a0c..614b274872e0 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2015).2.minified.js @@ -2,156 +2,243 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; import "@swc/helpers/_/_await_async_generator"; import "@swc/helpers/_/_wrap_async_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.a({ + _ts_add_disposable_resource(env, { [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); - try { - var _usingCtx1 = _using_ctx(); - _usingCtx1.a({ - [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); - } catch (_) { - _usingCtx1.e = _; - } finally{ - await _usingCtx1.d(); + }, !0); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } switch(Math.random()){ case 0: + let env1 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx2 = _using_ctx(); - _usingCtx2.a({ + _ts_add_disposable_resource(env1, { [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); + }, !0); break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e, env1.hasError = !0; } finally{ - await _usingCtx2.d(); + let result = _ts_dispose_resources(env1); + result && await result; } case 1: + let env2 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx3 = _using_ctx(); - _usingCtx3.a({ + _ts_add_disposable_resource(env2, { [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); - } catch (_) { - _usingCtx3.e = _; + }, !0); + } catch (e) { + env2.error = e, env2.hasError = !0; } finally{ - await _usingCtx3.d(); + let result = _ts_dispose_resources(env2); + result && await result; } } - try { - var _usingCtx4 = _using_ctx(); - _usingCtx4.a({ - [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); - } catch (_) { - _usingCtx4.e = _; - } finally{ - await _usingCtx4.d(); + { + let env3 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env3, { + [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() + }, !0); + } catch (e) { + env3.error = e, env3.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env3); + result && await result; + } } try { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx5 = _using_ctx(); - _usingCtx5.a({ + _ts_add_disposable_resource(env, { [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); - } catch (_) { - _usingCtx5.e = _; + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx5.d(); + let result = _ts_dispose_resources(env); + result && await result; } } catch (e) { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx6 = _using_ctx(); - _usingCtx6.a({ + _ts_add_disposable_resource(env, { [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); - } catch (_) { - _usingCtx6.e = _; + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx6.d(); + let result = _ts_dispose_resources(env); + result && await result; } } finally{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx7 = _using_ctx(); - _usingCtx7.a({ + _ts_add_disposable_resource(env, { [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); - } catch (_) { - _usingCtx7.e = _; + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx7.d(); + let result = _ts_dispose_resources(env); + result && await result; } } - try { - var _usingCtx8 = _using_ctx(); - _usingCtx8.a({ - [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); - } catch (_) { - _usingCtx8.e = _; - } finally{ - await _usingCtx8.d(); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(;;)try { - var _usingCtx10 = _using_ctx(); - _usingCtx10.a({ - [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); - break; - } catch (_) { - _usingCtx10.e = _; - } finally{ - await _usingCtx10.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() + }, !0); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(;;)try { - var _usingCtx11 = _using_ctx(); - _usingCtx11.a({ - [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); - break; - } catch (_) { - _usingCtx11.e = _; - } finally{ - await _usingCtx11.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() + }, !0); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(;;)try { - var _usingCtx12 = _using_ctx(); - _usingCtx12.a({ - [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); - break; - } catch (_) { - _usingCtx12.e = _; - } finally{ - await _usingCtx12.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() + }, !0); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(let x in {})try { - var _usingCtx13 = _using_ctx(); - _usingCtx13.a({ - [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); - } catch (_) { - _usingCtx13.e = _; - } finally{ - await _usingCtx13.d(); + for(let x in {}){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for (let x of [])try { - var _usingCtx14 = _using_ctx(); - _usingCtx14.a({ - [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); - } catch (_) { - _usingCtx14.e = _; - } finally{ - await _usingCtx14.d(); + for (let x of []){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx.d(); + let result = _ts_dispose_resources(env); + result && await result; } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2017).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2017).1.normal.js index 4ff13560ef08..8459da7c90be 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2017).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2017).1.normal.js @@ -1,267 +1,415 @@ //// [awaitUsingDeclarations.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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 d1 = _usingCtx.a({ + const d1 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; async function af() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d3 = _usingCtx.a({ + const d3 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; await null; - } 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; } } async function* ag() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d5 = _usingCtx.a({ + const d5 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; yield; await null; - } 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; } } const a = async ()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d6 = _usingCtx.a({ + const d6 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }; class C1 { async am() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d13 = _usingCtx.a({ + const d13 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; await null; - } 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; } } async *ag() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d15 = _usingCtx.a({ + const d15 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; yield; await null; - } 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; } } constructor(){ this.a = async ()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d7 = _usingCtx.a({ + const d7 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }; } } { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx1 = _using_ctx(); - const d19 = _usingCtx1.a({ + const d19 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx1.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx1.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } switch(Math.random()){ case 0: + const env1 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx2 = _using_ctx(); - const d20 = _usingCtx2.a({ + const d20 = _ts_add_disposable_resource(env1, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e; + env1.hasError = true; } finally{ - await _usingCtx2.d(); + const result = _ts_dispose_resources(env1); + if (result) await result; } case 1: + const env2 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx3 = _using_ctx(); - const d21 = _usingCtx3.a({ + const d21 = _ts_add_disposable_resource(env2, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx3.e = _; + } catch (e) { + env2.error = e; + env2.hasError = true; } finally{ - await _usingCtx3.d(); + const result = _ts_dispose_resources(env2); + if (result) await result; } } if (true) switch(0){ case 0: + const env3 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx4 = _using_ctx(); - const d22 = _usingCtx4.a({ + const d22 = _ts_add_disposable_resource(env3, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx4.e = _; + } catch (e) { + env3.error = e; + env3.hasError = true; } finally{ - await _usingCtx4.d(); + const result = _ts_dispose_resources(env3); + if (result) await result; } } try { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx5 = _using_ctx(); - const d23 = _usingCtx5.a({ + const d23 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx5.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx5.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } catch (e) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx6 = _using_ctx(); - const d24 = _usingCtx6.a({ + const d24 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx6.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx6.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } finally{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx7 = _using_ctx(); - const d25 = _usingCtx7.a({ + const d25 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx7.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx7.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } if (true) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx8 = _using_ctx(); - const d26 = _usingCtx8.a({ + const d26 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx8.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx8.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } else { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx9 = _using_ctx(); - const d27 = _usingCtx9.a({ + const d27 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx9.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx9.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } while(true){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx10 = _using_ctx(); - const d28 = _usingCtx10.a({ + const d28 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx10.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx10.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } do { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx11 = _using_ctx(); - const d29 = _usingCtx11.a({ + const d29 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx11.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx11.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }while (true) for(;;){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx12 = _using_ctx(); - const d30 = _usingCtx12.a({ + const d30 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx12.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx12.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } for(const x in {}){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx13 = _using_ctx(); - const d31 = _usingCtx13.a({ + const d31 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx13.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx13.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } for (const x of []){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx14 = _using_ctx(); - const d32 = _usingCtx14.a({ + const d32 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx14.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx14.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; } export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2017).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2017).2.minified.js index 6d3aad2315e7..78984ad266aa 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2017).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2017).2.minified.js @@ -1,154 +1,241 @@ //// [awaitUsingDeclarations.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.a({ + _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - try { - var _usingCtx1 = _using_ctx(); - _usingCtx1.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx1.e = _; - } finally{ - await _usingCtx1.d(); + }, !0); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } switch(Math.random()){ case 0: + let env1 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx2 = _using_ctx(); - _usingCtx2.a({ + _ts_add_disposable_resource(env1, { async [Symbol.asyncDispose] () {} - }); + }, !0); break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e, env1.hasError = !0; } finally{ - await _usingCtx2.d(); + let result = _ts_dispose_resources(env1); + result && await result; } case 1: + let env2 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx3 = _using_ctx(); - _usingCtx3.a({ + _ts_add_disposable_resource(env2, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx3.e = _; + }, !0); + } catch (e) { + env2.error = e, env2.hasError = !0; } finally{ - await _usingCtx3.d(); + let result = _ts_dispose_resources(env2); + result && await result; } } - try { - var _usingCtx4 = _using_ctx(); - _usingCtx4.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx4.e = _; - } finally{ - await _usingCtx4.d(); + { + let env3 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env3, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env3.error = e, env3.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env3); + result && await result; + } } try { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx5 = _using_ctx(); - _usingCtx5.a({ + _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx5.e = _; + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx5.d(); + let result = _ts_dispose_resources(env); + result && await result; } } catch (e) { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx6 = _using_ctx(); - _usingCtx6.a({ + _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx6.e = _; + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx6.d(); + let result = _ts_dispose_resources(env); + result && await result; } } finally{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx7 = _using_ctx(); - _usingCtx7.a({ + _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx7.e = _; + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx7.d(); + let result = _ts_dispose_resources(env); + result && await result; } } - try { - var _usingCtx8 = _using_ctx(); - _usingCtx8.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx8.e = _; - } finally{ - await _usingCtx8.d(); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(;;)try { - var _usingCtx10 = _using_ctx(); - _usingCtx10.a({ - async [Symbol.asyncDispose] () {} - }); - break; - } catch (_) { - _usingCtx10.e = _; - } finally{ - await _usingCtx10.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(;;)try { - var _usingCtx11 = _using_ctx(); - _usingCtx11.a({ - async [Symbol.asyncDispose] () {} - }); - break; - } catch (_) { - _usingCtx11.e = _; - } finally{ - await _usingCtx11.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(;;)try { - var _usingCtx12 = _using_ctx(); - _usingCtx12.a({ - async [Symbol.asyncDispose] () {} - }); - break; - } catch (_) { - _usingCtx12.e = _; - } finally{ - await _usingCtx12.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(let x in {})try { - var _usingCtx13 = _using_ctx(); - _usingCtx13.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx13.e = _; - } finally{ - await _usingCtx13.d(); + for(let x in {}){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for (let x of [])try { - var _usingCtx14 = _using_ctx(); - _usingCtx14.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx14.e = _; - } finally{ - await _usingCtx14.d(); + for (let x of []){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx.d(); + let result = _ts_dispose_resources(env); + result && await result; } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2022).1.normal.js index f4fb101df113..97a366e07e10 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2022).1.normal.js @@ -1,267 +1,415 @@ //// [awaitUsingDeclarations.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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 d1 = _usingCtx.a({ + const d1 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; async function af() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d3 = _usingCtx.a({ + const d3 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; await null; - } 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; } } async function* ag() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d5 = _usingCtx.a({ + const d5 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; yield; await null; - } 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; } } const a = async ()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d6 = _usingCtx.a({ + const d6 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }; class C1 { async am() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d13 = _usingCtx.a({ + const d13 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; await null; - } 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; } } async *ag() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d15 = _usingCtx.a({ + const d15 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; yield; await null; - } 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; } } constructor(){ this.a = async ()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d7 = _usingCtx.a({ + const d7 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }; } } { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx1 = _using_ctx(); - const d19 = _usingCtx1.a({ + const d19 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx1.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx1.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } switch(Math.random()){ case 0: + const env1 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx2 = _using_ctx(); - const d20 = _usingCtx2.a({ + const d20 = _ts_add_disposable_resource(env1, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e; + env1.hasError = true; } finally{ - await _usingCtx2.d(); + const result = _ts_dispose_resources(env1); + if (result) await result; } case 1: + const env2 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx3 = _using_ctx(); - const d21 = _usingCtx3.a({ + const d21 = _ts_add_disposable_resource(env2, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx3.e = _; + } catch (e) { + env2.error = e; + env2.hasError = true; } finally{ - await _usingCtx3.d(); + const result = _ts_dispose_resources(env2); + if (result) await result; } } if (true) switch(0){ case 0: + const env3 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx4 = _using_ctx(); - const d22 = _usingCtx4.a({ + const d22 = _ts_add_disposable_resource(env3, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx4.e = _; + } catch (e) { + env3.error = e; + env3.hasError = true; } finally{ - await _usingCtx4.d(); + const result = _ts_dispose_resources(env3); + if (result) await result; } } try { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx5 = _using_ctx(); - const d23 = _usingCtx5.a({ + const d23 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx5.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx5.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } catch { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx6 = _using_ctx(); - const d24 = _usingCtx6.a({ + const d24 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx6.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx6.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } finally{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx7 = _using_ctx(); - const d25 = _usingCtx7.a({ + const d25 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx7.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx7.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } if (true) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx8 = _using_ctx(); - const d26 = _usingCtx8.a({ + const d26 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx8.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx8.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } else { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx9 = _using_ctx(); - const d27 = _usingCtx9.a({ + const d27 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx9.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx9.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } while(true){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx10 = _using_ctx(); - const d28 = _usingCtx10.a({ + const d28 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx10.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx10.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } do { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx11 = _using_ctx(); - const d29 = _usingCtx11.a({ + const d29 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx11.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx11.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }while (true) for(;;){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx12 = _using_ctx(); - const d30 = _usingCtx12.a({ + const d30 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx12.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx12.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } for(const x in {}){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx13 = _using_ctx(); - const d31 = _usingCtx13.a({ + const d31 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx13.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx13.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } for (const x of []){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx14 = _using_ctx(); - const d32 = _usingCtx14.a({ + const d32 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx14.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx14.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; } export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2022).2.minified.js index db8011a13132..f9d271e26f50 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es2022).2.minified.js @@ -1,154 +1,241 @@ //// [awaitUsingDeclarations.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.a({ + _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - try { - var _usingCtx1 = _using_ctx(); - _usingCtx1.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx1.e = _; - } finally{ - await _usingCtx1.d(); + }, !0); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } switch(Math.random()){ case 0: + let env1 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx2 = _using_ctx(); - _usingCtx2.a({ + _ts_add_disposable_resource(env1, { async [Symbol.asyncDispose] () {} - }); + }, !0); break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e, env1.hasError = !0; } finally{ - await _usingCtx2.d(); + let result = _ts_dispose_resources(env1); + result && await result; } case 1: + let env2 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx3 = _using_ctx(); - _usingCtx3.a({ + _ts_add_disposable_resource(env2, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx3.e = _; + }, !0); + } catch (e) { + env2.error = e, env2.hasError = !0; } finally{ - await _usingCtx3.d(); + let result = _ts_dispose_resources(env2); + result && await result; } } - try { - var _usingCtx4 = _using_ctx(); - _usingCtx4.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx4.e = _; - } finally{ - await _usingCtx4.d(); + { + let env3 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env3, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env3.error = e, env3.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env3); + result && await result; + } } try { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx5 = _using_ctx(); - _usingCtx5.a({ + _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx5.e = _; + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx5.d(); + let result = _ts_dispose_resources(env); + result && await result; } } catch { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx6 = _using_ctx(); - _usingCtx6.a({ + _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx6.e = _; + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx6.d(); + let result = _ts_dispose_resources(env); + result && await result; } } finally{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx7 = _using_ctx(); - _usingCtx7.a({ + _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx7.e = _; + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx7.d(); + let result = _ts_dispose_resources(env); + result && await result; } } - try { - var _usingCtx8 = _using_ctx(); - _usingCtx8.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx8.e = _; - } finally{ - await _usingCtx8.d(); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(;;)try { - var _usingCtx10 = _using_ctx(); - _usingCtx10.a({ - async [Symbol.asyncDispose] () {} - }); - break; - } catch (_) { - _usingCtx10.e = _; - } finally{ - await _usingCtx10.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(;;)try { - var _usingCtx11 = _using_ctx(); - _usingCtx11.a({ - async [Symbol.asyncDispose] () {} - }); - break; - } catch (_) { - _usingCtx11.e = _; - } finally{ - await _usingCtx11.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(;;)try { - var _usingCtx12 = _using_ctx(); - _usingCtx12.a({ - async [Symbol.asyncDispose] () {} - }); - break; - } catch (_) { - _usingCtx12.e = _; - } finally{ - await _usingCtx12.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(let x in {})try { - var _usingCtx13 = _using_ctx(); - _usingCtx13.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx13.e = _; - } finally{ - await _usingCtx13.d(); + for(let x in {}){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for (let x of [])try { - var _usingCtx14 = _using_ctx(); - _usingCtx14.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx14.e = _; - } finally{ - await _usingCtx14.d(); + for (let x of []){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx.d(); + let result = _ts_dispose_resources(env); + result && await result; } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es5).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es5).1.normal.js index dd03b1149b1b..d03921b490a9 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es5).1.normal.js @@ -5,7 +5,13 @@ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _define_property } from "@swc/helpers/_/_define_property"; import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: false +}; try { var af = function af() { return _af.apply(this, arguments); @@ -13,8 +19,7 @@ try { var ag = function ag() { return _ag.apply(this, arguments); }; - var _usingCtx = _using_ctx(); - var d1 = _usingCtx.a(_define_property({}, Symbol.asyncDispose, function() { + var d1 = _ts_add_disposable_resource(env, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -22,21 +27,28 @@ try { ]; }); })(); - })); + }), true); + ; function _af() { _af = _async_to_generator(function() { - var _usingCtx, d3, _; + var env, d3, e, result; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: + env = { + stack: [], + error: void 0, + hasError: false + }; + _state.label = 1; + case 1: _state.trys.push([ - 0, - 2, + 1, 3, - 5 + 4, + 7 ]); - _usingCtx = _using_ctx(); - d3 = _usingCtx.a(_define_property({}, Symbol.asyncDispose, function() { + d3 = _ts_add_disposable_resource(env, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -44,35 +56,43 @@ try { ]; }); })(); - })); + }), true); return [ 4, null ]; - case 1: + case 2: _state.sent(); return [ 3, - 5 + 7 ]; - case 2: - _ = _state.sent(); - _usingCtx.e = _; + case 3: + e = _state.sent(); + env.error = e; + env.hasError = true; return [ 3, - 5 + 7 + ]; + case 4: + result = _ts_dispose_resources(env); + if (!result) return [ + 3, + 6 ]; - case 3: return [ 4, - _usingCtx.d() + result ]; - case 4: + case 5: _state.sent(); + _state.label = 6; + case 6: return [ 7 ]; - case 5: + case 7: return [ 2 ]; @@ -83,18 +103,24 @@ try { } function _ag() { _ag = _wrap_async_generator(function() { - var _usingCtx, d5, _; + var env, d5, e, result; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: + env = { + stack: [], + error: void 0, + hasError: false + }; + _state.label = 1; + case 1: _state.trys.push([ - 0, - 3, + 1, 4, - 6 + 5, + 8 ]); - _usingCtx = _using_ctx(); - d5 = _usingCtx.a(_define_property({}, Symbol.asyncDispose, function() { + d5 = _ts_add_disposable_resource(env, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -102,40 +128,48 @@ try { ]; }); })(); - })); + }), true); return [ 4 ]; - case 1: + case 2: _state.sent(); return [ 4, _await_async_generator(null) ]; - case 2: + case 3: _state.sent(); return [ 3, - 6 + 8 ]; - case 3: - _ = _state.sent(); - _usingCtx.e = _; + case 4: + e = _state.sent(); + env.error = e; + env.hasError = true; return [ 3, - 6 + 8 + ]; + case 5: + result = _ts_dispose_resources(env); + if (!result) return [ + 3, + 7 ]; - case 4: return [ 4, - _await_async_generator(_usingCtx.d()) + _await_async_generator(result) ]; - case 5: + case 6: _state.sent(); + _state.label = 7; + case 7: return [ 7 ]; - case 6: + case 8: return [ 2 ]; @@ -146,18 +180,24 @@ try { } var a = /*#__PURE__*/ function() { var _ref = _async_to_generator(function() { - var _usingCtx, d6, _; + var env, d6, e, result; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: + env = { + stack: [], + error: void 0, + hasError: false + }; + _state.label = 1; + case 1: _state.trys.push([ - 0, 1, 2, - 4 + 3, + 6 ]); - _usingCtx = _using_ctx(); - d6 = _usingCtx.a(_define_property({}, Symbol.asyncDispose, function() { + d6 = _ts_add_disposable_resource(env, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -165,29 +205,37 @@ try { ]; }); })(); - })); + }), true); return [ 3, - 4 + 6 ]; - case 1: - _ = _state.sent(); - _usingCtx.e = _; + case 2: + e = _state.sent(); + env.error = e; + env.hasError = true; return [ 3, - 4 + 6 + ]; + case 3: + result = _ts_dispose_resources(env); + if (!result) return [ + 3, + 5 ]; - case 2: return [ 4, - _usingCtx.d() + result ]; - case 3: + case 4: _state.sent(); + _state.label = 5; + case 5: return [ 7 ]; - case 4: + case 6: return [ 2 ]; @@ -203,18 +251,24 @@ try { function C1() { _class_call_check(this, C1); this.a = /*#__PURE__*/ _async_to_generator(function() { - var _usingCtx, d7, _; + var env, d7, e, result; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: + env = { + stack: [], + error: void 0, + hasError: false + }; + _state.label = 1; + case 1: _state.trys.push([ - 0, 1, 2, - 4 + 3, + 6 ]); - _usingCtx = _using_ctx(); - d7 = _usingCtx.a(_define_property({}, Symbol.asyncDispose, function() { + d7 = _ts_add_disposable_resource(env, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -222,29 +276,37 @@ try { ]; }); })(); - })); + }), true); return [ 3, - 4 + 6 ]; - case 1: - _ = _state.sent(); - _usingCtx.e = _; + case 2: + e = _state.sent(); + env.error = e; + env.hasError = true; return [ 3, - 4 + 6 + ]; + case 3: + result = _ts_dispose_resources(env); + if (!result) return [ + 3, + 5 ]; - case 2: return [ 4, - _usingCtx.d() + result ]; - case 3: + case 4: _state.sent(); + _state.label = 5; + case 5: return [ 7 ]; - case 4: + case 6: return [ 2 ]; @@ -255,18 +317,24 @@ try { var _proto = C1.prototype; _proto.am = function am() { return _async_to_generator(function() { - var _usingCtx, d13, _; + var env, d13, e, result; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: + env = { + stack: [], + error: void 0, + hasError: false + }; + _state.label = 1; + case 1: _state.trys.push([ - 0, - 2, + 1, 3, - 5 + 4, + 7 ]); - _usingCtx = _using_ctx(); - d13 = _usingCtx.a(_define_property({}, Symbol.asyncDispose, function() { + d13 = _ts_add_disposable_resource(env, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -274,35 +342,43 @@ try { ]; }); })(); - })); + }), true); return [ 4, null ]; - case 1: + case 2: _state.sent(); return [ 3, - 5 + 7 ]; - case 2: - _ = _state.sent(); - _usingCtx.e = _; + case 3: + e = _state.sent(); + env.error = e; + env.hasError = true; return [ 3, - 5 + 7 + ]; + case 4: + result = _ts_dispose_resources(env); + if (!result) return [ + 3, + 6 ]; - case 3: return [ 4, - _usingCtx.d() + result ]; - case 4: + case 5: _state.sent(); + _state.label = 6; + case 6: return [ 7 ]; - case 5: + case 7: return [ 2 ]; @@ -312,18 +388,24 @@ try { }; _proto.ag = function ag() { return _wrap_async_generator(function() { - var _usingCtx, d15, _; + var env, d15, e, result; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: + env = { + stack: [], + error: void 0, + hasError: false + }; + _state.label = 1; + case 1: _state.trys.push([ - 0, - 3, + 1, 4, - 6 + 5, + 8 ]); - _usingCtx = _using_ctx(); - d15 = _usingCtx.a(_define_property({}, Symbol.asyncDispose, function() { + d15 = _ts_add_disposable_resource(env, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -331,40 +413,48 @@ try { ]; }); })(); - })); + }), true); return [ 4 ]; - case 1: + case 2: _state.sent(); return [ 4, _await_async_generator(null) ]; - case 2: + case 3: _state.sent(); return [ 3, - 6 + 8 ]; - case 3: - _ = _state.sent(); - _usingCtx.e = _; + case 4: + e = _state.sent(); + env.error = e; + env.hasError = true; return [ 3, - 6 + 8 + ]; + case 5: + result = _ts_dispose_resources(env); + if (!result) return [ + 3, + 7 ]; - case 4: return [ 4, - _await_async_generator(_usingCtx.d()) + _await_async_generator(result) ]; - case 5: + case 6: _state.sent(); + _state.label = 7; + case 7: return [ 7 ]; - case 6: + case 8: return [ 2 ]; @@ -375,9 +465,13 @@ try { return C1; }(); { + var env1 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx1 = _using_ctx(); - var d19 = _usingCtx1.a(_define_property({}, Symbol.asyncDispose, function() { + var d19 = _ts_add_disposable_resource(env1, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -385,18 +479,25 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx1.e = _; + }), true); + ; + } catch (e) { + env1.error = e; + env1.hasError = true; } finally{ - await _usingCtx1.d(); + var result = _ts_dispose_resources(env1); + if (result) await result; } } switch(Math.random()){ case 0: + var env2 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx2 = _using_ctx(); - var d20 = _usingCtx2.a(_define_property({}, Symbol.asyncDispose, function() { + var d20 = _ts_add_disposable_resource(env2, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -404,17 +505,24 @@ try { ]; }); })(); - })); + }), true); + ; break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env2.error = e; + env2.hasError = true; } finally{ - await _usingCtx2.d(); + var result1 = _ts_dispose_resources(env2); + if (result1) await result1; } case 1: + var env3 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx3 = _using_ctx(); - var d21 = _usingCtx3.a(_define_property({}, Symbol.asyncDispose, function() { + var d21 = _ts_add_disposable_resource(env3, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -422,19 +530,26 @@ try { ]; }); })(); - })); + }), true); + ; break; - } catch (_) { - _usingCtx3.e = _; + } catch (e) { + env3.error = e; + env3.hasError = true; } finally{ - await _usingCtx3.d(); + var result2 = _ts_dispose_resources(env3); + if (result2) await result2; } } if (true) switch(0){ case 0: + var env4 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx4 = _using_ctx(); - var d22 = _usingCtx4.a(_define_property({}, Symbol.asyncDispose, function() { + var d22 = _ts_add_disposable_resource(env4, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -442,18 +557,25 @@ try { ]; }); })(); - })); + }), true); + ; break; - } catch (_) { - _usingCtx4.e = _; + } catch (e) { + env4.error = e; + env4.hasError = true; } finally{ - await _usingCtx4.d(); + var result3 = _ts_dispose_resources(env4); + if (result3) await result3; } } try { + var env5 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx5 = _using_ctx(); - var d23 = _usingCtx5.a(_define_property({}, Symbol.asyncDispose, function() { + var d23 = _ts_add_disposable_resource(env5, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -461,16 +583,23 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx5.e = _; + }), true); + ; + } catch (e) { + env5.error = e; + env5.hasError = true; } finally{ - await _usingCtx5.d(); + var result4 = _ts_dispose_resources(env5); + if (result4) await result4; } } catch (e) { + var env6 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx6 = _using_ctx(); - var d24 = _usingCtx6.a(_define_property({}, Symbol.asyncDispose, function() { + var d24 = _ts_add_disposable_resource(env6, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -478,16 +607,23 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx6.e = _; + }), true); + ; + } catch (e) { + env6.error = e; + env6.hasError = true; } finally{ - await _usingCtx6.d(); + var result5 = _ts_dispose_resources(env6); + if (result5) await result5; } } finally{ + var env7 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx7 = _using_ctx(); - var d25 = _usingCtx7.a(_define_property({}, Symbol.asyncDispose, function() { + var d25 = _ts_add_disposable_resource(env7, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -495,17 +631,24 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx7.e = _; + }), true); + ; + } catch (e) { + env7.error = e; + env7.hasError = true; } finally{ - await _usingCtx7.d(); + var result6 = _ts_dispose_resources(env7); + if (result6) await result6; } } if (true) { + var env8 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx8 = _using_ctx(); - var d26 = _usingCtx8.a(_define_property({}, Symbol.asyncDispose, function() { + var d26 = _ts_add_disposable_resource(env8, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -513,16 +656,23 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx8.e = _; + }), true); + ; + } catch (e) { + env8.error = e; + env8.hasError = true; } finally{ - await _usingCtx8.d(); + var result7 = _ts_dispose_resources(env8); + if (result7) await result7; } } else { + var env9 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx9 = _using_ctx(); - var d27 = _usingCtx9.a(_define_property({}, Symbol.asyncDispose, function() { + var d27 = _ts_add_disposable_resource(env9, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -530,17 +680,24 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx9.e = _; + }), true); + ; + } catch (e) { + env9.error = e; + env9.hasError = true; } finally{ - await _usingCtx9.d(); + var result8 = _ts_dispose_resources(env9); + if (result8) await result8; } } while(true){ + var env10 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx10 = _using_ctx(); - var d28 = _usingCtx10.a(_define_property({}, Symbol.asyncDispose, function() { + var d28 = _ts_add_disposable_resource(env10, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -548,18 +705,25 @@ try { ]; }); })(); - })); + }), true); + ; break; - } catch (_) { - _usingCtx10.e = _; + } catch (e) { + env10.error = e; + env10.hasError = true; } finally{ - await _usingCtx10.d(); + var result9 = _ts_dispose_resources(env10); + if (result9) await result9; } } do { + var env11 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx11 = _using_ctx(); - var d29 = _usingCtx11.a(_define_property({}, Symbol.asyncDispose, function() { + var d29 = _ts_add_disposable_resource(env11, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -567,18 +731,25 @@ try { ]; }); })(); - })); + }), true); + ; break; - } catch (_) { - _usingCtx11.e = _; + } catch (e) { + env11.error = e; + env11.hasError = true; } finally{ - await _usingCtx11.d(); + var result10 = _ts_dispose_resources(env11); + if (result10) await result10; } }while (true); for(;;){ + var env12 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx12 = _using_ctx(); - var d30 = _usingCtx12.a(_define_property({}, Symbol.asyncDispose, function() { + var d30 = _ts_add_disposable_resource(env12, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -586,18 +757,25 @@ try { ]; }); })(); - })); + }), true); + ; break; - } catch (_) { - _usingCtx12.e = _; + } catch (e) { + env12.error = e; + env12.hasError = true; } finally{ - await _usingCtx12.d(); + var result11 = _ts_dispose_resources(env12); + if (result11) await result11; } } for(var x in {}){ + var env13 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx13 = _using_ctx(); - var d31 = _usingCtx13.a(_define_property({}, Symbol.asyncDispose, function() { + var d31 = _ts_add_disposable_resource(env13, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -605,18 +783,25 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx13.e = _; + }), true); + ; + } catch (e) { + env13.error = e; + env13.hasError = true; } finally{ - await _usingCtx13.d(); + var result12 = _ts_dispose_resources(env13); + if (result12) await result12; } } for(var _i = 0, _iter = []; _i < _iter.length; _i++){ var x1 = _iter[_i]; + var env14 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx14 = _using_ctx(); - var d32 = _usingCtx14.a(_define_property({}, Symbol.asyncDispose, function() { + var d32 = _ts_add_disposable_resource(env14, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -624,16 +809,21 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx14.e = _; + }), true); + ; + } catch (e) { + env14.error = e; + env14.hasError = true; } finally{ - await _usingCtx14.d(); + var result13 = _ts_dispose_resources(env14); + if (result13) await result13; } } -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + var result14 = _ts_dispose_resources(env); + if (result14) await result14; } export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es5).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es5).2.minified.js index 64d976ae2176..6226b2d04d3a 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=es5).2.minified.js @@ -5,10 +5,15 @@ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _define_property } from "@swc/helpers/_/_define_property"; import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.a(_define_property({}, Symbol.asyncDispose, function() { + _ts_add_disposable_resource(env, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -16,10 +21,14 @@ try { ]; }); })(); - })); + }), !0); + var env1 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx1 = _using_ctx(); - _usingCtx1.a(_define_property({}, Symbol.asyncDispose, function() { + _ts_add_disposable_resource(env1, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -27,17 +36,22 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx1.e = _; + }), !0); + } catch (e) { + env1.error = e, env1.hasError = !0; } finally{ - await _usingCtx1.d(); + var result = _ts_dispose_resources(env1); + result && await result; } switch(Math.random()){ case 0: + var env2 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx2 = _using_ctx(); - _usingCtx2.a(_define_property({}, Symbol.asyncDispose, function() { + _ts_add_disposable_resource(env2, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -45,17 +59,22 @@ try { ]; }); })(); - })); + }), !0); break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env2.error = e, env2.hasError = !0; } finally{ - await _usingCtx2.d(); + var result1 = _ts_dispose_resources(env2); + result1 && await result1; } case 1: + var env3 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx3 = _using_ctx(); - _usingCtx3.a(_define_property({}, Symbol.asyncDispose, function() { + _ts_add_disposable_resource(env3, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -63,16 +82,21 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx3.e = _; + }), !0); + } catch (e) { + env3.error = e, env3.hasError = !0; } finally{ - await _usingCtx3.d(); + var result2 = _ts_dispose_resources(env3); + result2 && await result2; } } + var env4 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx4 = _using_ctx(); - _usingCtx4.a(_define_property({}, Symbol.asyncDispose, function() { + _ts_add_disposable_resource(env4, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -80,16 +104,21 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx4.e = _; + }), !0); + } catch (e) { + env4.error = e, env4.hasError = !0; } finally{ - await _usingCtx4.d(); + var result3 = _ts_dispose_resources(env4); + result3 && await result3; } try { + var env5 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx5 = _using_ctx(); - _usingCtx5.a(_define_property({}, Symbol.asyncDispose, function() { + _ts_add_disposable_resource(env5, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -97,16 +126,21 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx5.e = _; + }), !0); + } catch (e) { + env5.error = e, env5.hasError = !0; } finally{ - await _usingCtx5.d(); + var result4 = _ts_dispose_resources(env5); + result4 && await result4; } } catch (e) { + var env6 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx6 = _using_ctx(); - _usingCtx6.a(_define_property({}, Symbol.asyncDispose, function() { + _ts_add_disposable_resource(env6, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -114,16 +148,21 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx6.e = _; + }), !0); + } catch (e) { + env6.error = e, env6.hasError = !0; } finally{ - await _usingCtx6.d(); + var result5 = _ts_dispose_resources(env6); + result5 && await result5; } } finally{ + var env7 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx7 = _using_ctx(); - _usingCtx7.a(_define_property({}, Symbol.asyncDispose, function() { + _ts_add_disposable_resource(env7, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -131,16 +170,21 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx7.e = _; + }), !0); + } catch (e) { + env7.error = e, env7.hasError = !0; } finally{ - await _usingCtx7.d(); + var result6 = _ts_dispose_resources(env7); + result6 && await result6; } } + var env8 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx8 = _using_ctx(); - _usingCtx8.a(_define_property({}, Symbol.asyncDispose, function() { + _ts_add_disposable_resource(env8, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -148,84 +192,117 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx8.e = _; + }), !0); + } catch (e) { + env8.error = e, env8.hasError = !0; } finally{ - await _usingCtx8.d(); + var result7 = _ts_dispose_resources(env8); + result7 && await result7; } - for(;;)try { - var _usingCtx10 = _using_ctx(); - _usingCtx10.a(_define_property({}, Symbol.asyncDispose, function() { - return _async_to_generator(function() { - return _ts_generator(this, function(_state) { - return [ - 2 - ]; - }); - })(); - })); - break; - } catch (_) { - _usingCtx10.e = _; - } finally{ - await _usingCtx10.d(); + for(;;){ + var env10 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env10, _define_property({}, Symbol.asyncDispose, function() { + return _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); + })(); + }), !0); + break; + } catch (e) { + env10.error = e, env10.hasError = !0; + } finally{ + var result9 = _ts_dispose_resources(env10); + result9 && await result9; + } } - for(;;)try { - var _usingCtx11 = _using_ctx(); - _usingCtx11.a(_define_property({}, Symbol.asyncDispose, function() { - return _async_to_generator(function() { - return _ts_generator(this, function(_state) { - return [ - 2 - ]; - }); - })(); - })); - break; - } catch (_) { - _usingCtx11.e = _; - } finally{ - await _usingCtx11.d(); + for(;;){ + var env11 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env11, _define_property({}, Symbol.asyncDispose, function() { + return _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); + })(); + }), !0); + break; + } catch (e) { + env11.error = e, env11.hasError = !0; + } finally{ + var result10 = _ts_dispose_resources(env11); + result10 && await result10; + } } - for(;;)try { - var _usingCtx12 = _using_ctx(); - _usingCtx12.a(_define_property({}, Symbol.asyncDispose, function() { - return _async_to_generator(function() { - return _ts_generator(this, function(_state) { - return [ - 2 - ]; - }); - })(); - })); - break; - } catch (_) { - _usingCtx12.e = _; - } finally{ - await _usingCtx12.d(); + for(;;){ + var env12 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env12, _define_property({}, Symbol.asyncDispose, function() { + return _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); + })(); + }), !0); + break; + } catch (e) { + env12.error = e, env12.hasError = !0; + } finally{ + var result11 = _ts_dispose_resources(env12); + result11 && await result11; + } } - for(var x in {})try { - var _usingCtx13 = _using_ctx(); - _usingCtx13.a(_define_property({}, Symbol.asyncDispose, function() { - return _async_to_generator(function() { - return _ts_generator(this, function(_state) { - return [ - 2 - ]; - }); - })(); - })); - } catch (_) { - _usingCtx13.e = _; - } finally{ - await _usingCtx13.d(); + for(var x in {}){ + var env13 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env13, _define_property({}, Symbol.asyncDispose, function() { + return _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); + })(); + }), !0); + } catch (e) { + env13.error = e, env13.hasError = !0; + } finally{ + var result12 = _ts_dispose_resources(env13); + result12 && await result12; + } } for(var _i = 0, _iter = []; _i < _iter.length; _i++){ _iter[_i]; + var env14 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx14 = _using_ctx(); - _usingCtx14.a(_define_property({}, Symbol.asyncDispose, function() { + _ts_add_disposable_resource(env14, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -233,15 +310,17 @@ try { ]; }); })(); - })); - } catch (_) { - _usingCtx14.e = _; + }), !0); + } catch (e) { + env14.error = e, env14.hasError = !0; } finally{ - await _usingCtx14.d(); + var result13 = _ts_dispose_resources(env14); + result13 && await result13; } } -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx.d(); + var result14 = _ts_dispose_resources(env); + result14 && await result14; } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=esnext).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=esnext).1.normal.js index f4fb101df113..97a366e07e10 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=esnext).1.normal.js @@ -1,267 +1,415 @@ //// [awaitUsingDeclarations.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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 d1 = _usingCtx.a({ + const d1 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; async function af() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d3 = _usingCtx.a({ + const d3 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; await null; - } 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; } } async function* ag() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d5 = _usingCtx.a({ + const d5 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; yield; await null; - } 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; } } const a = async ()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d6 = _usingCtx.a({ + const d6 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }; class C1 { async am() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d13 = _usingCtx.a({ + const d13 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; await null; - } 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; } } async *ag() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d15 = _usingCtx.a({ + const d15 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; yield; await null; - } 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; } } constructor(){ this.a = async ()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d7 = _usingCtx.a({ + const d7 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }; } } { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx1 = _using_ctx(); - const d19 = _usingCtx1.a({ + const d19 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx1.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx1.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } switch(Math.random()){ case 0: + const env1 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx2 = _using_ctx(); - const d20 = _usingCtx2.a({ + const d20 = _ts_add_disposable_resource(env1, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e; + env1.hasError = true; } finally{ - await _usingCtx2.d(); + const result = _ts_dispose_resources(env1); + if (result) await result; } case 1: + const env2 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx3 = _using_ctx(); - const d21 = _usingCtx3.a({ + const d21 = _ts_add_disposable_resource(env2, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx3.e = _; + } catch (e) { + env2.error = e; + env2.hasError = true; } finally{ - await _usingCtx3.d(); + const result = _ts_dispose_resources(env2); + if (result) await result; } } if (true) switch(0){ case 0: + const env3 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx4 = _using_ctx(); - const d22 = _usingCtx4.a({ + const d22 = _ts_add_disposable_resource(env3, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx4.e = _; + } catch (e) { + env3.error = e; + env3.hasError = true; } finally{ - await _usingCtx4.d(); + const result = _ts_dispose_resources(env3); + if (result) await result; } } try { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx5 = _using_ctx(); - const d23 = _usingCtx5.a({ + const d23 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx5.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx5.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } catch { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx6 = _using_ctx(); - const d24 = _usingCtx6.a({ + const d24 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx6.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx6.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } finally{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx7 = _using_ctx(); - const d25 = _usingCtx7.a({ + const d25 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx7.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx7.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } if (true) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx8 = _using_ctx(); - const d26 = _usingCtx8.a({ + const d26 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx8.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx8.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } else { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx9 = _using_ctx(); - const d27 = _usingCtx9.a({ + const d27 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx9.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx9.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } while(true){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx10 = _using_ctx(); - const d28 = _usingCtx10.a({ + const d28 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx10.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx10.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } do { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx11 = _using_ctx(); - const d29 = _usingCtx11.a({ + const d29 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx11.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx11.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }while (true) for(;;){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx12 = _using_ctx(); - const d30 = _usingCtx12.a({ + const d30 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; break; - } catch (_) { - _usingCtx12.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx12.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } for(const x in {}){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx13 = _using_ctx(); - const d31 = _usingCtx13.a({ + const d31 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx13.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx13.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } for (const x of []){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx14 = _using_ctx(); - const d32 = _usingCtx14.a({ + const d32 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx14.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx14.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; } export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=esnext).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=esnext).2.minified.js index db8011a13132..f9d271e26f50 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.1(target=esnext).2.minified.js @@ -1,154 +1,241 @@ //// [awaitUsingDeclarations.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.a({ + _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - try { - var _usingCtx1 = _using_ctx(); - _usingCtx1.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx1.e = _; - } finally{ - await _usingCtx1.d(); + }, !0); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } switch(Math.random()){ case 0: + let env1 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx2 = _using_ctx(); - _usingCtx2.a({ + _ts_add_disposable_resource(env1, { async [Symbol.asyncDispose] () {} - }); + }, !0); break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e, env1.hasError = !0; } finally{ - await _usingCtx2.d(); + let result = _ts_dispose_resources(env1); + result && await result; } case 1: + let env2 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx3 = _using_ctx(); - _usingCtx3.a({ + _ts_add_disposable_resource(env2, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx3.e = _; + }, !0); + } catch (e) { + env2.error = e, env2.hasError = !0; } finally{ - await _usingCtx3.d(); + let result = _ts_dispose_resources(env2); + result && await result; } } - try { - var _usingCtx4 = _using_ctx(); - _usingCtx4.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx4.e = _; - } finally{ - await _usingCtx4.d(); + { + let env3 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env3, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env3.error = e, env3.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env3); + result && await result; + } } try { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx5 = _using_ctx(); - _usingCtx5.a({ + _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx5.e = _; + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx5.d(); + let result = _ts_dispose_resources(env); + result && await result; } } catch { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx6 = _using_ctx(); - _usingCtx6.a({ + _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx6.e = _; + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx6.d(); + let result = _ts_dispose_resources(env); + result && await result; } } finally{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx7 = _using_ctx(); - _usingCtx7.a({ + _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx7.e = _; + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx7.d(); + let result = _ts_dispose_resources(env); + result && await result; } } - try { - var _usingCtx8 = _using_ctx(); - _usingCtx8.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx8.e = _; - } finally{ - await _usingCtx8.d(); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(;;)try { - var _usingCtx10 = _using_ctx(); - _usingCtx10.a({ - async [Symbol.asyncDispose] () {} - }); - break; - } catch (_) { - _usingCtx10.e = _; - } finally{ - await _usingCtx10.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(;;)try { - var _usingCtx11 = _using_ctx(); - _usingCtx11.a({ - async [Symbol.asyncDispose] () {} - }); - break; - } catch (_) { - _usingCtx11.e = _; - } finally{ - await _usingCtx11.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(;;)try { - var _usingCtx12 = _using_ctx(); - _usingCtx12.a({ - async [Symbol.asyncDispose] () {} - }); - break; - } catch (_) { - _usingCtx12.e = _; - } finally{ - await _usingCtx12.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for(let x in {})try { - var _usingCtx13 = _using_ctx(); - _usingCtx13.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx13.e = _; - } finally{ - await _usingCtx13.d(); + for(let x in {}){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } - for (let x of [])try { - var _usingCtx14 = _using_ctx(); - _usingCtx14.a({ - async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx14.e = _; - } finally{ - await _usingCtx14.d(); + for (let x of []){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx.d(); + let result = _ts_dispose_resources(env); + result && await result; } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.12.1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.12.1.normal.js index 015814bfd05a..3b80794a6ff2 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.12.1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.12.1.normal.js @@ -1,12 +1,20 @@ //// [awaitUsingDeclarations.12.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; async function f() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const x = _usingCtx.a({}); - } catch (_) { - _usingCtx.e = _; + const x = _ts_add_disposable_resource(env, {}, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.12.2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.12.2.minified.js index aab4b1d8155a..4434dad4b40d 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.12.2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.12.2.minified.js @@ -1,2 +1,3 @@ //// [awaitUsingDeclarations.12.ts] -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.13.1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.13.1.normal.js index 5c4f259e5fe0..6dcad3c80047 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.13.1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.13.1.normal.js @@ -1,20 +1,35 @@ //// [awaitUsingDeclarations.13.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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 x = _usingCtx.a(null); + const x = _ts_add_disposable_resource(env, null, true); + ; function f() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const x = _usingCtx.a(null); - } catch (_) { - _usingCtx.e = _; + const x = _ts_add_disposable_resource(env, null, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.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; } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.13.2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.13.2.minified.js index 5ae54041146f..5f9d01b1e0aa 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.13.2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.13.2.minified.js @@ -1,10 +1,16 @@ //// [awaitUsingDeclarations.13.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.a(null); -} catch (_) { - _usingCtx.e = _; + _ts_add_disposable_resource(env, null, !0); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx.d(); + let result = _ts_dispose_resources(env); + result && await result; } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.15.1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.15.1.normal.js index 9790c4791081..1664d32ca7f3 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.15.1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.15.1.normal.js @@ -1,14 +1,22 @@ //// [awaitUsingDeclarations.15.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; async function f() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const _ = _usingCtx.a({ + const _ = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.15.2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.15.2.minified.js index 9ef0acd65b91..db4ce9dfe14d 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.15.2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.15.2.minified.js @@ -1,2 +1,3 @@ //// [awaitUsingDeclarations.15.ts] -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2015).1.normal.js index 7990b6670007..bfb9a6975992 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2015).1.normal.js @@ -1,21 +1,29 @@ //// [awaitUsingDeclarations.2.ts] import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.a({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }), d2 = _usingCtx.a({ + }, true), d2 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2015).2.minified.js index c1b77cca3149..7ae7149f5857 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2015).2.minified.js @@ -1,15 +1,23 @@ //// [awaitUsingDeclarations.2.ts] import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.a({ - [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }), _usingCtx.a({ - [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - await _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() + }, !0), _ts_add_disposable_resource(env, { + [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2017).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2017).1.normal.js index 5e64ce262f0e..32bcbe39c928 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2017).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2017).1.normal.js @@ -1,16 +1,24 @@ //// [awaitUsingDeclarations.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.a({ + const d1 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }), d2 = _usingCtx.a({ + }, true), d2 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2017).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2017).2.minified.js index b0930ba472dd..88c61a71250d 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2017).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2017).2.minified.js @@ -1,14 +1,22 @@ //// [awaitUsingDeclarations.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.a({ - async [Symbol.asyncDispose] () {} - }), _usingCtx.a({ - async [Symbol.asyncDispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - await _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0), _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2022).1.normal.js index 5e64ce262f0e..32bcbe39c928 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2022).1.normal.js @@ -1,16 +1,24 @@ //// [awaitUsingDeclarations.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.a({ + const d1 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }), d2 = _usingCtx.a({ + }, true), d2 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2022).2.minified.js index b0930ba472dd..88c61a71250d 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es2022).2.minified.js @@ -1,14 +1,22 @@ //// [awaitUsingDeclarations.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.a({ - async [Symbol.asyncDispose] () {} - }), _usingCtx.a({ - async [Symbol.asyncDispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - await _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0), _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es5).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es5).1.normal.js index 0717b41aba09..47fe4479092f 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es5).1.normal.js @@ -2,11 +2,16 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; import { _ as _define_property } from "@swc/helpers/_/_define_property"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; { + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d1 = _usingCtx.a(_define_property({}, Symbol.asyncDispose, function() { + var d1 = _ts_add_disposable_resource(env, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -14,7 +19,7 @@ import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; ]; }); })(); - })), d2 = _usingCtx.a(_define_property({}, Symbol.asyncDispose, function() { + }), true), d2 = _ts_add_disposable_resource(env, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -22,10 +27,13 @@ import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; ]; }); })(); - })); - } catch (_) { - _usingCtx.e = _; + }), true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + var result = _ts_dispose_resources(env); + if (result) await result; } }export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es5).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es5).2.minified.js index 589b225128b5..c8408a9b6d7e 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=es5).2.minified.js @@ -2,10 +2,15 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; import { _ as _define_property } from "@swc/helpers/_/_define_property"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.a(_define_property({}, Symbol.asyncDispose, function() { + _ts_add_disposable_resource(env, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -13,7 +18,7 @@ try { ]; }); })(); - })), _usingCtx.a(_define_property({}, Symbol.asyncDispose, function() { + }), !0), _ts_add_disposable_resource(env, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -21,9 +26,10 @@ try { ]; }); })(); - })); -} catch (_) { - _usingCtx.e = _; + }), !0); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx.d(); + var result = _ts_dispose_resources(env); + result && await result; } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=esnext).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=esnext).1.normal.js index 5e64ce262f0e..32bcbe39c928 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=esnext).1.normal.js @@ -1,16 +1,24 @@ //// [awaitUsingDeclarations.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.a({ + const d1 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }), d2 = _usingCtx.a({ + }, true), d2 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=esnext).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=esnext).2.minified.js index b0930ba472dd..88c61a71250d 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.2(target=esnext).2.minified.js @@ -1,14 +1,22 @@ //// [awaitUsingDeclarations.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.a({ - async [Symbol.asyncDispose] () {} - }), _usingCtx.a({ - async [Symbol.asyncDispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - await _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0), _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2015).1.normal.js index 46421b5f06bd..f1e8112adea2 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2015).1.normal.js @@ -1,19 +1,27 @@ //// [awaitUsingDeclarations.3.ts] import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.a({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); } - }), d2 = _usingCtx.a(null), d3 = _usingCtx.a(undefined), d4 = _usingCtx.a({ + }, true), d2 = _ts_add_disposable_resource(env, null, true), d3 = _ts_add_disposable_resource(env, undefined, true), d4 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2015).2.minified.js index 5122c7b8bfe5..6ea4158daa92 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2015).2.minified.js @@ -1,15 +1,23 @@ //// [awaitUsingDeclarations.3.ts] import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.a({ - [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() - }), _usingCtx.a(null), _usingCtx.a(void 0), _usingCtx.a({ - [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - await _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.asyncDispose]: ()=>_async_to_generator(function*() {})() + }, !0), _ts_add_disposable_resource(env, null, !0), _ts_add_disposable_resource(env, void 0, !0), _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2017).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2017).1.normal.js index 645f4b1c1805..7d8c83eefca5 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2017).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2017).1.normal.js @@ -1,16 +1,24 @@ //// [awaitUsingDeclarations.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.a({ + const d1 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }), d2 = _usingCtx.a(null), d3 = _usingCtx.a(undefined), d4 = _usingCtx.a({ + }, true), d2 = _ts_add_disposable_resource(env, null, true), d3 = _ts_add_disposable_resource(env, undefined, true), d4 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2017).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2017).2.minified.js index f2f521bcbbcd..689f0160d1e9 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2017).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2017).2.minified.js @@ -1,14 +1,22 @@ //// [awaitUsingDeclarations.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.a({ - async [Symbol.asyncDispose] () {} - }), _usingCtx.a(null), _usingCtx.a(void 0), _usingCtx.a({ - [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - await _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0), _ts_add_disposable_resource(env, null, !0), _ts_add_disposable_resource(env, void 0, !0), _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2022).1.normal.js index 645f4b1c1805..7d8c83eefca5 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2022).1.normal.js @@ -1,16 +1,24 @@ //// [awaitUsingDeclarations.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.a({ + const d1 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }), d2 = _usingCtx.a(null), d3 = _usingCtx.a(undefined), d4 = _usingCtx.a({ + }, true), d2 = _ts_add_disposable_resource(env, null, true), d3 = _ts_add_disposable_resource(env, undefined, true), d4 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2022).2.minified.js index f2f521bcbbcd..689f0160d1e9 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es2022).2.minified.js @@ -1,14 +1,22 @@ //// [awaitUsingDeclarations.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.a({ - async [Symbol.asyncDispose] () {} - }), _usingCtx.a(null), _usingCtx.a(void 0), _usingCtx.a({ - [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - await _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0), _ts_add_disposable_resource(env, null, !0), _ts_add_disposable_resource(env, void 0, !0), _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es5).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es5).1.normal.js index 09db876595f8..c2566fffdae3 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es5).1.normal.js @@ -2,11 +2,16 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; import { _ as _define_property } from "@swc/helpers/_/_define_property"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; { + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d1 = _usingCtx.a(_define_property({}, Symbol.asyncDispose, function() { + var d1 = _ts_add_disposable_resource(env, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -14,10 +19,13 @@ import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; ]; }); })(); - })), d2 = _usingCtx.a(null), d3 = _usingCtx.a(undefined), d4 = _usingCtx.a(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx.e = _; + }), true), d2 = _ts_add_disposable_resource(env, null, true), d3 = _ts_add_disposable_resource(env, undefined, true), d4 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + var result = _ts_dispose_resources(env); + if (result) await result; } }export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es5).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es5).2.minified.js index 550f4e0d8ef7..8c3cd12ee599 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=es5).2.minified.js @@ -2,10 +2,15 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; import { _ as _define_property } from "@swc/helpers/_/_define_property"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.a(_define_property({}, Symbol.asyncDispose, function() { + _ts_add_disposable_resource(env, _define_property({}, Symbol.asyncDispose, function() { return _async_to_generator(function() { return _ts_generator(this, function(_state) { return [ @@ -13,9 +18,10 @@ try { ]; }); })(); - })), _usingCtx.a(null), _usingCtx.a(void 0), _usingCtx.a(_define_property({}, Symbol.dispose, function() {})); -} catch (_) { - _usingCtx.e = _; + }), !0), _ts_add_disposable_resource(env, null, !0), _ts_add_disposable_resource(env, void 0, !0), _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), !0); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx.d(); + var result = _ts_dispose_resources(env); + result && await result; } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=esnext).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=esnext).1.normal.js index 645f4b1c1805..7d8c83eefca5 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=esnext).1.normal.js @@ -1,16 +1,24 @@ //// [awaitUsingDeclarations.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.a({ + const d1 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }), d2 = _usingCtx.a(null), d3 = _usingCtx.a(undefined), d4 = _usingCtx.a({ + }, true), d2 = _ts_add_disposable_resource(env, null, true), d3 = _ts_add_disposable_resource(env, undefined, true), d4 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=esnext).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=esnext).2.minified.js index f2f521bcbbcd..689f0160d1e9 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.3(target=esnext).2.minified.js @@ -1,14 +1,22 @@ //// [awaitUsingDeclarations.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.a({ - async [Symbol.asyncDispose] () {} - }), _usingCtx.a(null), _usingCtx.a(void 0), _usingCtx.a({ - [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - await _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + async [Symbol.asyncDispose] () {} + }, !0), _ts_add_disposable_resource(env, null, !0), _ts_add_disposable_resource(env, void 0, !0), _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.9.1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.9.1.normal.js index e3f89b0810d8..140cdd32dd4c 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.9.1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.9.1.normal.js @@ -1,12 +1,20 @@ //// [awaitUsingDeclarations.9.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const a = _usingCtx.a(null); - } catch (_) { - _usingCtx.e = _; + const a = _ts_add_disposable_resource(env, null, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } }export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarations.9.2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarations.9.2.minified.js index 10b581c62b46..6b3256386475 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarations.9.2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarations.9.2.minified.js @@ -1,10 +1,18 @@ //// [awaitUsingDeclarations.9.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.a(null); -} catch (_) { - _usingCtx.e = _; -} finally{ - await _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, null, !0); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + let result = _ts_dispose_resources(env); + result && await result; + } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2015).1.normal.js index 0f7daf3af093..7fd79d96a308 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2015).1.normal.js @@ -1,7 +1,8 @@ //// [awaitUsingDeclarationsInForAwaitOf.ts] import { _ as _async_iterator } from "@swc/helpers/_/_async_iterator"; import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; function main() { return _main.apply(this, arguments); } @@ -23,14 +24,21 @@ function _main() { undefined ]), _step; _iteratorAbruptCompletion = !(_step = yield _iterator.next()).done; _iteratorAbruptCompletion = false){ let _value = _step.value; - const d1 = _value; + const _ = _value; + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, true); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) yield result; } } } catch (err) { diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2015).2.minified.js index 7d7e834be922..d441e67e4c37 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2015).2.minified.js @@ -1,4 +1,5 @@ //// [awaitUsingDeclarationsInForAwaitOf.ts] import "@swc/helpers/_/_async_iterator"; import "@swc/helpers/_/_async_to_generator"; -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2017).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2017).1.normal.js index 51c6a9728631..8abe975f1b3e 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2017).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2017).1.normal.js @@ -1,7 +1,8 @@ //// [awaitUsingDeclarationsInForAwaitOf.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; async function main() { - for await (const d1 of [ + for await (const _ of [ { async [Symbol.asyncDispose] () {} }, @@ -11,13 +12,20 @@ async function main() { null, undefined ]){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, true); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2017).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2017).2.minified.js index 35eb661ced31..6a99dbb04c61 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2017).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2017).2.minified.js @@ -1,2 +1,3 @@ //// [awaitUsingDeclarationsInForAwaitOf.ts] -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2022).1.normal.js index 51c6a9728631..8abe975f1b3e 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2022).1.normal.js @@ -1,7 +1,8 @@ //// [awaitUsingDeclarationsInForAwaitOf.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; async function main() { - for await (const d1 of [ + for await (const _ of [ { async [Symbol.asyncDispose] () {} }, @@ -11,13 +12,20 @@ async function main() { null, undefined ]){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, true); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2022).2.minified.js index 35eb661ced31..6a99dbb04c61 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2022).2.minified.js @@ -1,2 +1,3 @@ //// [awaitUsingDeclarationsInForAwaitOf.ts] -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es5).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es5).1.normal.js index 39d65ce5006c..34e10367bb21 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es5).1.normal.js @@ -3,13 +3,14 @@ import { _ as _async_iterator } from "@swc/helpers/_/_async_iterator"; import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; import { _ as _define_property } from "@swc/helpers/_/_define_property"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; function main() { return _main.apply(this, arguments); } function _main() { _main = _async_to_generator(function() { - var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, d1, _usingCtx, err; + var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, _, env, d1, e, result, err; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: @@ -18,9 +19,9 @@ function _main() { case 1: _state.trys.push([ 1, - 6, - 7, - 12 + 11, + 12, + 17 ]); _iterator = _async_iterator([ _define_property({}, Symbol.asyncDispose, function() { @@ -45,73 +46,108 @@ function _main() { case 3: if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [ 3, - 5 + 10 ]; _value = _step.value; - d1 = _value; - try { - _usingCtx = _using_ctx(); - {} - } catch (_) { - _usingCtx.e = _; - } finally{ - _usingCtx.d(); - } + _ = _value; + env = { + stack: [], + error: void 0, + hasError: false + }; _state.label = 4; case 4: - _iteratorAbruptCompletion = false; + _state.trys.push([ + 4, + 5, + 6, + 9 + ]); + d1 = _ts_add_disposable_resource(env, _, true); + {} return [ 3, - 2 + 9 ]; case 5: + e = _state.sent(); + env.error = e; + env.hasError = true; return [ 3, - 12 + 9 ]; case 6: + result = _ts_dispose_resources(env); + if (!result) return [ + 3, + 8 + ]; + return [ + 4, + result + ]; + case 7: + _state.sent(); + _state.label = 8; + case 8: + return [ + 7 + ]; + case 9: + _iteratorAbruptCompletion = false; + return [ + 3, + 2 + ]; + case 10: + return [ + 3, + 17 + ]; + case 11: err = _state.sent(); _didIteratorError = true; _iteratorError = err; return [ 3, - 12 + 17 ]; - case 7: + case 12: _state.trys.push([ - 7, + 12, , - 10, - 11 + 15, + 16 ]); if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [ 3, - 9 + 14 ]; return [ 4, _iterator.return() ]; - case 8: + case 13: _state.sent(); - _state.label = 9; - case 9: + _state.label = 14; + case 14: return [ 3, - 11 + 16 ]; - case 10: + case 15: if (_didIteratorError) { throw _iteratorError; } return [ 7 ]; - case 11: + case 16: return [ 7 ]; - case 12: + case 17: return [ 2 ]; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es5).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es5).2.minified.js index 19e2c806ac5c..4169b2ebd344 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es5).2.minified.js @@ -3,4 +3,5 @@ import "@swc/helpers/_/_async_iterator"; import "@swc/helpers/_/_async_to_generator"; import "@swc/helpers/_/_define_property"; import "@swc/helpers/_/_ts_generator"; -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=esnext).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=esnext).1.normal.js index 51c6a9728631..8abe975f1b3e 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=esnext).1.normal.js @@ -1,7 +1,8 @@ //// [awaitUsingDeclarationsInForAwaitOf.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; async function main() { - for await (const d1 of [ + for await (const _ of [ { async [Symbol.asyncDispose] () {} }, @@ -11,13 +12,20 @@ async function main() { null, undefined ]){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, true); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=esnext).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=esnext).2.minified.js index 35eb661ced31..6a99dbb04c61 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=esnext).2.minified.js @@ -1,2 +1,3 @@ //// [awaitUsingDeclarationsInForAwaitOf.ts] -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2015).1.normal.js index 2c971032ffdc..ed35e670e4eb 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2015).1.normal.js @@ -1,12 +1,13 @@ //// [awaitUsingDeclarationsInForOf.1.ts] import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; function main() { return _main.apply(this, arguments); } function _main() { _main = _async_to_generator(function*() { - for (const d1 of [ + for (const _ of [ { [Symbol.asyncDispose] () { return _async_to_generator(function*() {})(); @@ -18,13 +19,20 @@ function _main() { null, undefined ]){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, true); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) yield result; } } }); diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2015).2.minified.js index d7eb364e989b..b3a87c780dd4 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2015).2.minified.js @@ -1,3 +1,4 @@ //// [awaitUsingDeclarationsInForOf.1.ts] import "@swc/helpers/_/_async_to_generator"; -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2017).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2017).1.normal.js index b539d27f7acb..eb45d86003a1 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2017).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2017).1.normal.js @@ -1,7 +1,8 @@ //// [awaitUsingDeclarationsInForOf.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; async function main() { - for (const d1 of [ + for (const _ of [ { async [Symbol.asyncDispose] () {} }, @@ -11,13 +12,20 @@ async function main() { null, undefined ]){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, true); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2017).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2017).2.minified.js index 7cfe7407750d..88acd2541720 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2017).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2017).2.minified.js @@ -1,2 +1,3 @@ //// [awaitUsingDeclarationsInForOf.1.ts] -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2022).1.normal.js index b539d27f7acb..eb45d86003a1 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2022).1.normal.js @@ -1,7 +1,8 @@ //// [awaitUsingDeclarationsInForOf.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; async function main() { - for (const d1 of [ + for (const _ of [ { async [Symbol.asyncDispose] () {} }, @@ -11,13 +12,20 @@ async function main() { null, undefined ]){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, true); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2022).2.minified.js index 7cfe7407750d..88acd2541720 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es2022).2.minified.js @@ -1,2 +1,3 @@ //// [awaitUsingDeclarationsInForOf.1.ts] -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es5).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es5).1.normal.js index a38b9bb9ee34..88cfd0d0a6a4 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es5).1.normal.js @@ -2,41 +2,93 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; import { _ as _define_property } from "@swc/helpers/_/_define_property"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; function main() { return _main.apply(this, arguments); } function _main() { _main = _async_to_generator(function() { - var _i, _iter, d1, _usingCtx; + var _i, _iter, _, env, d1, e, result; return _ts_generator(this, function(_state) { - for(_i = 0, _iter = [ - _define_property({}, Symbol.asyncDispose, function() { - return _async_to_generator(function() { - return _ts_generator(this, function(_state) { - return [ - 2 - ]; - }); - })(); - }), - _define_property({}, Symbol.dispose, function() {}), - null, - undefined - ]; _i < _iter.length; _i++){ - d1 = _iter[_i]; - try { - _usingCtx = _using_ctx(); + switch(_state.label){ + case 0: + _i = 0, _iter = [ + _define_property({}, Symbol.asyncDispose, function() { + return _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); + })(); + }), + _define_property({}, Symbol.dispose, function() {}), + null, + undefined + ]; + _state.label = 1; + case 1: + if (!(_i < _iter.length)) return [ + 3, + 8 + ]; + _ = _iter[_i]; + env = { + stack: [], + error: void 0, + hasError: false + }; + _state.label = 2; + case 2: + _state.trys.push([ + 2, + 3, + 4, + 7 + ]); + d1 = _ts_add_disposable_resource(env, _, true); {} - } catch (_) { - _usingCtx.e = _; - } finally{ - _usingCtx.d(); - } + return [ + 3, + 7 + ]; + case 3: + e = _state.sent(); + env.error = e; + env.hasError = true; + return [ + 3, + 7 + ]; + case 4: + result = _ts_dispose_resources(env); + if (!result) return [ + 3, + 6 + ]; + return [ + 4, + result + ]; + case 5: + _state.sent(); + _state.label = 6; + case 6: + return [ + 7 + ]; + case 7: + _i++; + return [ + 3, + 1 + ]; + case 8: + return [ + 2 + ]; } - return [ - 2 - ]; }); }); return _main.apply(this, arguments); diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es5).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es5).2.minified.js index 8057e88dc703..5ce6b07da1b7 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=es5).2.minified.js @@ -2,4 +2,5 @@ import "@swc/helpers/_/_async_to_generator"; import "@swc/helpers/_/_define_property"; import "@swc/helpers/_/_ts_generator"; -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=esnext).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=esnext).1.normal.js index b539d27f7acb..eb45d86003a1 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=esnext).1.normal.js @@ -1,7 +1,8 @@ //// [awaitUsingDeclarationsInForOf.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; async function main() { - for (const d1 of [ + for (const _ of [ { async [Symbol.asyncDispose] () {} }, @@ -11,13 +12,20 @@ async function main() { null, undefined ]){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, true); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } } diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=esnext).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=esnext).2.minified.js index 7cfe7407750d..88acd2541720 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsInForOf.1(target=esnext).2.minified.js @@ -1,2 +1,3 @@ //// [awaitUsingDeclarationsInForOf.1.ts] -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=es6).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=es6).1.normal.js index 4bd21fdc4282..f5ff5c2c96e9 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=es6).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=es6).1.normal.js @@ -1,25 +1,26 @@ //// [awaitUsingDeclarationsTopLevelOfModule.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -var _x; -export { y }; -var _w; -export { _default as default }; +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(); - const x = 1; - _x = x; - var z = _usingCtx.a({ + const z = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; const y = 2; - const w = 3; - _w = w; - var _default = 4; console.log(w, x, y, z); -} 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; } -export { _x as x }; -export { _w as w }; +export const x = 1; +export { y }; +export const w = 3; +export default 4; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=es6).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=es6).2.minified.js index 902428c27f5a..951287d208b3 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=es6).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=es6).2.minified.js @@ -1,17 +1,23 @@ //// [awaitUsingDeclarationsTopLevelOfModule.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _x, _w, _usingCtx = _using_ctx(); - _x = 1; - var z = _usingCtx.a({ + let z = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - _w = 3; - var _default = 4; - console.log(3, 1, 2, z); -} catch (_) { - _usingCtx.e = _; + }, !0); + console.log(w, x, 2, z); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx.d(); + let result = _ts_dispose_resources(env); + result && await result; } -export { y, _default as default, _x as x, _w as w }; +export const x = 1; +export const w = 3; +export default 4; +export { y }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=system).1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=system).1.normal.js index c1d33bdda846..62d1ec798214 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=system).1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=system).1.normal.js @@ -1,37 +1,42 @@ //// [awaitUsingDeclarationsTopLevelOfModule.1.ts] System.register([ - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _using_ctx, _x, _w; - _export({ - x: void 0, - w: void 0 - }); + var _ts_add_disposable_resource, _ts_dispose_resources, env, x, w; return { setters: [ - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: async function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const x = 1; - _export("x", _x = x); - var z = _usingCtx.a({ + const z = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); + }, true); + ; const y = 2; - const w = 3; - _export("w", _w = w); - var _default = 4; console.log(w, x, y, z); - } 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; } + _export("x", x = 1); + _export("w", w = 3); + _export("default", 4); } }; }); diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=system).2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=system).2.minified.js index 288b89f0e665..16100cadb80a 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=system).2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsTopLevelOfModule.1(module=system).2.minified.js @@ -1,30 +1,36 @@ //// [awaitUsingDeclarationsTopLevelOfModule.1.ts] System.register([ - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _using_ctx; - return _export({ - x: void 0, - w: void 0 - }), { + var _ts_add_disposable_resource, _ts_dispose_resources, env, x, w; + return { setters: [ - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: async function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _export("x", 1); - var z = _usingCtx.a({ + let z = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); - _export("w", 3), console.log(3, 1, 2, z); - } catch (_) { - _usingCtx.e = _; + }, !0); + console.log(w, x, 2, z); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx.d(); + let result = _ts_dispose_resources(env); + result && await result; } + _export("x", x = 1), _export("w", w = 3), _export("default", 4); } }; }); diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsWithImportHelpers.1.normal.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsWithImportHelpers.1.normal.js index 9c252bc04e02..68c67def3611 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsWithImportHelpers.1.normal.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsWithImportHelpers.1.normal.js @@ -1,13 +1,21 @@ //// [awaitUsingDeclarationsWithImportHelpers.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; async function f() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const a = _usingCtx.a(null); - } catch (_) { - _usingCtx.e = _; + const a = _ts_add_disposable_resource(env, null, true); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } } export { }; diff --git a/crates/swc/tests/tsc-references/awaitUsingDeclarationsWithImportHelpers.2.minified.js b/crates/swc/tests/tsc-references/awaitUsingDeclarationsWithImportHelpers.2.minified.js index 371b6dabb67b..68edcb5ca902 100644 --- a/crates/swc/tests/tsc-references/awaitUsingDeclarationsWithImportHelpers.2.minified.js +++ b/crates/swc/tests/tsc-references/awaitUsingDeclarationsWithImportHelpers.2.minified.js @@ -1,2 +1,3 @@ //// [awaitUsingDeclarationsWithImportHelpers.ts] -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2015).1.normal.js index 5d0142a2b5f1..de2c59fd5d50 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2015).1.normal.js @@ -2,22 +2,33 @@ 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"; +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 d1 = _usingCtx.u({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); function f() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d2 = _usingCtx.u({ + const d2 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } function af() { @@ -25,31 +36,43 @@ try { } function _af() { _af = _async_to_generator(function*() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d3 = _usingCtx.u({ + const d3 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }); return _af.apply(this, arguments); } function* g() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d4 = _usingCtx.u({ + const d4 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } function ag() { @@ -57,370 +80,541 @@ try { } function _ag() { _ag = _wrap_async_generator(function*() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d5 = _usingCtx.u({ + const d5 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; yield _await_async_generator(null); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }); return _ag.apply(this, arguments); } const a = ()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d6 = _usingCtx.u({ + const d6 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }; class C1 { m() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d10 = _usingCtx.u({ + const d10 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } get x() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d11 = _usingCtx.u({ + const d11 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; return 0; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } set x(v) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d12 = _usingCtx.u({ + const d12 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } am() { return _async_to_generator(function*() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d13 = _usingCtx.u({ + const d13 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } })(); } *g() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d14 = _usingCtx.u({ + const d14 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } ag() { return _wrap_async_generator(function*() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d15 = _usingCtx.u({ + const d15 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; yield _await_async_generator(null); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } })(); } constructor(){ this.a = ()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d7 = _usingCtx.u({ + const d7 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }; + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d8 = _usingCtx.u({ + const d8 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } (()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d9 = _usingCtx.u({ + const d9 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } })(); class C2 extends C1 { constructor(){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d16 = _usingCtx.u({ + const d16 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; super(); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } class C3 extends C1 { constructor(){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d17 = _usingCtx.u({ + const d17 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; super(), this.y = 1; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } (function(N) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d18 = _usingCtx.u({ + const d18 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } })(N || (N = {})); { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx1 = _using_ctx(); - const d19 = _usingCtx1.u({ + const d19 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx1.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx1.d(); + _ts_dispose_resources(env); } } switch(Math.random()){ case 0: + const env1 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx2 = _using_ctx(); - const d20 = _usingCtx2.u({ + const d20 = _ts_add_disposable_resource(env1, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e; + env1.hasError = true; } finally{ - _usingCtx2.d(); + _ts_dispose_resources(env1); } case 1: + const env2 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx3 = _using_ctx(); - const d21 = _usingCtx3.u({ + const d21 = _ts_add_disposable_resource(env2, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx3.e = _; + } catch (e) { + env2.error = e; + env2.hasError = true; } finally{ - _usingCtx3.d(); + _ts_dispose_resources(env2); } } if (true) switch(0){ case 0: + const env3 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx4 = _using_ctx(); - const d22 = _usingCtx4.u({ + const d22 = _ts_add_disposable_resource(env3, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx4.e = _; + } catch (e) { + env3.error = e; + env3.hasError = true; } finally{ - _usingCtx4.d(); + _ts_dispose_resources(env3); } } try { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx5 = _using_ctx(); - const d23 = _usingCtx5.u({ + const d23 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx5.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx5.d(); + _ts_dispose_resources(env); } } catch (e) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx6 = _using_ctx(); - const d24 = _usingCtx6.u({ + const d24 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx6.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx6.d(); + _ts_dispose_resources(env); } } finally{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx7 = _using_ctx(); - const d25 = _usingCtx7.u({ + const d25 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx7.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx7.d(); + _ts_dispose_resources(env); } } if (true) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx8 = _using_ctx(); - const d26 = _usingCtx8.u({ + const d26 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx8.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx8.d(); + _ts_dispose_resources(env); } } else { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx9 = _using_ctx(); - const d27 = _usingCtx9.u({ + const d27 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx9.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx9.d(); + _ts_dispose_resources(env); } } while(true){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx10 = _using_ctx(); - const d28 = _usingCtx10.u({ + const d28 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx10.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx10.d(); + _ts_dispose_resources(env); } } do { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx11 = _using_ctx(); - const d29 = _usingCtx11.u({ + const d29 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx11.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx11.d(); + _ts_dispose_resources(env); } }while (true) for(;;){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx12 = _using_ctx(); - const d30 = _usingCtx12.u({ + const d30 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx12.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx12.d(); + _ts_dispose_resources(env); } } for(const x in {}){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx13 = _using_ctx(); - const d31 = _usingCtx13.u({ + const d31 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx13.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx13.d(); + _ts_dispose_resources(env); } } for (const x of []){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx14 = _using_ctx(); - const d32 = _usingCtx14.u({ + const d32 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx14.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx14.d(); + _ts_dispose_resources(env); } } var N; } catch (_) { _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { }; diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2015).2.minified.js index 0935feef1992..ee802e897dee 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2015).2.minified.js @@ -2,178 +2,260 @@ import "@swc/helpers/_/_async_to_generator"; import "@swc/helpers/_/_await_async_generator"; import "@swc/helpers/_/_wrap_async_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var N, _usingCtx = _using_ctx(); - _usingCtx.u({ + var N; + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), (()=>{ + }, !1), (()=>{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } })(), function(N) { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }(N || (N = {})); - try { - var _usingCtx1 = _using_ctx(); - _usingCtx1.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx1.e = _; - } finally{ - _usingCtx1.d(); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } switch(Math.random()){ case 0: + let env1 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx2 = _using_ctx(); - _usingCtx2.u({ + _ts_add_disposable_resource(env1, { [Symbol.dispose] () {} - }); + }, !1); break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e, env1.hasError = !0; } finally{ - _usingCtx2.d(); + _ts_dispose_resources(env1); } case 1: + let env2 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx3 = _using_ctx(); - _usingCtx3.u({ + _ts_add_disposable_resource(env2, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx3.e = _; + }, !1); + } catch (e) { + env2.error = e, env2.hasError = !0; } finally{ - _usingCtx3.d(); + _ts_dispose_resources(env2); } } - try { - var _usingCtx4 = _using_ctx(); - _usingCtx4.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx4.e = _; - } finally{ - _usingCtx4.d(); + { + let env3 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env3, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env3.error = e, env3.hasError = !0; + } finally{ + _ts_dispose_resources(env3); + } } try { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx5 = _using_ctx(); - _usingCtx5.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx5.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx5.d(); + _ts_dispose_resources(env); } } catch (e) { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx6 = _using_ctx(); - _usingCtx6.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx6.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx6.d(); + _ts_dispose_resources(env); } } finally{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx7 = _using_ctx(); - _usingCtx7.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx7.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx7.d(); + _ts_dispose_resources(env); } } - try { - var _usingCtx8 = _using_ctx(); - _usingCtx8.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx8.e = _; - } finally{ - _usingCtx8.d(); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(;;)try { - var _usingCtx10 = _using_ctx(); - _usingCtx10.u({ - [Symbol.dispose] () {} - }); - break; - } catch (_) { - _usingCtx10.e = _; - } finally{ - _usingCtx10.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(;;)try { - var _usingCtx11 = _using_ctx(); - _usingCtx11.u({ - [Symbol.dispose] () {} - }); - break; - } catch (_) { - _usingCtx11.e = _; - } finally{ - _usingCtx11.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(;;)try { - var _usingCtx12 = _using_ctx(); - _usingCtx12.u({ - [Symbol.dispose] () {} - }); - break; - } catch (_) { - _usingCtx12.e = _; - } finally{ - _usingCtx12.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(let x in {})try { - var _usingCtx13 = _using_ctx(); - _usingCtx13.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx13.e = _; - } finally{ - _usingCtx13.d(); + for(let x in {}){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for (let x of [])try { - var _usingCtx14 = _using_ctx(); - _usingCtx14.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx14.e = _; - } finally{ - _usingCtx14.d(); + for (let x of []){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2017).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2017).1.normal.js index e2f478b2842c..2ad93dc3bb2f 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2017).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2017).1.normal.js @@ -1,407 +1,601 @@ //// [usingDeclarations.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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 d1 = _usingCtx.u({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); function f() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d2 = _usingCtx.u({ + const d2 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async function af() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d3 = _usingCtx.u({ + const d3 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; await null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } function* g() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d4 = _usingCtx.u({ + const d4 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async function* ag() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d5 = _usingCtx.u({ + const d5 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; await null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } const a = ()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d6 = _usingCtx.u({ + const d6 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }; class C1 { m() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d10 = _usingCtx.u({ + const d10 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } get x() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d11 = _usingCtx.u({ + const d11 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; return 0; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } set x(v) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d12 = _usingCtx.u({ + const d12 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async am() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d13 = _usingCtx.u({ + const d13 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; await null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } *g() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d14 = _usingCtx.u({ + const d14 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async *ag() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d15 = _usingCtx.u({ + const d15 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; await null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } constructor(){ this.a = ()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d7 = _usingCtx.u({ + const d7 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }; + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d8 = _usingCtx.u({ + const d8 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } (()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d9 = _usingCtx.u({ + const d9 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } })(); class C2 extends C1 { constructor(){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d16 = _usingCtx.u({ + const d16 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; super(); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } class C3 extends C1 { constructor(){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d17 = _usingCtx.u({ + const d17 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; super(), this.y = 1; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } (function(N) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d18 = _usingCtx.u({ + const d18 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } })(N || (N = {})); { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx1 = _using_ctx(); - const d19 = _usingCtx1.u({ + const d19 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx1.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx1.d(); + _ts_dispose_resources(env); } } switch(Math.random()){ case 0: + const env1 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx2 = _using_ctx(); - const d20 = _usingCtx2.u({ + const d20 = _ts_add_disposable_resource(env1, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e; + env1.hasError = true; } finally{ - _usingCtx2.d(); + _ts_dispose_resources(env1); } case 1: + const env2 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx3 = _using_ctx(); - const d21 = _usingCtx3.u({ + const d21 = _ts_add_disposable_resource(env2, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx3.e = _; + } catch (e) { + env2.error = e; + env2.hasError = true; } finally{ - _usingCtx3.d(); + _ts_dispose_resources(env2); } } if (true) switch(0){ case 0: + const env3 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx4 = _using_ctx(); - const d22 = _usingCtx4.u({ + const d22 = _ts_add_disposable_resource(env3, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx4.e = _; + } catch (e) { + env3.error = e; + env3.hasError = true; } finally{ - _usingCtx4.d(); + _ts_dispose_resources(env3); } } try { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx5 = _using_ctx(); - const d23 = _usingCtx5.u({ + const d23 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx5.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx5.d(); + _ts_dispose_resources(env); } } catch (e) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx6 = _using_ctx(); - const d24 = _usingCtx6.u({ + const d24 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx6.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx6.d(); + _ts_dispose_resources(env); } } finally{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx7 = _using_ctx(); - const d25 = _usingCtx7.u({ + const d25 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx7.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx7.d(); + _ts_dispose_resources(env); } } if (true) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx8 = _using_ctx(); - const d26 = _usingCtx8.u({ + const d26 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx8.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx8.d(); + _ts_dispose_resources(env); } } else { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx9 = _using_ctx(); - const d27 = _usingCtx9.u({ + const d27 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx9.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx9.d(); + _ts_dispose_resources(env); } } while(true){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx10 = _using_ctx(); - const d28 = _usingCtx10.u({ + const d28 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx10.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx10.d(); + _ts_dispose_resources(env); } } do { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx11 = _using_ctx(); - const d29 = _usingCtx11.u({ + const d29 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx11.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx11.d(); + _ts_dispose_resources(env); } }while (true) for(;;){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx12 = _using_ctx(); - const d30 = _usingCtx12.u({ + const d30 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx12.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx12.d(); + _ts_dispose_resources(env); } } for(const x in {}){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx13 = _using_ctx(); - const d31 = _usingCtx13.u({ + const d31 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx13.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx13.d(); + _ts_dispose_resources(env); } } for (const x of []){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx14 = _using_ctx(); - const d32 = _usingCtx14.u({ + const d32 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx14.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx14.d(); + _ts_dispose_resources(env); } } var N; } catch (_) { _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { }; diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2017).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2017).2.minified.js index 1a1a2e70b216..722b3f9dcddf 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2017).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2017).2.minified.js @@ -1,176 +1,258 @@ //// [usingDeclarations.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var N, _usingCtx = _using_ctx(); - _usingCtx.u({ + var N; + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), (()=>{ + }, !1), (()=>{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } })(), function(N) { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }(N || (N = {})); - try { - var _usingCtx1 = _using_ctx(); - _usingCtx1.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx1.e = _; - } finally{ - _usingCtx1.d(); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } switch(Math.random()){ case 0: + let env1 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx2 = _using_ctx(); - _usingCtx2.u({ + _ts_add_disposable_resource(env1, { [Symbol.dispose] () {} - }); + }, !1); break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e, env1.hasError = !0; } finally{ - _usingCtx2.d(); + _ts_dispose_resources(env1); } case 1: + let env2 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx3 = _using_ctx(); - _usingCtx3.u({ + _ts_add_disposable_resource(env2, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx3.e = _; + }, !1); + } catch (e) { + env2.error = e, env2.hasError = !0; } finally{ - _usingCtx3.d(); + _ts_dispose_resources(env2); } } - try { - var _usingCtx4 = _using_ctx(); - _usingCtx4.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx4.e = _; - } finally{ - _usingCtx4.d(); + { + let env3 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env3, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env3.error = e, env3.hasError = !0; + } finally{ + _ts_dispose_resources(env3); + } } try { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx5 = _using_ctx(); - _usingCtx5.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx5.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx5.d(); + _ts_dispose_resources(env); } } catch (e) { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx6 = _using_ctx(); - _usingCtx6.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx6.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx6.d(); + _ts_dispose_resources(env); } } finally{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx7 = _using_ctx(); - _usingCtx7.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx7.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx7.d(); + _ts_dispose_resources(env); } } - try { - var _usingCtx8 = _using_ctx(); - _usingCtx8.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx8.e = _; - } finally{ - _usingCtx8.d(); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(;;)try { - var _usingCtx10 = _using_ctx(); - _usingCtx10.u({ - [Symbol.dispose] () {} - }); - break; - } catch (_) { - _usingCtx10.e = _; - } finally{ - _usingCtx10.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(;;)try { - var _usingCtx11 = _using_ctx(); - _usingCtx11.u({ - [Symbol.dispose] () {} - }); - break; - } catch (_) { - _usingCtx11.e = _; - } finally{ - _usingCtx11.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(;;)try { - var _usingCtx12 = _using_ctx(); - _usingCtx12.u({ - [Symbol.dispose] () {} - }); - break; - } catch (_) { - _usingCtx12.e = _; - } finally{ - _usingCtx12.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(let x in {})try { - var _usingCtx13 = _using_ctx(); - _usingCtx13.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx13.e = _; - } finally{ - _usingCtx13.d(); + for(let x in {}){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for (let x of [])try { - var _usingCtx14 = _using_ctx(); - _usingCtx14.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx14.e = _; - } finally{ - _usingCtx14.d(); + for (let x of []){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2022).1.normal.js index c60cf682c836..00074c2d3667 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2022).1.normal.js @@ -1,407 +1,601 @@ //// [usingDeclarations.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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 d1 = _usingCtx.u({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); function f() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d2 = _usingCtx.u({ + const d2 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async function af() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d3 = _usingCtx.u({ + const d3 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; await null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } function* g() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d4 = _usingCtx.u({ + const d4 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async function* ag() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d5 = _usingCtx.u({ + const d5 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; await null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } const a = ()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d6 = _usingCtx.u({ + const d6 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }; class C1 { constructor(){ this.a = ()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d7 = _usingCtx.u({ + const d7 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }; + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d8 = _usingCtx.u({ + const d8 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } static{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d9 = _usingCtx.u({ + const d9 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } m() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d10 = _usingCtx.u({ + const d10 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } get x() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d11 = _usingCtx.u({ + const d11 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; return 0; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } set x(v) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d12 = _usingCtx.u({ + const d12 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async am() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d13 = _usingCtx.u({ + const d13 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; await null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } *g() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d14 = _usingCtx.u({ + const d14 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async *ag() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d15 = _usingCtx.u({ + const d15 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; await null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } class C2 extends C1 { constructor(){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d16 = _usingCtx.u({ + const d16 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; super(); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } class C3 extends C1 { constructor(){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d17 = _usingCtx.u({ + const d17 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; super(), this.y = 1; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } (function(N) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d18 = _usingCtx.u({ + const d18 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } })(N || (N = {})); { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx1 = _using_ctx(); - const d19 = _usingCtx1.u({ + const d19 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx1.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx1.d(); + _ts_dispose_resources(env); } } switch(Math.random()){ case 0: + const env1 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx2 = _using_ctx(); - const d20 = _usingCtx2.u({ + const d20 = _ts_add_disposable_resource(env1, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e; + env1.hasError = true; } finally{ - _usingCtx2.d(); + _ts_dispose_resources(env1); } case 1: + const env2 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx3 = _using_ctx(); - const d21 = _usingCtx3.u({ + const d21 = _ts_add_disposable_resource(env2, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx3.e = _; + } catch (e) { + env2.error = e; + env2.hasError = true; } finally{ - _usingCtx3.d(); + _ts_dispose_resources(env2); } } if (true) switch(0){ case 0: + const env3 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx4 = _using_ctx(); - const d22 = _usingCtx4.u({ + const d22 = _ts_add_disposable_resource(env3, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx4.e = _; + } catch (e) { + env3.error = e; + env3.hasError = true; } finally{ - _usingCtx4.d(); + _ts_dispose_resources(env3); } } try { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx5 = _using_ctx(); - const d23 = _usingCtx5.u({ + const d23 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx5.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx5.d(); + _ts_dispose_resources(env); } } catch { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx6 = _using_ctx(); - const d24 = _usingCtx6.u({ + const d24 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx6.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx6.d(); + _ts_dispose_resources(env); } } finally{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx7 = _using_ctx(); - const d25 = _usingCtx7.u({ + const d25 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx7.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx7.d(); + _ts_dispose_resources(env); } } if (true) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx8 = _using_ctx(); - const d26 = _usingCtx8.u({ + const d26 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx8.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx8.d(); + _ts_dispose_resources(env); } } else { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx9 = _using_ctx(); - const d27 = _usingCtx9.u({ + const d27 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx9.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx9.d(); + _ts_dispose_resources(env); } } while(true){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx10 = _using_ctx(); - const d28 = _usingCtx10.u({ + const d28 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx10.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx10.d(); + _ts_dispose_resources(env); } } do { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx11 = _using_ctx(); - const d29 = _usingCtx11.u({ + const d29 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx11.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx11.d(); + _ts_dispose_resources(env); } }while (true) for(;;){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx12 = _using_ctx(); - const d30 = _usingCtx12.u({ + const d30 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx12.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx12.d(); + _ts_dispose_resources(env); } } for(const x in {}){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx13 = _using_ctx(); - const d31 = _usingCtx13.u({ + const d31 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx13.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx13.d(); + _ts_dispose_resources(env); } } for (const x of []){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx14 = _using_ctx(); - const d32 = _usingCtx14.u({ + const d32 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx14.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx14.d(); + _ts_dispose_resources(env); } } var N; } catch (_) { _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { }; diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2022).2.minified.js index c757c3f676a5..4d259ef89d6f 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2022).2.minified.js @@ -1,276 +1,390 @@ //// [usingDeclarations.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var N, _usingCtx = _using_ctx(); - _usingCtx.u({ + var N; + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, !1); class C1 { constructor(){ this.a = ()=>{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }; + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } static{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } m() { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } get x() { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - return _usingCtx.u({ + return _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), 0; - } catch (_) { - _usingCtx.e = _; + }, !1), 0; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } set x(v) { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async am() { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), await null; - } catch (_) { - _usingCtx.e = _; + }, !1), await null; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } *g() { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), yield; - } catch (_) { - _usingCtx.e = _; + }, !1), yield; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async *ag() { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), yield, await null; - } catch (_) { - _usingCtx.e = _; + }, !1), yield, await null; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } !function(N) { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }(N || (N = {})); - try { - var _usingCtx1 = _using_ctx(); - _usingCtx1.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx1.e = _; - } finally{ - _usingCtx1.d(); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } switch(Math.random()){ case 0: + let env1 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx2 = _using_ctx(); - _usingCtx2.u({ + _ts_add_disposable_resource(env1, { [Symbol.dispose] () {} - }); + }, !1); break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e, env1.hasError = !0; } finally{ - _usingCtx2.d(); + _ts_dispose_resources(env1); } case 1: + let env2 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx3 = _using_ctx(); - _usingCtx3.u({ + _ts_add_disposable_resource(env2, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx3.e = _; + }, !1); + } catch (e) { + env2.error = e, env2.hasError = !0; } finally{ - _usingCtx3.d(); + _ts_dispose_resources(env2); } } - try { - var _usingCtx4 = _using_ctx(); - _usingCtx4.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx4.e = _; - } finally{ - _usingCtx4.d(); + { + let env3 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env3, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env3.error = e, env3.hasError = !0; + } finally{ + _ts_dispose_resources(env3); + } } try { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx5 = _using_ctx(); - _usingCtx5.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx5.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx5.d(); + _ts_dispose_resources(env); } } catch { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx6 = _using_ctx(); - _usingCtx6.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx6.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx6.d(); + _ts_dispose_resources(env); } } finally{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx7 = _using_ctx(); - _usingCtx7.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx7.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx7.d(); + _ts_dispose_resources(env); } } - try { - var _usingCtx8 = _using_ctx(); - _usingCtx8.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx8.e = _; - } finally{ - _usingCtx8.d(); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(;;)try { - var _usingCtx10 = _using_ctx(); - _usingCtx10.u({ - [Symbol.dispose] () {} - }); - break; - } catch (_) { - _usingCtx10.e = _; - } finally{ - _usingCtx10.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(;;)try { - var _usingCtx11 = _using_ctx(); - _usingCtx11.u({ - [Symbol.dispose] () {} - }); - break; - } catch (_) { - _usingCtx11.e = _; - } finally{ - _usingCtx11.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(;;)try { - var _usingCtx12 = _using_ctx(); - _usingCtx12.u({ - [Symbol.dispose] () {} - }); - break; - } catch (_) { - _usingCtx12.e = _; - } finally{ - _usingCtx12.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(let x in {})try { - var _usingCtx13 = _using_ctx(); - _usingCtx13.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx13.e = _; - } finally{ - _usingCtx13.d(); + for(let x in {}){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for (let x of [])try { - var _usingCtx14 = _using_ctx(); - _usingCtx14.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx14.e = _; - } finally{ - _usingCtx14.d(); + for (let x of []){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es5).1.normal.js index 2f2f80bc56de..1f55f824a7bb 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es5).1.normal.js @@ -9,56 +9,75 @@ import { _ as _define_property } from "@swc/helpers/_/_define_property"; import { _ as _inherits } from "@swc/helpers/_/_inherits"; import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: false +}; try { var f = function f() { + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d2 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx.e = _; + var d2 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }; var af = function af() { return _af.apply(this, arguments); }; var g = function g() { - var _usingCtx, d4, _; + var env, d4, e; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: + env = { + stack: [], + error: void 0, + hasError: false + }; + _state.label = 1; + case 1: _state.trys.push([ - 0, - 2, + 1, 3, - 4 + 4, + 5 ]); - _usingCtx = _using_ctx(); - d4 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); + d4 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); return [ 4 ]; - case 1: + case 2: _state.sent(); return [ 3, - 4 + 5 ]; - case 2: - _ = _state.sent(); - _usingCtx.e = _; + case 3: + e = _state.sent(); + env.error = e; + env.hasError = true; return [ 3, - 4 + 5 ]; - case 3: - _usingCtx.d(); + case 4: + _ts_dispose_resources(env); return [ 7 ]; - case 4: + case 5: return [ 2 ]; @@ -68,45 +87,51 @@ try { var ag = function ag() { return _ag.apply(this, arguments); }; - var _usingCtx = _using_ctx(); - var d1 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); + var d1 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); function _af() { _af = _async_to_generator(function() { - var _usingCtx, d3, _; + var env, d3, e; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: + env = { + stack: [], + error: void 0, + hasError: false + }; + _state.label = 1; + case 1: _state.trys.push([ - 0, - 2, + 1, 3, - 4 + 4, + 5 ]); - _usingCtx = _using_ctx(); - d3 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); + d3 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); return [ 4, null ]; - case 1: + case 2: _state.sent(); return [ 3, - 4 + 5 ]; - case 2: - _ = _state.sent(); - _usingCtx.e = _; + case 3: + e = _state.sent(); + env.error = e; + env.hasError = true; return [ 3, - 4 + 5 ]; - case 3: - _usingCtx.d(); + case 4: + _ts_dispose_resources(env); return [ 7 ]; - case 4: + case 5: return [ 2 ]; @@ -117,46 +142,53 @@ try { } function _ag() { _ag = _wrap_async_generator(function() { - var _usingCtx, d5, _; + var env, d5, e; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: + env = { + stack: [], + error: void 0, + hasError: false + }; + _state.label = 1; + case 1: _state.trys.push([ - 0, - 3, + 1, 4, - 5 + 5, + 6 ]); - _usingCtx = _using_ctx(); - d5 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); + d5 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); return [ 4 ]; - case 1: + case 2: _state.sent(); return [ 4, _await_async_generator(null) ]; - case 2: + case 3: _state.sent(); return [ 3, - 5 + 6 ]; - case 3: - _ = _state.sent(); - _usingCtx.e = _; + case 4: + e = _state.sent(); + env.error = e; + env.hasError = true; return [ 3, - 5 + 6 ]; - case 4: - _usingCtx.d(); + case 5: + _ts_dispose_resources(env); return [ 7 ]; - case 5: + case 6: return [ 2 ]; @@ -166,13 +198,19 @@ try { return _ag.apply(this, arguments); } var a = function() { + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d6 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx.e = _; + var d6 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }; var C1 = /*#__PURE__*/ function() { @@ -180,72 +218,97 @@ try { function C1() { _class_call_check(this, C1); this.a = function() { + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d7 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx.e = _; + var d7 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }; + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d8 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx.e = _; + var d8 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } var _proto = C1.prototype; _proto.m = function m() { + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d10 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx.e = _; + var d10 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }; _proto.am = function am() { return _async_to_generator(function() { - var _usingCtx, d13, _; + var env, d13, e; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: + env = { + stack: [], + error: void 0, + hasError: false + }; + _state.label = 1; + case 1: _state.trys.push([ - 0, - 2, + 1, 3, - 4 + 4, + 5 ]); - _usingCtx = _using_ctx(); - d13 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); + d13 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); return [ 4, null ]; - case 1: + case 2: _state.sent(); return [ 3, - 4 + 5 ]; - case 2: - _ = _state.sent(); - _usingCtx.e = _; + case 3: + e = _state.sent(); + env.error = e; + env.hasError = true; return [ 3, - 4 + 5 ]; - case 3: - _usingCtx.d(); + case 4: + _ts_dispose_resources(env); return [ 7 ]; - case 4: + case 5: return [ 2 ]; @@ -254,40 +317,47 @@ try { })(); }; _proto.g = function g() { - var _usingCtx, d14, _; + var env, d14, e; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: + env = { + stack: [], + error: void 0, + hasError: false + }; + _state.label = 1; + case 1: _state.trys.push([ - 0, - 2, + 1, 3, - 4 + 4, + 5 ]); - _usingCtx = _using_ctx(); - d14 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); + d14 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); return [ 4 ]; - case 1: + case 2: _state.sent(); return [ 3, - 4 + 5 ]; - case 2: - _ = _state.sent(); - _usingCtx.e = _; + case 3: + e = _state.sent(); + env.error = e; + env.hasError = true; return [ 3, - 4 + 5 ]; - case 3: - _usingCtx.d(); + case 4: + _ts_dispose_resources(env); return [ 7 ]; - case 4: + case 5: return [ 2 ]; @@ -296,46 +366,53 @@ try { }; _proto.ag = function ag() { return _wrap_async_generator(function() { - var _usingCtx, d15, _; + var env, d15, e; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: + env = { + stack: [], + error: void 0, + hasError: false + }; + _state.label = 1; + case 1: _state.trys.push([ - 0, - 3, + 1, 4, - 5 + 5, + 6 ]); - _usingCtx = _using_ctx(); - d15 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); + d15 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); return [ 4 ]; - case 1: + case 2: _state.sent(); return [ 4, _await_async_generator(null) ]; - case 2: + case 3: _state.sent(); return [ 3, - 5 + 6 ]; - case 3: - _ = _state.sent(); - _usingCtx.e = _; + case 4: + e = _state.sent(); + env.error = e; + env.hasError = true; return [ 3, - 5 + 6 ]; - case 4: - _usingCtx.d(); + case 5: + _ts_dispose_resources(env); return [ 7 ]; - case 5: + case 6: return [ 2 ]; @@ -347,24 +424,36 @@ try { { key: "x", get: function get() { + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d11 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); + var d11 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); + ; return 0; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }, set: function set(v) { + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d12 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx.e = _; + var d12 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } @@ -372,13 +461,19 @@ try { return C1; }(); (function() { + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d9 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx.e = _; + var d9 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } })(); var C2 = /*#__PURE__*/ function(C1) { @@ -387,14 +482,20 @@ try { function C2() { _class_call_check(this, C2); var _this; + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d16 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); + var d16 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); + ; _this = _call_super(this, C2); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } return _assert_this_initialized(_this); } @@ -406,178 +507,277 @@ try { function C3() { _class_call_check(this, C3); var _this; + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d17 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); + var d17 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); + ; _this = _call_super(this, C3), _this.y = 1; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } return _assert_this_initialized(_this); } return C3; }(C1); (function(N) { + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d18 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx.e = _; + var d18 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } })(N || (N = {})); { + var env1 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx1 = _using_ctx(); - var d19 = _usingCtx1.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx1.e = _; + var d19 = _ts_add_disposable_resource(env1, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env1.error = e; + env1.hasError = true; } finally{ - _usingCtx1.d(); + _ts_dispose_resources(env1); } } switch(Math.random()){ case 0: + var env2 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx2 = _using_ctx(); - var d20 = _usingCtx2.u(_define_property({}, Symbol.dispose, function() {})); + var d20 = _ts_add_disposable_resource(env2, _define_property({}, Symbol.dispose, function() {}), false); + ; break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env2.error = e; + env2.hasError = true; } finally{ - _usingCtx2.d(); + _ts_dispose_resources(env2); } case 1: + var env3 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx3 = _using_ctx(); - var d21 = _usingCtx3.u(_define_property({}, Symbol.dispose, function() {})); + var d21 = _ts_add_disposable_resource(env3, _define_property({}, Symbol.dispose, function() {}), false); + ; break; - } catch (_) { - _usingCtx3.e = _; + } catch (e) { + env3.error = e; + env3.hasError = true; } finally{ - _usingCtx3.d(); + _ts_dispose_resources(env3); } } if (true) switch(0){ case 0: + var env4 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx4 = _using_ctx(); - var d22 = _usingCtx4.u(_define_property({}, Symbol.dispose, function() {})); + var d22 = _ts_add_disposable_resource(env4, _define_property({}, Symbol.dispose, function() {}), false); + ; break; - } catch (_) { - _usingCtx4.e = _; + } catch (e) { + env4.error = e; + env4.hasError = true; } finally{ - _usingCtx4.d(); + _ts_dispose_resources(env4); } } try { + var env5 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx5 = _using_ctx(); - var d23 = _usingCtx5.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx5.e = _; + var d23 = _ts_add_disposable_resource(env5, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env5.error = e; + env5.hasError = true; } finally{ - _usingCtx5.d(); + _ts_dispose_resources(env5); } } catch (e) { + var env6 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx6 = _using_ctx(); - var d24 = _usingCtx6.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx6.e = _; + var d24 = _ts_add_disposable_resource(env6, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env6.error = e; + env6.hasError = true; } finally{ - _usingCtx6.d(); + _ts_dispose_resources(env6); } } finally{ + var env7 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx7 = _using_ctx(); - var d25 = _usingCtx7.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx7.e = _; + var d25 = _ts_add_disposable_resource(env7, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env7.error = e; + env7.hasError = true; } finally{ - _usingCtx7.d(); + _ts_dispose_resources(env7); } } if (true) { + var env8 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx8 = _using_ctx(); - var d26 = _usingCtx8.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx8.e = _; + var d26 = _ts_add_disposable_resource(env8, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env8.error = e; + env8.hasError = true; } finally{ - _usingCtx8.d(); + _ts_dispose_resources(env8); } } else { + var env9 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx9 = _using_ctx(); - var d27 = _usingCtx9.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx9.e = _; + var d27 = _ts_add_disposable_resource(env9, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env9.error = e; + env9.hasError = true; } finally{ - _usingCtx9.d(); + _ts_dispose_resources(env9); } } while(true){ + var env10 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx10 = _using_ctx(); - var d28 = _usingCtx10.u(_define_property({}, Symbol.dispose, function() {})); + var d28 = _ts_add_disposable_resource(env10, _define_property({}, Symbol.dispose, function() {}), false); + ; break; - } catch (_) { - _usingCtx10.e = _; + } catch (e) { + env10.error = e; + env10.hasError = true; } finally{ - _usingCtx10.d(); + _ts_dispose_resources(env10); } } do { + var env11 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx11 = _using_ctx(); - var d29 = _usingCtx11.u(_define_property({}, Symbol.dispose, function() {})); + var d29 = _ts_add_disposable_resource(env11, _define_property({}, Symbol.dispose, function() {}), false); + ; break; - } catch (_) { - _usingCtx11.e = _; + } catch (e) { + env11.error = e; + env11.hasError = true; } finally{ - _usingCtx11.d(); + _ts_dispose_resources(env11); } }while (true); for(;;){ + var env12 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx12 = _using_ctx(); - var d30 = _usingCtx12.u(_define_property({}, Symbol.dispose, function() {})); + var d30 = _ts_add_disposable_resource(env12, _define_property({}, Symbol.dispose, function() {}), false); + ; break; - } catch (_) { - _usingCtx12.e = _; + } catch (e) { + env12.error = e; + env12.hasError = true; } finally{ - _usingCtx12.d(); + _ts_dispose_resources(env12); } } for(var x in {}){ + var env13 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx13 = _using_ctx(); - var d31 = _usingCtx13.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx13.e = _; + var d31 = _ts_add_disposable_resource(env13, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env13.error = e; + env13.hasError = true; } finally{ - _usingCtx13.d(); + _ts_dispose_resources(env13); } } for(var _i = 0, _iter = []; _i < _iter.length; _i++){ var x1 = _iter[_i]; + var env14 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx14 = _using_ctx(); - var d32 = _usingCtx14.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx14.e = _; + var d32 = _ts_add_disposable_resource(env14, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env14.error = e; + env14.hasError = true; } finally{ - _usingCtx14.d(); + _ts_dispose_resources(env14); } } var N; } catch (_) { _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { }; diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es5).2.minified.js index e5b18e63bbb0..17f373b7d651 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es5).2.minified.js @@ -9,149 +9,222 @@ import { _ as _define_property } from "@swc/helpers/_/_define_property"; import { _ as _inherits } from "@swc/helpers/_/_inherits"; import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var N, _usingCtx = _using_ctx(); - _usingCtx.u(_define_property({}, Symbol.dispose, function() {})), function() { + _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), !1), function() { + var env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx.e = _; + _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }(), function(N) { + var env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx.e = _; + _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }(N || (N = {})); + var N, env1 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx1 = _using_ctx(); - _usingCtx1.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx1.e = _; + _ts_add_disposable_resource(env1, _define_property({}, Symbol.dispose, function() {}), !1); + } catch (e) { + env1.error = e, env1.hasError = !0; } finally{ - _usingCtx1.d(); + _ts_dispose_resources(env1); } switch(Math.random()){ case 0: + var env2 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx2 = _using_ctx(); - _usingCtx2.u(_define_property({}, Symbol.dispose, function() {})); + _ts_add_disposable_resource(env2, _define_property({}, Symbol.dispose, function() {}), !1); break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env2.error = e, env2.hasError = !0; } finally{ - _usingCtx2.d(); + _ts_dispose_resources(env2); } case 1: + var env3 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx3 = _using_ctx(); - _usingCtx3.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx3.e = _; + _ts_add_disposable_resource(env3, _define_property({}, Symbol.dispose, function() {}), !1); + } catch (e) { + env3.error = e, env3.hasError = !0; } finally{ - _usingCtx3.d(); + _ts_dispose_resources(env3); } } + var env4 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx4 = _using_ctx(); - _usingCtx4.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx4.e = _; + _ts_add_disposable_resource(env4, _define_property({}, Symbol.dispose, function() {}), !1); + } catch (e) { + env4.error = e, env4.hasError = !0; } finally{ - _usingCtx4.d(); + _ts_dispose_resources(env4); } try { + var env5 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx5 = _using_ctx(); - _usingCtx5.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx5.e = _; + _ts_add_disposable_resource(env5, _define_property({}, Symbol.dispose, function() {}), !1); + } catch (e) { + env5.error = e, env5.hasError = !0; } finally{ - _usingCtx5.d(); + _ts_dispose_resources(env5); } } catch (e) { + var env6 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx6 = _using_ctx(); - _usingCtx6.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx6.e = _; + _ts_add_disposable_resource(env6, _define_property({}, Symbol.dispose, function() {}), !1); + } catch (e) { + env6.error = e, env6.hasError = !0; } finally{ - _usingCtx6.d(); + _ts_dispose_resources(env6); } } finally{ + var env7 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx7 = _using_ctx(); - _usingCtx7.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx7.e = _; + _ts_add_disposable_resource(env7, _define_property({}, Symbol.dispose, function() {}), !1); + } catch (e) { + env7.error = e, env7.hasError = !0; } finally{ - _usingCtx7.d(); + _ts_dispose_resources(env7); } } + var env8 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx8 = _using_ctx(); - _usingCtx8.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx8.e = _; + _ts_add_disposable_resource(env8, _define_property({}, Symbol.dispose, function() {}), !1); + } catch (e) { + env8.error = e, env8.hasError = !0; } finally{ - _usingCtx8.d(); + _ts_dispose_resources(env8); } - for(;;)try { - var _usingCtx10 = _using_ctx(); - _usingCtx10.u(_define_property({}, Symbol.dispose, function() {})); - break; - } catch (_) { - _usingCtx10.e = _; - } finally{ - _usingCtx10.d(); + for(;;){ + var env10 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env10, _define_property({}, Symbol.dispose, function() {}), !1); + break; + } catch (e) { + env10.error = e, env10.hasError = !0; + } finally{ + _ts_dispose_resources(env10); + } } - for(;;)try { - var _usingCtx11 = _using_ctx(); - _usingCtx11.u(_define_property({}, Symbol.dispose, function() {})); - break; - } catch (_) { - _usingCtx11.e = _; - } finally{ - _usingCtx11.d(); + for(;;){ + var env11 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env11, _define_property({}, Symbol.dispose, function() {}), !1); + break; + } catch (e) { + env11.error = e, env11.hasError = !0; + } finally{ + _ts_dispose_resources(env11); + } } - for(;;)try { - var _usingCtx12 = _using_ctx(); - _usingCtx12.u(_define_property({}, Symbol.dispose, function() {})); - break; - } catch (_) { - _usingCtx12.e = _; - } finally{ - _usingCtx12.d(); + for(;;){ + var env12 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env12, _define_property({}, Symbol.dispose, function() {}), !1); + break; + } catch (e) { + env12.error = e, env12.hasError = !0; + } finally{ + _ts_dispose_resources(env12); + } } - for(var x in {})try { - var _usingCtx13 = _using_ctx(); - _usingCtx13.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx13.e = _; - } finally{ - _usingCtx13.d(); + for(var x in {}){ + var env13 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env13, _define_property({}, Symbol.dispose, function() {}), !1); + } catch (e) { + env13.error = e, env13.hasError = !0; + } finally{ + _ts_dispose_resources(env13); + } } for(var _i = 0, _iter = []; _i < _iter.length; _i++){ _iter[_i]; + var env14 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx14 = _using_ctx(); - _usingCtx14.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx14.e = _; + _ts_add_disposable_resource(env14, _define_property({}, Symbol.dispose, function() {}), !1); + } catch (e) { + env14.error = e, env14.hasError = !0; } finally{ - _usingCtx14.d(); + _ts_dispose_resources(env14); } } -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=esnext).1.normal.js index c60cf682c836..00074c2d3667 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=esnext).1.normal.js @@ -1,407 +1,601 @@ //// [usingDeclarations.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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 d1 = _usingCtx.u({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); function f() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d2 = _usingCtx.u({ + const d2 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async function af() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d3 = _usingCtx.u({ + const d3 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; await null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } function* g() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d4 = _usingCtx.u({ + const d4 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async function* ag() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d5 = _usingCtx.u({ + const d5 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; await null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } const a = ()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d6 = _usingCtx.u({ + const d6 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }; class C1 { constructor(){ this.a = ()=>{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d7 = _usingCtx.u({ + const d7 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }; + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d8 = _usingCtx.u({ + const d8 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } static{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d9 = _usingCtx.u({ + const d9 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } m() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d10 = _usingCtx.u({ + const d10 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } get x() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d11 = _usingCtx.u({ + const d11 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; return 0; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } set x(v) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d12 = _usingCtx.u({ + const d12 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async am() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d13 = _usingCtx.u({ + const d13 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; await null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } *g() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d14 = _usingCtx.u({ + const d14 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async *ag() { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d15 = _usingCtx.u({ + const d15 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; yield; await null; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } class C2 extends C1 { constructor(){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d16 = _usingCtx.u({ + const d16 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; super(); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } class C3 extends C1 { constructor(){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const d17 = _usingCtx.u({ + const d17 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; super(), this.y = 1; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } (function(N) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d18 = _usingCtx.u({ + const d18 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } })(N || (N = {})); { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx1 = _using_ctx(); - const d19 = _usingCtx1.u({ + const d19 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx1.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx1.d(); + _ts_dispose_resources(env); } } switch(Math.random()){ case 0: + const env1 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx2 = _using_ctx(); - const d20 = _usingCtx2.u({ + const d20 = _ts_add_disposable_resource(env1, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e; + env1.hasError = true; } finally{ - _usingCtx2.d(); + _ts_dispose_resources(env1); } case 1: + const env2 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx3 = _using_ctx(); - const d21 = _usingCtx3.u({ + const d21 = _ts_add_disposable_resource(env2, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx3.e = _; + } catch (e) { + env2.error = e; + env2.hasError = true; } finally{ - _usingCtx3.d(); + _ts_dispose_resources(env2); } } if (true) switch(0){ case 0: + const env3 = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx4 = _using_ctx(); - const d22 = _usingCtx4.u({ + const d22 = _ts_add_disposable_resource(env3, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx4.e = _; + } catch (e) { + env3.error = e; + env3.hasError = true; } finally{ - _usingCtx4.d(); + _ts_dispose_resources(env3); } } try { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx5 = _using_ctx(); - const d23 = _usingCtx5.u({ + const d23 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx5.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx5.d(); + _ts_dispose_resources(env); } } catch { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx6 = _using_ctx(); - const d24 = _usingCtx6.u({ + const d24 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx6.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx6.d(); + _ts_dispose_resources(env); } } finally{ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx7 = _using_ctx(); - const d25 = _usingCtx7.u({ + const d25 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx7.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx7.d(); + _ts_dispose_resources(env); } } if (true) { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx8 = _using_ctx(); - const d26 = _usingCtx8.u({ + const d26 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx8.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx8.d(); + _ts_dispose_resources(env); } } else { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx9 = _using_ctx(); - const d27 = _usingCtx9.u({ + const d27 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx9.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx9.d(); + _ts_dispose_resources(env); } } while(true){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx10 = _using_ctx(); - const d28 = _usingCtx10.u({ + const d28 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx10.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx10.d(); + _ts_dispose_resources(env); } } do { + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx11 = _using_ctx(); - const d29 = _usingCtx11.u({ + const d29 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx11.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx11.d(); + _ts_dispose_resources(env); } }while (true) for(;;){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx12 = _using_ctx(); - const d30 = _usingCtx12.u({ + const d30 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; break; - } catch (_) { - _usingCtx12.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx12.d(); + _ts_dispose_resources(env); } } for(const x in {}){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx13 = _using_ctx(); - const d31 = _usingCtx13.u({ + const d31 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx13.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx13.d(); + _ts_dispose_resources(env); } } for (const x of []){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx14 = _using_ctx(); - const d32 = _usingCtx14.u({ + const d32 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx14.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx14.d(); + _ts_dispose_resources(env); } } var N; } catch (_) { _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { }; diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=esnext).2.minified.js index c757c3f676a5..4d259ef89d6f 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=esnext).2.minified.js @@ -1,276 +1,390 @@ //// [usingDeclarations.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var N, _usingCtx = _using_ctx(); - _usingCtx.u({ + var N; + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, !1); class C1 { constructor(){ this.a = ()=>{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }; + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } static{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } m() { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } get x() { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - return _usingCtx.u({ + return _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), 0; - } catch (_) { - _usingCtx.e = _; + }, !1), 0; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } set x(v) { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async am() { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), await null; - } catch (_) { - _usingCtx.e = _; + }, !1), await null; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } *g() { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), yield; - } catch (_) { - _usingCtx.e = _; + }, !1), yield; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } async *ag() { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), yield, await null; - } catch (_) { - _usingCtx.e = _; + }, !1), yield, await null; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } !function(N) { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }(N || (N = {})); - try { - var _usingCtx1 = _using_ctx(); - _usingCtx1.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx1.e = _; - } finally{ - _usingCtx1.d(); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } switch(Math.random()){ case 0: + let env1 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx2 = _using_ctx(); - _usingCtx2.u({ + _ts_add_disposable_resource(env1, { [Symbol.dispose] () {} - }); + }, !1); break; - } catch (_) { - _usingCtx2.e = _; + } catch (e) { + env1.error = e, env1.hasError = !0; } finally{ - _usingCtx2.d(); + _ts_dispose_resources(env1); } case 1: + let env2 = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx3 = _using_ctx(); - _usingCtx3.u({ + _ts_add_disposable_resource(env2, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx3.e = _; + }, !1); + } catch (e) { + env2.error = e, env2.hasError = !0; } finally{ - _usingCtx3.d(); + _ts_dispose_resources(env2); } } - try { - var _usingCtx4 = _using_ctx(); - _usingCtx4.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx4.e = _; - } finally{ - _usingCtx4.d(); + { + let env3 = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env3, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env3.error = e, env3.hasError = !0; + } finally{ + _ts_dispose_resources(env3); + } } try { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx5 = _using_ctx(); - _usingCtx5.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx5.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx5.d(); + _ts_dispose_resources(env); } } catch { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx6 = _using_ctx(); - _usingCtx6.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx6.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx6.d(); + _ts_dispose_resources(env); } } finally{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx7 = _using_ctx(); - _usingCtx7.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx7.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx7.d(); + _ts_dispose_resources(env); } } - try { - var _usingCtx8 = _using_ctx(); - _usingCtx8.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx8.e = _; - } finally{ - _usingCtx8.d(); + { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(;;)try { - var _usingCtx10 = _using_ctx(); - _usingCtx10.u({ - [Symbol.dispose] () {} - }); - break; - } catch (_) { - _usingCtx10.e = _; - } finally{ - _usingCtx10.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(;;)try { - var _usingCtx11 = _using_ctx(); - _usingCtx11.u({ - [Symbol.dispose] () {} - }); - break; - } catch (_) { - _usingCtx11.e = _; - } finally{ - _usingCtx11.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(;;)try { - var _usingCtx12 = _using_ctx(); - _usingCtx12.u({ - [Symbol.dispose] () {} - }); - break; - } catch (_) { - _usingCtx12.e = _; - } finally{ - _usingCtx12.d(); + for(;;){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + break; + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for(let x in {})try { - var _usingCtx13 = _using_ctx(); - _usingCtx13.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx13.e = _; - } finally{ - _usingCtx13.d(); + for(let x in {}){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } - for (let x of [])try { - var _usingCtx14 = _using_ctx(); - _usingCtx14.u({ - [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx14.e = _; - } finally{ - _usingCtx14.d(); + for (let x of []){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.11.1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.11.1.normal.js index bde17922a3ad..2160e848a92a 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.11.1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.11.1.normal.js @@ -3,7 +3,8 @@ import { _ as _assert_this_initialized } from "@swc/helpers/_/_assert_this_initi import { _ as _call_super } from "@swc/helpers/_/_call_super"; import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _inherits } from "@swc/helpers/_/_inherits"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; var A = function A() { "use strict"; _class_call_check(this, A); @@ -14,14 +15,20 @@ var C1 = /*#__PURE__*/ function(A) { function C1() { _class_call_check(this, C1); var _this; + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var x = _usingCtx.u(null); + var x = _ts_add_disposable_resource(env, null, false); + ; _this = _call_super(this, C1); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } return _assert_this_initialized(_this); } @@ -33,14 +40,20 @@ var C2 = /*#__PURE__*/ function(A) { function C2() { _class_call_check(this, C2); var _this; + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); _this = _call_super(this, C2); - var x = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + var x = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } return _assert_this_initialized(_this); } @@ -52,14 +65,20 @@ var C3 = /*#__PURE__*/ function(A) { function C3() { _class_call_check(this, C3); var _this; + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var x = _usingCtx.u(null); + var x = _ts_add_disposable_resource(env, null, false); + ; _this = _call_super(this, C3), _this.y = 1; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } return _assert_this_initialized(_this); } @@ -71,14 +90,20 @@ var C4 = /*#__PURE__*/ function(A) { function C4(y) { _class_call_check(this, C4); var _this; + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var x = _usingCtx.u(null); + var x = _ts_add_disposable_resource(env, null, false); + ; _this = _call_super(this, C4), _this.y = y; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } return _assert_this_initialized(_this); } @@ -90,14 +115,20 @@ var C5 = /*#__PURE__*/ function(A) { function C5(y) { _class_call_check(this, C5); var _this; + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var x = _usingCtx.u(null); + var x = _ts_add_disposable_resource(env, null, false); + ; _this = _call_super(this, C5), _this.y = y, _this.z = 1; - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } return _assert_this_initialized(_this); } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.11.2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.11.2.minified.js index f381e8ae83a7..de8e1bdf8e66 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.11.2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.11.2.minified.js @@ -3,4 +3,5 @@ import { _ as _assert_this_initialized } from "@swc/helpers/_/_assert_this_initi import { _ as _call_super } from "@swc/helpers/_/_call_super"; import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _inherits } from "@swc/helpers/_/_inherits"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/usingDeclarations.12.1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.12.1.normal.js index c713862a7125..2788c140dafc 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.12.1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.12.1.normal.js @@ -1,20 +1,27 @@ //// [usingDeclarations.12.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; class C1 { constructor(){} } class C2 extends C1 { constructor(){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); super(), this.y = 1; - const d17 = _usingCtx.u({ + const d17 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.12.2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.12.2.minified.js index 542f787c77be..a2f4e593e4f1 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.12.2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.12.2.minified.js @@ -1,2 +1,3 @@ //// [usingDeclarations.12.ts] -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/usingDeclarations.14.1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.14.1.normal.js index cfbfba2ad869..4e7b11b07e03 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.14.1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.14.1.normal.js @@ -1,10 +1,17 @@ //// [usingDeclarations.14.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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 x = _usingCtx.u({}); -} catch (_) { - _usingCtx.e = _; + const x = _ts_add_disposable_resource(env, {}, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.14.2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.14.2.minified.js index e50f2dc1dea4..38112321844e 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.14.2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.14.2.minified.js @@ -1,10 +1,15 @@ //// [usingDeclarations.14.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({}); -} catch (_) { - _usingCtx.e = _; + _ts_add_disposable_resource(env, {}, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.15.1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.15.1.normal.js index bea8776ea040..93f4253be5f9 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.15.1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.15.1.normal.js @@ -1,13 +1,20 @@ //// [usingDeclarations.15.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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 _ = _usingCtx.u({ + const _ = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; + }, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { }; diff --git a/crates/swc/tests/tsc-references/usingDeclarations.15.2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.15.2.minified.js index a1f9133d0799..b5e2b8042b7d 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.15.2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.15.2.minified.js @@ -1,12 +1,17 @@ //// [usingDeclarations.15.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; + }, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2015).1.normal.js index ebd9d72663f3..ae0af1f91290 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2015).1.normal.js @@ -1,16 +1,23 @@ //// [usingDeclarations.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.u({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), d2 = _usingCtx.u({ + }, false), d2 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2015).2.minified.js index 45ef9b4d6f41..833e9d75ed8d 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2015).2.minified.js @@ -1,14 +1,21 @@ //// [usingDeclarations.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ - [Symbol.dispose] () {} - }), _usingCtx.u({ - [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1), _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2017).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2017).1.normal.js index ebd9d72663f3..ae0af1f91290 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2017).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2017).1.normal.js @@ -1,16 +1,23 @@ //// [usingDeclarations.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.u({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), d2 = _usingCtx.u({ + }, false), d2 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2017).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2017).2.minified.js index 45ef9b4d6f41..833e9d75ed8d 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2017).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2017).2.minified.js @@ -1,14 +1,21 @@ //// [usingDeclarations.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ - [Symbol.dispose] () {} - }), _usingCtx.u({ - [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1), _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2022).1.normal.js index ebd9d72663f3..ae0af1f91290 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2022).1.normal.js @@ -1,16 +1,23 @@ //// [usingDeclarations.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.u({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), d2 = _usingCtx.u({ + }, false), d2 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2022).2.minified.js index 45ef9b4d6f41..833e9d75ed8d 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es2022).2.minified.js @@ -1,14 +1,21 @@ //// [usingDeclarations.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ - [Symbol.dispose] () {} - }), _usingCtx.u({ - [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1), _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es5).1.normal.js index c146a8e5399a..3bea4a2099fa 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es5).1.normal.js @@ -1,13 +1,20 @@ //// [usingDeclarations.2.ts] import { _ as _define_property } from "@swc/helpers/_/_define_property"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; { + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d1 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})), d2 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx.e = _; + var d1 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false), d2 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es5).2.minified.js index c33fc5e1fcdb..c2e96207c0c8 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.2(target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.2(target=es5).2.minified.js @@ -1,11 +1,16 @@ //// [usingDeclarations.2.ts] import { _ as _define_property } from "@swc/helpers/_/_define_property"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(_define_property({}, Symbol.dispose, function() {})), _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); -} catch (_) { - _usingCtx.e = _; + _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), !1), _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.2(target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.2(target=esnext).1.normal.js index ebd9d72663f3..ae0af1f91290 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.2(target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.2(target=esnext).1.normal.js @@ -1,16 +1,23 @@ //// [usingDeclarations.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.u({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), d2 = _usingCtx.u({ + }, false), d2 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.2(target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.2(target=esnext).2.minified.js index 45ef9b4d6f41..833e9d75ed8d 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.2(target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.2(target=esnext).2.minified.js @@ -1,14 +1,21 @@ //// [usingDeclarations.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ - [Symbol.dispose] () {} - }), _usingCtx.u({ - [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1), _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2015).1.normal.js index 6f27d83c73a8..9f69daed7869 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2015).1.normal.js @@ -1,16 +1,23 @@ //// [usingDeclarations.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.u({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), d2 = _usingCtx.u(null), d3 = _usingCtx.u(undefined), d4 = _usingCtx.u({ + }, false), d2 = _ts_add_disposable_resource(env, null, false), d3 = _ts_add_disposable_resource(env, undefined, false), d4 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2015).2.minified.js index d9daab6fa430..f822730a8e49 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2015).2.minified.js @@ -1,14 +1,21 @@ //// [usingDeclarations.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ - [Symbol.dispose] () {} - }), _usingCtx.u(null), _usingCtx.u(void 0), _usingCtx.u({ - [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1), _ts_add_disposable_resource(env, null, !1), _ts_add_disposable_resource(env, void 0, !1), _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2017).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2017).1.normal.js index 6f27d83c73a8..9f69daed7869 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2017).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2017).1.normal.js @@ -1,16 +1,23 @@ //// [usingDeclarations.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.u({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), d2 = _usingCtx.u(null), d3 = _usingCtx.u(undefined), d4 = _usingCtx.u({ + }, false), d2 = _ts_add_disposable_resource(env, null, false), d3 = _ts_add_disposable_resource(env, undefined, false), d4 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2017).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2017).2.minified.js index d9daab6fa430..f822730a8e49 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2017).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2017).2.minified.js @@ -1,14 +1,21 @@ //// [usingDeclarations.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ - [Symbol.dispose] () {} - }), _usingCtx.u(null), _usingCtx.u(void 0), _usingCtx.u({ - [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1), _ts_add_disposable_resource(env, null, !1), _ts_add_disposable_resource(env, void 0, !1), _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2022).1.normal.js index 6f27d83c73a8..9f69daed7869 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2022).1.normal.js @@ -1,16 +1,23 @@ //// [usingDeclarations.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.u({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), d2 = _usingCtx.u(null), d3 = _usingCtx.u(undefined), d4 = _usingCtx.u({ + }, false), d2 = _ts_add_disposable_resource(env, null, false), d3 = _ts_add_disposable_resource(env, undefined, false), d4 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2022).2.minified.js index d9daab6fa430..f822730a8e49 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es2022).2.minified.js @@ -1,14 +1,21 @@ //// [usingDeclarations.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ - [Symbol.dispose] () {} - }), _usingCtx.u(null), _usingCtx.u(void 0), _usingCtx.u({ - [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1), _ts_add_disposable_resource(env, null, !1), _ts_add_disposable_resource(env, void 0, !1), _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es5).1.normal.js index b6791667ddbc..89943e3d2a48 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es5).1.normal.js @@ -1,13 +1,20 @@ //// [usingDeclarations.3.ts] import { _ as _define_property } from "@swc/helpers/_/_define_property"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; { + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var d1 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})), d2 = _usingCtx.u(null), d3 = _usingCtx.u(undefined), d4 = _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); - } catch (_) { - _usingCtx.e = _; + var d1 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false), d2 = _ts_add_disposable_resource(env, null, false), d3 = _ts_add_disposable_resource(env, undefined, false), d4 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es5).2.minified.js index 1b0448496e75..42b38ff59031 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.3(target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.3(target=es5).2.minified.js @@ -1,11 +1,16 @@ //// [usingDeclarations.3.ts] import { _ as _define_property } from "@swc/helpers/_/_define_property"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(_define_property({}, Symbol.dispose, function() {})), _usingCtx.u(null), _usingCtx.u(void 0), _usingCtx.u(_define_property({}, Symbol.dispose, function() {})); -} catch (_) { - _usingCtx.e = _; + _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), !1), _ts_add_disposable_resource(env, null, !1), _ts_add_disposable_resource(env, void 0, !1), _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.3(target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.3(target=esnext).1.normal.js index 6f27d83c73a8..9f69daed7869 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.3(target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.3(target=esnext).1.normal.js @@ -1,16 +1,23 @@ //// [usingDeclarations.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const d1 = _usingCtx.u({ + const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), d2 = _usingCtx.u(null), d3 = _usingCtx.u(undefined), d4 = _usingCtx.u({ + }, false), d2 = _ts_add_disposable_resource(env, null, false), d3 = _ts_add_disposable_resource(env, undefined, false), d4 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.3(target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.3(target=esnext).2.minified.js index d9daab6fa430..f822730a8e49 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.3(target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.3(target=esnext).2.minified.js @@ -1,14 +1,21 @@ //// [usingDeclarations.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ - [Symbol.dispose] () {} - }), _usingCtx.u(null), _usingCtx.u(void 0), _usingCtx.u({ - [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1), _ts_add_disposable_resource(env, null, !1), _ts_add_disposable_resource(env, void 0, !1), _ts_add_disposable_resource(env, { + [Symbol.dispose] () {} + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.9.1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.9.1.normal.js index 970efa4e9e24..840d829b0d82 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.9.1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.9.1.normal.js @@ -1,12 +1,19 @@ //// [usingDeclarations.9.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const a = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + const a = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarations.9.2.minified.js b/crates/swc/tests/tsc-references/usingDeclarations.9.2.minified.js index 838a1525bee2..fc07da773ca2 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.9.2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.9.2.minified.js @@ -1,10 +1,17 @@ //// [usingDeclarations.9.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.1.1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.1.1.normal.js index fb0905592aa1..546c52329eae 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.1.1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.1.1.normal.js @@ -1,17 +1,26 @@ //// [usingDeclarationsDeclarationEmit.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { r1 }; -export { r2 }; +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 r1 = _usingCtx.u({ + const r1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - var r2 = _usingCtx.a({ + }, false); + ; + const r2 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); -} catch (_) { - _usingCtx.e = _; + }, true); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } +export { r1 }; +export { r2 }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.1.2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.1.2.minified.js index 4222545f0b31..39c46acd5210 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.1.2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.1.2.minified.js @@ -1,14 +1,21 @@ //// [usingDeclarationsDeclarationEmit.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(), r1 = _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), r2 = _usingCtx.a({ + }, !1), _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); -} catch (_) { - _usingCtx.e = _; + }, !0); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx.d(); + let result = _ts_dispose_resources(env); + result && await result; } export { r1, r2 }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.2.1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.2.1.normal.js index 5c38eddf239d..5aceedc120b4 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.2.1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.2.1.normal.js @@ -1,16 +1,25 @@ //// [usingDeclarationsDeclarationEmit.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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 r1 = _usingCtx.u({ + const r1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - var r2 = _usingCtx.a({ + }, false); + ; + const r2 = _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); -} catch (_) { - _usingCtx.e = _; + }, true); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - await _usingCtx.d(); + const result = _ts_dispose_resources(env); + if (result) await result; } export { }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.2.2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.2.2.minified.js index 58dec52a1ed4..12e05288f106 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.2.2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsDeclarationEmit.2.2.minified.js @@ -1,14 +1,20 @@ //// [usingDeclarationsDeclarationEmit.2.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }), _usingCtx.a({ + }, !1), _ts_add_disposable_resource(env, { async [Symbol.asyncDispose] () {} - }); -} catch (_) { - _usingCtx.e = _; + }, !0); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - await _usingCtx.d(); + let result = _ts_dispose_resources(env); + result && await result; } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2015).1.normal.js index 048c1a1b02e1..603dcbb034c2 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2015).1.normal.js @@ -1,7 +1,8 @@ //// [usingDeclarationsInForAwaitOf.ts] import { _ as _async_iterator } from "@swc/helpers/_/_async_iterator"; import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; function main() { return _main.apply(this, arguments); } @@ -18,14 +19,20 @@ function _main() { undefined ]), _step; _iteratorAbruptCompletion = !(_step = yield _iterator.next()).done; _iteratorAbruptCompletion = false){ let _value = _step.value; - const d1 = _value; + const _ = _value; + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, false); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } catch (err) { diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2015).2.minified.js index 25676163c058..9ece74e904dc 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2015).2.minified.js @@ -1,4 +1,5 @@ //// [usingDeclarationsInForAwaitOf.ts] import "@swc/helpers/_/_async_iterator"; import "@swc/helpers/_/_async_to_generator"; -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2017).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2017).1.normal.js index c7af45306326..c6f2470d5660 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2017).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2017).1.normal.js @@ -1,20 +1,27 @@ //// [usingDeclarationsInForAwaitOf.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; async function main() { - for await (const d1 of [ + for await (const _ of [ { [Symbol.dispose] () {} }, null, undefined ]){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, false); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2017).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2017).2.minified.js index d4aece823eb8..91f9e75b2345 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2017).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2017).2.minified.js @@ -1,2 +1,3 @@ //// [usingDeclarationsInForAwaitOf.ts] -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2022).1.normal.js index c7af45306326..c6f2470d5660 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2022).1.normal.js @@ -1,20 +1,27 @@ //// [usingDeclarationsInForAwaitOf.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; async function main() { - for await (const d1 of [ + for await (const _ of [ { [Symbol.dispose] () {} }, null, undefined ]){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, false); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2022).2.minified.js index d4aece823eb8..91f9e75b2345 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es2022).2.minified.js @@ -1,2 +1,3 @@ //// [usingDeclarationsInForAwaitOf.ts] -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es5).1.normal.js index 4dc1b4513e28..873042207503 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es5).1.normal.js @@ -3,13 +3,14 @@ import { _ as _async_iterator } from "@swc/helpers/_/_async_iterator"; import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; import { _ as _define_property } from "@swc/helpers/_/_define_property"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; function main() { return _main.apply(this, arguments); } function _main() { _main = _async_to_generator(function() { - var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, d1, _usingCtx, err; + var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, _, env, d1, err; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: @@ -39,14 +40,20 @@ function _main() { 5 ]; _value = _step.value; - d1 = _value; + _ = _value; + env = { + stack: [], + error: void 0, + hasError: false + }; try { - _usingCtx = _using_ctx(); + d1 = _ts_add_disposable_resource(env, _, false); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } _state.label = 4; case 4: diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es5).2.minified.js index 1f36613b865b..f6e43478e6cc 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=es5).2.minified.js @@ -3,4 +3,5 @@ import "@swc/helpers/_/_async_iterator"; import "@swc/helpers/_/_async_to_generator"; import "@swc/helpers/_/_define_property"; import "@swc/helpers/_/_ts_generator"; -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=esnext).1.normal.js index c7af45306326..c6f2470d5660 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=esnext).1.normal.js @@ -1,20 +1,27 @@ //// [usingDeclarationsInForAwaitOf.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; async function main() { - for await (const d1 of [ + for await (const _ of [ { [Symbol.dispose] () {} }, null, undefined ]){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, false); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=esnext).2.minified.js index d4aece823eb8..91f9e75b2345 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForAwaitOf(target=esnext).2.minified.js @@ -1,2 +1,3 @@ //// [usingDeclarationsInForAwaitOf.ts] -import "@swc/helpers/_/_using_ctx"; +import "@swc/helpers/_/_ts_add_disposable_resource"; +import "@swc/helpers/_/_ts_dispose_resources"; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2015).1.normal.js index 800b83760a49..2307f95a3339 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2015).1.normal.js @@ -1,18 +1,25 @@ //// [usingDeclarationsInForOf.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -for (const d1 of [ +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +for (const _ of [ { [Symbol.dispose] () {} }, null, undefined ]){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, false); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2015).2.minified.js index 834d99aa8f7b..6d5891b0fe53 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2015).2.minified.js @@ -1,15 +1,23 @@ //// [usingDeclarationsInForOf.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -for (let d1 of [ +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +for (let _ of [ { [Symbol.dispose] () {} }, null, void 0 -])try { - var _usingCtx = _using_ctx(); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); +]){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, _, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2017).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2017).1.normal.js index 800b83760a49..2307f95a3339 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2017).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2017).1.normal.js @@ -1,18 +1,25 @@ //// [usingDeclarationsInForOf.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -for (const d1 of [ +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +for (const _ of [ { [Symbol.dispose] () {} }, null, undefined ]){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, false); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2017).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2017).2.minified.js index 834d99aa8f7b..6d5891b0fe53 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2017).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2017).2.minified.js @@ -1,15 +1,23 @@ //// [usingDeclarationsInForOf.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -for (let d1 of [ +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +for (let _ of [ { [Symbol.dispose] () {} }, null, void 0 -])try { - var _usingCtx = _using_ctx(); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); +]){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, _, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2022).1.normal.js index 800b83760a49..2307f95a3339 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2022).1.normal.js @@ -1,18 +1,25 @@ //// [usingDeclarationsInForOf.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -for (const d1 of [ +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +for (const _ of [ { [Symbol.dispose] () {} }, null, undefined ]){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, false); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2022).2.minified.js index 834d99aa8f7b..6d5891b0fe53 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es2022).2.minified.js @@ -1,15 +1,23 @@ //// [usingDeclarationsInForOf.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -for (let d1 of [ +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +for (let _ of [ { [Symbol.dispose] () {} }, null, void 0 -])try { - var _usingCtx = _using_ctx(); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); +]){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, _, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es5).1.normal.js index d2a1121d17b1..1a02aefa6f64 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es5).1.normal.js @@ -1,18 +1,25 @@ //// [usingDeclarationsInForOf.1.ts] import { _ as _define_property } from "@swc/helpers/_/_define_property"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; for(var _i = 0, _iter = [ _define_property({}, Symbol.dispose, function() {}), null, undefined ]; _i < _iter.length; _i++){ - var d1 = _iter[_i]; + var _ = _iter[_i]; + var env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + var d1 = _ts_add_disposable_resource(env, _, false); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es5).2.minified.js index ffd46258d0e9..df338ff15e4d 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=es5).2.minified.js @@ -1,17 +1,22 @@ //// [usingDeclarationsInForOf.1.ts] import { _ as _define_property } from "@swc/helpers/_/_define_property"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; for(var _i = 0, _iter = [ _define_property({}, Symbol.dispose, function() {}), null, void 0 ]; _i < _iter.length; _i++){ - _iter[_i]; + var _ = _iter[_i], env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - } catch (_) { - _usingCtx.e = _; + _ts_add_disposable_resource(env, _, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=esnext).1.normal.js index 800b83760a49..2307f95a3339 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=esnext).1.normal.js @@ -1,18 +1,25 @@ //// [usingDeclarationsInForOf.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -for (const d1 of [ +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +for (const _ of [ { [Symbol.dispose] () {} }, null, undefined ]){ + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); + const d1 = _ts_add_disposable_resource(env, _, false); {} - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=esnext).2.minified.js index 834d99aa8f7b..6d5891b0fe53 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsInForOf.1(target=esnext).2.minified.js @@ -1,15 +1,23 @@ //// [usingDeclarationsInForOf.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -for (let d1 of [ +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +for (let _ of [ { [Symbol.dispose] () {} }, null, void 0 -])try { - var _usingCtx = _using_ctx(); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); +]){ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, _, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=amd).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=amd).1.normal.js index 40ce3e5e2018..495a34482de1 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=amd).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=amd).1.normal.js @@ -2,8 +2,9 @@ define([ "require", "exports", - "@swc/helpers/_/_using_ctx" -], function(require, exports, _using_ctx) { + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" +], function(require, exports, _ts_add_disposable_resource, _ts_dispose_resources) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true @@ -19,32 +20,34 @@ define([ return _default; }, w: function() { - return _w; + return w; }, x: function() { - return _x; + return x; }, y: function() { return y; } }); - var _x; - var _w; + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx._(); - const x = 1; - _x = x; - var z = _usingCtx.u({ + const z = _ts_add_disposable_resource._(env, { [Symbol.dispose] () {} - }); + }, false); + ; const y = 2; - const w = 3; - _w = w; - var _default = 4; console.log(w, x, y, z); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } + const x = 1; + const w = 3; + const _default = 4; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=amd).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=amd).2.minified.js index 0d11f96f11ba..339dbb6f6054 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=amd).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=amd).2.minified.js @@ -2,8 +2,9 @@ define([ "require", "exports", - "@swc/helpers/_/_using_ctx" -], function(require, exports, _using_ctx) { + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" +], function(require, exports, _ts_add_disposable_resource, _ts_dispose_resources) { Object.defineProperty(exports, "__esModule", { value: !0 }), function(target, all) { @@ -16,27 +17,29 @@ define([ return _default; }, w: function() { - return _w; + return w; }, x: function() { - return _x; + return x; }, y: function() { return y; } }); + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _x, _w, _usingCtx = _using_ctx._(); - _x = 1; - var z = _usingCtx.u({ + let z = _ts_add_disposable_resource._(env, { [Symbol.dispose] () {} - }); - _w = 3; - var _default = 4; - console.log(3, 1, 2, z); - } catch (_) { - _usingCtx.e = _; + }, !1); + console.log(w, x, 2, z); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } + let x = 1, w = 3, _default = 4; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=commonjs).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=commonjs).1.normal.js index 148c08be13dc..af24bc227bf0 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=commonjs).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=commonjs).1.normal.js @@ -14,32 +14,35 @@ _export(exports, { return _default; }, w: function() { - return _w; + return w; }, x: function() { - return _x; + return x; }, y: function() { return y; } }); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); -var _x; -var _w; +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - const x = 1; - _x = x; - var z = _usingCtx.u({ + const z = _ts_add_disposable_resource._(env, { [Symbol.dispose] () {} - }); + }, false); + ; const y = 2; - const w = 3; - _w = w; - var _default = 4; console.log(w, x, y, z); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } +const x = 1; +const w = 3; +const _default = 4; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=commonjs).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=commonjs).2.minified.js index 518a0b1c01e1..0b3edff35c37 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=commonjs).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=commonjs).2.minified.js @@ -11,27 +11,28 @@ Object.defineProperty(exports, "__esModule", { return _default; }, w: function() { - return _w; + return w; }, x: function() { - return _x; + return x; }, y: function() { return y; } }); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _x, _w, _usingCtx = _using_ctx._(); - _x = 1; - var z = _usingCtx.u({ + let z = _ts_add_disposable_resource._(env, { [Symbol.dispose] () {} - }); - _w = 3; - var _default = 4; - console.log(3, 1, 2, z); -} catch (_) { - _usingCtx.e = _; + }, !1); + console.log(w, x, 2, z); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } +const x = 1, w = 3, _default = 4; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=es6).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=es6).1.normal.js index e97ab951662c..2d597b140453 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=es6).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=es6).1.normal.js @@ -1,25 +1,25 @@ //// [usingDeclarationsTopLevelOfModule.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -var _x; -export { y }; -var _w; -export { _default as default }; +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(); - const x = 1; - _x = x; - var z = _usingCtx.u({ + const z = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; const y = 2; - const w = 3; - _w = w; - var _default = 4; console.log(w, x, y, z); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } -export { _x as x }; -export { _w as w }; +export const x = 1; +export { y }; +export const w = 3; +export default 4; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=es6).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=es6).2.minified.js index 21e3eb7e7903..1bc8e5dd3fcd 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=es6).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=es6).2.minified.js @@ -1,17 +1,22 @@ //// [usingDeclarationsTopLevelOfModule.1.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _x, _w, _usingCtx = _using_ctx(); - _x = 1; - var z = _usingCtx.u({ + let z = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - _w = 3; - var _default = 4; - console.log(3, 1, 2, z); -} catch (_) { - _usingCtx.e = _; + }, !1); + console.log(w, x, 2, z); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } -export { y, _default as default, _x as x, _w as w }; +export const x = 1; +export const w = 3; +export default 4; +export { y }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=system).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=system).1.normal.js index 2ef834ca120a..3d9fbfd96ce0 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=system).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=system).1.normal.js @@ -1,37 +1,41 @@ //// [usingDeclarationsTopLevelOfModule.1.ts] System.register([ - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _using_ctx, _x, _w; - _export({ - x: void 0, - w: void 0 - }); + var _ts_add_disposable_resource, _ts_dispose_resources, env, x, w; return { setters: [ - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - const x = 1; - _export("x", _x = x); - var z = _usingCtx.u({ + const z = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; const y = 2; - const w = 3; - _export("w", _w = w); - var _default = 4; console.log(w, x, y, z); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("x", x = 1); + _export("w", w = 3); + _export("default", 4); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=system).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=system).2.minified.js index a39976e2ff26..99fc4525e734 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=system).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.1(module=system).2.minified.js @@ -1,30 +1,35 @@ //// [usingDeclarationsTopLevelOfModule.1.ts] System.register([ - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _using_ctx; - return _export({ - x: void 0, - w: void 0 - }), { + var _ts_add_disposable_resource, _ts_dispose_resources, env, x, w; + return { setters: [ - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _export("x", 1); - var z = _usingCtx.u({ + let z = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - _export("w", 3), console.log(3, 1, 2, z); - } catch (_) { - _usingCtx.e = _; + }, !1); + console.log(w, x, 2, z); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("x", x = 1), _export("w", w = 3), _export("default", 4); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=amd).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=amd).1.normal.js index c179a99ce919..b8f522ed6daa 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=amd).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=amd).1.normal.js @@ -1,20 +1,27 @@ //// [usingDeclarationsTopLevelOfModule.2.ts] define([ "require", - "@swc/helpers/_/_using_ctx" -], function(require, _using_ctx) { + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" +], function(require, _ts_add_disposable_resource, _ts_dispose_resources) { "use strict"; + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx._(); - var z = _usingCtx.u({ + const z = _ts_add_disposable_resource._(env, { [Symbol.dispose] () {} - }); + }, false); + ; const y = 2; console.log(y, z); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } return 4; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=amd).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=amd).2.minified.js index 89b5b04b6252..5729223b30c5 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=amd).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=amd).2.minified.js @@ -1,17 +1,23 @@ //// [usingDeclarationsTopLevelOfModule.2.ts] define([ "require", - "@swc/helpers/_/_using_ctx" -], function(require, _using_ctx) { + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" +], function(require, _ts_add_disposable_resource, _ts_dispose_resources) { + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx._(), z = _usingCtx.u({ + let z = _ts_add_disposable_resource._(env, { [Symbol.dispose] () {} - }); + }, !1); console.log(2, z); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } return 4; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=commonjs).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=commonjs).1.normal.js index ae3cb448f448..da18f285c7ae 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=commonjs).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=commonjs).1.normal.js @@ -1,16 +1,23 @@ //// [usingDeclarationsTopLevelOfModule.2.ts] "use strict"; -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var z = _usingCtx.u({ + const z = _ts_add_disposable_resource._(env, { [Symbol.dispose] () {} - }); + }, false); + ; const y = 2; console.log(y, z); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } module.exports = 4; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=commonjs).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=commonjs).2.minified.js index 21d7176e8f0f..d7f7932dd3ae 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=commonjs).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.2(module=commonjs).2.minified.js @@ -1,13 +1,17 @@ //// [usingDeclarationsTopLevelOfModule.2.ts] -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(), z = _usingCtx.u({ + let z = _ts_add_disposable_resource._(env, { [Symbol.dispose] () {} - }); + }, !1); console.log(2, z); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } module.exports = 4; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=amd).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=amd).1.normal.js index 999774e3ca9b..a9b1fc73027c 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=amd).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=amd).1.normal.js @@ -2,8 +2,9 @@ define([ "require", "exports", - "@swc/helpers/_/_using_ctx" -], function(require, exports, _using_ctx) { + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" +], function(require, exports, _ts_add_disposable_resource, _ts_dispose_resources) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true @@ -14,20 +15,26 @@ define([ return y; } }); + const env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx._(); - var z = _usingCtx.u({ + const z = _ts_add_disposable_resource._(env, { [Symbol.dispose] () {} - }); + }, false); + ; if (false) { var y = 1; } function f() { console.log(y, z); } - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=amd).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=amd).2.minified.js index 773ec14e9b2c..64315aec2ddc 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=amd).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=amd).2.minified.js @@ -2,8 +2,9 @@ define([ "require", "exports", - "@swc/helpers/_/_using_ctx" -], function(require, exports, _using_ctx) { + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" +], function(require, exports, _ts_add_disposable_resource, _ts_dispose_resources) { Object.defineProperty(exports, "__esModule", { value: !0 }), Object.defineProperty(exports, "y", { @@ -12,14 +13,19 @@ define([ return y; } }); + let env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var y, _usingCtx = _using_ctx._(); - _usingCtx.u({ + var y; + _ts_add_disposable_resource._(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=commonjs).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=commonjs).1.normal.js index 947f97c17a2c..434f2f8aac83 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=commonjs).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=commonjs).1.normal.js @@ -9,20 +9,27 @@ Object.defineProperty(exports, "y", { return y; } }); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var z = _usingCtx.u({ + const z = _ts_add_disposable_resource._(env, { [Symbol.dispose] () {} - }); + }, false); + ; if (false) { var y = 1; } function f() { console.log(y, z); } -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=commonjs).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=commonjs).2.minified.js index 8ce33f9e3e3c..7b229693999e 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=commonjs).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=commonjs).2.minified.js @@ -7,14 +7,18 @@ Object.defineProperty(exports, "__esModule", { return y; } }); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var y, _usingCtx = _using_ctx._(); - _usingCtx.u({ + var y; + _ts_add_disposable_resource._(env, { [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; + }, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=es6).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=es6).1.normal.js index 26971dbd5b13..daff034dd099 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=es6).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=es6).1.normal.js @@ -1,19 +1,26 @@ //// [usingDeclarationsTopLevelOfModule.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { y }; +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 z = _usingCtx.u({ + const z = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; if (false) { var y = 1; } function f() { console.log(y, z); } -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +export { y }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=es6).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=es6).2.minified.js index 9589e9d10f9a..8b6e6fa4c0e1 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=es6).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=es6).2.minified.js @@ -1,13 +1,19 @@ //// [usingDeclarationsTopLevelOfModule.3.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var y, _usingCtx = _using_ctx(); - _usingCtx.u({ + var y; + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); -} catch (_) { - _usingCtx.e = _; + }, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { y }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=system).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=system).1.normal.js index 6020805d8211..20f0808487ad 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=system).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=system).1.normal.js @@ -1,31 +1,41 @@ //// [usingDeclarationsTopLevelOfModule.3.ts] System.register([ - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _using_ctx; + var _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var z = _usingCtx.u({ + const z = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); + }, false); + ; if (false) { var y = 1; } function f() { console.log(y, z); } - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=system).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=system).2.minified.js index 5684a13c1acc..9a8aacda7385 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=system).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsTopLevelOfModule.3(module=system).2.minified.js @@ -1,24 +1,32 @@ //// [usingDeclarationsTopLevelOfModule.3.ts] System.register([ - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _using_ctx; + var _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u({ + _ts_add_disposable_resource(env, { [Symbol.dispose] () {} - }); - } catch (_) { - _usingCtx.e = _; + }, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithImportHelpers.1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithImportHelpers.1.normal.js index 8263f40ba35b..38cb244828a7 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithImportHelpers.1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithImportHelpers.1.normal.js @@ -1,12 +1,19 @@ //// [usingDeclarationsWithImportHelpers.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); - const a = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + const a = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } }export { }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithImportHelpers.2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithImportHelpers.2.minified.js index 253ed876295c..2404ca101cc8 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithImportHelpers.2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithImportHelpers.2.minified.js @@ -1,10 +1,17 @@ //// [usingDeclarationsWithImportHelpers.ts] -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; -} finally{ - _usingCtx.d(); +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +{ + let env = { + stack: [], + error: void 0, + hasError: !1 + }; + try { + _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; + } finally{ + _ts_dispose_resources(env); + } } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es2015).1.normal.js index b29dc452d1fe..e33064934ada 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es2015).1.normal.js @@ -4,17 +4,24 @@ Object.defineProperty(exports, "__esModule", { value: true }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); + const before = _ts_add_disposable_resource._(env, null, false); + ; class C { } C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es2015).2.minified.js index c4a2f9568a0f..6336a4018d42 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es2015).2.minified.js @@ -2,17 +2,20 @@ Object.defineProperty(exports, "__esModule", { value: !0 }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); + _ts_add_disposable_resource._(env, null, !1); class C { } C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es5).1.normal.js index 70dc22dd5dda..42f9463765cb 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es5).1.normal.js @@ -5,10 +5,16 @@ Object.defineProperty(exports, "__esModule", { }); var _class_call_check = require("@swc/helpers/_/_class_call_check"); var _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -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"); +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); + var before = _ts_add_disposable_resource._(env, null, false); + ; var C = function C() { "use strict"; _class_call_check._(this, C); @@ -16,8 +22,9 @@ try { C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es5).2.minified.js index 80fe04afdaae..2457015fec55 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=es5).2.minified.js @@ -2,18 +2,21 @@ Object.defineProperty(exports, "__esModule", { value: !0 }); -var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); + _ts_add_disposable_resource._(env, null, !1); var C = function C() { _class_call_check._(this, C); }; C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=esnext).1.normal.js index b29dc452d1fe..e33064934ada 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=esnext).1.normal.js @@ -4,17 +4,24 @@ Object.defineProperty(exports, "__esModule", { value: true }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); + const before = _ts_add_disposable_resource._(env, null, false); + ; class C { } C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=esnext).2.minified.js index c4a2f9568a0f..6336a4018d42 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=commonjs,target=esnext).2.minified.js @@ -2,17 +2,20 @@ Object.defineProperty(exports, "__esModule", { value: !0 }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); + _ts_add_disposable_resource._(env, null, !1); class C { } C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es2015).1.normal.js index 036b36e82eb7..103447b3b116 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es2015).1.normal.js @@ -1,17 +1,24 @@ //// [usingDeclarationsWithLegacyClassDecorators.1.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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 before = _usingCtx.u(null); + const before = _ts_add_disposable_resource(env, null, false); + ; class C { } C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es2015).2.minified.js index 89afdaf62485..6ec50d7494b2 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es2015).2.minified.js @@ -1,16 +1,21 @@ //// [usingDeclarationsWithLegacyClassDecorators.1.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); class C { } C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es5).1.normal.js index 1f8c924c6150..4b4e049a856b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es5).1.normal.js @@ -1,10 +1,16 @@ //// [usingDeclarationsWithLegacyClassDecorators.1.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); + var before = _ts_add_disposable_resource(env, null, false); + ; var C = function C() { "use strict"; _class_call_check(this, C); @@ -12,9 +18,10 @@ try { C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es5).2.minified.js index 1df3155cec14..2a624f466c49 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=es5).2.minified.js @@ -1,18 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.1.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); var C = function C() { _class_call_check(this, C); }; C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=esnext).1.normal.js index 036b36e82eb7..103447b3b116 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=esnext).1.normal.js @@ -1,17 +1,24 @@ //// [usingDeclarationsWithLegacyClassDecorators.1.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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 before = _usingCtx.u(null); + const before = _ts_add_disposable_resource(env, null, false); + ; class C { } C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=esnext).2.minified.js index 89afdaf62485..6ec50d7494b2 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=es6,target=esnext).2.minified.js @@ -1,16 +1,21 @@ //// [usingDeclarationsWithLegacyClassDecorators.1.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); class C { } C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es2015).1.normal.js index bf6171222432..2e64f31fff5b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es2015).1.normal.js @@ -1,32 +1,42 @@ //// [usingDeclarationsWithLegacyClassDecorators.1.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); + const before = _ts_add_disposable_resource(env, null, false); + ; class C { } C = _ts_decorate([ dec ], C); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es2015).2.minified.js index eb06e75805f5..00bddfff4e2f 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es2015).2.minified.js @@ -1,31 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.1.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); class C { } C = _ts_decorate([ dec ], C); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es5).1.normal.js index 10ae37db19a1..1136121e67e8 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es5).1.normal.js @@ -2,10 +2,11 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_class_call_check1) { @@ -14,14 +15,22 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); + var before = _ts_add_disposable_resource(env, null, false); + ; var C = function C() { "use strict"; _class_call_check(this, C); @@ -29,10 +38,11 @@ System.register([ C = _ts_decorate([ dec ], C); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es5).2.minified.js index 425273eedcc5..770dd3bbf025 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=es5).2.minified.js @@ -2,9 +2,10 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_class_call_check1) { @@ -13,24 +14,31 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); var C = function C() { _class_call_check(this, C); }; C = _ts_decorate([ dec ], C); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=esnext).1.normal.js index bf6171222432..2e64f31fff5b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=esnext).1.normal.js @@ -1,32 +1,42 @@ //// [usingDeclarationsWithLegacyClassDecorators.1.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); + const before = _ts_add_disposable_resource(env, null, false); + ; class C { } C = _ts_decorate([ dec ], C); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=esnext).2.minified.js index eb06e75805f5..00bddfff4e2f 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.1(module=system,target=esnext).2.minified.js @@ -1,31 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.1.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); class C { } C = _ts_decorate([ dec ], C); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es2015).1.normal.js index abdfcde66ed6..10755716d80f 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es2015).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "default", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var _class = class _class { - }; _class = _ts_decorate._([ dec ], _class); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class _class { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es2015).2.minified.js index 025220975440..9444de3e55e3 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es2015).2.minified.js @@ -7,15 +7,19 @@ Object.defineProperty(exports, "__esModule", { return _class; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(), _class = class { - }; _class = _ts_decorate._([ dec - ], _class), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], _class), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class _class { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es5).1.normal.js index 865696319f96..87f8c28c399e 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es5).1.normal.js @@ -11,19 +11,26 @@ Object.defineProperty(exports, "default", { }); var _class_call_check = require("@swc/helpers/_/_class_call_check"); var _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -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"); +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var _class = function _class() { - "use strict"; - _class_call_check._(this, _class); - }; _class = _ts_decorate._([ dec ], _class); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } +var _class = function _class() { + "use strict"; + _class_call_check._(this, _class); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es5).2.minified.js index 123ab2d2f173..eedbfea8900d 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=es5).2.minified.js @@ -7,16 +7,20 @@ Object.defineProperty(exports, "__esModule", { return _class; } }); -var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(), _class = function _class() { - _class_call_check._(this, _class); - }; _class = _ts_decorate._([ dec - ], _class), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], _class), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } +var _class = function _class() { + _class_call_check._(this, _class); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=esnext).1.normal.js index abdfcde66ed6..10755716d80f 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=esnext).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "default", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var _class = class _class { - }; _class = _ts_decorate._([ dec ], _class); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class _class { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=esnext).2.minified.js index 025220975440..9444de3e55e3 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=commonjs,target=esnext).2.minified.js @@ -7,15 +7,19 @@ Object.defineProperty(exports, "__esModule", { return _class; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(), _class = class { - }; _class = _ts_decorate._([ dec - ], _class), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], _class), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class _class { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es2015).1.normal.js index ffed1694dcb1..dfde64ae774f 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es2015).1.normal.js @@ -1,17 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.10.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { _class as default }; +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 _class = class _class { - }; _class = _ts_decorate([ dec ], _class); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class _class { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es2015).2.minified.js index 8b1e6147911a..fa4c09c0c3b4 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es2015).2.minified.js @@ -1,15 +1,20 @@ //// [usingDeclarationsWithLegacyClassDecorators.10.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(), _class = class { - }; _class = _ts_decorate([ dec - ], _class), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], _class), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class _class { } -export { _class as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es5).1.normal.js index 9c71428b2c81..e1a0daf8935d 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es5).1.normal.js @@ -1,20 +1,27 @@ //// [usingDeclarationsWithLegacyClassDecorators.10.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { _class as default }; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx(); - var _class = function _class() { - "use strict"; - _class_call_check(this, _class); - }; _class = _ts_decorate([ dec ], _class); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +var _class = function _class() { + "use strict"; + _class_call_check(this, _class); +}; +export { _class as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es5).2.minified.js index 309d1a77bebb..ee25329ece31 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=es5).2.minified.js @@ -1,17 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.10.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(), _class = function _class() { - _class_call_check(this, _class); - }; _class = _ts_decorate([ dec - ], _class), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], _class), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +var _class = function _class() { + _class_call_check(this, _class); +}; export { _class as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=esnext).1.normal.js index ffed1694dcb1..dfde64ae774f 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=esnext).1.normal.js @@ -1,17 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.10.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { _class as default }; +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 _class = class _class { - }; _class = _ts_decorate([ dec ], _class); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class _class { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=esnext).2.minified.js index 8b1e6147911a..fa4c09c0c3b4 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=es6,target=esnext).2.minified.js @@ -1,15 +1,20 @@ //// [usingDeclarationsWithLegacyClassDecorators.10.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(), _class = class { - }; _class = _ts_decorate([ dec - ], _class), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], _class), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class _class { } -export { _class as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es2015).1.normal.js index 881ecb69908c..319b32d3255f 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es2015).1.normal.js @@ -1,33 +1,44 @@ //// [usingDeclarationsWithLegacyClassDecorators.10.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, _class, env; + _export("default", void 0); return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var _class = class _class { - }; _export("default", _class = _ts_decorate([ dec ], _class)); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", _class = class _class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es2015).2.minified.js index 118dd094ae31..1b9d80749472 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es2015).2.minified.js @@ -1,30 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.10.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; - return { + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, _class, env; + return _export("default", void 0), { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(), _class = class { - }; _export("default", _class = _ts_decorate([ dec - ], _class)), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], _class)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", _class = class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es5).1.normal.js index cb38103c539a..92cefe943cdf 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es5).1.normal.js @@ -2,10 +2,11 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env, _class; return { setters: [ function(_class_call_check1) { @@ -14,26 +15,35 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var _class = function _class() { - "use strict"; - _class_call_check(this, _class); - }; _export("default", _class = _ts_decorate([ dec ], _class)); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", _class = function _class() { + "use strict"; + _class_call_check(this, _class); + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es5).2.minified.js index 1430703415a7..f575c137f869 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=es5).2.minified.js @@ -2,9 +2,10 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env, _class; return { setters: [ function(_class_call_check1) { @@ -13,23 +14,31 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(), _class = function _class() { - _class_call_check(this, _class); - }; _export("default", _class = _ts_decorate([ dec - ], _class)), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], _class)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", _class = function _class() { + _class_call_check(this, _class); + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=esnext).1.normal.js index 881ecb69908c..319b32d3255f 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=esnext).1.normal.js @@ -1,33 +1,44 @@ //// [usingDeclarationsWithLegacyClassDecorators.10.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, _class, env; + _export("default", void 0); return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var _class = class _class { - }; _export("default", _class = _ts_decorate([ dec ], _class)); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", _class = class _class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=esnext).2.minified.js index 118dd094ae31..1b9d80749472 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.10(module=system,target=esnext).2.minified.js @@ -1,30 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.10.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; - return { + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, _class, env; + return _export("default", void 0), { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(), _class = class { - }; _export("default", _class = _ts_decorate([ dec - ], _class)), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], _class)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", _class = class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es2015).1.normal.js index 5cbd98dbc701..c66eda070692 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es2015).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "C", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); class C { } C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es2015).2.minified.js index 892d8ceeb02b..4557e48f3a49 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es2015).2.minified.js @@ -7,16 +7,19 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); class C1 { } C1 = _ts_decorate._([ dec - ], C1), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C1), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es5).1.normal.js index 8b84463d0a1a..dbff83853f06 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es5).1.normal.js @@ -11,9 +11,14 @@ Object.defineProperty(exports, "C", { }); var _class_call_check = require("@swc/helpers/_/_class_call_check"); var _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -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"); +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); var C = function C() { "use strict"; _class_call_check._(this, C); @@ -21,9 +26,11 @@ try { C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es5).2.minified.js index 2b7c106f9f2b..9645d3c927c7 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=es5).2.minified.js @@ -7,16 +7,20 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(), C = function C() { + var C = function C() { _class_call_check._(this, C); }; C = _ts_decorate._([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=esnext).1.normal.js index 5cbd98dbc701..c66eda070692 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=esnext).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "C", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); class C { } C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=esnext).2.minified.js index 892d8ceeb02b..4557e48f3a49 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=commonjs,target=esnext).2.minified.js @@ -7,16 +7,19 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); class C1 { } C1 = _ts_decorate._([ dec - ], C1), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C1), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es2015).1.normal.js index 2daa7fe9636f..124c0cf27de5 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es2015).1.normal.js @@ -1,17 +1,24 @@ //// [usingDeclarationsWithLegacyClassDecorators.11.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C }; +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(); class C { } C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +export { C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es2015).2.minified.js index 74007d040bac..313e5ca4fe2c 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es2015).2.minified.js @@ -1,16 +1,21 @@ //// [usingDeclarationsWithLegacyClassDecorators.11.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); class C { } C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es5).1.normal.js index b3e990cd56ad..5954c738ab91 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es5).1.normal.js @@ -1,10 +1,14 @@ //// [usingDeclarationsWithLegacyClassDecorators.11.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C }; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx(); var C = function C() { "use strict"; _class_call_check(this, C); @@ -12,9 +16,12 @@ try { C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +export { C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es5).2.minified.js index 35f3137e9e11..b2373b50cb08 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=es5).2.minified.js @@ -1,17 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.11.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(), C = function C() { + var C = function C() { _class_call_check(this, C); }; C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=esnext).1.normal.js index 2daa7fe9636f..124c0cf27de5 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=esnext).1.normal.js @@ -1,17 +1,24 @@ //// [usingDeclarationsWithLegacyClassDecorators.11.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C }; +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(); class C { } C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +export { C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=esnext).2.minified.js index 74007d040bac..313e5ca4fe2c 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=es6,target=esnext).2.minified.js @@ -1,16 +1,21 @@ //// [usingDeclarationsWithLegacyClassDecorators.11.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); class C { } C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es2015).1.normal.js index 7d98f05d9d82..0894c042773b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es2015).1.normal.js @@ -1,32 +1,42 @@ //// [usingDeclarationsWithLegacyClassDecorators.11.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); class C { } _export("C", C = _ts_decorate([ dec ], C)); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es2015).2.minified.js index 1f6e0fa7f09c..3260b2c0b99a 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es2015).2.minified.js @@ -1,30 +1,38 @@ //// [usingDeclarationsWithLegacyClassDecorators.11.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); class C { } _export("C", C = _ts_decorate([ dec - ], C)), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es5).1.normal.js index 1221ef2e9cf0..d54b7909ea57 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es5).1.normal.js @@ -2,10 +2,11 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_class_call_check1) { @@ -14,13 +15,20 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); var C = function C() { "use strict"; _class_call_check(this, C); @@ -28,11 +36,13 @@ System.register([ _export("C", C = _ts_decorate([ dec ], C)); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es5).2.minified.js index ef43f70c7b46..b2ea41387e7a 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=es5).2.minified.js @@ -2,9 +2,10 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_class_call_check1) { @@ -13,22 +14,30 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(), C = function C() { + var C = function C() { _class_call_check(this, C); }; _export("C", C = _ts_decorate([ dec - ], C)), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=esnext).1.normal.js index 7d98f05d9d82..0894c042773b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=esnext).1.normal.js @@ -1,32 +1,42 @@ //// [usingDeclarationsWithLegacyClassDecorators.11.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); class C { } _export("C", C = _ts_decorate([ dec ], C)); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=esnext).2.minified.js index 1f6e0fa7f09c..3260b2c0b99a 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.11(module=system,target=esnext).2.minified.js @@ -1,30 +1,38 @@ //// [usingDeclarationsWithLegacyClassDecorators.11.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); class C { } _export("C", C = _ts_decorate([ dec - ], C)), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es2015).1.normal.js index eaef720a233d..9cc3cb5d8491 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es2015).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "D", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); class C { } C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es2015).2.minified.js index e9dd78c1b36d..1a2d3dd6ba57 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es2015).2.minified.js @@ -7,16 +7,19 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); class C1 { } C1 = _ts_decorate._([ dec - ], C1), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C1), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es5).1.normal.js index ae267c344a62..7d49b036b632 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es5).1.normal.js @@ -11,9 +11,14 @@ Object.defineProperty(exports, "D", { }); var _class_call_check = require("@swc/helpers/_/_class_call_check"); var _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -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"); +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); var C = function C() { "use strict"; _class_call_check._(this, C); @@ -21,9 +26,11 @@ try { C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es5).2.minified.js index fd8bd2b2ef3c..083ffd12a62d 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=es5).2.minified.js @@ -7,16 +7,20 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(), C = function C() { + var C = function C() { _class_call_check._(this, C); }; C = _ts_decorate._([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=esnext).1.normal.js index eaef720a233d..9cc3cb5d8491 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=esnext).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "D", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); class C { } C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=esnext).2.minified.js index e9dd78c1b36d..1a2d3dd6ba57 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=commonjs,target=esnext).2.minified.js @@ -7,16 +7,19 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); class C1 { } C1 = _ts_decorate._([ dec - ], C1), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C1), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es2015).1.normal.js index a21418310128..578505e0f5f9 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es2015).1.normal.js @@ -1,17 +1,24 @@ //// [usingDeclarationsWithLegacyClassDecorators.12.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C as D }; +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(); class C { } C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +export { C as D }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es2015).2.minified.js index 96a12738b3e3..87285a634f30 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es2015).2.minified.js @@ -1,16 +1,21 @@ //// [usingDeclarationsWithLegacyClassDecorators.12.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); class C { } C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { C as D }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es5).1.normal.js index 2d2972eea9ce..27b1b070d680 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es5).1.normal.js @@ -1,10 +1,14 @@ //// [usingDeclarationsWithLegacyClassDecorators.12.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C as D }; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx(); var C = function C() { "use strict"; _class_call_check(this, C); @@ -12,9 +16,12 @@ try { C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +export { C as D }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es5).2.minified.js index 2b67039e2d30..cd3204ab11ee 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=es5).2.minified.js @@ -1,17 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.12.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(), C = function C() { + var C = function C() { _class_call_check(this, C); }; C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { C as D }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=esnext).1.normal.js index a21418310128..578505e0f5f9 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=esnext).1.normal.js @@ -1,17 +1,24 @@ //// [usingDeclarationsWithLegacyClassDecorators.12.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C as D }; +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(); class C { } C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +export { C as D }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=esnext).2.minified.js index 96a12738b3e3..87285a634f30 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=es6,target=esnext).2.minified.js @@ -1,16 +1,21 @@ //// [usingDeclarationsWithLegacyClassDecorators.12.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); class C { } C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { C as D }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es2015).1.normal.js index 8aae998a8767..1437a8eb3c8b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es2015).1.normal.js @@ -1,32 +1,42 @@ //// [usingDeclarationsWithLegacyClassDecorators.12.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); class C { } _export("D", C = _ts_decorate([ dec ], C)); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es2015).2.minified.js index 0d8a2fe98456..56ae59649d66 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es2015).2.minified.js @@ -1,30 +1,38 @@ //// [usingDeclarationsWithLegacyClassDecorators.12.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); class C { } _export("D", C = _ts_decorate([ dec - ], C)), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es5).1.normal.js index 90deef8402c2..ac0e73d08ecb 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es5).1.normal.js @@ -2,10 +2,11 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_class_call_check1) { @@ -14,13 +15,20 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); var C = function C() { "use strict"; _class_call_check(this, C); @@ -28,11 +36,13 @@ System.register([ _export("D", C = _ts_decorate([ dec ], C)); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es5).2.minified.js index 67e97e0a65fb..01e0765bbbdf 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=es5).2.minified.js @@ -2,9 +2,10 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_class_call_check1) { @@ -13,22 +14,30 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(), C = function C() { + var C = function C() { _class_call_check(this, C); }; _export("D", C = _ts_decorate([ dec - ], C)), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=esnext).1.normal.js index 8aae998a8767..1437a8eb3c8b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=esnext).1.normal.js @@ -1,32 +1,42 @@ //// [usingDeclarationsWithLegacyClassDecorators.12.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); class C { } _export("D", C = _ts_decorate([ dec ], C)); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=esnext).2.minified.js index 0d8a2fe98456..56ae59649d66 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.12(module=system,target=esnext).2.minified.js @@ -1,30 +1,38 @@ //// [usingDeclarationsWithLegacyClassDecorators.12.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); class C { } _export("D", C = _ts_decorate([ dec - ], C)), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es2015).1.normal.js index 0deba7a50d7f..43713dfa3a07 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es2015).1.normal.js @@ -6,23 +6,28 @@ Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "C", { enumerable: true, get: function() { - return _C; + return C; } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); -var _C; +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); - class C { - } - _C = C; + const before = _ts_add_disposable_resource._(env, null, false); + ; C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es2015).2.minified.js index f3849d640a99..4977c31d7bae 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es2015).2.minified.js @@ -4,20 +4,22 @@ Object.defineProperty(exports, "__esModule", { }), Object.defineProperty(exports, "C", { enumerable: !0, get: function() { - return _C; + return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _C, _usingCtx = _using_ctx._(); - _usingCtx.u(null); - class C { - } - _C = C, C = _ts_decorate._([ + _ts_add_disposable_resource._(env, null, !1), C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es5).1.normal.js index fb8f76404e59..88df8ee9c0d6 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es5).1.normal.js @@ -6,26 +6,31 @@ Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "C", { enumerable: true, get: function() { - return _C; + return C; } }); var _class_call_check = require("@swc/helpers/_/_class_call_check"); var _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -var _using_ctx = require("@swc/helpers/_/_using_ctx"); -var _C; +var _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +var _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); - var C = function C() { - "use strict"; - _class_call_check._(this, C); - }; - _C = C; + var before = _ts_add_disposable_resource._(env, null, false); + ; C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } +var C = function C() { + "use strict"; + _class_call_check._(this, C); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es5).2.minified.js index 8c0db9b467c1..c04a309084e8 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=es5).2.minified.js @@ -4,21 +4,23 @@ Object.defineProperty(exports, "__esModule", { }), Object.defineProperty(exports, "C", { enumerable: !0, get: function() { - return _C; + return C; } }); -var _C, _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); - var C = function C() { - _class_call_check._(this, C); - }; - _C = C, C = _ts_decorate._([ + _ts_add_disposable_resource._(env, null, !1), C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } +var C = function C() { + _class_call_check._(this, C); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=esnext).1.normal.js index 0deba7a50d7f..43713dfa3a07 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=esnext).1.normal.js @@ -6,23 +6,28 @@ Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "C", { enumerable: true, get: function() { - return _C; + return C; } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); -var _C; +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); - class C { - } - _C = C; + const before = _ts_add_disposable_resource._(env, null, false); + ; C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=esnext).2.minified.js index f3849d640a99..4977c31d7bae 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=commonjs,target=esnext).2.minified.js @@ -4,20 +4,22 @@ Object.defineProperty(exports, "__esModule", { }), Object.defineProperty(exports, "C", { enumerable: !0, get: function() { - return _C; + return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _C, _usingCtx = _using_ctx._(); - _usingCtx.u(null); - class C { - } - _C = C, C = _ts_decorate._([ + _ts_add_disposable_resource._(env, null, !1), C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es2015).1.normal.js index 27865d30b109..39f330f52a6d 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es2015).1.normal.js @@ -1,19 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.2.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -var _C; +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 before = _usingCtx.u(null); - class C { - } - _C = C; + const before = _ts_add_disposable_resource(env, null, false); + ; C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export class C { } -export { _C as C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es2015).2.minified.js index 7e5c750c71b3..8e6204ccbdbf 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es2015).2.minified.js @@ -1,17 +1,20 @@ //// [usingDeclarationsWithLegacyClassDecorators.2.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _C, _usingCtx = _using_ctx(); - _usingCtx.u(null); - class C { - } - _C = C, C = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export class C { } -export { _C as C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es5).1.normal.js index 0e8568e1559c..86be885cd6e8 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es5).1.normal.js @@ -1,22 +1,26 @@ //// [usingDeclarationsWithLegacyClassDecorators.2.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -var _C; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); - var C = function C() { - "use strict"; - _class_call_check(this, C); - }; - _C = C; + var before = _ts_add_disposable_resource(env, null, false); + ; C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } -export { _C as C }; +export var C = function C() { + "use strict"; + _class_call_check(this, C); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es5).2.minified.js index 28c8b045f567..5a8e7a5884d7 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=es5).2.minified.js @@ -1,19 +1,22 @@ //// [usingDeclarationsWithLegacyClassDecorators.2.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _C, _usingCtx = _using_ctx(); - _usingCtx.u(null); - var C = function C() { - _class_call_check(this, C); - }; - _C = C, C = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } -export { _C as C }; +export var C = function C() { + _class_call_check(this, C); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=esnext).1.normal.js index 27865d30b109..39f330f52a6d 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=esnext).1.normal.js @@ -1,19 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.2.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -var _C; +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 before = _usingCtx.u(null); - class C { - } - _C = C; + const before = _ts_add_disposable_resource(env, null, false); + ; C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export class C { } -export { _C as C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=esnext).2.minified.js index 7e5c750c71b3..8e6204ccbdbf 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=es6,target=esnext).2.minified.js @@ -1,17 +1,20 @@ //// [usingDeclarationsWithLegacyClassDecorators.2.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _C, _usingCtx = _using_ctx(); - _usingCtx.u(null); - class C { - } - _C = C, C = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export class C { } -export { _C as C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es2015).1.normal.js index 98691c8149e1..e0484281fc0b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es2015).1.normal.js @@ -1,35 +1,44 @@ //// [usingDeclarationsWithLegacyClassDecorators.2.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx, _C; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; _export("C", void 0); return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); - class C { - } - _export("C", _C = C); - C = _ts_decorate([ + const before = _ts_add_disposable_resource(env, null, false); + ; + _export("C", C = _ts_decorate([ dec - ], C); - } catch (_) { - _usingCtx.e = _; + ], C)); + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("C", C = class C { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es2015).2.minified.js index f7a8aae41569..9223a81d5368 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es2015).2.minified.js @@ -1,32 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.2.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; return _export("C", void 0), { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - class C { - } - _export("C", C), C = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), _export("C", C = _ts_decorate([ dec - ], C); - } catch (_) { - _usingCtx.e = _; + ], C)); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("C", C = class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es5).1.normal.js index d98e2b865441..0f0e716304e0 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es5).1.normal.js @@ -2,11 +2,11 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _class_call_check, _ts_decorate, _using_ctx, _C; - _export("C", void 0); + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env, C; return { setters: [ function(_class_call_check1) { @@ -15,27 +15,35 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); - var C = function C() { - "use strict"; - _class_call_check(this, C); - }; - _export("C", _C = C); - C = _ts_decorate([ + var before = _ts_add_disposable_resource(env, null, false); + ; + _export("C", C = _ts_decorate([ dec - ], C); - } catch (_) { - _usingCtx.e = _; + ], C)); + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("C", C = function C() { + "use strict"; + _class_call_check(this, C); + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es5).2.minified.js index 6b81ece727b5..c9487b0e349e 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=es5).2.minified.js @@ -2,10 +2,11 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _class_call_check, _ts_decorate, _using_ctx; - return _export("C", void 0), { + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env, C; + return { setters: [ function(_class_call_check1) { _class_call_check = _class_call_check1._; @@ -13,25 +14,31 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - var C = function C() { - _class_call_check(this, C); - }; - _export("C", C), C = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), _export("C", C = _ts_decorate([ dec - ], C); - } catch (_) { - _usingCtx.e = _; + ], C)); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("C", C = function C() { + _class_call_check(this, C); + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=esnext).1.normal.js index 98691c8149e1..e0484281fc0b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=esnext).1.normal.js @@ -1,35 +1,44 @@ //// [usingDeclarationsWithLegacyClassDecorators.2.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx, _C; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; _export("C", void 0); return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); - class C { - } - _export("C", _C = C); - C = _ts_decorate([ + const before = _ts_add_disposable_resource(env, null, false); + ; + _export("C", C = _ts_decorate([ dec - ], C); - } catch (_) { - _usingCtx.e = _; + ], C)); + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("C", C = class C { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=esnext).2.minified.js index f7a8aae41569..9223a81d5368 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.2(module=system,target=esnext).2.minified.js @@ -1,32 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.2.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; return _export("C", void 0), { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - class C { - } - _export("C", C), C = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), _export("C", C = _ts_decorate([ dec - ], C); - } catch (_) { - _usingCtx.e = _; + ], C)); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("C", C = class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es2015).1.normal.js index cdfae9e0bf96..c60cc03d9c35 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es2015).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "default", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); - var C = class C { - }; + const before = _ts_add_disposable_resource._(env, null, false); + ; C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es2015).2.minified.js index 8a31f307ff05..30dc5717bebd 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es2015).2.minified.js @@ -7,17 +7,19 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); - var C = class { - }; - C = _ts_decorate._([ + _ts_add_disposable_resource._(env, null, !1), C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es5).1.normal.js index 8f52201b81c1..df7d2487d5ff 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es5).1.normal.js @@ -11,19 +11,26 @@ Object.defineProperty(exports, "default", { }); var _class_call_check = require("@swc/helpers/_/_class_call_check"); var _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -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"); +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); - var C = function C() { - "use strict"; - _class_call_check._(this, C); - }; + var before = _ts_add_disposable_resource._(env, null, false); + ; C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } +var C = function C() { + "use strict"; + _class_call_check._(this, C); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es5).2.minified.js index fc6a89834b02..fe969c6c8263 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=es5).2.minified.js @@ -7,18 +7,20 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); - var C = function C() { - _class_call_check._(this, C); - }; - C = _ts_decorate._([ + _ts_add_disposable_resource._(env, null, !1), C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } +var C = function C() { + _class_call_check._(this, C); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=esnext).1.normal.js index cdfae9e0bf96..c60cc03d9c35 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=esnext).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "default", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); - var C = class C { - }; + const before = _ts_add_disposable_resource._(env, null, false); + ; C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=esnext).2.minified.js index 8a31f307ff05..30dc5717bebd 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=commonjs,target=esnext).2.minified.js @@ -7,17 +7,19 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); - var C = class { - }; - C = _ts_decorate._([ + _ts_add_disposable_resource._(env, null, !1), C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es2015).1.normal.js index 06cb6c24d36c..e27f115bbf4b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es2015).1.normal.js @@ -1,17 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.3.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C as default }; +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 before = _usingCtx.u(null); - var C = class C { - }; + const before = _ts_add_disposable_resource(env, null, false); + ; C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es2015).2.minified.js index 904b8a4b8e8d..4d9c9ddb3626 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es2015).2.minified.js @@ -1,17 +1,20 @@ //// [usingDeclarationsWithLegacyClassDecorators.3.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - var C = class { - }; - C = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class C { } -export { C as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es5).1.normal.js index cd4aa2b73926..d68c8354d58d 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es5).1.normal.js @@ -1,20 +1,27 @@ //// [usingDeclarationsWithLegacyClassDecorators.3.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C as default }; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); - var C = function C() { - "use strict"; - _class_call_check(this, C); - }; + var before = _ts_add_disposable_resource(env, null, false); + ; C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +var C = function C() { + "use strict"; + _class_call_check(this, C); +}; +export { C as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es5).2.minified.js index fff9ac887e78..86829d5793ac 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=es5).2.minified.js @@ -1,19 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.3.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - var C = function C() { - _class_call_check(this, C); - }; - C = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +var C = function C() { + _class_call_check(this, C); +}; export { C as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=esnext).1.normal.js index 06cb6c24d36c..e27f115bbf4b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=esnext).1.normal.js @@ -1,17 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.3.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C as default }; +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 before = _usingCtx.u(null); - var C = class C { - }; + const before = _ts_add_disposable_resource(env, null, false); + ; C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=esnext).2.minified.js index 904b8a4b8e8d..4d9c9ddb3626 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=es6,target=esnext).2.minified.js @@ -1,17 +1,20 @@ //// [usingDeclarationsWithLegacyClassDecorators.3.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - var C = class { - }; - C = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class C { } -export { C as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es2015).1.normal.js index 728117336184..c52f7a40fa32 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es2015).1.normal.js @@ -1,33 +1,44 @@ //// [usingDeclarationsWithLegacyClassDecorators.3.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; + _export("default", void 0); return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); - var C = class C { - }; + const before = _ts_add_disposable_resource(env, null, false); + ; _export("default", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", C = class C { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es2015).2.minified.js index 068fe6225f59..da235a0f8a30 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es2015).2.minified.js @@ -1,32 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.3.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; - return { + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; + return _export("default", void 0), { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - var C = class { - }; - _export("default", C = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), _export("default", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", C = class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es5).1.normal.js index cbeb2031f31f..26257bb609b6 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es5).1.normal.js @@ -2,10 +2,11 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env, C; return { setters: [ function(_class_call_check1) { @@ -14,26 +15,35 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); - var C = function C() { - "use strict"; - _class_call_check(this, C); - }; + var before = _ts_add_disposable_resource(env, null, false); + ; _export("default", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", C = function C() { + "use strict"; + _class_call_check(this, C); + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es5).2.minified.js index 55f32c104ee5..316a8df5db09 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=es5).2.minified.js @@ -2,9 +2,10 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env, C; return { setters: [ function(_class_call_check1) { @@ -13,25 +14,31 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - var C = function C() { - _class_call_check(this, C); - }; - _export("default", C = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), _export("default", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", C = function C() { + _class_call_check(this, C); + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=esnext).1.normal.js index 728117336184..c52f7a40fa32 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=esnext).1.normal.js @@ -1,33 +1,44 @@ //// [usingDeclarationsWithLegacyClassDecorators.3.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; + _export("default", void 0); return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); - var C = class C { - }; + const before = _ts_add_disposable_resource(env, null, false); + ; _export("default", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", C = class C { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=esnext).2.minified.js index 068fe6225f59..da235a0f8a30 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.3(module=system,target=esnext).2.minified.js @@ -1,32 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.3.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; - return { + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; + return _export("default", void 0), { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - var C = class { - }; - _export("default", C = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), _export("default", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", C = class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es2015).1.normal.js index 40ccb45028ff..520546b63699 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es2015).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "default", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); - var _class = class _class { - }; + const before = _ts_add_disposable_resource._(env, null, false); + ; _class = _ts_decorate._([ dec ], _class); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class _class { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es2015).2.minified.js index 651b4dbc09d5..fba38de30fd2 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es2015).2.minified.js @@ -7,17 +7,19 @@ Object.defineProperty(exports, "__esModule", { return _class; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); - var _class = class { - }; - _class = _ts_decorate._([ + _ts_add_disposable_resource._(env, null, !1), _class = _ts_decorate._([ dec ], _class); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class _class { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es5).1.normal.js index b08de63aba0d..874c182778f9 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es5).1.normal.js @@ -11,19 +11,26 @@ Object.defineProperty(exports, "default", { }); var _class_call_check = require("@swc/helpers/_/_class_call_check"); var _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -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"); +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); - var _class = function _class() { - "use strict"; - _class_call_check._(this, _class); - }; + var before = _ts_add_disposable_resource._(env, null, false); + ; _class = _ts_decorate._([ dec ], _class); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } +var _class = function _class() { + "use strict"; + _class_call_check._(this, _class); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es5).2.minified.js index a3c0f621c3d5..833c640b49e4 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=es5).2.minified.js @@ -7,18 +7,20 @@ Object.defineProperty(exports, "__esModule", { return _class; } }); -var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); - var _class = function _class() { - _class_call_check._(this, _class); - }; - _class = _ts_decorate._([ + _ts_add_disposable_resource._(env, null, !1), _class = _ts_decorate._([ dec ], _class); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } +var _class = function _class() { + _class_call_check._(this, _class); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=esnext).1.normal.js index 40ccb45028ff..520546b63699 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=esnext).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "default", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); - var _class = class _class { - }; + const before = _ts_add_disposable_resource._(env, null, false); + ; _class = _ts_decorate._([ dec ], _class); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class _class { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=esnext).2.minified.js index 651b4dbc09d5..fba38de30fd2 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=commonjs,target=esnext).2.minified.js @@ -7,17 +7,19 @@ Object.defineProperty(exports, "__esModule", { return _class; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); - var _class = class { - }; - _class = _ts_decorate._([ + _ts_add_disposable_resource._(env, null, !1), _class = _ts_decorate._([ dec ], _class); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class _class { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es2015).1.normal.js index 494956940d4a..d70a7bda4f0e 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es2015).1.normal.js @@ -1,17 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.4.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { _class as default }; +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 before = _usingCtx.u(null); - var _class = class _class { - }; + const before = _ts_add_disposable_resource(env, null, false); + ; _class = _ts_decorate([ dec ], _class); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class _class { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es2015).2.minified.js index 16fd923fd420..6c58328c4d65 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es2015).2.minified.js @@ -1,17 +1,20 @@ //// [usingDeclarationsWithLegacyClassDecorators.4.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - var _class = class { - }; - _class = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), _class = _ts_decorate([ dec ], _class); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class _class { } -export { _class as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es5).1.normal.js index 61c57de6872a..c05dd767e355 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es5).1.normal.js @@ -1,20 +1,27 @@ //// [usingDeclarationsWithLegacyClassDecorators.4.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { _class as default }; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); - var _class = function _class() { - "use strict"; - _class_call_check(this, _class); - }; + var before = _ts_add_disposable_resource(env, null, false); + ; _class = _ts_decorate([ dec ], _class); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +var _class = function _class() { + "use strict"; + _class_call_check(this, _class); +}; +export { _class as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es5).2.minified.js index e45139543abc..51bccd82931d 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=es5).2.minified.js @@ -1,19 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.4.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - var _class = function _class() { - _class_call_check(this, _class); - }; - _class = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), _class = _ts_decorate([ dec ], _class); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +var _class = function _class() { + _class_call_check(this, _class); +}; export { _class as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=esnext).1.normal.js index 494956940d4a..d70a7bda4f0e 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=esnext).1.normal.js @@ -1,17 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.4.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { _class as default }; +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 before = _usingCtx.u(null); - var _class = class _class { - }; + const before = _ts_add_disposable_resource(env, null, false); + ; _class = _ts_decorate([ dec ], _class); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class _class { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=esnext).2.minified.js index 16fd923fd420..6c58328c4d65 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=es6,target=esnext).2.minified.js @@ -1,17 +1,20 @@ //// [usingDeclarationsWithLegacyClassDecorators.4.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - var _class = class { - }; - _class = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), _class = _ts_decorate([ dec ], _class); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class _class { } -export { _class as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es2015).1.normal.js index d19071f6100c..9d045cb03472 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es2015).1.normal.js @@ -1,33 +1,44 @@ //// [usingDeclarationsWithLegacyClassDecorators.4.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, _class, env; + _export("default", void 0); return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); - var _class = class _class { - }; + const before = _ts_add_disposable_resource(env, null, false); + ; _export("default", _class = _ts_decorate([ dec ], _class)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", _class = class _class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es2015).2.minified.js index f2954e1f4b1b..7e3454e4c967 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es2015).2.minified.js @@ -1,32 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.4.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; - return { + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, _class, env; + return _export("default", void 0), { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - var _class = class { - }; - _export("default", _class = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), _export("default", _class = _ts_decorate([ dec ], _class)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", _class = class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es5).1.normal.js index beb4a5ec9b05..4f5d2479b21a 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es5).1.normal.js @@ -2,10 +2,11 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env, _class; return { setters: [ function(_class_call_check1) { @@ -14,26 +15,35 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); - var _class = function _class() { - "use strict"; - _class_call_check(this, _class); - }; + var before = _ts_add_disposable_resource(env, null, false); + ; _export("default", _class = _ts_decorate([ dec ], _class)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", _class = function _class() { + "use strict"; + _class_call_check(this, _class); + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es5).2.minified.js index 4ea3d1a4993d..f3452e937959 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=es5).2.minified.js @@ -2,9 +2,10 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env, _class; return { setters: [ function(_class_call_check1) { @@ -13,25 +14,31 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - var _class = function _class() { - _class_call_check(this, _class); - }; - _export("default", _class = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), _export("default", _class = _ts_decorate([ dec ], _class)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", _class = function _class() { + _class_call_check(this, _class); + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=esnext).1.normal.js index d19071f6100c..9d045cb03472 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=esnext).1.normal.js @@ -1,33 +1,44 @@ //// [usingDeclarationsWithLegacyClassDecorators.4.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, _class, env; + _export("default", void 0); return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); - var _class = class _class { - }; + const before = _ts_add_disposable_resource(env, null, false); + ; _export("default", _class = _ts_decorate([ dec ], _class)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", _class = class _class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=esnext).2.minified.js index f2954e1f4b1b..7e3454e4c967 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.4(module=system,target=esnext).2.minified.js @@ -1,32 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.4.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; - return { + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, _class, env; + return _export("default", void 0), { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); - var _class = class { - }; - _export("default", _class = _ts_decorate([ + _ts_add_disposable_resource(env, null, !1), _export("default", _class = _ts_decorate([ dec ], _class)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", _class = class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es2015).1.normal.js index 3ec36fd8d880..492d91e77f37 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es2015).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "C", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); + const before = _ts_add_disposable_resource._(env, null, false); + ; class C { } C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es2015).2.minified.js index b6b98e01017c..f4f45f6bd4fb 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es2015).2.minified.js @@ -7,17 +7,20 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); + _ts_add_disposable_resource._(env, null, !1); class C1 { } C1 = _ts_decorate._([ dec ], C1); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es5).1.normal.js index f23d67fc97d3..6165d7f18b3b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es5).1.normal.js @@ -11,10 +11,16 @@ Object.defineProperty(exports, "C", { }); var _class_call_check = require("@swc/helpers/_/_class_call_check"); var _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -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"); +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); + var before = _ts_add_disposable_resource._(env, null, false); + ; var C = function C() { "use strict"; _class_call_check._(this, C); @@ -22,8 +28,9 @@ try { C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es5).2.minified.js index 0ece95382e4c..da52b2480864 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=es5).2.minified.js @@ -7,18 +7,21 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); + _ts_add_disposable_resource._(env, null, !1); var C = function C() { _class_call_check._(this, C); }; C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=esnext).1.normal.js index 3ec36fd8d880..492d91e77f37 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=esnext).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "C", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); + const before = _ts_add_disposable_resource._(env, null, false); + ; class C { } C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=esnext).2.minified.js index b6b98e01017c..f4f45f6bd4fb 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=commonjs,target=esnext).2.minified.js @@ -7,17 +7,20 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); + _ts_add_disposable_resource._(env, null, !1); class C1 { } C1 = _ts_decorate._([ dec ], C1); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es2015).1.normal.js index 5ca6582ea6a7..530061460ba6 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es2015).1.normal.js @@ -1,17 +1,24 @@ //// [usingDeclarationsWithLegacyClassDecorators.5.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C }; +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 before = _usingCtx.u(null); + const before = _ts_add_disposable_resource(env, null, false); + ; class C { } C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +export { C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es2015).2.minified.js index 07486ef3ac46..1f9ac7aca718 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es2015).2.minified.js @@ -1,17 +1,22 @@ //// [usingDeclarationsWithLegacyClassDecorators.5.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); class C { } C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es5).1.normal.js index 253e725123fa..81fb2fc9e2f4 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es5).1.normal.js @@ -1,11 +1,16 @@ //// [usingDeclarationsWithLegacyClassDecorators.5.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C }; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); + var before = _ts_add_disposable_resource(env, null, false); + ; var C = function C() { "use strict"; _class_call_check(this, C); @@ -13,8 +18,10 @@ try { C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +export { C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es5).2.minified.js index b36fc3fe2288..f579aa512aff 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=es5).2.minified.js @@ -1,19 +1,24 @@ //// [usingDeclarationsWithLegacyClassDecorators.5.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); var C = function C() { _class_call_check(this, C); }; C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=esnext).1.normal.js index 5ca6582ea6a7..530061460ba6 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=esnext).1.normal.js @@ -1,17 +1,24 @@ //// [usingDeclarationsWithLegacyClassDecorators.5.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C }; +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 before = _usingCtx.u(null); + const before = _ts_add_disposable_resource(env, null, false); + ; class C { } C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +export { C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=esnext).2.minified.js index 07486ef3ac46..1f9ac7aca718 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=es6,target=esnext).2.minified.js @@ -1,17 +1,22 @@ //// [usingDeclarationsWithLegacyClassDecorators.5.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); class C { } C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es2015).1.normal.js index 3c77cb98fa4e..0a7e4c10fa3b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es2015).1.normal.js @@ -1,32 +1,42 @@ //// [usingDeclarationsWithLegacyClassDecorators.5.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); + const before = _ts_add_disposable_resource(env, null, false); + ; class C { } _export("C", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es2015).2.minified.js index 93eeefd42634..1edba44f7985 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es2015).2.minified.js @@ -1,31 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.5.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); class C { } _export("C", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es5).1.normal.js index 878d18d69ebb..7f8b42903eba 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es5).1.normal.js @@ -2,10 +2,11 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_class_call_check1) { @@ -14,14 +15,22 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); + var before = _ts_add_disposable_resource(env, null, false); + ; var C = function C() { "use strict"; _class_call_check(this, C); @@ -29,10 +38,11 @@ System.register([ _export("C", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es5).2.minified.js index 3e6cdfcd4378..0e892d03334f 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=es5).2.minified.js @@ -2,9 +2,10 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_class_call_check1) { @@ -13,24 +14,31 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); var C = function C() { _class_call_check(this, C); }; _export("C", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=esnext).1.normal.js index 3c77cb98fa4e..0a7e4c10fa3b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=esnext).1.normal.js @@ -1,32 +1,42 @@ //// [usingDeclarationsWithLegacyClassDecorators.5.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); + const before = _ts_add_disposable_resource(env, null, false); + ; class C { } _export("C", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=esnext).2.minified.js index 93eeefd42634..1edba44f7985 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.5(module=system,target=esnext).2.minified.js @@ -1,31 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.5.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); class C { } _export("C", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es2015).1.normal.js index 68c7b549b012..1cf9521a4628 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es2015).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "D", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); + const before = _ts_add_disposable_resource._(env, null, false); + ; class C { } C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es2015).2.minified.js index 336700d32d3e..4eb0a010c5f3 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es2015).2.minified.js @@ -7,17 +7,20 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); + _ts_add_disposable_resource._(env, null, !1); class C1 { } C1 = _ts_decorate._([ dec ], C1); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es5).1.normal.js index 94273ef9a875..084eb51af822 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es5).1.normal.js @@ -11,10 +11,16 @@ Object.defineProperty(exports, "D", { }); var _class_call_check = require("@swc/helpers/_/_class_call_check"); var _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -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"); +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); + var before = _ts_add_disposable_resource._(env, null, false); + ; var C = function C() { "use strict"; _class_call_check._(this, C); @@ -22,8 +28,9 @@ try { C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es5).2.minified.js index 598796f98807..9d977a8917df 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=es5).2.minified.js @@ -7,18 +7,21 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); + _ts_add_disposable_resource._(env, null, !1); var C = function C() { _class_call_check._(this, C); }; C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=esnext).1.normal.js index 68c7b549b012..1cf9521a4628 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=esnext).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "D", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var before = _usingCtx.u(null); + const before = _ts_add_disposable_resource._(env, null, false); + ; class C { } C = _ts_decorate._([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=esnext).2.minified.js index 336700d32d3e..4eb0a010c5f3 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=commonjs,target=esnext).2.minified.js @@ -7,17 +7,20 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); - _usingCtx.u(null); + _ts_add_disposable_resource._(env, null, !1); class C1 { } C1 = _ts_decorate._([ dec ], C1); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es2015).1.normal.js index 34a460c4368c..05caf9ee76b1 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es2015).1.normal.js @@ -1,17 +1,24 @@ //// [usingDeclarationsWithLegacyClassDecorators.6.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C as D }; +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 before = _usingCtx.u(null); + const before = _ts_add_disposable_resource(env, null, false); + ; class C { } C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +export { C as D }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es2015).2.minified.js index 0bcad536860c..89fb8cbd1b79 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es2015).2.minified.js @@ -1,17 +1,22 @@ //// [usingDeclarationsWithLegacyClassDecorators.6.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); class C { } C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { C as D }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es5).1.normal.js index 8f8b72455193..b7914d546642 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es5).1.normal.js @@ -1,11 +1,16 @@ //// [usingDeclarationsWithLegacyClassDecorators.6.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C as D }; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); + var before = _ts_add_disposable_resource(env, null, false); + ; var C = function C() { "use strict"; _class_call_check(this, C); @@ -13,8 +18,10 @@ try { C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +export { C as D }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es5).2.minified.js index f386f567fce9..110a8a75d070 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=es5).2.minified.js @@ -1,19 +1,24 @@ //// [usingDeclarationsWithLegacyClassDecorators.6.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); var C = function C() { _class_call_check(this, C); }; C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { C as D }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=esnext).1.normal.js index 34a460c4368c..05caf9ee76b1 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=esnext).1.normal.js @@ -1,17 +1,24 @@ //// [usingDeclarationsWithLegacyClassDecorators.6.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C as D }; +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 before = _usingCtx.u(null); + const before = _ts_add_disposable_resource(env, null, false); + ; class C { } C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +export { C as D }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=esnext).2.minified.js index 0bcad536860c..89fb8cbd1b79 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=es6,target=esnext).2.minified.js @@ -1,17 +1,22 @@ //// [usingDeclarationsWithLegacyClassDecorators.6.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); class C { } C = _ts_decorate([ dec ], C); -} catch (_) { - _usingCtx.e = _; +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { C as D }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es2015).1.normal.js index ddf501115f38..0a1f6587b6cd 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es2015).1.normal.js @@ -1,32 +1,42 @@ //// [usingDeclarationsWithLegacyClassDecorators.6.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); + const before = _ts_add_disposable_resource(env, null, false); + ; class C { } _export("D", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es2015).2.minified.js index 8ed7bef15037..77dbc8d6241c 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es2015).2.minified.js @@ -1,31 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.6.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); class C { } _export("D", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es5).1.normal.js index f21e5cbe8d3c..4e22ca9ba296 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es5).1.normal.js @@ -2,10 +2,11 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_class_call_check1) { @@ -14,14 +15,22 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); + var before = _ts_add_disposable_resource(env, null, false); + ; var C = function C() { "use strict"; _class_call_check(this, C); @@ -29,10 +38,11 @@ System.register([ _export("D", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es5).2.minified.js index 7ab0eb31a202..1c476e61bf67 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=es5).2.minified.js @@ -2,9 +2,10 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_class_call_check1) { @@ -13,24 +14,31 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); var C = function C() { _class_call_check(this, C); }; _export("D", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=esnext).1.normal.js index ddf501115f38..0a1f6587b6cd 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=esnext).1.normal.js @@ -1,32 +1,42 @@ //// [usingDeclarationsWithLegacyClassDecorators.6.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var before = _usingCtx.u(null); + const before = _ts_add_disposable_resource(env, null, false); + ; class C { } _export("D", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=esnext).2.minified.js index 8ed7bef15037..77dbc8d6241c 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.6(module=system,target=esnext).2.minified.js @@ -1,31 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.6.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - _usingCtx.u(null); + _ts_add_disposable_resource(env, null, !1); class C { } _export("D", C = _ts_decorate([ dec ], C)); - } catch (_) { - _usingCtx.e = _; + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es2015).1.normal.js index 9c2698aaab74..b66d229133a5 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es2015).1.normal.js @@ -4,17 +4,24 @@ Object.defineProperty(exports, "__esModule", { value: true }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); class C { } C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es2015).2.minified.js index dd66a6ff87ea..c65c64e4cece 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es2015).2.minified.js @@ -2,16 +2,19 @@ Object.defineProperty(exports, "__esModule", { value: !0 }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); class C { } C = _ts_decorate._([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es5).1.normal.js index ea9b2d8c46e7..fde9c081fba4 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es5).1.normal.js @@ -5,9 +5,14 @@ Object.defineProperty(exports, "__esModule", { }); var _class_call_check = require("@swc/helpers/_/_class_call_check"); var _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -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"); +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); var C = function C() { "use strict"; _class_call_check._(this, C); @@ -15,9 +20,11 @@ try { C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es5).2.minified.js index 98f1b834405e..7a03cdcd6bbe 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=es5).2.minified.js @@ -2,16 +2,20 @@ Object.defineProperty(exports, "__esModule", { value: !0 }); -var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(), C = function C() { + var C = function C() { _class_call_check._(this, C); }; C = _ts_decorate._([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=esnext).1.normal.js index 9c2698aaab74..b66d229133a5 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=esnext).1.normal.js @@ -4,17 +4,24 @@ Object.defineProperty(exports, "__esModule", { value: true }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); class C { } C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=esnext).2.minified.js index dd66a6ff87ea..c65c64e4cece 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=commonjs,target=esnext).2.minified.js @@ -2,16 +2,19 @@ Object.defineProperty(exports, "__esModule", { value: !0 }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(); class C { } C = _ts_decorate._([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es2015).1.normal.js index 853a3b6b62e6..f069d6d35501 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es2015).1.normal.js @@ -1,17 +1,24 @@ //// [usingDeclarationsWithLegacyClassDecorators.7.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); class C { } C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es2015).2.minified.js index 86d340d23276..021acc7b10c7 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es2015).2.minified.js @@ -1,15 +1,20 @@ //// [usingDeclarationsWithLegacyClassDecorators.7.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); class C { } C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es5).1.normal.js index 06de5faa4046..02482c9f660b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es5).1.normal.js @@ -1,9 +1,14 @@ //// [usingDeclarationsWithLegacyClassDecorators.7.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx(); var C = function C() { "use strict"; _class_call_check(this, C); @@ -11,10 +16,12 @@ try { C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es5).2.minified.js index 0fbdd9b8ee3f..9abac7c404be 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=es5).2.minified.js @@ -1,16 +1,22 @@ //// [usingDeclarationsWithLegacyClassDecorators.7.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(), C = function C() { + var C = function C() { _class_call_check(this, C); }; C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=esnext).1.normal.js index 853a3b6b62e6..f069d6d35501 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=esnext).1.normal.js @@ -1,17 +1,24 @@ //// [usingDeclarationsWithLegacyClassDecorators.7.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +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(); class C { } C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } export { }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=esnext).2.minified.js index 86d340d23276..021acc7b10c7 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=es6,target=esnext).2.minified.js @@ -1,15 +1,20 @@ //// [usingDeclarationsWithLegacyClassDecorators.7.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(); class C { } C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es2015).1.normal.js index 2e8581f536ce..3b01a0d1448c 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es2015).1.normal.js @@ -1,32 +1,42 @@ //// [usingDeclarationsWithLegacyClassDecorators.7.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); class C { } C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es2015).2.minified.js index 59a9df2f1e1e..2a9ab4f8fc77 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es2015).2.minified.js @@ -1,30 +1,38 @@ //// [usingDeclarationsWithLegacyClassDecorators.7.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); class C { } C = _ts_decorate([ dec - ], C), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es5).1.normal.js index 02d1f7ea7e7c..56f3eda3da75 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es5).1.normal.js @@ -2,10 +2,11 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_class_call_check1) { @@ -14,13 +15,20 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); var C = function C() { "use strict"; _class_call_check(this, C); @@ -28,11 +36,13 @@ System.register([ C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es5).2.minified.js index 1cc637894ae3..3f022d229514 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=es5).2.minified.js @@ -2,9 +2,10 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_class_call_check1) { @@ -13,22 +14,30 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(), C = function C() { + var C = function C() { _class_call_check(this, C); }; C = _ts_decorate([ dec - ], C), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=esnext).1.normal.js index 2e8581f536ce..3b01a0d1448c 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=esnext).1.normal.js @@ -1,32 +1,42 @@ //// [usingDeclarationsWithLegacyClassDecorators.7.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); class C { } C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=esnext).2.minified.js index 59a9df2f1e1e..2a9ab4f8fc77 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.7(module=system,target=esnext).2.minified.js @@ -1,30 +1,38 @@ //// [usingDeclarationsWithLegacyClassDecorators.7.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env; return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); class C { } C = _ts_decorate([ dec - ], C), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } } }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es2015).1.normal.js index 8ae1ece99a0f..b2bef5eed5a7 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es2015).1.normal.js @@ -6,23 +6,28 @@ Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "C", { enumerable: true, get: function() { - return _C; + return C; } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); -var _C; +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - class C { - } - _C = C; C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es2015).2.minified.js index 6ba8203d51f1..c333d02c3718 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es2015).2.minified.js @@ -4,19 +4,22 @@ Object.defineProperty(exports, "__esModule", { }), Object.defineProperty(exports, "C", { enumerable: !0, get: function() { - return _C; + return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _C, _usingCtx = _using_ctx._(); - class C { - } - _C = C, C = _ts_decorate._([ + C = _ts_decorate._([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es5).1.normal.js index 3449d82df4ab..cfe4bd2dc1c5 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es5).1.normal.js @@ -6,26 +6,31 @@ Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "C", { enumerable: true, get: function() { - return _C; + return C; } }); var _class_call_check = require("@swc/helpers/_/_class_call_check"); var _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -var _using_ctx = require("@swc/helpers/_/_using_ctx"); -var _C; +var _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +var _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var C = function C() { - "use strict"; - _class_call_check._(this, C); - }; - _C = C; C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } +var C = function C() { + "use strict"; + _class_call_check._(this, C); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es5).2.minified.js index 8ac7c0bb5c95..ba5de4108c7c 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=es5).2.minified.js @@ -4,19 +4,23 @@ Object.defineProperty(exports, "__esModule", { }), Object.defineProperty(exports, "C", { enumerable: !0, get: function() { - return _C; + return C; } }); -var _C, _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(), C = function C() { - _class_call_check._(this, C); - }; - _C = C, C = _ts_decorate._([ + C = _ts_decorate._([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } +var C = function C() { + _class_call_check._(this, C); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=esnext).1.normal.js index 8ae1ece99a0f..b2bef5eed5a7 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=esnext).1.normal.js @@ -6,23 +6,28 @@ Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "C", { enumerable: true, get: function() { - return _C; + return C; } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); -var _C; +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - class C { - } - _C = C; C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=esnext).2.minified.js index 6ba8203d51f1..c333d02c3718 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=commonjs,target=esnext).2.minified.js @@ -4,19 +4,22 @@ Object.defineProperty(exports, "__esModule", { }), Object.defineProperty(exports, "C", { enumerable: !0, get: function() { - return _C; + return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _C, _usingCtx = _using_ctx._(); - class C { - } - _C = C, C = _ts_decorate._([ + C = _ts_decorate._([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es2015).1.normal.js index aa6a7ceef736..1af565ff38ce 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es2015).1.normal.js @@ -1,19 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.8.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -var _C; +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(); - class C { - } - _C = C; C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export class C { } -export { _C as C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es2015).2.minified.js index 10cbe3e0e41f..85f40d6a9a37 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es2015).2.minified.js @@ -1,16 +1,20 @@ //// [usingDeclarationsWithLegacyClassDecorators.8.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _C, _usingCtx = _using_ctx(); - class C { - } - _C = C, C = _ts_decorate([ + C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export class C { } -export { _C as C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es5).1.normal.js index b9ad72b0c0e4..19ab5479b91b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es5).1.normal.js @@ -1,22 +1,26 @@ //// [usingDeclarationsWithLegacyClassDecorators.8.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -var _C; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx(); - var C = function C() { - "use strict"; - _class_call_check(this, C); - }; - _C = C; C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } -export { _C as C }; +export var C = function C() { + "use strict"; + _class_call_check(this, C); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es5).2.minified.js index 76f2e248d861..d52a4b0eaf37 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=es5).2.minified.js @@ -1,17 +1,22 @@ //// [usingDeclarationsWithLegacyClassDecorators.8.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _C, _usingCtx = _using_ctx(), C = function C() { - _class_call_check(this, C); - }; - _C = C, C = _ts_decorate([ + C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } -export { _C as C }; +export var C = function C() { + _class_call_check(this, C); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=esnext).1.normal.js index aa6a7ceef736..1af565ff38ce 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=esnext).1.normal.js @@ -1,19 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.8.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -var _C; +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(); - class C { - } - _C = C; C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export class C { } -export { _C as C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=esnext).2.minified.js index 10cbe3e0e41f..85f40d6a9a37 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=es6,target=esnext).2.minified.js @@ -1,16 +1,20 @@ //// [usingDeclarationsWithLegacyClassDecorators.8.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _C, _usingCtx = _using_ctx(); - class C { - } - _C = C, C = _ts_decorate([ + C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export class C { } -export { _C as C }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es2015).1.normal.js index d1024d13d7db..eb77033fe56a 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es2015).1.normal.js @@ -1,35 +1,44 @@ //// [usingDeclarationsWithLegacyClassDecorators.8.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx, _C; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; _export("C", void 0); return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - class C { - } - _export("C", _C = C); - C = _ts_decorate([ + _export("C", C = _ts_decorate([ dec - ], C); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)); + const after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("C", C = class C { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es2015).2.minified.js index b85e72b2b16e..6995798920c0 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es2015).2.minified.js @@ -1,31 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.8.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; return _export("C", void 0), { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - class C { - } - _export("C", C), C = _ts_decorate([ + _export("C", C = _ts_decorate([ dec - ], C), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("C", C = class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es5).1.normal.js index d25512b1fd3e..6791296f1c6e 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es5).1.normal.js @@ -2,11 +2,11 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _class_call_check, _ts_decorate, _using_ctx, _C; - _export("C", void 0); + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env, C; return { setters: [ function(_class_call_check1) { @@ -15,27 +15,35 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var C = function C() { - "use strict"; - _class_call_check(this, C); - }; - _export("C", _C = C); - C = _ts_decorate([ + _export("C", C = _ts_decorate([ dec - ], C); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)); + var after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("C", C = function C() { + "use strict"; + _class_call_check(this, C); + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es5).2.minified.js index b20766568cb1..2990d6d5e428 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=es5).2.minified.js @@ -2,10 +2,11 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _class_call_check, _ts_decorate, _using_ctx; - return _export("C", void 0), { + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env, C; + return { setters: [ function(_class_call_check1) { _class_call_check = _class_call_check1._; @@ -13,23 +14,31 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(), C = function C() { - _class_call_check(this, C); - }; - _export("C", C), C = _ts_decorate([ + _export("C", C = _ts_decorate([ dec - ], C), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("C", C = function C() { + _class_call_check(this, C); + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=esnext).1.normal.js index d1024d13d7db..eb77033fe56a 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=esnext).1.normal.js @@ -1,35 +1,44 @@ //// [usingDeclarationsWithLegacyClassDecorators.8.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx, _C; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; _export("C", void 0); return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - class C { - } - _export("C", _C = C); - C = _ts_decorate([ + _export("C", C = _ts_decorate([ dec - ], C); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)); + const after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("C", C = class C { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=esnext).2.minified.js index b85e72b2b16e..6995798920c0 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.8(module=system,target=esnext).2.minified.js @@ -1,31 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.8.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; return _export("C", void 0), { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(); - class C { - } - _export("C", C), C = _ts_decorate([ + _export("C", C = _ts_decorate([ dec - ], C), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("C", C = class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es2015).1.normal.js index a4bd4accb1a7..869d475d87c4 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es2015).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "default", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var C = class C { - }; C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es2015).2.minified.js index 6c68fbfb6168..bff6bdef5af7 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es2015).2.minified.js @@ -7,15 +7,19 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(), C = class { - }; C = _ts_decorate._([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es5).1.normal.js index 3e2b6a072242..ab0292f4aa4f 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es5).1.normal.js @@ -11,19 +11,26 @@ Object.defineProperty(exports, "default", { }); var _class_call_check = require("@swc/helpers/_/_class_call_check"); var _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -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"); +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var C = function C() { - "use strict"; - _class_call_check._(this, C); - }; C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } +var C = function C() { + "use strict"; + _class_call_check._(this, C); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es5).2.minified.js index 2e8e8391c8db..008530334f54 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=es5).2.minified.js @@ -7,16 +7,20 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +var _class_call_check = require("@swc/helpers/_/_class_call_check"), _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(), C = function C() { - _class_call_check._(this, C); - }; C = _ts_decorate._([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); } +var C = function C() { + _class_call_check._(this, C); +}; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=esnext).1.normal.js index a4bd4accb1a7..869d475d87c4 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=esnext).1.normal.js @@ -10,17 +10,24 @@ Object.defineProperty(exports, "default", { } }); const _ts_decorate = require("@swc/helpers/_/_ts_decorate"); -const _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"); +const _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"); +const env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx._(); - var C = class C { - }; C = _ts_decorate._([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource._(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=esnext).2.minified.js index 6c68fbfb6168..bff6bdef5af7 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=commonjs,target=esnext).2.minified.js @@ -7,15 +7,19 @@ Object.defineProperty(exports, "__esModule", { return C; } }); -const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _using_ctx = require("@swc/helpers/_/_using_ctx"); +const _ts_decorate = require("@swc/helpers/_/_ts_decorate"), _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource"), _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources"), env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx._(), C = class { - }; C = _ts_decorate._([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource._(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources._(env); +} +class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es2015).1.normal.js index 7084d7b2830d..cdf1b124d841 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es2015).1.normal.js @@ -1,17 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.9.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C as default }; +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 C = class C { - }; C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es2015).2.minified.js index 7110630aa11e..08d8cc086805 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es2015).2.minified.js @@ -1,15 +1,20 @@ //// [usingDeclarationsWithLegacyClassDecorators.9.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(), C = class { - }; C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class C { } -export { C as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es5).1.normal.js index 8e93165a0f35..75df3acdefc6 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es5).1.normal.js @@ -1,20 +1,27 @@ //// [usingDeclarationsWithLegacyClassDecorators.9.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C as default }; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: false +}; try { - var _usingCtx = _using_ctx(); - var C = function C() { - "use strict"; - _class_call_check(this, C); - }; C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +var C = function C() { + "use strict"; + _class_call_check(this, C); +}; +export { C as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es5).2.minified.js index babb12144ca5..459cf8274873 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=es5).2.minified.js @@ -1,17 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.9.ts] import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +var env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(), C = function C() { - _class_call_check(this, C); - }; C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } +var C = function C() { + _class_call_check(this, C); +}; export { C as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=esnext).1.normal.js index 7084d7b2830d..cdf1b124d841 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=esnext).1.normal.js @@ -1,17 +1,23 @@ //// [usingDeclarationsWithLegacyClassDecorators.9.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; -export { C as default }; +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 C = class C { - }; C = _ts_decorate([ dec ], C); - var after = _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; +} catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class C { } diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=esnext).2.minified.js index 7110630aa11e..08d8cc086805 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=es6,target=esnext).2.minified.js @@ -1,15 +1,20 @@ //// [usingDeclarationsWithLegacyClassDecorators.9.ts] import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; -import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx"; +import { _ as _ts_add_disposable_resource } from "@swc/helpers/_/_ts_add_disposable_resource"; +import { _ as _ts_dispose_resources } from "@swc/helpers/_/_ts_dispose_resources"; +let env = { + stack: [], + error: void 0, + hasError: !1 +}; try { - var _usingCtx = _using_ctx(), C = class { - }; C = _ts_decorate([ dec - ], C), _usingCtx.u(null); -} catch (_) { - _usingCtx.e = _; + ], C), _ts_add_disposable_resource(env, null, !1); +} catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); +} +export default class C { } -export { C as default }; diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es2015).1.normal.js index a9d1eccb0f2b..f77c53c06fd9 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es2015).1.normal.js @@ -1,33 +1,44 @@ //// [usingDeclarationsWithLegacyClassDecorators.9.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; + _export("default", void 0); return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var C = class C { - }; _export("default", C = _ts_decorate([ dec ], C)); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", C = class C { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es2015).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es2015).2.minified.js index b6ba6d8a9800..1c45689416df 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es2015).2.minified.js @@ -1,30 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.9.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; - return { + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; + return _export("default", void 0), { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(), C = class { - }; _export("default", C = _ts_decorate([ dec - ], C)), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", C = class { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es5).1.normal.js index c5eeb1dd3398..2b4a27e794cb 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es5).1.normal.js @@ -2,10 +2,11 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env, C; return { setters: [ function(_class_call_check1) { @@ -14,26 +15,35 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var C = function C() { - "use strict"; - _class_call_check(this, C); - }; _export("default", C = _ts_decorate([ dec ], C)); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + var after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", C = function C() { + "use strict"; + _class_call_check(this, C); + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es5).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es5).2.minified.js index dc0750bb89c2..7baee53bcc06 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=es5).2.minified.js @@ -2,9 +2,10 @@ System.register([ "@swc/helpers/_/_class_call_check", "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _class_call_check, _ts_decorate, _using_ctx; + var _class_call_check, _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, env, C; return { setters: [ function(_class_call_check1) { @@ -13,23 +14,31 @@ System.register([ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(), C = function C() { - _class_call_check(this, C); - }; _export("default", C = _ts_decorate([ dec - ], C)), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", C = function C() { + _class_call_check(this, C); + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=esnext).1.normal.js index a9d1eccb0f2b..f77c53c06fd9 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=esnext).1.normal.js @@ -1,33 +1,44 @@ //// [usingDeclarationsWithLegacyClassDecorators.9.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { "use strict"; - var _ts_decorate, _using_ctx; + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; + _export("default", void 0); return { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: false + }; try { - var _usingCtx = _using_ctx(); - var C = class C { - }; _export("default", C = _ts_decorate([ dec ], C)); - var after = _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + const after = _ts_add_disposable_resource(env, null, false); + ; + } catch (e) { + env.error = e; + env.hasError = true; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", C = class C { + }); } }; }); diff --git a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=esnext).2.minified.js b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=esnext).2.minified.js index b6ba6d8a9800..1c45689416df 100644 --- a/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=esnext).2.minified.js +++ b/crates/swc/tests/tsc-references/usingDeclarationsWithLegacyClassDecorators.9(module=system,target=esnext).2.minified.js @@ -1,30 +1,39 @@ //// [usingDeclarationsWithLegacyClassDecorators.9.ts] System.register([ "@swc/helpers/_/_ts_decorate", - "@swc/helpers/_/_using_ctx" + "@swc/helpers/_/_ts_add_disposable_resource", + "@swc/helpers/_/_ts_dispose_resources" ], function(_export, _context) { - var _ts_decorate, _using_ctx; - return { + var _ts_decorate, _ts_add_disposable_resource, _ts_dispose_resources, C, env; + return _export("default", void 0), { setters: [ function(_ts_decorate1) { _ts_decorate = _ts_decorate1._; }, - function(_using_ctx1) { - _using_ctx = _using_ctx1._; + function(_ts_add_disposable_resource1) { + _ts_add_disposable_resource = _ts_add_disposable_resource1._; + }, + function(_ts_dispose_resources1) { + _ts_dispose_resources = _ts_dispose_resources1._; } ], execute: function() { + env = { + stack: [], + error: void 0, + hasError: !1 + }; try { - var _usingCtx = _using_ctx(), C = class { - }; _export("default", C = _ts_decorate([ dec - ], C)), _usingCtx.u(null); - } catch (_) { - _usingCtx.e = _; + ], C)), _ts_add_disposable_resource(env, null, !1); + } catch (e) { + env.error = e, env.hasError = !0; } finally{ - _usingCtx.d(); + _ts_dispose_resources(env); } + _export("default", C = class { + }); } }; }); From cc5c52d970a0c7b9583acf6379690df07fd49dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 14:23:12 +0900 Subject: [PATCH 28/28] Update test refs --- .../usingDeclarations.1(target=es2015).1.normal.js | 3 +-- .../usingDeclarations.1(target=es2017).1.normal.js | 3 +-- .../usingDeclarations.1(target=es2022).1.normal.js | 3 +-- .../tsc-references/usingDeclarations.1(target=es5).1.normal.js | 3 +-- .../usingDeclarations.1(target=esnext).1.normal.js | 3 +-- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2015).1.normal.js index de2c59fd5d50..b5212ff4ec21 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2015).1.normal.js @@ -13,6 +13,7 @@ try { const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} }, false); + ; function f() { const env = { stack: [], @@ -609,8 +610,6 @@ try { } } var N; -} catch (_) { - _usingCtx.e = _; } catch (e) { env.error = e; env.hasError = true; diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2017).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2017).1.normal.js index 2ad93dc3bb2f..6aab606dac7d 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2017).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2017).1.normal.js @@ -10,6 +10,7 @@ try { const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} }, false); + ; function f() { const env = { stack: [], @@ -590,8 +591,6 @@ try { } } var N; -} catch (_) { - _usingCtx.e = _; } catch (e) { env.error = e; env.hasError = true; diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2022).1.normal.js index 00074c2d3667..1049e1a225fa 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es2022).1.normal.js @@ -10,6 +10,7 @@ try { const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} }, false); + ; function f() { const env = { stack: [], @@ -590,8 +591,6 @@ try { } } var N; -} catch (_) { - _usingCtx.e = _; } catch (e) { env.error = e; env.hasError = true; diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es5).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es5).1.normal.js index 1f55f824a7bb..5708bd40ca7b 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=es5).1.normal.js @@ -88,6 +88,7 @@ try { return _ag.apply(this, arguments); }; var d1 = _ts_add_disposable_resource(env, _define_property({}, Symbol.dispose, function() {}), false); + ; function _af() { _af = _async_to_generator(function() { var env, d3, e; @@ -772,8 +773,6 @@ try { } } var N; -} catch (_) { - _usingCtx.e = _; } catch (e) { env.error = e; env.hasError = true; diff --git a/crates/swc/tests/tsc-references/usingDeclarations.1(target=esnext).1.normal.js b/crates/swc/tests/tsc-references/usingDeclarations.1(target=esnext).1.normal.js index 00074c2d3667..1049e1a225fa 100644 --- a/crates/swc/tests/tsc-references/usingDeclarations.1(target=esnext).1.normal.js +++ b/crates/swc/tests/tsc-references/usingDeclarations.1(target=esnext).1.normal.js @@ -10,6 +10,7 @@ try { const d1 = _ts_add_disposable_resource(env, { [Symbol.dispose] () {} }, false); + ; function f() { const env = { stack: [], @@ -590,8 +591,6 @@ try { } } var N; -} catch (_) { - _usingCtx.e = _; } catch (e) { env.error = e; env.hasError = true;