Debian Codegraph @

packages/babel-types/src/converters/ensureBlock.ts

raw
1 import toBlock from "./toBlock";
2 import type * as t from "..";
3
4 /**
5 * Ensure the `key` (defaults to "body") of a `node` is a block.
6 * Casting it to a block if it is not.
7 *
8 * Returns the BlockStatement
9 */
10 export default function ensureBlock(
11 node: t.Node,
12 key: string = "body",
13 ): t.BlockStatement {
14 // @ts-expect-error Fixme: key may not exist in node, consider remove key = "body"
15 const result = toBlock(node[key], node);
16 // @ts-expect-error Fixme: key may not exist in node, consider remove key = "body"
17 node[key] = result;
18 return result;
19 }