From 7a13aabeb735f210c8bfd220eea92d6ebad05ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 17 Aug 2020 14:09:12 +0200 Subject: [PATCH] remove codegen::Handlers (#974) --- bundler/examples/path.rs | 6 ------ bundler/src/debug/mod.rs | 5 ----- bundler/src/hash.rs | 4 ---- ecmascript/codegen/benches/bench.rs | 6 ------ ecmascript/codegen/benches/with_parse.rs | 6 ------ ecmascript/codegen/src/lib.rs | 10 ---------- ecmascript/codegen/src/tests.rs | 4 ---- ecmascript/codegen/tests/test262.rs | 6 ------ ecmascript/preset_env/tests/test.rs | 6 ------ ecmascript/transforms/src/tests.rs | 7 ------- ecmascript/transforms/tests/common/mod.rs | 7 ------- ecmascript/transforms/tests/fixer_test262.rs | 8 -------- .../transforms/tests/typescript_strip_correctness.rs | 6 ------ src/lib.rs | 6 ------ 14 files changed, 87 deletions(-) diff --git a/bundler/examples/path.rs b/bundler/examples/path.rs index 2a18c988b73..0a41ac76824 100644 --- a/bundler/examples/path.rs +++ b/bundler/examples/path.rs @@ -46,17 +46,11 @@ fn main() { cm: cm.clone(), comments: None, wr: Box::new(JsWriter::new(cm.clone(), "\n", wr.lock(), None)), - handlers: Box::new(Handllers), }; emitter.emit_module(&bundle.module).unwrap(); } -/// I should remove this... -struct Handllers; - -impl swc_ecma_codegen::Handlers for Handllers {} - struct PathLoader { cm: Lrc, } diff --git a/bundler/src/debug/mod.rs b/bundler/src/debug/mod.rs index 57fc2174c6e..ca281ee7108 100644 --- a/bundler/src/debug/mod.rs +++ b/bundler/src/debug/mod.rs @@ -18,17 +18,12 @@ pub(crate) fn print_hygiene(event: &str, cm: &Lrc, t: &Module) { cm: cm.clone(), comments: None, wr: Box::new(JsWriter::new(cm.clone(), "\n", &mut w, None)), - handlers: Box::new(Handlers), } .emit_module(&module) .unwrap(); writeln!(w, "==================== @ ====================").unwrap(); } -impl swc_ecma_codegen::Handlers for Handlers {} - -struct Handlers; - struct HygieneVisualizer; impl Fold for HygieneVisualizer { diff --git a/bundler/src/hash.rs b/bundler/src/hash.rs index e89cf30f33e..b24db437b41 100644 --- a/bundler/src/hash.rs +++ b/bundler/src/hash.rs @@ -15,7 +15,6 @@ pub(crate) fn calc_hash(cm: Lrc, m: &Module) -> Result cm, comments: None, wr: Box::new(&mut buf) as Box, - handlers: Box::new(Handlers), }; emitter @@ -28,9 +27,6 @@ pub(crate) fn calc_hash(cm: Lrc, m: &Module) -> Result Ok(radix_fmt::radix(result, 36).to_string()) } -impl swc_ecma_codegen::Handlers for Handlers {} -struct Handlers; - struct Hasher { digest: Digest, } diff --git a/ecmascript/codegen/benches/bench.rs b/ecmascript/codegen/benches/bench.rs index 61c23b4b61e..5703505ccfb 100644 --- a/ecmascript/codegen/benches/bench.rs +++ b/ecmascript/codegen/benches/bench.rs @@ -102,7 +102,6 @@ fn bench_emitter(b: &mut Bencher, s: &str) { b.iter(|| { let mut buf = vec![]; { - let handlers = Box::new(MyHandlers); let mut emitter = Emitter { cfg: swc_ecma_codegen::Config { ..Default::default() @@ -115,7 +114,6 @@ fn bench_emitter(b: &mut Bencher, s: &str) { &mut buf, Some(&mut src_map_buf), )), - handlers, }; let _ = emitter.emit_module(&module); @@ -137,7 +135,3 @@ fn emit_colors(b: &mut Bencher) { fn emit_large(b: &mut Bencher) { bench_emitter(b, LARGE_PARTIAL_JS) } - -struct MyHandlers; - -impl swc_ecma_codegen::Handlers for MyHandlers {} diff --git a/ecmascript/codegen/benches/with_parse.rs b/ecmascript/codegen/benches/with_parse.rs index 9e09968b8fd..32743c71db1 100644 --- a/ecmascript/codegen/benches/with_parse.rs +++ b/ecmascript/codegen/benches/with_parse.rs @@ -101,7 +101,6 @@ fn bench_emitter(b: &mut Bencher, s: &str) { let mut buf = vec![]; { - let handlers = Box::new(MyHandlers); let mut emitter = Emitter { cfg: swc_ecma_codegen::Config { ..Default::default() @@ -114,7 +113,6 @@ fn bench_emitter(b: &mut Bencher, s: &str) { &mut buf, Some(&mut src_map_buf), )), - handlers, }; let _ = emitter.emit_module(&module); @@ -136,7 +134,3 @@ fn colors(b: &mut Bencher) { fn large_partial(b: &mut Bencher) { bench_emitter(b, LARGE_PARTIAL_JS) } - -struct MyHandlers; - -impl swc_ecma_codegen::Handlers for MyHandlers {} diff --git a/ecmascript/codegen/src/lib.rs b/ecmascript/codegen/src/lib.rs index 7aeb3337585..530f7129548 100644 --- a/ecmascript/codegen/src/lib.rs +++ b/ecmascript/codegen/src/lib.rs @@ -32,11 +32,6 @@ pub mod util; pub type Result = io::Result<()>; -pub trait Handlers { - // fn on_before_emit_token(&mut self, _node: &Any) {} - // fn on_after_emit_token(&mut self, _node: &Any) {} -} - pub trait Node: Spanned { fn emit_with(&self, e: &mut Emitter<'_>) -> Result; } @@ -58,7 +53,6 @@ pub struct Emitter<'a> { pub cm: Lrc, pub comments: Option<&'a dyn Comments>, pub wr: Box<(dyn 'a + WriteJs)>, - pub handlers: Box<(dyn 'a + Handlers)>, } impl<'a> Emitter<'a> { @@ -1431,10 +1425,6 @@ impl<'a> Emitter<'a> { let is_empty = children.is_none() || start > children.unwrap().len() || count == 0; if is_empty && format.contains(ListFormat::OptionalIfEmpty) { - // self.handlers.onBeforeEmitNodeArray(children) - - // self.handlers.onAfterEmitNodeArray(children); - return Ok(()); } diff --git a/ecmascript/codegen/src/tests.rs b/ecmascript/codegen/src/tests.rs index 48738e8ab3c..c3dba323574 100644 --- a/ecmascript/codegen/src/tests.rs +++ b/ecmascript/codegen/src/tests.rs @@ -9,9 +9,6 @@ use std::{ use swc_common::{comments::SingleThreadedComments, FileName, SourceMap}; use swc_ecma_parser; -struct Noop; -impl Handlers for Noop {} - struct Builder { cfg: Config, cm: Lrc, @@ -28,7 +25,6 @@ impl Builder { cm: self.cm.clone(), wr: Box::new(text_writer::JsWriter::new(self.cm.clone(), "\n", s, None)), comments: Some(&self.comments), - handlers: Box::new(Noop), }; let ret = op(&mut e); diff --git a/ecmascript/codegen/tests/test262.rs b/ecmascript/codegen/tests/test262.rs index 5c60929a1cc..66f84f3e20f 100644 --- a/ecmascript/codegen/tests/test262.rs +++ b/ecmascript/codegen/tests/test262.rs @@ -89,10 +89,6 @@ fn add_test( }); } -struct MyHandlers; - -impl swc_ecma_codegen::Handlers for MyHandlers {} - fn error_tests(tests: &mut Vec) -> Result<(), io::Error> { let ref_dir = Path::new(env!("CARGO_MANIFEST_DIR")) .join("tests") @@ -148,7 +144,6 @@ fn error_tests(tests: &mut Vec) -> Result<(), io::Error> { ); let comments = SingleThreadedComments::default(); - let handlers = Box::new(MyHandlers); let lexer = Lexer::new( Syntax::default(), Default::default(), @@ -165,7 +160,6 @@ fn error_tests(tests: &mut Vec) -> Result<(), io::Error> { cm, "\n", &mut wr, None, )), comments: Some(&comments), - handlers, }; // Parse source diff --git a/ecmascript/preset_env/tests/test.rs b/ecmascript/preset_env/tests/test.rs index d382d048039..137b209f2ac 100644 --- a/ecmascript/preset_env/tests/test.rs +++ b/ecmascript/preset_env/tests/test.rs @@ -203,7 +203,6 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { let print = |m: &Module| { let mut buf = vec![]; { - let handlers = Box::new(MyHandlers); let mut emitter = Emitter { cfg: swc_ecma_codegen::Config { minify: false }, comments: None, @@ -214,7 +213,6 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { &mut buf, None, )), - handlers, }; emitter.emit_module(m).expect("failed to emit module"); @@ -344,7 +342,3 @@ fn fixtures() { let args: Vec<_> = env::args().collect(); test_main(&args, tests, Some(test::Options::new())); } - -struct MyHandlers; - -impl swc_ecma_codegen::Handlers for MyHandlers {} diff --git a/ecmascript/transforms/src/tests.rs b/ecmascript/transforms/src/tests.rs index d9f365e8a39..c5b5b7670de 100644 --- a/ecmascript/transforms/src/tests.rs +++ b/ecmascript/transforms/src/tests.rs @@ -17,10 +17,6 @@ use swc_ecma_utils::DropSpan; use swc_ecma_visit::{Fold, FoldWith}; use tempfile::tempdir_in; -struct MyHandlers; - -impl swc_ecma_codegen::Handlers for MyHandlers {} - pub(crate) struct Tester<'a> { pub cm: Lrc, pub handler: &'a Handler, @@ -128,8 +124,6 @@ impl<'a> Tester<'a> { } pub fn print(&mut self, module: &Module) -> String { - let handlers = Box::new(MyHandlers); - let mut wr = Buf(Arc::new(RwLock::new(vec![]))); { let mut emitter = Emitter { @@ -142,7 +136,6 @@ impl<'a> Tester<'a> { None, )), comments: None, - handlers, }; // println!("Emitting: {:?}", module); diff --git a/ecmascript/transforms/tests/common/mod.rs b/ecmascript/transforms/tests/common/mod.rs index 7cf59c40484..a6d1d892884 100644 --- a/ecmascript/transforms/tests/common/mod.rs +++ b/ecmascript/transforms/tests/common/mod.rs @@ -46,10 +46,6 @@ macro_rules! validate { }}; } -struct MyHandlers; - -impl swc_ecma_codegen::Handlers for MyHandlers {} - pub struct Tester<'a> { pub cm: Lrc, pub handler: &'a Handler, @@ -142,8 +138,6 @@ impl<'a> Tester<'a> { } pub fn print(&mut self, module: &Module) -> String { - let handlers = Box::new(MyHandlers); - let mut wr = Buf(Arc::new(RwLock::new(vec![]))); { let mut emitter = Emitter { @@ -156,7 +150,6 @@ impl<'a> Tester<'a> { None, )), comments: None, - handlers, }; // println!("Emitting: {:?}", module); diff --git a/ecmascript/transforms/tests/fixer_test262.rs b/ecmascript/transforms/tests/fixer_test262.rs index c2e059254ad..79524bce6e9 100644 --- a/ecmascript/transforms/tests/fixer_test262.rs +++ b/ecmascript/transforms/tests/fixer_test262.rs @@ -109,10 +109,6 @@ fn add_test( }); } -struct MyHandlers; - -impl swc_ecma_codegen::Handlers for MyHandlers {} - fn identity_tests(tests: &mut Vec) -> Result<(), io::Error> { let dir = Path::new(env!("CARGO_MANIFEST_DIR")) .parent() @@ -166,8 +162,6 @@ fn identity_tests(tests: &mut Vec) -> Result<(), io::Error> { let mut wr = Buf(Arc::new(RwLock::new(vec![]))); let mut wr2 = Buf(Arc::new(RwLock::new(vec![]))); - let handlers = Box::new(MyHandlers); - let handlers2 = Box::new(MyHandlers); let mut parser: Parser> = Parser::new(Syntax::default(), (&*src).into(), None); @@ -182,7 +176,6 @@ fn identity_tests(tests: &mut Vec) -> Result<(), io::Error> { None, )), comments: None, - handlers, }; let mut expected_emitter = Emitter { cfg: swc_ecma_codegen::Config { minify: false }, @@ -191,7 +184,6 @@ fn identity_tests(tests: &mut Vec) -> Result<(), io::Error> { cm, "\n", &mut wr2, None, )), comments: None, - handlers: handlers2, }; // Parse source diff --git a/ecmascript/transforms/tests/typescript_strip_correctness.rs b/ecmascript/transforms/tests/typescript_strip_correctness.rs index f5f2924471c..4b15654f6fb 100644 --- a/ecmascript/transforms/tests/typescript_strip_correctness.rs +++ b/ecmascript/transforms/tests/typescript_strip_correctness.rs @@ -36,10 +36,6 @@ fn add_test( }); } -struct MyHandlers; - -impl swc_ecma_codegen::Handlers for MyHandlers {} - fn correctness_tests(tests: &mut Vec) -> Result<(), io::Error> { let dir = Path::new(env!("CARGO_MANIFEST_DIR")) .parent() @@ -161,7 +157,6 @@ fn correctness_tests(tests: &mut Vec) -> Result<(), io::Error> { let mut wr = Buf(Arc::new(RwLock::new(vec![]))); - let handlers = Box::new(MyHandlers); { let mut emitter = Emitter { cfg: swc_ecma_codegen::Config { minify: false }, @@ -173,7 +168,6 @@ fn correctness_tests(tests: &mut Vec) -> Result<(), io::Error> { None, )), comments: None, - handlers, }; // Parse source diff --git a/src/lib.rs b/src/lib.rs index 0bb9953e6c5..3f6a6873ec1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -200,7 +200,6 @@ impl Compiler { let src = { let mut buf = vec![]; { - let handlers = Box::new(MyHandlers); let mut emitter = Emitter { cfg: swc_ecma_codegen::Config { minify }, comments: if minify { None } else { Some(&self.comments) }, @@ -215,7 +214,6 @@ impl Compiler { None }, )), - handlers, }; node.emit_with(&mut emitter) @@ -453,10 +451,6 @@ impl Compiler { } } -struct MyHandlers; - -impl swc_ecma_codegen::Handlers for MyHandlers {} - fn load_swcrc(path: &Path) -> Result { fn convert_json_err(e: serde_json::Error) -> Error { let line = e.line();