From 84f175991004cecdffc0a95a7702875a72912cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Mon, 25 May 2020 22:53:48 +0900 Subject: [PATCH] Fix folder for stable rustc (#797) --- ecmascript/visit/Cargo.toml | 2 +- ecmascript/visit/macros/Cargo.toml | 2 +- ecmascript/visit/macros/src/lib.rs | 32 ++++++++++++++++-------- ecmascript/visit/macros/tests/fold.rs | 29 +++++++++++++++++++++ ecmascript/visit/macros/tests/opt_vec.rs | 25 ++++++++++++++++++ ecmascript/visit/macros/tests/vec_opt.rs | 25 ++++++++++++++++++ 6 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 ecmascript/visit/macros/tests/fold.rs create mode 100644 ecmascript/visit/macros/tests/opt_vec.rs create mode 100644 ecmascript/visit/macros/tests/vec_opt.rs diff --git a/ecmascript/visit/Cargo.toml b/ecmascript/visit/Cargo.toml index 74f18ab920e..8abd94df198 100644 --- a/ecmascript/visit/Cargo.toml +++ b/ecmascript/visit/Cargo.toml @@ -13,5 +13,5 @@ edition = "2018" swc_atoms = { version = "0.2", path = "../../atoms" } swc_common = { version = "0.5.9", path = "../../common" } swc_ecma_ast = { version = "0.20.0", path ="../ast" } -swc_ecma_visit_macros = { version = "0.3.0", path ="./macros" } +swc_ecma_visit_macros = { version = "0.4.0", path ="./macros" } num-bigint = { version = "0.2", features = ["serde"] } diff --git a/ecmascript/visit/macros/Cargo.toml b/ecmascript/visit/macros/Cargo.toml index d5bb8942b5a..08b2d7b99d2 100644 --- a/ecmascript/visit/macros/Cargo.toml +++ b/ecmascript/visit/macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "swc_ecma_visit_macros" -version = "0.3.0" +version = "0.4.0" authors = ["강동윤 "] license = "Apache-2.0/MIT" repository = "https://github.com/swc-project/swc.git" diff --git a/ecmascript/visit/macros/src/lib.rs b/ecmascript/visit/macros/src/lib.rs index da266a5b152..b02eaf9f8fa 100644 --- a/ecmascript/visit/macros/src/lib.rs +++ b/ecmascript/visit/macros/src/lib.rs @@ -778,16 +778,28 @@ fn create_method_body(mode: Mode, ty: &Type) -> Block { _ => {} } - return q!( - Vars { ident }, - ({ - match n { - Some(n) => _visitor.ident(n, _parent), - None => {} - } - }) - ) - .parse(); + return match mode { + Mode::Folder => q!( + Vars { ident }, + ({ + match n { + Some(n) => Some(_visitor.ident(n)), + None => None, + } + }) + ) + .parse(), + Mode::Visitor => q!( + Vars { ident }, + ({ + match n { + Some(n) => _visitor.ident(n, _parent), + None => {} + } + }) + ) + .parse(), + }; } _ => unimplemented!("generic parameter other than type"), } diff --git a/ecmascript/visit/macros/tests/fold.rs b/ecmascript/visit/macros/tests/fold.rs new file mode 100644 index 00000000000..d0aa214c205 --- /dev/null +++ b/ecmascript/visit/macros/tests/fold.rs @@ -0,0 +1,29 @@ +use std::any::Any; +use swc_ecma_visit_macros::define; + +/// Visitable nodes. +pub trait Node: Any {} + +impl Node for T where T: Any {} + +pub struct Item { + // pub field: usize, + // pub inner: Option>, + pub opt_vec: Option>, + pub vec_opt: Vec>, +} +pub enum Enum { + Item(Item), +} + +define!({ + pub struct Item { + // pub field: usize, + // pub inner: Option>, + pub opt_vec: Option>, + pub vec_opt: Vec>, + } + pub enum Enum { + Item(Item), + } +}); diff --git a/ecmascript/visit/macros/tests/opt_vec.rs b/ecmascript/visit/macros/tests/opt_vec.rs new file mode 100644 index 00000000000..7358ad5ad66 --- /dev/null +++ b/ecmascript/visit/macros/tests/opt_vec.rs @@ -0,0 +1,25 @@ +use std::any::Any; +use swc_ecma_visit_macros::define; + +/// Visitable nodes. +pub trait Node: Any {} + +impl Node for T where T: Any {} + +pub struct Item { + pub opt_vec1: Option>, + pub opt_vec2: Option>, +} +pub enum Enum { + Item(Item), +} + +define!({ + pub struct Item { + pub opt_vec1: Option>, + pub opt_vec2: Option>, + } + pub enum Enum { + Item(Item), + } +}); diff --git a/ecmascript/visit/macros/tests/vec_opt.rs b/ecmascript/visit/macros/tests/vec_opt.rs new file mode 100644 index 00000000000..99c887e4654 --- /dev/null +++ b/ecmascript/visit/macros/tests/vec_opt.rs @@ -0,0 +1,25 @@ +use std::any::Any; +use swc_ecma_visit_macros::define; + +/// Visitable nodes. +pub trait Node: Any {} + +impl Node for T where T: Any {} + +pub struct Item { + pub vec_opt1: Vec>, + pub vec_opt2: Vec>, +} +pub enum Enum { + Item(Item), +} + +define!({ + pub struct Item { + pub vec_opt1: Vec>, + pub vec_opt2: Vec>, + } + pub enum Enum { + Item(Item), + } +});