Unverified Commit 47e6b180 authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

fix(next-swc): coerce mdxrs default options (#54068)



### What?

wasm-bindgen's serde deserialization is more strict to not automatically coerce non-optionable default values for the mdx configurations. Since these are required options anyway, consolidate to construct default options.


Closes WEB-1384
parent 36602e7f
......@@ -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))
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment