Fix casing of babel option in getting-started.server.mdx#2148
Fix casing of babel option in getting-started.server.mdx#2148wooorm merged 1 commit intomdx-js:mainfrom
getting-started.server.mdx#2148Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportBase: 100.00% // Head: 100.00% // No change to project coverage 👍
Additional details and impacted files@@ Coverage Diff @@
## main #2148 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 2044 2044
=========================================
Hits 2044 2044 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
|
Can you confirm that this gave a warning, or didn’t work at all? I remember running into babel using two casings of I believe this word. I think I raised an issue with them and that it’s been solved. |
|
Yeah I just wrote a transformer for jest and needed to change the case to get it working. No warning just a silent failure because the value was undefined. // import { compile, compileSync } from '@mdx-js/mdx'
import babel from '@babel/core'
import path from 'path'
import parser from '@babel/parser'
import estreeToBabel from 'estree-to-babel'
import { compileSync } from '@mdx-js/mdx'
export function babelPluginSyntaxMdx() {
// Tell Babel to use a different parser.
return { parserOverride: babelParserWithMdx }
}
// A Babel parser that parses MDX files with `@mdx-js/mdx` and passes any
// other things through to the normal Babel parser.
function babelParserWithMdx(value, options) {
console.log(
options
// /\.mdx?$/.test(path.extname(options.sourceFilename))
)
if (
options.sourceFileName &&
/\.mdx?$/.test(path.extname(options.sourceFileName))
) {
// Babel does not support async parsers, unfortunately.
return compileSync(
{ value, path: options.sourceFileName },
// Tell `@mdx-js/mdx` to return a Babel tree instead of serialized JS.
{
recmaPlugins: [recmaBabel] /* jsxImportSource: …, otherOptions… */,
// outputFormat: 'function-body',
}
).result
}
return parser.parse(value, options)
}
// A “recma” plugin is a unified plugin that runs on the estree (used by
// `@mdx-js/mdx` and much of the JS ecosystem but not Babel).
// This plugin defines `'estree-to-babel'` as the compiler, which means that
// the resulting Babel tree is given back by `compileSync`.
function recmaBabel() {
Object.assign(this, { Compiler: estreeToBabel })
}
export default {
process(sourceText, sourcePath, options) {
const babelRes = babel.transform(sourceText, {
filename: sourcePath,
presets: ['@babel/preset-env'],
plugins: [babelPluginSyntaxMdx],
})
console.log(babelRes.code)
return babelRes
},
}I should point out I'm using jest with esm modules enabled, not sure if that would cause any difference. |
getting-started.server.mdx
|
Cool, thanks! |
Fixes a small typo in the babel config where the
sourceFilenameis actuallysourceFileNamein the latest babel version.