Skip to content
File

Blob: types/src/print.ts

typescript27 lines
1// Copyright (c) 2022-2023 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4 
5import ts, { factory as f } from "typescript";
6 
7const placeholderFile = ts.createSourceFile(
8 "placeholder.ts", // File name doesn't matter here
9 "",
10 ts.ScriptTarget.ESNext,
11 false,
12 ts.ScriptKind.TS
13);
14export const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
15 
16export function printNode(node: ts.Node): string {
17 return printer.printNode(ts.EmitHint.Unspecified, node, placeholderFile);
18}
19 
20export function printNodeList(nodes: ts.Node[]): string {
21 return printer.printList(
22 ts.ListFormat.MultiLine,
23 f.createNodeArray(nodes),
24 placeholderFile
25 );
26}