Skip to content
Merged
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
7 changes: 5 additions & 2 deletions packages/mdx/mdx-hast-to-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ MDXContent.isMDXComponent = true`
// Check JSX nodes against imports
const babelPluginExtractImportNamesInstance = new BabelPluginExtractImportNames()
transformSync(importStatements, {
filename: options.file.path,
configFile: false,
babelrc: false,
plugins: [
Expand All @@ -135,6 +136,7 @@ MDXContent.isMDXComponent = true`
const babelPluginApplyMdxPropToExportsInstance = new BabelPluginApplyMdxProp()

const fnPostMdxTypeProp = transformSync(fn, {
filename: options.file.path,
configFile: false,
babelrc: false,
plugins: [
Expand All @@ -145,6 +147,7 @@ MDXContent.isMDXComponent = true`
}).code

const exportStatementsPostMdxTypeProps = transformSync(exportStatements, {
filename: options.file.path,
configFile: false,
babelrc: false,
plugins: [
Expand Down Expand Up @@ -250,8 +253,8 @@ export default ${fnPostMdxTypeProp}`
}

function compile(options = {}) {
this.Compiler = function (tree) {
return toJSX(tree, {}, options)
this.Compiler = function (tree, file) {
return toJSX(tree, {}, { file, ...options })
}
}

Expand Down
16 changes: 16 additions & 0 deletions packages/mdx/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,19 @@ test('Should handle layout props', () => {
MDXContent.isMDXComponent = true;"
`)
})

it('Should include file name in Babel error', async () => {
expect(async () => {
await mdx(`<br>`, {filepath: '/path/to/file.mdx'})
}).rejects.toThrowErrorMatchingInlineSnapshot(`
"/path/to/file.mdx: Unterminated JSX contents (8:16)

  6 |  components={components}>
  7 | <br>
> 8 |  </MDXLayout>
  |  ^
  9 |  )
  10 | };
  11 | MDXContent.isMDXComponent = true"
`)
})