Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/slang-nodes/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,11 @@ export type StrictAstNode =
| YulPaths
| YulPath;

export type FunctionWithBody = Extract<
FunctionLike,
{ body: FunctionBody['variant'] }
>;

export type PolymorphicNode = Extract<StrictAstNode, { variant: unknown }>;

export type StrictPolymorphicNode = Extract<
Expand Down
9 changes: 3 additions & 6 deletions src/slang-printers/print-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { doc } from 'prettier';
import { joinExisting } from '../slang-utils/join-existing.js';

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

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

Expand All @@ -15,9 +14,7 @@ export function printFunction(
path: AstPath<FunctionLike>,
print: PrintFunction
): Doc {
const body = (
node as Extract<FunctionLike, { body: FunctionBody['variant'] }>
).body;
const body = (node as FunctionWithBody).body;

return group([
functionName,
Expand All @@ -37,7 +34,7 @@ export function printFunction(
export function printFunctionWithBody(
functionName: Doc,
node: FunctionLike,
path: AstPath<Extract<FunctionLike, { body: unknown }>>,
path: AstPath<FunctionWithBody>,
print: PrintFunction
): Doc {
return [
Expand Down
4 changes: 2 additions & 2 deletions src/slangPrinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function ignoreComments(path: AstPath<AstNode>): void {
let key: keyof StrictAstNode;
for (key in node) {
switch (key) {
// We ignore `kind`, `loc`, and `comments` since these are added by the
// parser. `updateMetadata` is an internal function.
// We ignore `kind` and `loc` since these are added by the parser.
// `updateMetadata` is an internal function.
case 'kind':
case 'loc':
case 'updateMetadata':
Expand Down