fix(es/codegen): Emit decorators on class methods (#4103)

This commit is contained in:
Donny/강동윤 2022-03-20 16:53:53 +09:00 committed by GitHub
parent 133bfb43d3
commit 9b64a6960f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 10 deletions

1
Cargo.lock generated
View File

@ -3039,6 +3039,7 @@ dependencies = [
"swc_ecma_parser",
"swc_ecma_transforms_base",
"swc_ecma_transforms_optimization",
"swc_ecma_transforms_proposal",
"swc_ecma_transforms_react",
"swc_ecma_transforms_typescript",
"swc_ecma_utils",

View File

@ -65,6 +65,7 @@ swc_ecma_loader = { version = "0.29.0", path = "../swc_ecma_loader", features =
"cache",
] }
swc_ecma_minifier = { version = "0.94.0", path = "../swc_ecma_minifier" }
swc_ecma_transforms_proposal = { version = "0.91.0", path = "../swc_ecma_transforms_proposal" }
swc_ecma_transforms_react = { version = "0.98.0", path = "../swc_ecma_transforms_react" }
swc_ecma_transforms_typescript = { version = "0.101.0", path = "../swc_ecma_transforms_typescript" }
swc_node_base = { version = "0.5.0", path = "../swc_node_base" }

View File

@ -18,7 +18,11 @@ use swc_common::{
};
use swc_ecma_ast::EsVersion;
use swc_ecma_parser::{parse_file_as_module, Syntax, TsConfig};
use swc_ecma_transforms_base::resolver::resolver_with_mark;
use swc_ecma_transforms_base::{
helpers::{inject_helpers, Helpers, HELPERS},
resolver::resolver_with_mark,
};
use swc_ecma_transforms_proposal::decorators;
use swc_ecma_transforms_react::react;
use swc_ecma_transforms_typescript::strip;
use swc_ecma_visit::FoldWith;
@ -128,15 +132,22 @@ impl Load for Loader {
});
let mark = Mark::fresh(Mark::root());
let module = module
.fold_with(&mut resolver_with_mark(mark))
.fold_with(&mut strip(mark))
.fold_with(&mut react::<SingleThreadedComments>(
self.cm.clone(),
None,
Default::default(),
top_level_mark,
));
let module = HELPERS.set(&Helpers::new(false), || {
module
.fold_with(&mut resolver_with_mark(mark))
.fold_with(&mut decorators(decorators::Config {
legacy: true,
emit_metadata: Default::default(),
}))
.fold_with(&mut strip(mark))
.fold_with(&mut react::<SingleThreadedComments>(
self.cm.clone(),
None,
Default::default(),
top_level_mark,
))
.fold_with(&mut inject_helpers())
});
Ok(ModuleData {
fm,

View File

@ -1223,6 +1223,10 @@ where
srcmap!(n, true);
for d in &n.function.decorators {
emit!(d);
}
self.emit_accessibility(n.accessibility)?;
if n.is_static {