From 52e9819232a8e9d89023ce6b50b6db82c6f73e8c Mon Sep 17 00:00:00 2001 From: hawkgs Date: Wed, 1 May 2019 22:12:50 +0300 Subject: [PATCH] fix(@schematics/angular): allow insertion when there are no occurrences --- packages/schematics/angular/utility/ast-utils.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/schematics/angular/utility/ast-utils.ts b/packages/schematics/angular/utility/ast-utils.ts index 101a26cd107b..dc659003f9dc 100644 --- a/packages/schematics/angular/utility/ast-utils.ts +++ b/packages/schematics/angular/utility/ast-utils.ts @@ -191,10 +191,7 @@ export function insertAfterLastOccurrence(nodes: ts.Node[], syntaxKind?: ts.SyntaxKind): Change { // sort() has a side effect, so make a copy so that we won't overwrite the parent's object. let lastItem = [...nodes].sort(nodesByPosition).pop(); - if (!lastItem) { - throw new Error(); - } - if (syntaxKind) { + if (syntaxKind && lastItem) { lastItem = findNodes(lastItem, syntaxKind).sort(nodesByPosition).pop(); } if (!lastItem && fallbackPos == undefined) {