aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_utils/to_document.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-10-06 17:35:34 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-10-06 17:35:34 +0200
commit2d7b34983699a0d140fb322b494f0572bf157fe1 (patch)
treea03cc1ea412b79757793a5dce6f39e4d7a32cb1d /tests/test_utils/to_document.rs
parentcd5bb2d16c6b28332b0b6077b27b2b90a8051896 (diff)
downloadmarkdown-rs-2d7b34983699a0d140fb322b494f0572bf157fe1.tar.gz
markdown-rs-2d7b34983699a0d140fb322b494f0572bf157fe1.tar.bz2
markdown-rs-2d7b34983699a0d140fb322b494f0572bf157fe1.zip
Refactor to improve `to_hast` internals
Diffstat (limited to '')
-rw-r--r--tests/test_utils/to_document.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/tests/test_utils/to_document.rs b/tests/test_utils/to_document.rs
index 91fc134..ded028a 100644
--- a/tests/test_utils/to_document.rs
+++ b/tests/test_utils/to_document.rs
@@ -181,16 +181,20 @@ pub fn to_document(mut program: Program, options: &Options) -> Result<Program, S
// To do: set positional info.
layout = true;
- replacements.push(create_layout_decl(match decl.decl {
- swc_ecma_ast::DefaultDecl::Class(cls) => swc_ecma_ast::Expr::Class(cls),
- swc_ecma_ast::DefaultDecl::Fn(func) => swc_ecma_ast::Expr::Fn(func),
+ match decl.decl {
+ swc_ecma_ast::DefaultDecl::Class(cls) => {
+ replacements.push(create_layout_decl(swc_ecma_ast::Expr::Class(cls)))
+ }
+ swc_ecma_ast::DefaultDecl::Fn(func) => {
+ replacements.push(create_layout_decl(swc_ecma_ast::Expr::Fn(func)))
+ }
swc_ecma_ast::DefaultDecl::TsInterfaceDecl(_) => {
- // To do: improved error? Not sure what a real example of this is?
- unreachable!(
- "Cannot use TypeScript interface declarations as default export in MDX"
+ return Err(
+ "Cannot use TypeScript interface declarations as default export in MDX files. The default export is reserved for a layout, which must be a component"
+ .into(),
)
}
- }));
+ }
}
swc_ecma_ast::ModuleItem::ModuleDecl(swc_ecma_ast::ModuleDecl::ExportDefaultExpr(
expr,