📄 useProvidedPrograms¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 2 |
| 📦 Imports | 5 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/typescript-estree/src/create-program/useProvidedPrograms.ts
📦 Imports¶
| Name | Source |
|---|---|
getParsedConfigFile |
@typescript-eslint/tsconfig-utils |
debug |
debug |
ParseSettings |
../parseSettings |
ASTAndDefiniteProgram |
./shared |
getAstFromProgram |
./shared |
Functions¶
useProvidedPrograms(programInstances: Iterable<ts.Program>, parseSettings: ParseSettings): ASTAndDefiniteProgram¶
Parameters:
programInstancesIterable<ts.Program>parseSettingsParseSettings
Returns: ASTAndDefiniteProgram
Calls:
loggetAstFromProgram (from ./shared)astAndProgram.program.getTypeCheckerpath.relativeerrorLines.join
Internal Comments:
Code
export function useProvidedPrograms(
programInstances: Iterable<ts.Program>,
parseSettings: ParseSettings,
): ASTAndDefiniteProgram {
log(
'Retrieving ast for %s from provided program instance(s)',
parseSettings.filePath,
);
let astAndProgram: ASTAndDefiniteProgram | undefined;
for (const programInstance of programInstances) {
astAndProgram = getAstFromProgram(programInstance, parseSettings.filePath);
// Stop at the first applicable program instance
if (astAndProgram) {
break;
}
}
if (astAndProgram) {
astAndProgram.program.getTypeChecker(); // ensure parent pointers are set in source files
return astAndProgram;
}
const relativeFilePath = path.relative(
parseSettings.tsconfigRootDir,
parseSettings.filePath,
);
const [typeSource, typeSources] =
parseSettings.projects.size > 0
? ['project', 'project(s)']
: ['programs', 'program instance(s)'];
const errorLines = [
`"parserOptions.${typeSource}" has been provided for @typescript-eslint/parser.`,
`The file was not found in any of the provided ${typeSources}: ${relativeFilePath}`,
];
throw new Error(errorLines.join('\n'));
}
createProgramFromConfigFile(configFile: string, projectDirectory: string): ts.Program¶
Utility offered by parser to help consumers construct their own program instance.
Parameters:
configFileany: the path to the tsconfig.json file, relative toprojectDirectoryprojectDirectoryany: the project directory to use as the CWD, defaults toprocess.cwd()
Raw JSDoc
Calls:
getParsedConfigFile (from @typescript-eslint/tsconfig-utils)ts.createCompilerHostts.createProgram
Code
export function createProgramFromConfigFile(
configFile: string,
projectDirectory?: string,
): ts.Program {
const parsed = getParsedConfigFile(ts, configFile, projectDirectory);
const host = ts.createCompilerHost(parsed.options, true);
return ts.createProgram(parsed.fileNames, parsed.options, host);
}
Generated by Syntax Scribe