Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Upgrade to remark-parse@10 #11867

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 45 additions & 19 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ if (INSTALL_PACKAGE || (isProduction && !TEST_STANDALONE)) {
}
process.env.PRETTIER_DIR = PRETTIER_DIR;

const babelJestTransform = [
"babel-jest",
{
presets: [
[
"@babel/env",
{
targets: { node: "current" },
exclude: [
"transform-async-to-generator",
"transform-classes",
"proposal-async-generator-functions",
"transform-regenerator",
],
},
],
],
},
];

const testPathIgnorePatterns = [];
let transform = {};
if (TEST_STANDALONE) {
Expand All @@ -25,33 +45,36 @@ if (TEST_STANDALONE) {
if (isProduction) {
// `esm` bundles need transform
transform = {
"(?:\\.mjs|codeSamples\\.js)$": [
"babel-jest",
{
presets: [
[
"@babel/env",
{
targets: { node: "current" },
exclude: [
"transform-async-to-generator",
"transform-classes",
"proposal-async-generator-functions",
"transform-regenerator",
],
},
],
],
},
],
"(?:\\.mjs|codeSamples\\.js)$": babelJestTransform,
};
} else {
transform = {
".js$": babelJestTransform,
};
// Only test bundles for production
testPathIgnorePatterns.push(
"<rootDir>/tests/integration/__tests__/bundle.js"
);
}

const esmPackagePatterns = [
"bail",
"ccount",
"character-entities",
"decode-named-character-reference",
"fault",
"is-plain-obj",
"longest-streak",
"markdown-table",
"mdast.*",
"micromark.*",
"remark.*",
"trough",
"unified",
"unist.*",
"vfile.*",
];

module.exports = {
setupFiles: ["<rootDir>/tests/config/setup.js"],
snapshotSerializers: [
Expand All @@ -77,6 +100,9 @@ module.exports = {
"<rootDir>/scripts/release",
],
transform,
transformIgnorePatterns: [
`<rootDir>/node_modules/(?!(${esmPackagePatterns.join("|")})/)`,
],
watchPlugins: [
"jest-watch-typeahead/filename",
"jest-watch-typeahead/testname",
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,19 @@
"postcss-selector-parser": "2.2.3",
"postcss-values-parser": "2.0.1",
"regexp-util": "1.2.2",
"remark-footnotes": "2.0.0",
"remark-math": "3.0.1",
"remark-parse": "8.0.3",
"remark-frontmatter": "4.0.1",
"remark-gfm": "3.0.1",
"remark-math": "5.1.1",
"remark-mdx": "1.6.22",
"remark-parse": "10.0.1",
"remark-wiki-link": "1.0.4",
"resolve": "1.20.0",
"semver": "7.3.5",
"string-width": "4.2.3",
"strip-ansi": "6.0.0",
"typescript": "4.5.2",
"unicode-regex": "3.0.0",
"unified": "9.2.1",
"unified": "10.1.1",
"vnopts": "1.0.2",
"wcwidth": "1.0.1",
"yaml-unist-parser": "1.3.1"
Expand Down
82 changes: 0 additions & 82 deletions src/language-markdown/mdx.js

This file was deleted.

37 changes: 15 additions & 22 deletions src/language-markdown/parser-markdown.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
"use strict";

const remarkParse = require("remark-parse");
const unified = require("unified");
const { default: remarkParse } = require("remark-parse");
const { unified } = require("unified");
const remarkMath = require("remark-math");
const footnotes = require("remark-footnotes");
const remarkGfm = require("remark-gfm");
const remarkMdx = require("remark-mdx");
const remarkFrontmatter = require("remark-frontmatter");
const remarkWikiLink = require("remark-wiki-link");
const pragma = require("./pragma.js");
const { locStart, locEnd } = require("./loc.js");
const mdx = require("./mdx.js");
const htmlToJsx = require("./unified-plugins/html-to-jsx.js");
const frontMatter = require("./unified-plugins/front-matter.js");
const liquid = require("./unified-plugins/liquid.js");
const wikiLink = require("./unified-plugins/wiki-link.js");
const looseItems = require("./unified-plugins/loose-items.js");

/**
Expand All @@ -30,26 +29,20 @@ const looseItems = require("./unified-plugins/loose-items.js");
function createParse({ isMDX }) {
return (text) => {
const processor = unified()
.use(remarkParse, {
commonmark: true,
...(isMDX && { blocks: [mdx.BLOCKS_REGEX] }),
})
.use(footnotes)
.use(frontMatter)
.use(remarkParse)
.use(remarkGfm)
.use(remarkMath)
.use(isMDX ? mdx.esSyntax : identity)
.use(liquid)
.use(isMDX ? htmlToJsx : identity)
.use(wikiLink)
.use(looseItems);
.use(remarkFrontmatter)
.use(remarkWikiLink);
// .use(liquid)
// .use(looseItems);
if (isMDX) {
processor.use(remarkMdx);
}
return processor.runSync(processor.parse(text));
};
}

function identity(x) {
return x;
}

const baseParser = {
astFormat: "mdast",
hasPragma: pragma.hasPragma,
Expand Down
20 changes: 0 additions & 20 deletions src/language-markdown/unified-plugins/front-matter.js

This file was deleted.

21 changes: 0 additions & 21 deletions src/language-markdown/unified-plugins/html-to-jsx.js

This file was deleted.

29 changes: 0 additions & 29 deletions src/language-markdown/unified-plugins/wiki-link.js

This file was deleted.