fix(es/typescript): Fix name of decorated classes (#3689)

This commit is contained in:
Guillaume Malette 2022-02-23 00:07:53 -05:00 committed by GitHub
parent 738d153609
commit 1e49fcd44d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 2 deletions

View File

@ -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")

View File

@ -411,11 +411,13 @@ where
} else {
for m in class.body.iter_mut() {
if let ClassMember::ClassProp(m) = m {
if m.is_static {
if let Some(orig_ident) = &orig_ident {
replace_ident(&mut m.value, orig_ident.to_id(), &ident)
}
}
}
}
let mut key_computations = vec![];
let mut assign_exprs = vec![];