-
-
Notifications
You must be signed in to change notification settings - Fork 527
/
ts-compiler-types.ts
139 lines (135 loc) · 5.92 KB
/
ts-compiler-types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import type * as _ts from 'typescript';
/**
* Common TypeScript interfaces between versions. We endeavour to write ts-node's own code against these types instead
* of against `import "typescript"`, though we are not yet doing this consistently.
*
* Sometimes typescript@next adds an API we need to use. But we build ts-node against typescript@latest.
* In these cases, we must declare that API explicitly here. Our declarations include the newer typescript@next APIs.
* Importantly, these re-declarations are *not* TypeScript internals. They are public APIs that only exist in
* pre-release versions of typescript.
*/
export interface TSCommon {
version: typeof _ts.version;
sys: typeof _ts.sys;
ScriptSnapshot: typeof _ts.ScriptSnapshot;
displayPartsToString: typeof _ts.displayPartsToString;
createLanguageService: typeof _ts.createLanguageService;
getDefaultLibFilePath: typeof _ts.getDefaultLibFilePath;
getPreEmitDiagnostics: typeof _ts.getPreEmitDiagnostics;
flattenDiagnosticMessageText: typeof _ts.flattenDiagnosticMessageText;
transpileModule: typeof _ts.transpileModule;
ModuleKind: TSCommon.ModuleKindEnum;
ScriptTarget: typeof _ts.ScriptTarget;
findConfigFile: typeof _ts.findConfigFile;
readConfigFile: typeof _ts.readConfigFile;
parseJsonConfigFileContent: typeof _ts.parseJsonConfigFileContent;
formatDiagnostics: typeof _ts.formatDiagnostics;
formatDiagnosticsWithColorAndContext: typeof _ts.formatDiagnosticsWithColorAndContext;
createDocumentRegistry: typeof _ts.createDocumentRegistry;
JsxEmit: typeof _ts.JsxEmit;
createModuleResolutionCache: typeof _ts.createModuleResolutionCache;
resolveModuleName: typeof _ts.resolveModuleName;
resolveModuleNameFromCache: typeof _ts.resolveModuleNameFromCache;
resolveTypeReferenceDirective: typeof _ts.resolveTypeReferenceDirective;
createIncrementalCompilerHost: typeof _ts.createIncrementalCompilerHost;
createSourceFile: typeof _ts.createSourceFile;
getDefaultLibFileName: typeof _ts.getDefaultLibFileName;
createIncrementalProgram: typeof _ts.createIncrementalProgram;
createEmitAndSemanticDiagnosticsBuilderProgram: typeof _ts.createEmitAndSemanticDiagnosticsBuilderProgram;
Extension: typeof _ts.Extension;
ModuleResolutionKind: typeof _ts.ModuleResolutionKind;
}
export namespace TSCommon {
export interface LanguageServiceHost extends _ts.LanguageServiceHost {}
export type ModuleResolutionHost = _ts.ModuleResolutionHost;
export type ParsedCommandLine = _ts.ParsedCommandLine;
export type ResolvedModule = _ts.ResolvedModule;
export type ResolvedTypeReferenceDirective =
_ts.ResolvedTypeReferenceDirective;
export type CompilerOptions = _ts.CompilerOptions;
export type ResolvedProjectReference = _ts.ResolvedProjectReference;
export type ResolvedModuleWithFailedLookupLocations =
_ts.ResolvedModuleWithFailedLookupLocations;
export type FileReference = _ts.FileReference;
export type SourceFile = _ts.SourceFile;
// Hack until we start building against TS >= 4.7.0
export type ModuleKindEnum = typeof _ts.ModuleKind & {
Node16: typeof _ts.ModuleKind extends { Node16: any }
? typeof _ts.ModuleKind['Node16']
: 100;
};
// Can't figure out how to re-export an enum
// `export import ... =` complains that _ts is type-only import
export namespace ModuleKind {
export type CommonJS = _ts.ModuleKind.CommonJS;
export type ESNext = _ts.ModuleKind.ESNext;
}
}
/**
* Compiler APIs we use that are marked internal and not included in TypeScript's public API declarations
* @internal
*/
export interface TSInternal {
// https://github.com/microsoft/TypeScript/blob/4a34294908bed6701dcba2456ca7ac5eafe0ddff/src/compiler/core.ts#L1906-L1909
createGetCanonicalFileName(
useCaseSensitiveFileNames: boolean
): TSInternal.GetCanonicalFileName;
// https://github.com/microsoft/TypeScript/blob/c117c266e09c80e8a06b24a6e94b9d018f5fae6b/src/compiler/commandLineParser.ts#L2054
convertToTSConfig(
configParseResult: _ts.ParsedCommandLine,
configFileName: string,
host: TSInternal.ConvertToTSConfigHost
): any;
libs?: string[];
Diagnostics: {
File_0_not_found: _ts.DiagnosticMessage;
};
createCompilerDiagnostic(
message: _ts.DiagnosticMessage,
...args: (string | number | undefined)[]
): _ts.Diagnostic;
nodeModuleNameResolver(
moduleName: string,
containingFile: string,
compilerOptions: _ts.CompilerOptions,
host: _ts.ModuleResolutionHost,
cache?: _ts.ModuleResolutionCache,
redirectedReference?: _ts.ResolvedProjectReference,
lookupConfig?: boolean
): _ts.ResolvedModuleWithFailedLookupLocations;
// Added in TS 4.7
getModeForFileReference?: (
ref: _ts.FileReference | string,
containingFileMode: _ts.SourceFile['impliedNodeFormat']
) => _ts.SourceFile['impliedNodeFormat'];
// TODO do we need these? Which TS version adds them?
getPatternFromSpec(
spec: string,
basePath: string,
usage: 'files' | 'directories' | 'exclude'
): string | undefined;
getRegularExpressionForWildcard(
specs: readonly string[] | undefined,
basePath: string,
usage: 'files' | 'directories' | 'exclude'
): string | undefined;
// Added in TS 4.7
getModeForResolutionAtIndex?(
file: TSInternal.SourceFileImportsList,
index: number
): _ts.SourceFile['impliedNodeFormat'];
}
/** @internal */
export namespace TSInternal {
// https://github.com/microsoft/TypeScript/blob/4a34294908bed6701dcba2456ca7ac5eafe0ddff/src/compiler/core.ts#L1906
export type GetCanonicalFileName = (fileName: string) => string;
// https://github.com/microsoft/TypeScript/blob/c117c266e09c80e8a06b24a6e94b9d018f5fae6b/src/compiler/commandLineParser.ts#L2041
export interface ConvertToTSConfigHost {
getCurrentDirectory(): string;
useCaseSensitiveFileNames: boolean;
}
// Note: is only a partial declaration, TS sources declare other fields
export interface SourceFileImportsList {
impliedNodeFormat?: TSCommon.SourceFile['impliedNodeFormat'];
}
}