From a33162bb662f5da243ff54fa48ffd48f4cd481ee Mon Sep 17 00:00:00 2001 From: Keen Yee Liau Date: Thu, 7 Nov 2019 11:00:38 -0800 Subject: [PATCH] fix(compiler-cli): Pass SourceFile to getFullText() (#33660) Similar to https://github.com/angular/angular/pull/33633, this commit is needed to fix an outage with the Angular Kythe indexer. Crash logs: ``` TypeError: Cannot read property 'text' of undefined at NodeObject.getFullText (typescript/stable/lib/typescript.js:121443:57) at FactoryGenerator.generate (angular2/rc/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts:67:34) at GeneratedShimsHostWrapper.getSourceFile (angular2/rc/packages/compiler-cli/src/ngtsc/shims/src/host.ts:88:26) at findSourceFile (typescript/stable/lib/typescript.js:90654:29) at typescript/stable/lib/typescript.js:90553:85 at getSourceFileFromReferenceWorker (typescript/stable/lib/typescript.js:90520:34) at processSourceFile (typescript/stable/lib/typescript.js:90553:13) at processRootFile (typescript/stable/lib/typescript.js:90383:13) at typescript/stable/lib/typescript.js:89399:60 at Object.forEach (typescript/stable/lib/typescript.js:280:30) ``` PR Close #33660 --- .../compiler-cli/src/ngtsc/shims/src/factory_generator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 42377926ed..6f68065418 100644 --- a/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts +++ b/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts @@ -59,12 +59,12 @@ export class FactoryGenerator implements ShimGenerator { let comment: string = ''; if (original.statements.length > 0) { const firstStatement = original.statements[0]; - // Must pass SourceFile to getLeadingTriviaWidth(), otherwise it'll try to + // Must pass SourceFile to getLeadingTriviaWidth() and getFullText(), 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); + comment = firstStatement.getFullText(original).substr(0, leadingTriviaWidth); } }