aboutsummaryrefslogtreecommitdiffstats
path: root/tests/xxx_document.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-10-11 09:54:56 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-10-11 09:55:16 +0200
commita4b56e7b971fa81c56a59b465f90c8016f01320d (patch)
tree7002a44087e57c8158a51dd30b6eb89eb260af2b /tests/xxx_document.rs
parent1fd94f512834aa7bd70f22a60229ce01edfc754e (diff)
downloadmarkdown-rs-a4b56e7b971fa81c56a59b465f90c8016f01320d.tar.gz
markdown-rs-a4b56e7b971fa81c56a59b465f90c8016f01320d.tar.bz2
markdown-rs-a4b56e7b971fa81c56a59b465f90c8016f01320d.zip
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`
Diffstat (limited to 'tests/xxx_document.rs')
-rw-r--r--tests/xxx_document.rs16
1 files changed, 12 insertions, 4 deletions
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<String, String> {
+ let location = Location::new(value.as_bytes());
let mdast = micromark_to_mdast(
value,
&ParseOptions {
@@ -23,7 +24,8 @@ fn from_markdown(value: &str) -> Result<String, String> {
},
)?;
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(())
}