Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ examples/*/package-lock.json
examples/*/.next
dist/
*.tgz
.idea/
18 changes: 18 additions & 0 deletions __tests__/serialize.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,24 @@ hello: world
expect(result).toMatchInlineSnapshot(`"<h1>Hello world</h1>"`)
})

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} <Component />`
)

expect(result).toMatchInlineSnapshot(`"<h1>1 foo true from component</h1>"`)
})

test('prints helpful message from compile error', async () => {
try {
await serialize(`This is very bad <GITHUB_USER>`)
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/remove-imports-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
}