From dd5f17463ea99f43a57765eab137cd79d9bdf37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Thu, 7 Mar 2019 22:42:16 +0900 Subject: [PATCH] hygiene now handles class name correctly (#323) --- ecmascript/transforms/src/hygiene/mod.rs | 26 ++++++++++++++ ecmascript/transforms/src/hygiene/tests.rs | 42 ++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/ecmascript/transforms/src/hygiene/mod.rs b/ecmascript/transforms/src/hygiene/mod.rs index 2bebaba3a60..6b83cef1640 100644 --- a/ecmascript/transforms/src/hygiene/mod.rs +++ b/ecmascript/transforms/src/hygiene/mod.rs @@ -537,6 +537,32 @@ macro_rules! track_ident { ContinueStmt { label, ..s } } } + + impl<'a> Fold 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 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 } + } + } }; } diff --git a/ecmascript/transforms/src/hygiene/tests.rs b/ecmascript/transforms/src/hygiene/tests.rs index 4217f5a3838..5902f467cfa 100644 --- a/ecmascript/transforms/src/hygiene/tests.rs +++ b/ecmascript/transforms/src/hygiene/tests.rs @@ -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 };", + ); +}