diff --git a/packages/compiler-cli/src/ngtsc/testing/src/utils.ts b/packages/compiler-cli/src/ngtsc/testing/src/utils.ts index 13fe87a560..fe72f5e67f 100644 --- a/packages/compiler-cli/src/ngtsc/testing/src/utils.ts +++ b/packages/compiler-cli/src/ngtsc/testing/src/utils.ts @@ -138,3 +138,12 @@ function bindingNameEquals(node: ts.BindingName, name: string): boolean { } return false; } + +export function getSourceCodeForDiagnostic(diag: ts.Diagnostic): string { + if (diag.file === undefined || diag.start === undefined || diag.length === undefined) { + throw new Error( + `Unable to get source code for diagnostic. Provided diagnostic instance doesn't contain "file", "start" and/or "length" properties.`); + } + const text = diag.file.text; + return text.substr(diag.start, diag.length); +} diff --git a/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts b/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts index 1cc1497288..a6c5d44954 100644 --- a/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts +++ b/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts @@ -11,7 +11,7 @@ import * as ts from 'typescript'; import {ErrorCode, ngErrorCode} from '../../src/ngtsc/diagnostics'; import {absoluteFrom as _, getFileSystem, getSourceFileOrError} from '../../src/ngtsc/file_system'; import {runInEachFileSystem} from '../../src/ngtsc/file_system/testing'; -import {expectCompleteReuse, loadStandardTestFiles} from '../../src/ngtsc/testing'; +import {expectCompleteReuse, getSourceCodeForDiagnostic, loadStandardTestFiles} from '../../src/ngtsc/testing'; import {NgtscTestEnvironment} from './env'; @@ -2506,8 +2506,3 @@ export declare class AnimationEvent { }); }); }); - -function getSourceCodeForDiagnostic(diag: ts.Diagnostic): string { - const text = diag.file!.text; - return text.substr(diag.start!, diag.length!); -}