Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
404 changes: 210 additions & 194 deletions npm-shrinkwrap.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"eslint-import-resolver-node": "^0.3.9",
"eslint-plugin-import-x": "^4.16.1",
"eslint-plugin-jsdoc": "^61.4.1",
"eslint-plugin-react-x": "^2.3.13",
"husky": "^9.1.7",
"lint-staged": "^16.2.7",
"prettier": "3.7.4"
Expand All @@ -50,11 +51,9 @@
"acorn": "^8.15.0",
"commander": "^14.0.2",
"dedent": "^1.7.0",
"eslint-plugin-react-x": "^2.3.12",
"estree-util-to-js": "^2.0.0",
"estree-util-visit": "^2.0.0",
"github-slugger": "^2.0.0",
"glob": "^13.0.0",
"globals": "^16.5.0",
"hast-util-to-string": "^3.0.1",
"hastscript": "^9.0.1",
Expand All @@ -75,7 +74,7 @@
"rolldown": "^1.0.0-beta.53",
"semver": "^7.7.3",
"shiki": "^3.19.0",
"to-vfile": "^8.0.0",
"tinyglobby": "^0.2.15",
"unified": "^11.0.5",
"unist-builder": "^4.0.0",
"unist-util-find-after": "^5.0.0",
Expand Down
19 changes: 12 additions & 7 deletions src/generators/ast-js/index.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { readFile } from 'node:fs/promises';
import { extname } from 'node:path';

import { globSync } from 'glob';
import { read } from 'to-vfile';

import { parseJsSource } from '../../parsers/javascript.mjs';
import { parse } from 'acorn';
import { globSync } from 'tinyglobby';

/**
* This generator parses Javascript sources passed into the generator's input
Expand Down Expand Up @@ -39,11 +38,17 @@ export default {
const results = [];

for (const path of filePaths) {
const vfile = await read(path, 'utf-8');
const value = await readFile(path, 'utf-8');

const parsed = parse(value, {
allowReturnOutsideFunction: true,
ecmaVersion: 'latest',
locations: true,
});

const parsedJS = await parseJsSource(vfile);
parsed.path = path;

results.push(parsedJS);
results.push(parsed);
}

return results;
Expand Down
7 changes: 4 additions & 3 deletions src/generators/ast/index.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

import { readFile } from 'node:fs/promises';
import { extname } from 'node:path';

import { globSync } from 'glob';
import { read } from 'to-vfile';
import { globSync } from 'tinyglobby';
import { VFile } from 'vfile';

import createQueries from '../../utils/queries/index.mjs';
import { getRemark } from '../../utils/remark.mjs';
Expand Down Expand Up @@ -41,7 +42,7 @@ export default {
const results = [];

for (const path of filePaths) {
const vfile = await read(path, 'utf-8');
const vfile = new VFile({ path, value: await readFile(path, 'utf-8') });

updateStabilityPrefixToLink(vfile);

Expand Down
2 changes: 2 additions & 0 deletions src/generators/jsx-ast/utils/transformer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const transformer = tree => {
const thead = node.children.find(el => el.tagName === 'thead');

if (thead) {
// TODO(@avivkeller): These are only strings afaict, so a `toString` dependency
// might not actually be needed.
const headers = thead.children[0].children.map(toString);
const tbody = node.children.find(el => el.tagName === 'tbody');

Expand Down
25 changes: 0 additions & 25 deletions src/parsers/javascript.mjs

This file was deleted.

17 changes: 8 additions & 9 deletions src/utils/highlighter.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

import createHighlighter from '@node-core/rehype-shiki';
import { toString } from 'hast-util-to-string';
import { h as createElement } from 'hastscript';
import { SKIP, visit } from 'unist-util-visit';

Expand Down Expand Up @@ -84,18 +83,18 @@ export default function rehypeShikiji() {
return;
}

// Retrieve the whole <pre> contents as a parsed DOM string
const preElementContents = toString(preElement);

// Grabs the relevant alias/name of the language
const languageId = codeLanguage.slice(languagePrefix.length);

// Parses the <pre> contents and returns a HAST tree with the highlighted code
const { children } = highlighter.shiki.codeToHast(preElementContents, {
lang: languageId,
// Allows support for dual themes (light, dark) for Shiki
themes: { light: shikiConfig.themes[0], dark: shikiConfig.themes[1] },
});
const { children } = highlighter.shiki.codeToHast(
preElement.children[0].value,
{
lang: languageId,
// Allows support for dual themes (light, dark) for Shiki
themes: { light: shikiConfig.themes[0], dark: shikiConfig.themes[1] },
}
);

// Adds the original language back to the <pre> element
children[0].properties.class = `${children[0].properties.class} ${codeLanguage}`;
Expand Down
Loading