remove codegen::Handlers (#974)

This commit is contained in:
Bartek Iwańczuk 2020-08-17 14:09:12 +02:00 committed by GitHub
parent 28398280f7
commit 7a13aabeb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 0 additions and 87 deletions

View File

@ -46,17 +46,11 @@ fn main() {
cm: cm.clone(), cm: cm.clone(),
comments: None, comments: None,
wr: Box::new(JsWriter::new(cm.clone(), "\n", wr.lock(), None)), wr: Box::new(JsWriter::new(cm.clone(), "\n", wr.lock(), None)),
handlers: Box::new(Handllers),
}; };
emitter.emit_module(&bundle.module).unwrap(); emitter.emit_module(&bundle.module).unwrap();
} }
/// I should remove this...
struct Handllers;
impl swc_ecma_codegen::Handlers for Handllers {}
struct PathLoader { struct PathLoader {
cm: Lrc<SourceMap>, cm: Lrc<SourceMap>,
} }

View File

@ -18,17 +18,12 @@ pub(crate) fn print_hygiene(event: &str, cm: &Lrc<SourceMap>, t: &Module) {
cm: cm.clone(), cm: cm.clone(),
comments: None, comments: None,
wr: Box::new(JsWriter::new(cm.clone(), "\n", &mut w, None)), wr: Box::new(JsWriter::new(cm.clone(), "\n", &mut w, None)),
handlers: Box::new(Handlers),
} }
.emit_module(&module) .emit_module(&module)
.unwrap(); .unwrap();
writeln!(w, "==================== @ ====================").unwrap(); writeln!(w, "==================== @ ====================").unwrap();
} }
impl swc_ecma_codegen::Handlers for Handlers {}
struct Handlers;
struct HygieneVisualizer; struct HygieneVisualizer;
impl Fold for HygieneVisualizer { impl Fold for HygieneVisualizer {

View File

@ -15,7 +15,6 @@ pub(crate) fn calc_hash(cm: Lrc<SourceMap>, m: &Module) -> Result<String, Error>
cm, cm,
comments: None, comments: None,
wr: Box::new(&mut buf) as Box<dyn WriteJs>, wr: Box::new(&mut buf) as Box<dyn WriteJs>,
handlers: Box::new(Handlers),
}; };
emitter emitter
@ -28,9 +27,6 @@ pub(crate) fn calc_hash(cm: Lrc<SourceMap>, m: &Module) -> Result<String, Error>
Ok(radix_fmt::radix(result, 36).to_string()) Ok(radix_fmt::radix(result, 36).to_string())
} }
impl swc_ecma_codegen::Handlers for Handlers {}
struct Handlers;
struct Hasher { struct Hasher {
digest: Digest, digest: Digest,
} }

View File

