Skip to content

Commit 7e456ec

Browse files
authored
feat(mdx-loader): upgrade to MDX v3 + (#9451)
1 parent 8d19054 commit 7e456ec

File tree

49 files changed

+42734
-35852
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+42734
-35852
lines changed

jest.config.mjs

+12-8
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,20 @@ export default {
8686
// MDX packages are ESM-only and it is a pain to use in Jest
8787
// So we use them in Jest tests as CJS versions
8888
// see https://mdxjs.com/docs/troubleshooting-mdx/#problems-integrating-mdx
89-
'^unified$': '<rootDir>/jest/vendor/[email protected].js',
90-
'^@mdx-js/mdx$': '<rootDir>/jest/vendor/@[email protected].js',
91-
'^remark$': '<rootDir>/jest/vendor/remark@14.0.2.js',
92-
'^remark-mdx$': '<rootDir>/jest/vendor/remark-mdx@2.1.5.js',
93-
'^remark-directive$': '<rootDir>/jest/vendor/remark-directive@2.0.1.js',
94-
'^remark-gfm$': '<rootDir>/jest/vendor/remark-gfm@3.0.1.js',
89+
'^@mdx-js/mdx$': '<rootDir>/jest/vendor/@[email protected].js',
90+
'^remark$': '<rootDir>/jest/vendor/[email protected].js',
91+
'^remark-rehype$': '<rootDir>/jest/vendor/remark-rehype@11.0.0.js',
92+
'^remark-mdx$': '<rootDir>/jest/vendor/remark-mdx@3.0.0.js',
93+
'^remark-directive$': '<rootDir>/jest/vendor/remark-directive@3.0.0.js',
94+
'^remark-gfm$': '<rootDir>/jest/vendor/remark-gfm@4.0.0.js',
9595
'^estree-util-value-to-estree$':
96-
'<rootDir>/jest/vendor/estree-util-value-to-estree@2.1.0.js',
96+
'<rootDir>/jest/vendor/estree-util-value-to-estree@3.0.1.js',
9797
'^mdast-util-to-string$':
98-
'<rootDir>/jest/vendor/[email protected]',
98+
'<rootDir>/jest/vendor/[email protected]',
99+
'^unist-util-visit$': '<rootDir>/jest/vendor/[email protected]',
100+
'^unist-util-remove-position$':
101+
'<rootDir>/jest/vendor/[email protected]',
102+
'^rehype-stringify$': '<rootDir>/jest/vendor/[email protected]',
99103
},
100104
snapshotSerializers: [
101105
'<rootDir>/jest/snapshotPathNormalizer.ts',
+17,035-13,998
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ __export(estree_util_value_to_estree_exports, {
2323
});
2424
module.exports = __toCommonJS(estree_util_value_to_estree_exports);
2525

26-
// node_modules/estree-util-value-to-estree/node_modules/is-plain-obj/index.js
26+
// node_modules/is-plain-obj/index.js
2727
function isPlainObject(value) {
2828
if (typeof value !== "object" || value === null) {
2929
return false;
@@ -49,7 +49,7 @@ function valueToEstree(value, options = {}) {
4949
};
5050
}
5151
if (typeof value === "number") {
52-
return value >= 0 ? { type: "Literal", value } : {
52+
return value >= 0 && !Object.is(value, -0) ? { type: "Literal", value } : {
5353
type: "UnaryExpression",
5454
operator: "-",
5555
prefix: true,
@@ -130,17 +130,29 @@ function valueToEstree(value, options = {}) {
130130
};
131131
}
132132
if (options.instanceAsObject || isPlainObject(value)) {
133-
return {
134-
type: "ObjectExpression",
135-
properties: Reflect.ownKeys(value).map((key) => ({
133+
const properties = Reflect.ownKeys(value).map((key) => ({
134+
type: "Property",
135+
method: false,
136+
shorthand: false,
137+
computed: typeof key !== "string",
138+
kind: "init",
139+
key: valueToEstree(key, options),
140+
value: valueToEstree(value[key], options)
141+
}));
142+
if (Object.getPrototypeOf(value) == null) {
143+
properties.unshift({
136144
type: "Property",
137145
method: false,
138146
shorthand: false,
139-
computed: typeof key !== "string",
147+
computed: false,
140148
kind: "init",
141-
key: valueToEstree(key, options),
142-
value: valueToEstree(value[key], options)
143-
}))
149+
key: { type: "Identifier", name: "__proto__" },
150+
value: { type: "Literal", value: null }
151+
});
152+
}
153+
return {
154+
type: "ObjectExpression",
155+
properties
144156
};
145157
}
146158
throw new TypeError(`Unsupported value: ${String(value)}`);
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,43 @@ __export(mdast_util_to_string_exports, {
2222
toString: () => toString
2323
});
2424
module.exports = __toCommonJS(mdast_util_to_string_exports);
25-
function toString(node, options) {
26-
var { includeImageAlt = true } = options || {};
27-
return one(node, includeImageAlt);
25+
26+
// node_modules/mdast-util-to-string/lib/index.js
27+
var emptyOptions = {};
28+
function toString(value, options) {
29+
const settings = options || emptyOptions;
30+
const includeImageAlt = typeof settings.includeImageAlt === "boolean" ? settings.includeImageAlt : true;
31+
const includeHtml = typeof settings.includeHtml === "boolean" ? settings.includeHtml : true;
32+
return one(value, includeImageAlt, includeHtml);
2833
}
29-
function one(node, includeImageAlt) {
30-
return node && typeof node === "object" && (node.value || (includeImageAlt ? node.alt : "") || "children" in node && all(node.children, includeImageAlt) || Array.isArray(node) && all(node, includeImageAlt)) || "";
34+
function one(value, includeImageAlt, includeHtml) {
35+
if (node(value)) {
36+
if ("value" in value) {
37+
return value.type === "html" && !includeHtml ? "" : value.value;
38+
}
39+
if (includeImageAlt && "alt" in value && value.alt) {
40+
return value.alt;
41+
}
42+
if ("children" in value) {
43+
return all(value.children, includeImageAlt, includeHtml);
44+
}
45+
}
46+
if (Array.isArray(value)) {
47+
return all(value, includeImageAlt, includeHtml);
48+
}
49+
return "";
3150
}
32-
function all(values, includeImageAlt) {
33-
var result = [];
34-
var index = -1;
51+
function all(values, includeImageAlt, includeHtml) {
52+
const result = [];
53+
let index = -1;
3554
while (++index < values.length) {
36-
result[index] = one(values[index], includeImageAlt);
55+
result[index] = one(values[index], includeImageAlt, includeHtml);
3756
}
3857
return result.join("");
3958
}
59+
function node(value) {
60+
return Boolean(value && typeof value === "object");
61+
}
4062
// Annotate the CommonJS export names for ESM import in node:
4163
0 && (module.exports = {
4264
toString

0 commit comments

Comments
 (0)