Skip to content

Commit

Permalink
pass filename to babel transform if present (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
jescalan authored and johno committed Mar 27, 2019
1 parent a3f68d6 commit ab48d0a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/remark-mdx/extract-imports-and-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ const partitionString = (str, indices) =>
return str.slice(val, indices[i + 1])
})

module.exports = value => {
module.exports = (value, vfile) => {
const instance = new BabelPluginExtractImportsAndExports()

transformSync(value, {
plugins: [
'@babel/plugin-syntax-jsx',
'@babel/plugin-proposal-object-rest-spread',
instance.plugin
]
],
filename: vfile.path
})

const sortedNodes = instance.state.nodes.sort((a, b) => a.start - b.start)
Expand Down
2 changes: 1 addition & 1 deletion packages/remark-mdx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function tokenizeEsSyntax(eat, value) {
const subvalue = index !== -1 ? value.slice(0, index) : value

if (isExport(subvalue) || isImport(subvalue)) {
const nodes = extractImportsAndExports(subvalue)
const nodes = extractImportsAndExports(subvalue, this.file)
nodes.map(node => eat(node.value)(node))
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/remark-mdx/test/import-export.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const extract = require('../extract-imports-and-exports')
const fixtures = require('./fixtures/import-export')
const vfile = require('vfile')

fixtures.forEach(fixture => {
it(fixture.description, () => {
const result = extract(fixture.mdx)
const result = extract(fixture.mdx, vfile({ path: '/test', content: 'testing' }))

expect(result).toMatchSnapshot(fixture.result)
})
Expand Down

0 comments on commit ab48d0a

Please sign in to comment.