diff --git a/.gitignore b/.gitignore index 061e07f..dcb4547 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ examples/*/package-lock.json examples/*/.next dist/ *.tgz +.idea/ diff --git a/__tests__/serialize.test.tsx b/__tests__/serialize.test.tsx index 6364ac0..c602ead 100644 --- a/__tests__/serialize.test.tsx +++ b/__tests__/serialize.test.tsx @@ -177,6 +177,24 @@ hello: world expect(result).toMatchInlineSnapshot(`"

Hello world

"`) }) + test('should works with `export` statement', async () => { + const result = await renderStatic( + `export const num = 1 + +export let str = 'foo' + +export var bool = true && 'true' + +export function Component() { + return 'from component' +} + +# {num} {str} {bool} ` + ) + + expect(result).toMatchInlineSnapshot(`"

1 foo true from component

"`) + }) + test('prints helpful message from compile error', async () => { try { await serialize(`This is very bad `) diff --git a/src/plugins/remove-imports-exports.ts b/src/plugins/remove-imports-exports.ts index 2c2010e..61ab4bf 100644 --- a/src/plugins/remove-imports-exports.ts +++ b/src/plugins/remove-imports-exports.ts @@ -10,5 +10,11 @@ import { Plugin } from 'unified' * remark plugin which removes all import and export statements */ export function removeImportsExportsPlugin(): Plugin { - return (tree) => remove(tree, 'mdxjsEsm') + return (ast) => + remove( + ast, + (node) => + node.type === 'mdxjsEsm' && + node.data.estree.body[0].type === 'ImportDeclaration' + ) }