diff --git a/packages/compiler-cli/src/ngtsc/typecheck/api/checker.ts b/packages/compiler-cli/src/ngtsc/typecheck/api/checker.ts index 25ce5e7c5e..a6bc3c4c40 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/api/checker.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/api/checker.ts @@ -7,6 +7,7 @@ */ import {AST, ParseError, TmplAstNode, TmplAstTemplate} from '@angular/compiler'; +import {AbsoluteFsPath} from '@angular/compiler-cli/src/ngtsc/file_system'; import * as ts from 'typescript'; import {FullTemplateMapping} from './api'; @@ -87,6 +88,12 @@ export interface TemplateTypeChecker { */ generateAllTypeCheckBlocks(): void; + /** + * Returns `true` if the given file is in the record of known shims generated by the compiler, + * `false` if we cannot find the file in the shim records. + */ + isTrackedTypeCheckFile(filePath: AbsoluteFsPath): boolean; + /** * Retrieve the top-level node representing the TCB for the given component. * diff --git a/packages/compiler-cli/src/ngtsc/typecheck/src/checker.ts b/packages/compiler-cli/src/ngtsc/typecheck/src/checker.ts index ca5cb27478..cd009e34ef 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/src/checker.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/src/checker.ts @@ -172,6 +172,10 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker { return {nodes}; } + isTrackedTypeCheckFile(filePath: AbsoluteFsPath): boolean { + return this.getFileAndShimRecordsForPath(filePath) !== null; + } + private getFileAndShimRecordsForPath(shimPath: AbsoluteFsPath): {fileRecord: FileTypeCheckingData, shimRecord: ShimTypeCheckingData}|null { for (const fileRecord of this.state.values()) { diff --git a/packages/language-service/ivy/references.ts b/packages/language-service/ivy/references.ts index 2fc5170023..ad287cec66 100644 --- a/packages/language-service/ivy/references.ts +++ b/packages/language-service/ivy/references.ts @@ -103,9 +103,7 @@ export class ReferenceBuilder { const entries: ts.ReferenceEntry[] = []; for (const ref of refs) { - // TODO(atscott): Determine if a file is a shim file in a more robust way and make the API - // available in an appropriate location. - if (ref.fileName.endsWith('ngtypecheck.ts')) { + if (this.ttc.isTrackedTypeCheckFile(absoluteFrom(ref.fileName))) { const entry = convertToTemplateReferenceEntry(ref, this.ttc); if (entry !== null) { entries.push(entry);