definesFunction

tcmts.core.ir.definesFunction · #l7xjquui · term · runs anywhere

Whether a definition is a function: function f() {}, or a const holding an arrow function or function expression. Its source text is its code (String(f)), as a constant's isn't: ${n} reads a value something ran.

import type { IR } from "#codebase/tcmts/core/hash";
import { declarationOf, initializerOf } from "#codebase/tcmts/core/ir";

export function definesFunction(ir: string | IR[]): boolean {
  if (declarationOf(ir)?.[0] === "FunctionDeclaration") return true;
  const init = initializerOf(ir)?.[0];
  return init === "ArrowFunction" || init === "FunctionExpression";
}

uses

used by