Skip to content

Commit

Permalink
feat(mdx-loader): upgrade to MDX v3 + (#9451)
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Oct 26, 2023
1 parent 8d19054 commit 7e456ec
Show file tree
Hide file tree
Showing 49 changed files with 42,734 additions and 35,852 deletions.
20 changes: 12 additions & 8 deletions jest.config.mjs
Expand Up @@ -86,16 +86,20 @@ export default {
// MDX packages are ESM-only and it is a pain to use in Jest
// So we use them in Jest tests as CJS versions
// see https://mdxjs.com/docs/troubleshooting-mdx/#problems-integrating-mdx
'^unified$': '<rootDir>/jest/vendor/unified@10.1.2.js',
'^@mdx-js/mdx$': '<rootDir>/jest/vendor/@mdx-js__mdx@2.1.5.js',
'^remark$': '<rootDir>/jest/vendor/remark@14.0.2.js',
'^remark-mdx$': '<rootDir>/jest/vendor/remark-mdx@2.1.5.js',
'^remark-directive$': '<rootDir>/jest/vendor/remark-directive@2.0.1.js',
'^remark-gfm$': '<rootDir>/jest/vendor/remark-gfm@3.0.1.js',
'^@mdx-js/mdx$': '<rootDir>/jest/vendor/@mdx-js__mdx@3.0.0.js',
'^remark$': '<rootDir>/jest/vendor/remark@15.0.1.js',
'^remark-rehype$': '<rootDir>/jest/vendor/remark-rehype@11.0.0.js',
'^remark-mdx$': '<rootDir>/jest/vendor/remark-mdx@3.0.0.js',
'^remark-directive$': '<rootDir>/jest/vendor/remark-directive@3.0.0.js',
'^remark-gfm$': '<rootDir>/jest/vendor/remark-gfm@4.0.0.js',
'^estree-util-value-to-estree$':
'<rootDir>/jest/vendor/estree-util-value-to-estree@2.1.0.js',
'<rootDir>/jest/vendor/estree-util-value-to-estree@3.0.1.js',
'^mdast-util-to-string$':
'<rootDir>/jest/vendor/mdast-util-to-string@3.1.0.js',
'<rootDir>/jest/vendor/mdast-util-to-string@4.0.0.js',
'^unist-util-visit$': '<rootDir>/jest/vendor/unist-util-visit@5.0.0.js',
'^unist-util-remove-position$':
'<rootDir>/jest/vendor/unist-util-remove-position@5.0.0.js',
'^rehype-stringify$': '<rootDir>/jest/vendor/rehype-stringify@10.0.0.js',
},
snapshotSerializers: [
'<rootDir>/jest/snapshotPathNormalizer.ts',
Expand Down
31,033 changes: 17,035 additions & 13,998 deletions jest/vendor/@mdx-js__mdx@2.1.5.js → jest/vendor/@mdx-js__mdx@3.0.0.js

Large diffs are not rendered by default.

Expand Up @@ -23,7 +23,7 @@ __export(estree_util_value_to_estree_exports, {
});
module.exports = __toCommonJS(estree_util_value_to_estree_exports);

// node_modules/estree-util-value-to-estree/node_modules/is-plain-obj/index.js
// node_modules/is-plain-obj/index.js
function isPlainObject(value) {
if (typeof value !== "object" || value === null) {
return false;
Expand All @@ -49,7 +49,7 @@ function valueToEstree(value, options = {}) {
};
}
if (typeof value === "number") {
return value >= 0 ? { type: "Literal", value } : {
return value >= 0 && !Object.is(value, -0) ? { type: "Literal", value } : {
type: "UnaryExpression",
operator: "-",
prefix: true,
Expand Down Expand Up @@ -130,17 +130,29 @@ function valueToEstree(value, options = {}) {
};
}
if (options.instanceAsObject || isPlainObject(value)) {
return {
type: "ObjectExpression",
properties: Reflect.ownKeys(value).map((key) => ({
const properties = Reflect.ownKeys(value).map((key) => ({
type: "Property",
method: false,
shorthand: false,
computed: typeof key !== "string",
kind: "init",
key: valueToEstree(key, options),
value: valueToEstree(value[key], options)
}));
if (Object.getPrototypeOf(value) == null) {
properties.unshift({
type: "Property",
method: false,
shorthand: false,
computed: typeof key !== "string",
computed: false,
kind: "init",
key: valueToEstree(key, options),
value: valueToEstree(value[key], options)
}))
key: { type: "Identifier", name: "__proto__" },
value: { type: "Literal", value: null }
});
}
return {
type: "ObjectExpression",
properties
};
}
throw new TypeError(`Unsupported value: ${String(value)}`);
Expand Down
Expand Up @@ -22,21 +22,43 @@ __export(mdast_util_to_string_exports, {
toString: () => toString
});
module.exports = __toCommonJS(mdast_util_to_string_exports);
function toString(node, options) {
var { includeImageAlt = true } = options || {};
return one(node, includeImageAlt);

// node_modules/mdast-util-to-string/lib/index.js
var emptyOptions = {};
function toString(value, options) {
const settings = options || emptyOptions;
const includeImageAlt = typeof settings.includeImageAlt === "boolean" ? settings.includeImageAlt : true;
const includeHtml = typeof settings.includeHtml === "boolean" ? settings.includeHtml : true;
return one(value, includeImageAlt, includeHtml);
}
function one(node, includeImageAlt) {
return node && typeof node === "object" && (node.value || (includeImageAlt ? node.alt : "") || "children" in node && all(node.children, includeImageAlt) || Array.isArray(node) && all(node, includeImageAlt)) || "";
function one(value, includeImageAlt, includeHtml) {
if (node(value)) {
if ("value" in value) {
return value.type === "html" && !includeHtml ? "" : value.value;
}
if (includeImageAlt && "alt" in value && value.alt) {
return value.alt;
}
if ("children" in value) {
return all(value.children, includeImageAlt, includeHtml);
}
}
if (Array.isArray(value)) {
return all(value, includeImageAlt, includeHtml);
}
return "";
}
function all(values, includeImageAlt) {
var result = [];
var index = -1;
function all(values, includeImageAlt, includeHtml) {
const result = [];
let index = -1;
while (++index < values.length) {
result[index] = one(values[index], includeImageAlt);
result[index] = one(values[index], includeImageAlt, includeHtml);
}
return result.join("");
}
function node(value) {
return Boolean(value && typeof value === "object");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
toString
Expand Down

0 comments on commit 7e456ec

Please sign in to comment.