Skip to content

Commit 8ad105d

Browse files
committed
refactor: simplify test for code cells
1 parent 7bd35c3 commit 8ad105d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/myst-execute/src/execute.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function buildCacheKey(kernelSpec: KernelSpec, nodes: (CodeBlock | InlineExpress
114114
raisesException: boolean;
115115
}[] = [];
116116
for (const node of nodes) {
117-
if (isCellBlock(node)) {
117+
if (isCodeBlock(node)) {
118118
hashableItems.push({
119119
kind: node.type,
120120
content: (select('code', node) as Code).value,
@@ -165,8 +165,8 @@ type CodeBlock = Block & {
165165
*
166166
* @param node node to test
167167
*/
168-
function isCellBlock(node: GenericNode): node is CodeBlock {
169-
return node.type === 'block' && select('code', node) !== null && select('outputs', node) !== null;
168+
function isCodeBlock(node: GenericNode): node is CodeBlock {
169+
return node.type === 'block' && node.kind === NotebookCell.code;
170170
}
171171

172172
/**
@@ -215,7 +215,7 @@ async function computeExecutableNodes(
215215

216216
const results: (IOutput[] | IExpressionResult)[] = [];
217217
for (const matchedNode of nodes) {
218-
if (isCellBlock(matchedNode)) {
218+
if (isCodeBlock(matchedNode)) {
219219
// Pull out code to execute
220220
const code = select('code', matchedNode) as Code;
221221
const { status, outputs } = await executeCode(kernel, code.value);
@@ -281,7 +281,7 @@ function applyComputedOutputsToNodes(
281281
// Pull out the result for this node
282282
const thisResult = computedResult.shift();
283283

284-
if (isCellBlock(matchedNode)) {
284+
if (isCodeBlock(matchedNode)) {
285285
const rawOutputData = (thisResult as IOutput[]) ?? [];
286286
// Pull out outputs to set data
287287
const outputs = select('outputs', matchedNode) as Outputs;
@@ -329,7 +329,7 @@ export async function kernelExecutionTransform(tree: GenericParent, vfile: VFile
329329
)[]
330330
)
331331
// Filter out nodes that skip execution
332-
.filter((node) => !(isCellBlock(node) && codeBlockSkipsExecution(node)));
332+
.filter((node) => !(isCodeBlock(node) && codeBlockSkipsExecution(node)));
333333

334334
// Only do something if we have any nodes!
335335
if (executableNodes.length === 0) {

0 commit comments

Comments
 (0)