Skip to content

Commit f4ed887

Browse files
authored
fix: throw descriptive error when inserting variable statement with no declarations (#1598)
1 parent 84613e5 commit f4ed887

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

packages/ts-morph/src/structurePrinters/statement/VariableStatementStructurePrinter.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export class VariableStatementStructurePrinter extends NodePrinter<OptionalKind<
1717
writer.hangingIndent(() => {
1818
this.factory.forModifierableNode().printText(writer, structure);
1919
writer.write(`${structure.declarationKind || VariableDeclarationKind.Let} `);
20+
if (structure.declarations.length === 0)
21+
throw new Error("You must provide at least one declaration when inserting a variable statement.");
2022
this.factory.forVariableDeclaration().printTexts(writer, structure.declarations);
2123
writer.write(";");
2224
});

0 commit comments

Comments
 (0)