Skip to content

Commit 083df6b

Browse files
authored
new type for functions with body (#1368)
1 parent 5f67255 commit 083df6b

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
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 [

src/slangPrinter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ function ignoreComments(path: AstPath<AstNode>): void {
3030
let key: keyof StrictAstNode;
3131
for (key in node) {
3232
switch (key) {
33-
// We ignore `kind`, `loc`, and `comments` since these are added by the
34-
// parser. `updateMetadata` is an internal function.
33+
// We ignore `kind` and `loc` since these are added by the parser.
34+
// `updateMetadata` is an internal function.
3535
case 'kind':
3636
case 'loc':
3737
case 'updateMetadata':

0 commit comments

Comments
 (0)