mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 17:54:15 +03:00
hygiene now handles class name correctly (#323)
This commit is contained in:
parent
a311f42acf
commit
dd5f17463e
@ -537,6 +537,32 @@ macro_rules! track_ident {
|
||||
ContinueStmt { label, ..s }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Fold<ClassDecl> for $T<'a> {
|
||||
fn fold(&mut self, n: ClassDecl) -> ClassDecl {
|
||||
let old = self.ident_type;
|
||||
self.ident_type = IdentType::Binding;
|
||||
let ident = n.ident.fold_with(self);
|
||||
self.ident_type = old;
|
||||
|
||||
let class = n.class.fold_with(self);
|
||||
|
||||
ClassDecl { ident, class, ..n }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Fold<ClassExpr> for $T<'a> {
|
||||
fn fold(&mut self, n: ClassExpr) -> ClassExpr {
|
||||
let old = self.ident_type;
|
||||
self.ident_type = IdentType::Binding;
|
||||
let ident = n.ident.fold_with(self);
|
||||
self.ident_type = old;
|
||||
|
||||
let class = n.class.fold_with(self);
|
||||
|
||||
ClassExpr { ident, class, ..n }
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1123,3 +1123,45 @@ fn issue_295_02() {
|
||||
}",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exported_function() {
|
||||
test_module(
|
||||
|tester| {
|
||||
let mark1 = Mark::fresh(Mark::root());
|
||||
let mark2 = Mark::fresh(Mark::root());
|
||||
|
||||
Ok(tester
|
||||
.parse_module(
|
||||
"actual1.js",
|
||||
"const foo = {};
|
||||
export function foo(){}",
|
||||
)?
|
||||
.fold_with(&mut OnceMarker::new(&[("foo", &[mark1, mark2])])))
|
||||
},
|
||||
"const foo = {};
|
||||
function foo1(){}
|
||||
export { foo1 as foo };",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exported_class_1() {
|
||||
test_module(
|
||||
|tester| {
|
||||
let mark1 = Mark::fresh(Mark::root());
|
||||
let mark2 = Mark::fresh(Mark::root());
|
||||
|
||||
Ok(tester
|
||||
.parse_module(
|
||||
"actual1.js",
|
||||
"var Foo = {};
|
||||
export class Foo {}",
|
||||
)?
|
||||
.fold_with(&mut OnceMarker::new(&[("Foo", &[mark1, mark2])])))
|
||||
},
|
||||
"var Foo = {};
|
||||
class Foo1 {}
|
||||
export { Foo1 as Foo };",
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user