From 69fc2ddd5a8650db266ef73002c8a3352af6bf80 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 30 Dec 2024 11:31:13 -0500 Subject: [PATCH] fix: throw descriptive error when inserting variable statement with no declarations --- .../statement/VariableStatementStructurePrinter.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/ts-morph/src/structurePrinters/statement/VariableStatementStructurePrinter.ts b/packages/ts-morph/src/structurePrinters/statement/VariableStatementStructurePrinter.ts index 515fbf526..b38ab5ee5 100644 --- a/packages/ts-morph/src/structurePrinters/statement/VariableStatementStructurePrinter.ts +++ b/packages/ts-morph/src/structurePrinters/statement/VariableStatementStructurePrinter.ts @@ -17,6 +17,8 @@ export class VariableStatementStructurePrinter extends NodePrinter { this.factory.forModifierableNode().printText(writer, structure); writer.write(`${structure.declarationKind || VariableDeclarationKind.Let} `); + if (structure.declarations.length === 0) + throw new Error("You must provide at least one declaration when inserting a variable statement."); this.factory.forVariableDeclaration().printTexts(writer, structure.declarations); writer.write(";"); });