Utilizing the compiler API for Typescript code generation, I encountered an issue where printer.printFile
consistently outputs empty strings. Despite successfully using printer.printNode
and printer.printList
to print my AST, printer.printFile
remains uncooperative.
const printer = createPrinter();
const sourceFile = createSourceFile(
'dummy.ts',
'',
ScriptTarget.ESNext,
false,
ScriptKind.TS
);
const classDeclaration = factory.createClassDeclaration(
undefined,
undefined,
'Foo',
undefined,
undefined,
[]
);
factory.updateSourceFile(sourceFile, factory.createNodeArray([classDeclaration]));
console.log(printer.printFile(sourceFile)); // '';
I am perplexed by the behavior of printer.printFile
and would appreciate any insights on why it consistently results in an empty string.