diff --git a/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts b/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts index 945229f378..42377926ed 100644 --- a/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts +++ b/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts @@ -59,8 +59,12 @@ export class FactoryGenerator implements ShimGenerator { let comment: string = ''; if (original.statements.length > 0) { const firstStatement = original.statements[0]; - if (firstStatement.getLeadingTriviaWidth() > 0) { - comment = firstStatement.getFullText().substr(0, firstStatement.getLeadingTriviaWidth()); + // Must pass SourceFile to getLeadingTriviaWidth(), otherwise it'll try to + // get SourceFile by recursively looking up the parent of the Node and fail, + // because parent is undefined. + const leadingTriviaWidth = firstStatement.getLeadingTriviaWidth(original); + if (leadingTriviaWidth > 0) { + comment = firstStatement.getFullText().substr(0, leadingTriviaWidth); } }