Skip to content

Commit b5a8fd2

Browse files
committed
new type for functions with body
1 parent 37fa9b5 commit b5a8fd2

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/slang-nodes/types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ export type StrictAstNode =
461461
| YulPaths
462462
| YulPath;
463463

464+
export type FunctionWithBody = Extract<
465+
FunctionLike,
466+
{ body: FunctionBody['variant'] }
467+
>;
468+
464469
export type PolymorphicNode = Extract<StrictAstNode, { variant: unknown }>;
465470

466471
export type StrictPolymorphicNode = Extract<

src/slang-printers/print-function.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import { doc } from 'prettier';
33
import { joinExisting } from '../slang-utils/join-existing.js';
44

55
import type { AstPath, Doc } from 'prettier';
6-
import type { FunctionLike } from '../slang-nodes/types.d.ts';
6+
import type { FunctionLike, FunctionWithBody } from '../slang-nodes/types.d.ts';
77
import type { PrintFunction } from '../types.d.ts';
8-
import type { FunctionBody } from '../slang-nodes/FunctionBody.js';
98

109
const { dedent, group, indent, line } = doc.builders;
1110

@@ -15,9 +14,7 @@ export function printFunction(
1514
path: AstPath<FunctionLike>,
1615
print: PrintFunction
1716
): Doc {
18-
const body = (
19-
node as Extract<FunctionLike, { body: FunctionBody['variant'] }>
20-
).body;
17+
const body = (node as FunctionWithBody).body;
2118

2219
return group([
2320
functionName,
@@ -37,7 +34,7 @@ export function printFunction(
3734
export function printFunctionWithBody(
3835
functionName: Doc,
3936
node: FunctionLike,
40-
path: AstPath<Extract<FunctionLike, { body: unknown }>>,
37+
path: AstPath<FunctionWithBody>,
4138
print: PrintFunction
4239
): Doc {
4340
return [

0 commit comments

Comments
 (0)