From 7e7b4526ba397b9492a8d42cc2da8240250be77b Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 31 May 2024 05:39:46 +0000 Subject: [PATCH] refactor(transformer): panic on illegal cases in TS namespace transform (#3477) Panic on function or class declaration without `id`. This should be impossible. --- .../oxc_transformer/src/typescript/namespace.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/crates/oxc_transformer/src/typescript/namespace.rs b/crates/oxc_transformer/src/typescript/namespace.rs index 242e9db2c..5e34bfbd2 100644 --- a/crates/oxc_transformer/src/typescript/namespace.rs +++ b/crates/oxc_transformer/src/typescript/namespace.rs @@ -105,15 +105,11 @@ impl<'a> TypeScript<'a> { } // Collect bindings from class, function, variable and enum declarations Statement::FunctionDeclaration(ref decl) => { - if let Some(ident) = &decl.id { - names.insert(ident.name.clone()); - } + names.insert(decl.id.as_ref().unwrap().name.clone()); new_stmts.push(stmt); } Statement::ClassDeclaration(ref decl) => { - if let Some(ident) = &decl.id { - names.insert(ident.name.clone()); - } + names.insert(decl.id.as_ref().unwrap().name.clone()); new_stmts.push(stmt); } Statement::TSEnumDeclaration(ref decl) => { @@ -196,15 +192,11 @@ impl<'a> TypeScript<'a> { } } Statement::ClassDeclaration(ref decl) => { - decl.bound_names(&mut |id| { - names.insert(id.name.clone()); - }); + names.insert(decl.id.as_ref().unwrap().name.clone()); new_stmts.push(stmt); } Statement::FunctionDeclaration(ref decl) => { - decl.bound_names(&mut |id| { - names.insert(id.name.clone()); - }); + names.insert(decl.id.as_ref().unwrap().name.clone()); new_stmts.push(stmt); } Statement::TSEnumDeclaration(ref enum_decl) => {