Skip to content

Commit 52e9819

Browse files
hawkgsKeen Yee Liau
authored and
Keen Yee Liau
committed
fix(@schematics/angular): allow insertion when there are no occurrences
1 parent 548fefd commit 52e9819

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

packages/schematics/angular/utility/ast-utils.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,7 @@ export function insertAfterLastOccurrence(nodes: ts.Node[],
191191
syntaxKind?: ts.SyntaxKind): Change {
192192
// sort() has a side effect, so make a copy so that we won't overwrite the parent's object.
193193
let lastItem = [...nodes].sort(nodesByPosition).pop();
194-
if (!lastItem) {
195-
throw new Error();
196-
}
197-
if (syntaxKind) {
194+
if (syntaxKind && lastItem) {
198195
lastItem = findNodes(lastItem, syntaxKind).sort(nodesByPosition).pop();
199196
}
200197
if (!lastItem && fallbackPos == undefined) {

0 commit comments

Comments
 (0)