hygiene now handles class name correctly (#323)

This commit is contained in:
강동윤 2019-03-07 22:42:16 +09:00 committed by GitHub
parent a311f42acf
commit dd5f17463e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 0 deletions

View File

@ -537,6 +537,32 @@ macro_rules! track_ident {
ContinueStmt { label, ..s } 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 }
}
}
}; };
} }

View File

@ -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 };",
);
}