refactor(compiler-cli): move getSourceCodeForDiagnostic
to utils (#42984)
Export `getSourceCodeForDiagnostic` from `ngtsc/testing` to make it available for other packages. This will help confirm that the source code is correct in other tests. Refs #42966 PR Close #42984
This commit is contained in:
parent
29e2bc7d91
commit
29a5a90111
@ -138,3 +138,12 @@ function bindingNameEquals(node: ts.BindingName, name: string): boolean {
|
|||||||
}
|
}
|
||||||
return false;
|
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);
|
||||||
|
}
|
||||||
|
@ -11,7 +11,7 @@ import * as ts from 'typescript';
|
|||||||
import {ErrorCode, ngErrorCode} from '../../src/ngtsc/diagnostics';
|
import {ErrorCode, ngErrorCode} from '../../src/ngtsc/diagnostics';
|
||||||
import {absoluteFrom as _, getFileSystem, getSourceFileOrError} from '../../src/ngtsc/file_system';
|
import {absoluteFrom as _, getFileSystem, getSourceFileOrError} from '../../src/ngtsc/file_system';
|
||||||
import {runInEachFileSystem} from '../../src/ngtsc/file_system/testing';
|
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';
|
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!);
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user