diff --git a/packages/next/src/build/swc/index.ts b/packages/next/src/build/swc/index.ts index 772ffe2005eb..8583300348d7 100644 --- a/packages/next/src/build/swc/index.ts +++ b/packages/next/src/build/swc/index.ts @@ -1135,9 +1135,9 @@ async function loadWasm(importPath = '', isCustomTurbopack: boolean) { }, mdx: { compile: (src: string, options: any) => - bindings.mdxCompile(src, options), + bindings.mdxCompile(src, getMdxOptions(options)), compileSync: (src: string, options: any) => - bindings.mdxCompileSync(src, options), + bindings.mdxCompileSync(src, getMdxOptions(options)), }, } return wasmBindings @@ -1409,9 +1409,9 @@ function loadNative(isCustomTurbopack = false, importPath?: string) { }, mdx: { compile: (src: string, options: any) => - bindings.mdxCompile(src, toBuffer(options ?? {})), + bindings.mdxCompile(src, toBuffer(getMdxOptions(options))), compileSync: (src: string, options: any) => - bindings.mdxCompileSync(src, toBuffer(options ?? {})), + bindings.mdxCompileSync(src, toBuffer(getMdxOptions(options))), }, } return nativeBindings @@ -1420,6 +1420,22 @@ function loadNative(isCustomTurbopack = false, importPath?: string) { throw attempts } +/// Build a mdx options object contains default values that +/// can be parsed with serde_wasm_bindgen. +function getMdxOptions(options: any = {}) { + const ret = { + ...options, + development: options.development ?? false, + jsx: options.jsx ?? false, + parse: options.parse ?? { + gfmStrikethroughSingleTilde: true, + mathTextSingleDollar: true, + }, + } + + return ret +} + function toBuffer(t: any) { return Buffer.from(JSON.stringify(t)) }