@ -102,7 +102,6 @@ fn bench_emitter(b: &mut Bencher, s: &str) {
b.iter(|| { b.iter(|| {
let mut buf = vec![]; let mut buf = vec![];
{ {
let handlers = Box::new(MyHandlers);
let mut emitter = Emitter { let mut emitter = Emitter {
cfg: swc_ecma_codegen::Config { cfg: swc_ecma_codegen::Config {
..Default::default() ..Default::default()
@ -115,7 +114,6 @@ fn bench_emitter(b: &mut Bencher, s: &str) {
&mut buf, &mut buf,
Some(&mut src_map_buf), Some(&mut src_map_buf),
)), )),
handlers,
}; };
let _ = emitter.emit_module(&module); let _ = emitter.emit_module(&module);
@ -137,7 +135,3 @@ fn emit_colors(b: &mut Bencher) {
fn emit_large(b: &mut Bencher) { fn emit_large(b: &mut Bencher) {
bench_emitter(b, LARGE_PARTIAL_JS) bench_emitter(b, LARGE_PARTIAL_JS)
} }
struct MyHandlers;
impl swc_ecma_codegen::Handlers for MyHandlers {}

View File

@ -101,7 +101,6 @@ fn bench_emitter(b: &mut Bencher, s: &str) {
let mut buf = vec![]; let mut buf = vec![];
{ {
let handlers = Box::new(MyHandlers);
let mut emitter = Emitter { let mut emitter = Emitter {
cfg: swc_ecma_codegen::Config { cfg: swc_ecma_codegen::Config {
..Default::default() ..Default::default()
@ -114,7 +113,6 @@ fn bench_emitter(b: &mut Bencher, s: &str) {
&mut buf, &mut buf,
Some(&mut src_map_buf), Some(&mut src_map_buf),
)), )),
handlers,
}; };
let _ = emitter.emit_module(&module); let _ = emitter.emit_module(&module);
@ -136,7 +134,3 @@ fn colors(b: &mut Bencher) {
fn large_partial(b: &mut Bencher) { fn large_partial(b: &mut Bencher) {
bench_emitter(b, LARGE_PARTIAL_JS) bench_emitter(b, LARGE_PARTIAL_JS)
} }
struct MyHandlers;
impl swc_ecma_codegen::Handlers for MyHandlers {}

View File

@ -32,11 +32,6 @@ pub mod util;
pub type Result = io::Result<()>; 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 { pub trait Node: Spanned {
fn emit_with(&self, e: &mut Emitter<'_>) -> Result; fn emit_with(&self, e: &mut Emitter<'_>) -> Result;
} }
@ -58,7 +53,6 @@ pub struct Emitter<'a> {
pub cm: Lrc<SourceMap>, pub cm: Lrc<SourceMap>,
pub comments: Option<&'a dyn Comments>, pub comments: Option<&'a dyn Comments>,
pub wr: Box<(dyn 'a + WriteJs)>, pub wr: Box<(dyn 'a + WriteJs)>,
pub handlers: Box<(dyn 'a + Handlers)>,
} }
impl<'a> Emitter<'a> { impl<'a> Emitter<'a> {
@ -1431,10 +1425,6 @@ impl<'a> Emitter<'a> {
let is_empty = children.is_none() || start > children.unwrap().len() || count == 0; let is_empty = children.is_none() || start > children.unwrap().len() || count == 0;
if is_empty && format.contains(ListFormat::OptionalIfEmpty) { if is_empty && format.contains(ListFormat::OptionalIfEmpty) {
// self.handlers.onBeforeEmitNodeArray(children)
// self.handlers.onAfterEmitNodeArray(children);
return Ok(()); return Ok(());
} }

View File

@ -9,9 +9,6 @@ use std::{
use swc_common::{comments::SingleThreadedComments, FileName, SourceMap}; use swc_common::{comments::SingleThreadedComments, FileName, SourceMap};
use swc_ecma_parser; use swc_ecma_parser;
struct Noop;
impl Handlers for Noop {}
struct Builder { struct Builder {
cfg: Config, cfg: Config,
cm: Lrc<SourceMap>, cm: Lrc<SourceMap>,
@ -28,7 +25,6 @@ impl Builder {
cm: self.cm.clone(), cm: self.cm.clone(),
wr: Box::new(text_writer::JsWriter::new(self.cm.clone(), "\n", s, None)), wr: Box::new(text_writer::JsWriter::new(self.cm.clone(), "\n", s, None)),
comments: Some(&self.comments), comments: Some(&self.comments),
handlers: Box::new(Noop),
}; };
let ret = op(&mut e); let ret = op(&mut e);

View File

@ -89,10 +89,6 @@ fn add_test<F: FnOnce() + Send + 'static>(
}); });
} }
struct MyHandlers;
impl swc_ecma_codegen::Handlers for MyHandlers {}
fn error_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> { fn error_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> {
let ref_dir = Path::new(env!("CARGO_MANIFEST_DIR")) let ref_dir = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests") .join("tests")
@ -148,7 +144,6 @@ fn error_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> {
); );
let comments = SingleThreadedComments::default(); let comments = SingleThreadedComments::default();
let handlers = Box::new(MyHandlers);
let lexer = Lexer::new( let lexer = Lexer::new(
Syntax::default(), Syntax::default(),
Default::default(), Default::default(),
@ -165,7 +160,6 @@ fn error_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> {
cm, "\n", &mut wr, None, cm, "\n", &mut wr, None,
)), )),
comments: Some(&comments), comments: Some(&comments),
handlers,
}; };
// Parse source // Parse source

View File

@ -203,7 +203,6 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> {
let print = |m: &Module| { let print = |m: &Module| {
let mut buf = vec![]; let mut buf = vec![];
{ {
let handlers = Box::new(MyHandlers);
let mut emitter = Emitter { let mut emitter = Emitter {
cfg: swc_ecma_codegen::Config { minify: false }, cfg: swc_ecma_codegen::Config { minify: false },
comments: None, comments: None,
@ -214,7 +213,6 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> {
&mut buf, &mut buf,
None, None,
)), )),
handlers,
}; };
emitter.emit_module(m).expect("failed to emit module"); emitter.emit_module(m).expect("failed to emit module");
@ -344,7 +342,3 @@ fn fixtures() {
let args: Vec<_> = env::args().collect(); let args: Vec<_> = env::args().collect();
test_main(&args, tests, Some(test::Options::new())); test_main(&args, tests, Some(test::Options::new()));
} }
struct MyHandlers;
impl swc_ecma_codegen::Handlers for MyHandlers {}

View File

@ -17,10 +17,6 @@ use swc_ecma_utils::DropSpan;
use swc_ecma_visit::{Fold, FoldWith}; use swc_ecma_visit::{Fold, FoldWith};
use tempfile::tempdir_in; use tempfile::tempdir_in;
struct MyHandlers;
impl swc_ecma_codegen::Handlers for MyHandlers {}
pub(crate) struct Tester<'a> { pub(crate) struct Tester<'a> {
pub cm: Lrc<SourceMap>, pub cm: Lrc<SourceMap>,
pub handler: &'a Handler, pub handler: &'a Handler,
@ -128,8 +124,6 @@ impl<'a> Tester<'a> {
} }
pub fn print(&mut self, module: &Module) -> String { pub fn print(&mut self, module: &Module) -> String {
let handlers = Box::new(MyHandlers);
let mut wr = Buf(Arc::new(RwLock::new(vec![]))); let mut wr = Buf(Arc::new(RwLock::new(vec![])));
{ {
let mut emitter = Emitter { let mut emitter = Emitter {
@ -142,7 +136,6 @@ impl<'a> Tester<'a> {
None, None,
)), )),
comments: None, comments: None,
handlers,
}; };
// println!("Emitting: {:?}", module); // println!("Emitting: {:?}", module);

View File

@ -46,10 +46,6 @@ macro_rules! validate {
}}; }};
} }
struct MyHandlers;
impl swc_ecma_codegen::Handlers for MyHandlers {}
pub struct Tester<'a> { pub struct Tester<'a> {
pub cm: Lrc<SourceMap>, pub cm: Lrc<SourceMap>,
pub handler: &'a Handler, pub handler: &'a Handler,
@ -142,8 +138,6 @@ impl<'a> Tester<'a> {
} }
pub fn print(&mut self, module: &Module) -> String { pub fn print(&mut self, module: &Module) -> String {
let handlers = Box::new(MyHandlers);
let mut wr = Buf(Arc::new(RwLock::new(vec![]))); let mut wr = Buf(Arc::new(RwLock::new(vec![])));
{ {
let mut emitter = Emitter { let mut emitter = Emitter {
@ -156,7 +150,6 @@ impl<'a> Tester<'a> {
None, None,
)), )),
comments: None, comments: None,
handlers,
}; };
// println!("Emitting: {:?}", module); // println!("Emitting: {:?}", module);

View File

@ -109,10 +109,6 @@ fn add_test<F: FnOnce() + Send + 'static>(
}); });
} }
struct MyHandlers;
impl swc_ecma_codegen::Handlers for MyHandlers {}
fn identity_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> { fn identity_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> {
let dir = Path::new(env!("CARGO_MANIFEST_DIR")) let dir = Path::new(env!("CARGO_MANIFEST_DIR"))
.parent() .parent()
@ -166,8 +162,6 @@ fn identity_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> {
let mut wr = Buf(Arc::new(RwLock::new(vec![]))); let mut wr = Buf(Arc::new(RwLock::new(vec![])));
let mut wr2 = 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<Lexer<StringInput>> = let mut parser: Parser<Lexer<StringInput>> =
Parser::new(Syntax::default(), (&*src).into(), None); Parser::new(Syntax::default(), (&*src).into(), None);
@ -182,7 +176,6 @@ fn identity_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> {
None, None,
)), )),
comments: None, comments: None,
handlers,
}; };
let mut expected_emitter = Emitter { let mut expected_emitter = Emitter {
cfg: swc_ecma_codegen::Config { minify: false }, cfg: swc_ecma_codegen::Config { minify: false },
@ -191,7 +184,6 @@ fn identity_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> {
cm, "\n", &mut wr2, None, cm, "\n", &mut wr2, None,
)), )),
comments: None, comments: None,
handlers: handlers2,
}; };
// Parse source // Parse source

