Skip to content

Commit

Permalink
馃悰 findExpression allows undefined metadata (#1044)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 committed Apr 2, 2024
1 parent 855414f commit 6a6f445
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-mice-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-cli": patch
---

Avoid undefined bug when finding expressions
4 changes: 3 additions & 1 deletion packages/myst-cli/src/process/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export async function processNotebook(
const block = blockParent(cell, cellMdast.children) as GenericNode;

// Embed expression results into expression
const userExpressions = block.data?.[metadataSection] as IUserExpressionMetadata[];
const userExpressions = block.data?.[metadataSection] as
| IUserExpressionMetadata[]
| undefined;
const inlineNodes = selectAll('inlineExpression', block) as InlineExpression[];
inlineNodes.forEach((inlineExpression) => {
const data = findExpression(userExpressions, inlineExpression.value);
Expand Down
4 changes: 2 additions & 2 deletions packages/myst-cli/src/transforms/inlineExpressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export interface IUserExpressionsMetadata {
}

export function findExpression(
expressions: IUserExpressionMetadata[],
expressions: IUserExpressionMetadata[] | undefined,
value: string,
): IUserExpressionMetadata | undefined {
return expressions.find((expr) => expr.expression === value);
return expressions?.find((expr) => expr.expression === value);
}

function processLatex(value: string) {
Expand Down

0 comments on commit 6a6f445

Please sign in to comment.