Skip to content

Commit 548a326

Browse files
committed
CONVERTED TO MODULES
1 parent 2c98a7b commit 548a326

File tree

558 files changed

+24559
-31609
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

558 files changed

+24559
-31609
lines changed

src/cancellationToken/cancellationToken.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function createCancellationToken(args: string[]): ServerCancellationToken {
6262
}
6363
else {
6464
return {
65-
isCancellationRequested: () => pipeExists(cancellationPipeName!), // TODO: GH#18217
65+
isCancellationRequested: () => pipeExists(cancellationPipeName!),
6666
setRequest: (_requestId: number): void => void 0,
6767
resetRequest: (_requestId: number): void => void 0
6868
};

src/compiler/binder.ts

+77-74
Large diffs are not rendered by default.

src/compiler/builder.ts

+153-150
Large diffs are not rendered by default.

src/compiler/builderPublic.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
namespace ts {
2-
export type AffectedFileResult<T> = { result: T; affected: SourceFile | Program; } | undefined;
1+
import { SourceFile, Program, WriteFileCallback, ReusableBuilderProgramState, CompilerOptions, CancellationToken, Diagnostic, DiagnosticWithLocation, CustomTransformers, EmitResult, CompilerHost, ProjectReference, createBuilderProgram, BuilderProgramKind, getBuilderCreationParameters, createRedirectedBuilderProgram } from "./ts";
2+
export type AffectedFileResult<T> = {
3+
result: T;
4+
affected: SourceFile | Program;
5+
} | undefined;
36

47
export interface BuilderProgramHost {
58
/**
@@ -166,4 +169,3 @@ export function createAbstractBuilder(newProgramOrRootNames: Program | readonly
166169
const { newProgram, configFileParsingDiagnostics: newConfigFileParsingDiagnostics } = getBuilderCreationParameters(newProgramOrRootNames, hostOrOptions, oldProgramOrHost, configFileParsingDiagnosticsOrOldProgram, configFileParsingDiagnostics, projectReferences);
167170
return createRedirectedBuilderProgram(() => ({ program: newProgram, compilerOptions: newProgram.getCompilerOptions() }), newConfigFileParsingDiagnostics);
168171
}
169-
}

src/compiler/builderState.ts

+45-43
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { Program, SourceFile, CancellationToken, CustomTransformers, EmitOutput, OutputFile, ReadonlyESMap, Path, ESMap, Symbol, mapDefined, getSourceFileOfNode, TypeChecker, StringLiteralLike, GetCanonicalFileName, toPath, getDirectoryPath, isStringLiteral, ModuleKind, Debug, emptyArray, firstOrUndefined, fileExtensionIsOneOf, Extension, getAnyExtensionFromPath, generateDjb2Hash, ExportedModulesFromDeclarationEmit, outFile, arrayFrom, mapDefinedIterator, isModuleWithStringLiteralName, some, isGlobalScopeAugmentation, ModuleDeclaration, isExternalOrCommonJsModule, isJsonSourceFile } from "./ts";
2+
import * as ts from "./ts";
13
/*@internal*/
2-
namespace ts {
3-
export function getFileEmitOutput(program: Program, sourceFile: SourceFile, emitOnlyDtsFiles: boolean,
4-
cancellationToken?: CancellationToken, customTransformers?: CustomTransformers, forceDtsEmit?: boolean): EmitOutput {
4+
export function getFileEmitOutput(program: Program, sourceFile: SourceFile, emitOnlyDtsFiles: boolean, cancellationToken?: CancellationToken, customTransformers?: CustomTransformers, forceDtsEmit?: boolean): EmitOutput {
55
const outputFiles: OutputFile[] = [];
66
const { emitSkipped, diagnostics, exportedModulesFromDeclarationEmit } = program.emit(sourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers, forceDtsEmit);
77
return { outputFiles, emitSkipped, diagnostics, exportedModulesFromDeclarationEmit };
@@ -11,6 +11,7 @@ export function getFileEmitOutput(program: Program, sourceFile: SourceFile, emit
1111
}
1212
}
1313

14+
/* @internal */
1415
export interface ReusableBuilderState {
1516
/**
1617
* Information of the file eg. its version, signature etc
@@ -29,6 +30,7 @@ export interface ReusableBuilderState {
2930
readonly exportedModulesMap?: BuilderState.ReadonlyManyToManyPathMap | undefined;
3031
}
3132

33+
/* @internal */
3234
export interface BuilderState {
3335
/**
3436
* Information of the file eg. its version, signature etc
@@ -49,8 +51,8 @@ export interface BuilderState {
4951
readonly exportedModulesMap: BuilderState.ManyToManyPathMap | undefined;
5052

5153
previousCache?: {
52-
id: number,
53-
version: number,
54+
id: number;
55+
version: number;
5456
};
5557

5658
/**
@@ -63,7 +65,7 @@ export interface BuilderState {
6365
* That means hence forth these files are assumed to have
6466
* no change in their signature for this version of the program
6567
*/
66-
hasCalledUpdateShapeSignature: Set<Path>;
68+
hasCalledUpdateShapeSignature: ts.Set<Path>;
6769
/**
6870
* Cache of all files excluding default library file for the current program
6971
*/
@@ -74,6 +76,7 @@ export interface BuilderState {
7476
allFileNames?: readonly string[];
7577
}
7678

79+
/* @internal */
7780
export namespace BuilderState {
7881
/**
7982
* Information about the source file: Its version and optional signature from last emit
@@ -88,34 +91,34 @@ export namespace BuilderState {
8891
export interface ReadonlyManyToManyPathMap {
8992
readonly id: number;
9093
clone(): ManyToManyPathMap;
91-
forEach(action: (v: ReadonlySet<Path>, k: Path) => void): void;
92-
getKeys(v: Path): ReadonlySet<Path> | undefined;
93-
getValues(k: Path): ReadonlySet<Path> | undefined;
94+
forEach(action: (v: ts.ReadonlySet<Path>, k: Path) => void): void;
95+
getKeys(v: Path): ts.ReadonlySet<Path> | undefined;
96+
getValues(k: Path): ts.ReadonlySet<Path> | undefined;
9497
hasKey(k: Path): boolean;
95-
keys(): Iterator<Path>;
98+
keys(): ts.Iterator<Path>;
9699

97100
/**
98101
* The set of arguments to {@link deleteKeys} which have not subsequently
99102
* been arguments to {@link set}. Note that a key does not have to have
100103
* ever been in the map to appear in this set.
101104
*/
102-
deletedKeys(): ReadonlySet<Path> | undefined;
105+
deletedKeys(): ts.ReadonlySet<Path> | undefined;
103106
}
104107

105108
export interface ManyToManyPathMap extends ReadonlyManyToManyPathMap {
106109
version(): number; // Incremented each time the contents are changed
107110
deleteKey(k: Path): boolean;
108-
set(k: Path, v: ReadonlySet<Path>): void;
111+
set(k: Path, v: ts.ReadonlySet<Path>): void;
109112
}
110113

111114
let manyToManyPathMapCount = 0;
112115
export function createManyToManyPathMap(): ManyToManyPathMap {
113-
function create(forward: ESMap<Path, ReadonlySet<Path>>, reverse: ESMap<Path, Set<Path>>, deleted: Set<Path> | undefined): ManyToManyPathMap {
116+
function create(forward: ESMap<Path, ts.ReadonlySet<Path>>, reverse: ESMap<Path, ts.Set<Path>>, deleted: ts.Set<Path> | undefined): ManyToManyPathMap {
114117
let version = 0;
115118
const map: ManyToManyPathMap = {
116119
id: manyToManyPathMapCount++,
117120
version: () => version,
118-
clone: () => create(new Map(forward), new Map(reverse), deleted && new Set(deleted)),
121+
clone: () => create(new ts.Map(forward), new ts.Map(reverse), deleted && new ts.Set(deleted)),
119122
forEach: fn => forward.forEach(fn),
120123
getKeys: v => reverse.get(v),
121124
getValues: k => forward.get(k),
@@ -124,7 +127,7 @@ export namespace BuilderState {
124127

125128
deletedKeys: () => deleted,
126129
deleteKey: k => {
127-
(deleted ||= new Set<Path>()).add(k);
130+
(deleted ||= new ts.Set<Path>()).add(k);
128131

129132
const set = forward.get(k);
130133
if (!set) {
@@ -167,19 +170,19 @@ export namespace BuilderState {
167170
return map;
168171
}
169172

170-
return create(new Map<Path, Set<Path>>(), new Map<Path, Set<Path>>(), /*deleted*/ undefined);
173+
return create(new ts.Map<Path, ts.Set<Path>>(), new ts.Map<Path, ts.Set<Path>>(), /*deleted*/ undefined);
171174
}
172175

173-
function addToMultimap<K, V>(map: ESMap<K, Set<V>>, k: K, v: V): void {
176+
function addToMultimap<K, V>(map: ESMap<K, ts.Set<V>>, k: K, v: V): void {
174177
let set = map.get(k);
175178
if (!set) {
176-
set = new Set<V>();
179+
set = new ts.Set<V>();
177180
map.set(k, set);
178181
}
179182
set.add(v);
180183
}
181184

182-
function deleteFromMultimap<K, V>(map: ESMap<K, Set<V>>, k: K, v: V, removeEmpty = true): boolean {
185+
function deleteFromMultimap<K, V>(map: ESMap<K, ts.Set<V>>, k: K, v: V, removeEmpty = true): boolean {
183186
const set = map.get(k);
184187

185188
if (set?.delete(v)) {
@@ -219,8 +222,8 @@ export namespace BuilderState {
219222
/**
220223
* Gets the referenced files for a file from the program with values for the keys as referenced file's path to be true
221224
*/
222-
function getReferencedFiles(program: Program, sourceFile: SourceFile, getCanonicalFileName: GetCanonicalFileName): Set<Path> | undefined {
223-
let referencedFiles: Set<Path> | undefined;
225+
function getReferencedFiles(program: Program, sourceFile: SourceFile, getCanonicalFileName: GetCanonicalFileName): ts.Set<Path> | undefined {
226+
let referencedFiles: ts.Set<Path> | undefined;
224227

225228
// We need to use a set here since the code can contain the same import twice,
226229
// but that will only be one dependency.
@@ -259,9 +262,11 @@ export namespace BuilderState {
259262
if (sourceFile.moduleAugmentations.length) {
260263
const checker = program.getTypeChecker();
261264
for (const moduleName of sourceFile.moduleAugmentations) {
262-
if (!isStringLiteral(moduleName)) continue;
265+
if (!isStringLiteral(moduleName))
266+
continue;
263267
const symbol = checker.getSymbolAtLocation(moduleName);
264-
if (!symbol) continue;
268+
if (!symbol)
269+
continue;
265270

266271
// Add any file other than our own as reference
267272
addReferenceFromAmbientModule(symbol);
@@ -292,7 +297,7 @@ export namespace BuilderState {
292297
}
293298

294299
function addReferencedFile(referencedPath: Path) {
295-
(referencedFiles || (referencedFiles = new Set())).add(referencedPath);
300+
(referencedFiles || (referencedFiles = new ts.Set())).add(referencedPath);
296301
}
297302
}
298303

@@ -307,10 +312,10 @@ export namespace BuilderState {
307312
* Creates the state of file references and signature for the new program from oldState if it is safe
308313
*/
309314
export function create(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState?: Readonly<ReusableBuilderState>, disableUseFileVersionAsSignature?: boolean): BuilderState {
310-
const fileInfos = new Map<Path, FileInfo>();
315+
const fileInfos = new ts.Map<Path, FileInfo>();
311316
const referencedMap = newProgram.getCompilerOptions().module !== ModuleKind.None ? createManyToManyPathMap() : undefined;
312317
const exportedModulesMap = referencedMap ? createManyToManyPathMap() : undefined;
313-
const hasCalledUpdateShapeSignature = new Set<Path>();
318+
const hasCalledUpdateShapeSignature = new ts.Set<Path>();
314319
const useOldState = canReuseOldState(referencedMap, oldState);
315320

316321
// Ensure source files have parent pointers set
@@ -359,10 +364,10 @@ export namespace BuilderState {
359364
export function clone(state: Readonly<BuilderState>): BuilderState {
360365
// Dont need to backup allFiles info since its cache anyway
361366
return {
362-
fileInfos: new Map(state.fileInfos),
367+
fileInfos: new ts.Map(state.fileInfos),
363368
referencedMap: state.referencedMap?.clone(),
364369
exportedModulesMap: state.exportedModulesMap?.clone(),
365-
hasCalledUpdateShapeSignature: new Set(state.hasCalledUpdateShapeSignature),
370+
hasCalledUpdateShapeSignature: new ts.Set(state.hasCalledUpdateShapeSignature),
366371
useFileVersionAsSignature: state.useFileVersionAsSignature,
367372
};
368373
}
@@ -375,7 +380,7 @@ export namespace BuilderState {
375380
// They will be committed once it is safe to use them
376381
// eg when calling this api from tsserver, if there is no cancellation of the operation
377382
// In the other cases the affected files signatures are committed only after the iteration through the result is complete
378-
const signatureCache = cacheToUpdateSignature || new Map();
383+
const signatureCache = cacheToUpdateSignature || new ts.Map();
379384
const sourceFile = programOfThisState.getSourceFileByPath(path);
380385
if (!sourceFile) {
381386
return emptyArray;
@@ -419,19 +424,16 @@ export namespace BuilderState {
419424
}
420425

421426
const info = state.fileInfos.get(sourceFile.resolvedPath);
422-
if (!info) return Debug.fail();
427+
if (!info)
428+
return Debug.fail();
423429

424430
const prevSignature = info.signature;
425431
let latestSignature: string | undefined;
426432
if (!sourceFile.isDeclarationFile && !useFileVersionAsSignature) {
427-
const emitOutput = getFileEmitOutput(
428-
programOfThisState,
429-
sourceFile,
430-
/*emitOnlyDtsFiles*/ true,
431-
cancellationToken,
433+
const emitOutput = getFileEmitOutput(programOfThisState, sourceFile,
434+
/*emitOnlyDtsFiles*/ true, cancellationToken,
432435
/*customTransformers*/ undefined,
433-
/*forceDtsEmit*/ true
434-
);
436+
/*forceDtsEmit*/ true);
435437
const firstDts = firstOrUndefined(emitOutput.outputFiles);
436438
if (firstDts) {
437439
Debug.assert(fileExtensionIsOneOf(firstDts.name, [Extension.Dts, Extension.Dmts, Extension.Dcts]), "File extension for signature expected to be dts", () => `Found: ${getAnyExtensionFromPath(firstDts.name)} for ${firstDts.name}:: All output files: ${JSON.stringify(emitOutput.outputFiles.map(f => f.name))}`);
@@ -468,7 +470,7 @@ export namespace BuilderState {
468470
return;
469471
}
470472

471-
let exportedModules: Set<Path> | undefined;
473+
let exportedModules: ts.Set<Path> | undefined;
472474
exportedModulesFromDeclarationEmit.forEach(symbol => addExportedModule(getReferencedFilesFromImportedModuleSymbol(symbol)));
473475
if (exportedModules) {
474476
exportedModulesMapCache.set(sourceFile.resolvedPath, exportedModules);
@@ -480,7 +482,7 @@ export namespace BuilderState {
480482
function addExportedModule(exportedModulePaths: Path[] | undefined) {
481483
if (exportedModulePaths?.length) {
482484
if (!exportedModules) {
483-
exportedModules = new Set();
485+
exportedModules = new ts.Set();
484486
}
485487
exportedModulePaths.forEach(path => exportedModules!.add(path));
486488
}
@@ -531,7 +533,7 @@ export namespace BuilderState {
531533
}
532534

533535
// Get the references, traversing deep from the referenceMap
534-
const seenMap = new Set<Path>();
536+
const seenMap = new ts.Set<Path>();
535537
const queue = [sourceFile.resolvedPath];
536538
while (queue.length) {
537539
const path = queue.pop()!;
@@ -610,7 +612,8 @@ export namespace BuilderState {
610612
}
611613

612614
let result: SourceFile[] | undefined;
613-
if (firstSourceFile) addSourceFile(firstSourceFile);
615+
if (firstSourceFile)
616+
addSourceFile(firstSourceFile);
614617
for (const sourceFile of programOfThisState.getSourceFiles()) {
615618
if (sourceFile !== firstSourceFile) {
616619
addSourceFile(sourceFile);
@@ -655,7 +658,7 @@ export namespace BuilderState {
655658
// Now we need to if each file in the referencedBy list has a shape change as well.
656659
// Because if so, its own referencedBy files need to be saved as well to make the
657660
// emitting result consistent with files on disk.
658-
const seenFileNamesMap = new Map<Path, SourceFile>();
661+
const seenFileNamesMap = new ts.Map<Path, SourceFile>();
659662

660663
// Start with the paths this file was referenced by
661664
seenFileNamesMap.set(sourceFileWithUpdatedShape.resolvedPath, sourceFileWithUpdatedShape);
@@ -675,4 +678,3 @@ export namespace BuilderState {
675678
return arrayFrom(mapDefinedIterator(seenFileNamesMap.values(), value => value));
676679
}
677680
}
678-
}

src/compiler/builderStatePublic.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ts {
1+
import { Diagnostic, ExportedModulesFromDeclarationEmit } from "./ts";
22
export interface EmitOutput {
33
outputFiles: OutputFile[];
44
emitSkipped: boolean;
@@ -11,4 +11,3 @@ export interface OutputFile {
1111
writeByteOrderMark: boolean;
1212
text: string;
1313
}
14-
}

src/compiler/checker.ts

+2,698-3,460
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)