11import { NonterminalKind } from '@nomicfoundation/slang/cst' ;
22import { doc } from 'prettier' ;
33import { joinExisting } from '../slang-utils/join-existing.js' ;
4- import { printVariant } from './print-variant.js' ;
54
65import type { AstPath , Doc } from 'prettier' ;
7- import type {
8- FunctionLike ,
9- StrictPolymorphicNode
10- } from '../slang-nodes/types.d.ts' ;
6+ import type { FunctionLike } from '../slang-nodes/types.d.ts' ;
117import type { PrintFunction } from '../types.d.ts' ;
128import type { FunctionBody } from '../slang-nodes/FunctionBody.js' ;
139
@@ -19,7 +15,9 @@ export function printFunction(
1915 path : AstPath < FunctionLike > ,
2016 print : PrintFunction
2117) : Doc {
22- const body = ( node as Extract < FunctionLike , { body : FunctionBody } > ) . body ;
18+ const body = (
19+ node as Extract < FunctionLike , { body : FunctionBody [ 'variant' ] } >
20+ ) . body ;
2321
2422 return group ( [
2523 functionName ,
@@ -30,9 +28,7 @@ export function printFunction(
3028 path . call ( print , 'attributes' ) ,
3129 path . call ( print , 'returns' )
3230 ] ) ,
33- body && ( ! body . variant || body . variant . kind === NonterminalKind . Block )
34- ? dedent ( line )
35- : ''
31+ body && body . kind === NonterminalKind . Block ? dedent ( line ) : ''
3632 ] )
3733 )
3834 ] ) ;
@@ -46,12 +42,6 @@ export function printFunctionWithBody(
4642) : Doc {
4743 return [
4844 printFunction ( functionName , node , path , print ) ,
49- node . kind !== NonterminalKind . ConstructorDefinition
50- ? (
51- path as AstPath <
52- Extract < FunctionLike , { body : StrictPolymorphicNode } >
53- >
54- ) . call ( printVariant ( print ) , 'body' )
55- : path . call ( print , 'body' )
45+ path . call ( print , 'body' )
5646 ] ;
5747}
0 commit comments