Skip to content

Commit

Permalink
fix(es/transforms/base): Fix resolver (#1414)
Browse files Browse the repository at this point in the history
swc_ecma_transforms_base:
 - `resolver`: Handle private class methods. (denoland/deno_lint#615)
  • Loading branch information
kdy1 authored Feb 19, 2021
1 parent 27aad87 commit eecdca4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ecmascript/transforms/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecma_transforms_base"
repository = "https://github.com/swc-project/swc.git"
version = "0.5.0"
version = "0.5.1"

[dependencies]
fxhash = "0.2.1"
Expand Down
18 changes: 18 additions & 0 deletions ecmascript/transforms/base/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,24 @@ impl<'a> VisitMut for Resolver<'a> {
self.cur_defining = folder.cur_defining;
}

fn visit_mut_private_method(&mut self, m: &mut PrivateMethod) {
m.key.visit_mut_with(self);

{
let child_mark = Mark::fresh(self.mark);

// Child folder
let mut child = Resolver::new(
child_mark,
Scope::new(ScopeKind::Fn, Some(&self.current)),
None,
self.handle_types,
);

m.function.visit_mut_with(&mut child)
}
}

fn visit_mut_class_method(&mut self, m: &mut ClassMethod) {
m.key.visit_mut_with(self);

Expand Down
42 changes: 42 additions & 0 deletions ecmascript/transforms/base/src/resolver/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2187,3 +2187,45 @@ to!(
}
"
);

to_ts!(
deno_lint_612_1,
"
class T {
#foo(x) {}
#bar(x) {}
}
",
"
class T {
#foo__0(x__2) {
}
#bar__0(x__3) {
}
}
"
);

to_ts!(
deno_lint_612_2,
"
class T {
#foo(x) {
use(x)
}
#bar(x) {
use(x)
}
}
",
"
class T {
#foo__0(x__2) {
use(x__2);
}
#bar__0(x__3) {
use(x__3);
}
}
"
);

0 comments on commit eecdca4

Please sign in to comment.