From 9d90e35d51555d9f853f2eccfa771f47d71a6bc1 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 4 Oct 2022 10:29:30 +0200 Subject: Refactor to share a test utility --- tests/xxx_document.rs | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) (limited to 'tests/xxx_document.rs') diff --git a/tests/xxx_document.rs b/tests/xxx_document.rs index 2d89f16..dcbb56b 100644 --- a/tests/xxx_document.rs +++ b/tests/xxx_document.rs @@ -5,37 +5,13 @@ extern crate swc_ecma_codegen; mod test_utils; use micromark::{micromark_to_mdast, Constructs, Options}; use pretty_assertions::assert_eq; -use swc_common::{sync::Lrc, FilePathMapping, SourceMap}; -use swc_ecma_codegen::{text_writer::JsWriter, Emitter}; use test_utils::{ - swc::{parse_esm, parse_expression}, + swc::{parse_esm, parse_expression, serialize}, to_document::{to_document, Options as DocumentOptions}, to_hast::to_hast, - to_swc::{to_swc, Program}, + to_swc::to_swc, }; -// To do: share with `xxx_swc`. -fn serialize(program: &Program) -> String { - let mut buf = vec![]; - let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - // let comm = &program.comments as &dyn swc_common::comments::Comments; - { - let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - ..Default::default() - }, - cm: cm.clone(), - // To do: figure out how to pass them. - comments: None, - wr: JsWriter::new(cm, "\n", &mut buf, None), - }; - - emitter.emit_module(&program.module).unwrap(); - } - - String::from_utf8_lossy(&buf).to_string() -} - fn from_markdown(value: &str) -> Result { let mdast = micromark_to_mdast( value, @@ -48,7 +24,7 @@ fn from_markdown(value: &str) -> Result { )?; let hast = to_hast(&mdast); let program = to_document(to_swc(&hast)?, &DocumentOptions::default())?; - let value = serialize(&program); + let value = serialize(&program.module); Ok(value) } -- cgit