diff --git a/crates/swc/tests/projects.rs b/crates/swc/tests/projects.rs index 18c67d06e2c..cf7bb1a16bd 100644 --- a/crates/swc/tests/projects.rs +++ b/crates/swc/tests/projects.rs @@ -900,6 +900,37 @@ fn opt_source_file_name_1() { assert!(map.contains("entry-foo")); } +#[test] +fn issue_2224() { + let output = str_with_opt( + r#" + const Injectable = () => {}; + + @Injectable + export class TestClass { + private readonly property = TestClass.name; + }"#, + Options { + is_module: IsModule::Bool(true), + config: Config { + jsc: JscConfig { + syntax: Some(Syntax::Typescript(TsConfig { + decorators: true, + ..Default::default() + })), + ..Default::default() + }, + ..Default::default() + }, + ..Default::default() + }, + ) + .unwrap(); + println!("{}", output); + + assert!(output.contains("this.property = TestClass.name")); +} + #[test] fn bom() { project("tests/projects/bom") diff --git a/crates/swc_ecma_transforms_typescript/src/strip.rs b/crates/swc_ecma_transforms_typescript/src/strip.rs index 4219d4eec01..5c6e27530c5 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip.rs @@ -411,8 +411,10 @@ where } else { for m in class.body.iter_mut() { if let ClassMember::ClassProp(m) = m { - if let Some(orig_ident) = &orig_ident { - replace_ident(&mut m.value, orig_ident.to_id(), &ident) + if m.is_static { + if let Some(orig_ident) = &orig_ident { + replace_ident(&mut m.value, orig_ident.to_id(), &ident) + } } } }