View File

@ -36,10 +36,6 @@ fn add_test<F: FnOnce() + Send + 'static>(
}); });
} }
struct MyHandlers;
impl swc_ecma_codegen::Handlers for MyHandlers {}
fn correctness_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> { fn correctness_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> {
let dir = Path::new(env!("CARGO_MANIFEST_DIR")) let dir = Path::new(env!("CARGO_MANIFEST_DIR"))
.parent() .parent()
@ -161,7 +157,6 @@ fn correctness_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> {
let mut wr = Buf(Arc::new(RwLock::new(vec![]))); let mut wr = Buf(Arc::new(RwLock::new(vec![])));
let handlers = Box::new(MyHandlers);
{ {
let mut emitter = Emitter { let mut emitter = Emitter {
cfg: swc_ecma_codegen::Config { minify: false }, cfg: swc_ecma_codegen::Config { minify: false },
@ -173,7 +168,6 @@ fn correctness_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> {
None, None,
)), )),
comments: None, comments: None,
handlers,
}; };
// Parse source // Parse source

View File

@ -200,7 +200,6 @@ impl Compiler {
let src = { let src = {
let mut buf = vec![]; let mut buf = vec![];
{ {
let handlers = Box::new(MyHandlers);
let mut emitter = Emitter { let mut emitter = Emitter {
cfg: swc_ecma_codegen::Config { minify }, cfg: swc_ecma_codegen::Config { minify },
comments: if minify { None } else { Some(&self.comments) }, comments: if minify { None } else { Some(&self.comments) },
@ -215,7 +214,6 @@ impl Compiler {
None None
}, },
)), )),
handlers,
}; };
node.emit_with(&mut emitter) 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<Rc, Error> { fn load_swcrc(path: &Path) -> Result<Rc, Error> {
fn convert_json_err(e: serde_json::Error) -> Error { fn convert_json_err(e: serde_json::Error) -> Error {
let line = e.line(); let line = e.line();