Skip to content

Commit ebb59b3

Browse files
committed
Support semicolons when exporting MDX layout
Fixes #277.
1 parent c1b0937 commit ebb59b3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/mdx/mdx-hast-to-jsx.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ function toJSX(node, parentNode = {}, options = {}) {
3737

3838
if (childNode.type === 'export') {
3939
if (childNode.default) {
40-
layout = childNode.value.replace(/^export\s+default\s+/, '')
40+
layout = childNode.value
41+
.replace(/^export\s+default\s+/, '')
42+
.replace(/;\s*$/, '')
4143
continue
4244
}
4345

packages/mdx/test/index.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ it('Should support multiline default export statement', async () => {
157157
expect(() => parse(result)).not.toThrow()
158158
})
159159

160+
it('Should support semicolons in default export statement', async () => {
161+
const result = await mdx(`export default Layout;`)
162+
expect(() => parse(result)).not.toThrow()
163+
})
164+
160165
it('Should throw when exporting default via named export', async () => {
161166
await expect(mdx(`export { default } from './Layout'`)).rejects.toThrow()
162167
await expect(mdx(`export { Layout as default }`)).rejects.toThrow()

0 commit comments

Comments
 (0)