📄 useProvidedPrograms.ts
¶
📊 Analysis Summary¶
Metric | Count |
---|---|
🔧 Functions | 2 |
📦 Imports | 5 |
📊 Variables & Constants | 2 |
📚 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 |
Variables & Constants¶
Name | Type | Kind | Value | Exported |
---|---|---|---|---|
astAndProgram |
ASTAndDefiniteProgram | undefined |
let/var | *not shown* |
✗ |
errorLines |
string[] |
const | `[ | |
"parserOptions.${typeSource}" has been provided for @typescript-eslint/parser. , |
||||
The file was not found in any of the provided ${typeSources}: ${relativeFilePath} , |
||||
]` | ✗ |
Functions¶
useProvidedPrograms(programInstances: Iterable<ts.Program>, parseSettings: ParseSettings): ASTAndDefiniteProgram | undefined
¶
Code
export function useProvidedPrograms(
programInstances: Iterable<ts.Program>,
parseSettings: ParseSettings,
): ASTAndDefiniteProgram | undefined {
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'));
}
- Parameters:
programInstances: Iterable<ts.Program>
parseSettings: ParseSettings
- Return Type:
ASTAndDefiniteProgram | undefined
- Calls:
log
getAstFromProgram (from ./shared)
astAndProgram.program.getTypeChecker
path.relative
errorLines.join
- Internal Comments:
createProgramFromConfigFile(configFile: string, projectDirectory: string): ts.Program
¶
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);
}
-
JSDoc:
-
Parameters:
configFile: string
projectDirectory: string
- Return Type:
ts.Program
- Calls:
getParsedConfigFile (from @typescript-eslint/tsconfig-utils)
ts.createCompilerHost
ts.createProgram