From a4b56e7b971fa81c56a59b465f90c8016f01320d Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 11 Oct 2022 09:54:56 +0200 Subject: Add support for proper positional info in swc tree * Fix some positional info in SWC error messages * Add positional info in `to_document` on duplicate layouts * Add support for `path` on `Program` (`to_swc`, `to_document`, `jsx_rewrite`), for the path of a file on disk * Add support for `development` to `jsx-rewrite`, which when defined will embed info on where tags were written into the runtime code when they are not passed * Refactor to move some utilities to `micromark_swc_utils.rs`, `swc_utils.rs` --- tests/xxx_document.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'tests/xxx_document.rs') diff --git a/tests/xxx_document.rs b/tests/xxx_document.rs index d5c8eef..7e43b1c 100644 --- a/tests/xxx_document.rs +++ b/tests/xxx_document.rs @@ -3,7 +3,7 @@ extern crate swc_common; extern crate swc_ecma_ast; extern crate swc_ecma_codegen; mod test_utils; -use micromark::{micromark_to_mdast, Constructs, ParseOptions}; +use micromark::{micromark_to_mdast, Constructs, Location, ParseOptions}; use pretty_assertions::assert_eq; use test_utils::{ swc::{parse_esm, parse_expression, serialize}, @@ -13,6 +13,7 @@ use test_utils::{ }; fn from_markdown(value: &str) -> Result { + let location = Location::new(value.as_bytes()); let mdast = micromark_to_mdast( value, &ParseOptions { @@ -23,7 +24,8 @@ fn from_markdown(value: &str) -> Result { }, )?; let hast = to_hast(&mdast); - let program = to_document(to_swc(&hast)?, &DocumentOptions::default())?; + let swc_tree = to_swc(&hast, None, Some(&location))?; + let program = to_document(swc_tree, &DocumentOptions::default(), Some(&location))?; let value = serialize(&program.module); Ok(value) } @@ -156,8 +158,6 @@ export default MDXContent; "should support a named export w/o source, w/o a specifiers", ); - // ........... - assert_eq!( from_markdown("export {a, b as default} from 'c'")?, "export { a } from 'c'; @@ -201,5 +201,13 @@ export default MDXContent; "should support a named export w/ source, w/o a specifiers", ); + assert_eq!( + from_markdown("export default a = 1\n\nexport default b = 2") + .err() + .unwrap(), + "3:1: Cannot specify multiple layouts (previous: 1:1-1:21 (0-20))", + "should crash on a comment spread" + ); + Ok(()) } -- cgit