Skip to content

⬅️ Back to Table of Contents

📄 create-program/shared

📊 Analysis Summary

Metric Count
🔧 Functions 7
📦 Imports 4
📊 Variables & Constants 5
📐 Interfaces 2
📑 Type Aliases 2

📚 Table of Contents

🛠️ File Location:

📂 packages/typescript-estree/src/create-program/shared.ts

📦 Imports

Name Source
Program typescript
CORE_COMPILER_OPTIONS @typescript-eslint/tsconfig-utils
path node:path
ParseSettings ../parseSettings

Variables & Constants

Name Type Kind Value Exported
DEFAULT_COMPILER_OPTIONS ts.CompilerOptions const { ...CORE_COMPILER_OPTIONS, allowJs: true, allowNonTsExtensions: true, checkJ...
DEFAULT_EXTRA_FILE_EXTENSIONS Set<string> const new Set<string>([ ts.Extension.Cjs, ts.Extension.Cts, ts.Extension.Js, ts.Ext...
useCaseSensitiveFileNames any const ts.sys !== undefined ? ts.sys.useCaseSensitiveFileNames : true
correctPathCasing (filePath: string) => string const useCaseSensitiveFileNames ? (filePath: string): string => filePath : (filePat...
DEFINITION_EXTENSIONS readonly [any, any, any] const [ ts.Extension.Dts, ts.Extension.Dcts, ts.Extension.Dmts, ] as const

Functions

createDefaultCompilerOptionsFromExtra(parseSettings: ParseSettings): ts.CompilerOptions

Parameters:

  • parseSettings ParseSettings

Returns: ts.CompilerOptions

Calls:

  • parseSettings.debugLevel.has
Code
export function createDefaultCompilerOptionsFromExtra(
  parseSettings: ParseSettings,
): ts.CompilerOptions {
  if (parseSettings.debugLevel.has('typescript')) {
    return {
      ...DEFAULT_COMPILER_OPTIONS,
      extendedDiagnostics: true,
    };
  }

  return DEFAULT_COMPILER_OPTIONS;
}

getCanonicalFileName(filePath: string): CanonicalPath

Parameters:

  • filePath string

Returns: CanonicalPath

Calls:

  • path.normalize
  • normalized.endsWith
  • normalized.slice
  • correctPathCasing
Code
export function getCanonicalFileName(filePath: string): CanonicalPath {
  let normalized = path.normalize(filePath);
  if (normalized.endsWith(path.sep)) {
    normalized = normalized.slice(0, -1);
  }
  return correctPathCasing(normalized) as CanonicalPath;
}

ensureAbsolutePath(p: string, tsconfigRootDir: string): string

Parameters:

  • p string
  • tsconfigRootDir string

Returns: string

Calls:

  • path.resolve
Code
export function ensureAbsolutePath(p: string, tsconfigRootDir: string): string {
  return path.resolve(tsconfigRootDir, p);
}

canonicalDirname(p: CanonicalPath): CanonicalPath

Parameters:

  • p CanonicalPath

Returns: CanonicalPath

Calls:

  • path.dirname
Code
export function canonicalDirname(p: CanonicalPath): CanonicalPath {
  return path.dirname(p) as CanonicalPath;
}

getAstFromProgram(currentProgram: Program, filePath: string): ASTAndDefiniteProgram | undefined

Parameters:

  • currentProgram Program
  • filePath string

Returns: ASTAndDefiniteProgram | undefined

Calls:

  • currentProgram.getSourceFile
  • getExtension

Internal Comments:

// working around https://github.com/typescript-eslint/typescript-eslint/issues/1573 (x2)

Code
export function getAstFromProgram(
  currentProgram: Program,
  filePath: string,
): ASTAndDefiniteProgram | undefined {
  const ast = currentProgram.getSourceFile(filePath);

  // working around https://github.com/typescript-eslint/typescript-eslint/issues/1573
  const expectedExt = getExtension(filePath);
  const returnedExt = getExtension(ast?.fileName);
  if (expectedExt !== returnedExt) {
    return undefined;
  }

  return ast && { ast, program: currentProgram };
}

createHash(content: string): string

Hash content for compare content.

Parameters:

  • content any: hashed contend

Returns: undefined hashed result

Raw JSDoc
/**
 * Hash content for compare content.
 * @param content hashed contend
 * @returns hashed result
 */

Calls:

  • ts.sys.createHash

Internal Comments:

// No ts.sys in browser environments.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition

Code
export function createHash(content: string): string {
  // No ts.sys in browser environments.
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
  if (ts.sys?.createHash) {
    return ts.sys.createHash(content);
  }
  return content;
}

getExtension(fileName: string | undefined): string | null

Parameters:

  • fileName string | undefined

Returns: string | null

Calls:

  • DEFINITION_EXTENSIONS.find
  • fileName.endsWith
  • path.extname
Code
function getExtension(fileName: string | undefined): string | null {
  if (!fileName) {
    return null;
  }

  return (
    DEFINITION_EXTENSIONS.find(definitionExt =>
      fileName.endsWith(definitionExt),
    ) ?? path.extname(fileName)
  );
}

Interfaces

ASTAndNoProgram

Interface Code
export interface ASTAndNoProgram {
  ast: ts.SourceFile;
  program: null;
}

Properties

Name Type Optional Description
ast ts.SourceFile not shown
program null not shown

ASTAndDefiniteProgram

Interface Code
export interface ASTAndDefiniteProgram {
  ast: ts.SourceFile;
  program: ts.Program;
}

Properties

Name Type Optional Description
ast ts.SourceFile not shown
program ts.Program not shown

Type Aliases

ASTAndProgram

type ASTAndProgram = ASTAndDefiniteProgram | ASTAndNoProgram;

CanonicalPath

type CanonicalPath = { __brand: unknown } & string;

Generated by Syntax Scribe