Skip to content

Commit

Permalink
Hoist safelyGetAstroData() call and add statement null check
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo committed Jan 26, 2023
1 parent a7951cf commit 05ec52f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/markdown/remark/src/rehype-collect-headings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function rehypeHeadingIds(): ReturnType<RehypePlugin> {
const headings: MarkdownHeading[] = [];
const slugger = new Slugger();
const isMDX = isMDXFile(file);
const astroData = safelyGetAstroData(file.data);
visit(tree, (node) => {
if (node.type !== 'element') return;
const { tagName } = node;
Expand All @@ -35,7 +36,6 @@ export function rehypeHeadingIds(): ReturnType<RehypePlugin> {
if (rawNodeTypes.has(child.type)) {
if (isMDX || codeTagNames.has(parent.tagName)) {
let value = child.value;
const astroData = safelyGetAstroData(file.data);
if (isMdxTextExpression(child) && !(astroData instanceof InvalidAstroDataError)) {
const frontmatterPath = getMdxFrontmatterVariablePath(child);
if (Array.isArray(frontmatterPath) && frontmatterPath.length > 0) {
Expand Down Expand Up @@ -82,7 +82,7 @@ function getMdxFrontmatterVariablePath(node: MdxTextExpression): string[] | Erro
const statement = node.data.estree.body[0];

// Check for "[ANYTHING].[ANYTHING]".
if (statement.type !== 'ExpressionStatement' || statement.expression.type !== 'MemberExpression')
if (statement?.type !== 'ExpressionStatement' || statement.expression.type !== 'MemberExpression')
return new Error();

let expression: Expression | Super = statement.expression;
Expand Down

0 comments on commit 05ec52f

Please sign in to comment.