/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/language-service/testing/src/language_service_test_cache.ts
73 строки
2 KB
Jessica Janiuk
Revert "refactor(compiler-cli): remove deep imports from `compiler-cli` (#64732)"
07 ноя 2025, 00:09
07 ноя 2025, 00:09
37092d0
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {getCachedSourceFile} from '@angular/compiler-cli/src/ngtsc/testing'; import ts from 'typescript'; interface TsProjectWithInternals { // typescript/src/server/project.ts#ConfiguredProject setCompilerHost?(host: ts.CompilerHost): void; } let patchedLanguageServiceProjectHost = false; /** * Updates `ts.server.Project` to use efficient test caching of source files * that aren't expected to be changed. E.g. the default libs. */ export function patchLanguageServiceProjectsWithTestHost() { if (patchedLanguageServiceProjectHost) { return; } patchedLanguageServiceProjectHost = true; (ts.server.Project.prototype as TsProjectWithInternals).setCompilerHost = (host) => { const _originalHostGetSourceFile = host.getSourceFile; const _originalHostGetSourceFileByPath = host.getSourceFileByPath; host.getSourceFile = ( fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile, ) => { return ( getCachedSourceFile(fileName, () => host.readFile(fileName)) ?? _originalHostGetSourceFile.call( host, fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile, ) ); }; if (_originalHostGetSourceFileByPath !== undefined) { host.getSourceFileByPath = ( fileName, path, languageVersionOrOptions, onError, shouldCreateNewSourceFile, ) => { return ( getCachedSourceFile(fileName, () => host.readFile(fileName)) ?? _originalHostGetSourceFileByPath.call( host, fileName, path, languageVersionOrOptions, onError, shouldCreateNewSourceFile, ) ); }; } }; }