rehype-optimize-static.test.js — astro Source File
Architecture documentation for rehype-optimize-static.test.js, a javascript file in the astro codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 29763700_7244_a511_48c0_47ed43973e4b["rehype-optimize-static.test.js"] 95070a7b_3374_dbd2_0eb1_a5f7ed010ab7["../../dist/rehype-optimize-static.js"] 29763700_7244_a511_48c0_47ed43973e4b --> 95070a7b_3374_dbd2_0eb1_a5f7ed010ab7 e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"] 29763700_7244_a511_48c0_47ed43973e4b --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607 6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"] 29763700_7244_a511_48c0_47ed43973e4b --> 6b0635f9_51ea_77aa_767b_7857878e98a6 8482adb2_32d8_4a04_7e12_83abee7f874a["mdx"] 29763700_7244_a511_48c0_47ed43973e4b --> 8482adb2_32d8_4a04_7e12_83abee7f874a style 29763700_7244_a511_48c0_47ed43973e4b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { compile as _compile } from '@mdx-js/mdx';
import { rehypeOptimizeStatic } from '../../dist/rehype-optimize-static.js';
/**
* @param {string} mdxCode
* @param {Readonly<import('@mdx-js/mdx').CompileOptions>} options
*/
async function compile(mdxCode, options) {
const result = await _compile(mdxCode, {
jsx: true,
rehypePlugins: [rehypeOptimizeStatic],
...options,
});
const code = result.toString();
// Capture the returned JSX code for testing
const jsx = /return (.+);\n\}\nexport default function MDXContent/s.exec(code)?.[1];
if (jsx == null) throw new Error('Could not find JSX code in compiled MDX');
return dedent(jsx);
}
function dedent(str) {
const lines = str.split('\n');
if (lines.length <= 1) return str;
// Get last line indent, and dedent this amount for the other lines
const lastLineIndent = lines[lines.length - 1].match(/^\s*/)[0].length;
return lines.map((line, i) => (i === 0 ? line : line.slice(lastLineIndent))).join('\n');
}
describe('rehype-optimize-static', () => {
it('works', async () => {
const jsx = await compile(`# hello`);
assert.equal(
jsx,
`\
<_components.h1 {...{
"set:html": "hello"
}} />`,
);
});
it('groups sibling nodes as a single Fragment', async () => {
const jsx = await compile(`\
# hello
foo bar
`);
assert.equal(
jsx,
`\
<Fragment set:html="<h1>hello</h1>
<p>foo bar</p>" />`,
);
});
it('skips optimization of components', async () => {
const jsx = await compile(`\
import Comp from './Comp.jsx';
# hello
This is a <Comp />
`);
assert.equal(
jsx,
`\
<><Fragment set:html="<h1>hello</h1>
" /><_components.p>{"This is a "}<Comp /></_components.p></>`,
);
});
it('optimizes explicit html elements', async () => {
const jsx = await compile(`\
# hello
foo <strong>bar</strong> baz
<strong>qux</strong>
`);
assert.equal(
jsx,
`\
<Fragment set:html="<h1>hello</h1>
<p>foo <strong>bar</strong> baz</p>
<strong>qux</strong>" />`,
);
});
});
Domain
Subdomains
Dependencies
- ../../dist/rehype-optimize-static.js
- mdx
- node:test
- strict
Source
Frequently Asked Questions
What does rehype-optimize-static.test.js do?
rehype-optimize-static.test.js is a source file in the astro codebase, written in javascript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in rehype-optimize-static.test.js?
rehype-optimize-static.test.js defines 2 function(s): compile, dedent.
What does rehype-optimize-static.test.js depend on?
rehype-optimize-static.test.js imports 4 module(s): ../../dist/rehype-optimize-static.js, mdx, node:test, strict.
Where is rehype-optimize-static.test.js in the architecture?
rehype-optimize-static.test.js is located at packages/integrations/mdx/test/units/rehype-optimize-static.test.js (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/integrations/mdx/test/units).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free