Skip to content

Commit 0f626fd

Browse files
committed
Last round PR comments
1 parent b97bc8e commit 0f626fd

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

src/compiler/tsbuild.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,36 +246,39 @@ namespace ts {
246246
}
247247

248248
export function createDependencyMapper() {
249-
const childToParents: { [key: string]: ResolvedConfigFileName[] } = {};
250-
const parentToChildren: { [key: string]: ResolvedConfigFileName[] } = {};
251-
const allKeys: ResolvedConfigFileName[] = [];
249+
const childToParents = createFileMap<ResolvedConfigFileName[]>();
250+
const parentToChildren = createFileMap<ResolvedConfigFileName[]>();
251+
const allKeys = createFileMap<true>();
252252

253253
function addReference(childConfigFileName: ResolvedConfigFileName, parentConfigFileName: ResolvedConfigFileName): void {
254254
addEntry(childToParents, childConfigFileName, parentConfigFileName);
255255
addEntry(parentToChildren, parentConfigFileName, childConfigFileName);
256256
}
257257

258258
function getReferencesTo(parentConfigFileName: ResolvedConfigFileName): ResolvedConfigFileName[] {
259-
return parentToChildren[normalizePath(parentConfigFileName)] || [];
259+
return parentToChildren.getValueOrUndefined(parentConfigFileName) || [];
260260
}
261261

262262
function getReferencesOf(childConfigFileName: ResolvedConfigFileName): ResolvedConfigFileName[] {
263-
return childToParents[normalizePath(childConfigFileName)] || [];
263+
return childToParents.getValueOrUndefined(childConfigFileName) || [];
264264
}
265265

266266
function getKeys(): ReadonlyArray<ResolvedConfigFileName> {
267-
return allKeys;
267+
return allKeys.getKeys() as ResolvedConfigFileName[];
268268
}
269269

270270
function addEntry(mapToAddTo: typeof childToParents | typeof parentToChildren, key: ResolvedConfigFileName, element: ResolvedConfigFileName) {
271271
key = normalizePath(key) as ResolvedConfigFileName;
272272
element = normalizePath(element) as ResolvedConfigFileName;
273-
const arr = (mapToAddTo[key] = mapToAddTo[key] || []);
273+
let arr = mapToAddTo.getValueOrUndefined(key);
274+
if (arr === undefined) {
275+
mapToAddTo.setValue(key, arr = []);
276+
}
274277
if (arr.indexOf(element) < 0) {
275278
arr.push(element);
276279
}
277-
if (allKeys.indexOf(key) < 0) allKeys.push(key);
278-
if (allKeys.indexOf(element) < 0) allKeys.push(element);
280+
allKeys.setValue(key, true);
281+
allKeys.setValue(element, true);
279282
}
280283

281284
return {
@@ -289,13 +292,13 @@ namespace ts {
289292
function getOutputDeclarationFileName(inputFileName: string, configFile: ParsedCommandLine) {
290293
const relativePath = getRelativePathFromDirectory(rootDirOfOptions(configFile.options, configFile.options.configFilePath!), inputFileName, /*ignoreCase*/ true);
291294
const outputPath = resolvePath(configFile.options.declarationDir || configFile.options.outDir || getDirectoryPath(configFile.options.configFilePath!), relativePath);
292-
return changeExtension(outputPath, ".d.ts");
295+
return changeExtension(outputPath, Extension.Dts);
293296
}
294297

295298
function getOutputJavaScriptFileName(inputFileName: string, configFile: ParsedCommandLine) {
296299
const relativePath = getRelativePathFromDirectory(rootDirOfOptions(configFile.options, configFile.options.configFilePath!), inputFileName, /*ignoreCase*/ true);
297300
const outputPath = resolvePath(configFile.options.outDir || getDirectoryPath(configFile.options.configFilePath!), relativePath);
298-
return changeExtension(outputPath, (fileExtensionIs(inputFileName, ".tsx") && configFile.options.jsx === JsxEmit.Preserve) ? ".jsx" : ".js");
301+
return changeExtension(outputPath, (fileExtensionIs(inputFileName, Extension.Tsx) && configFile.options.jsx === JsxEmit.Preserve) ? Extension.Jsx : Extension.Js);
299302
}
300303

301304
function getOutputFileNames(inputFileName: string, configFile: ParsedCommandLine): ReadonlyArray<string> {
@@ -316,12 +319,12 @@ namespace ts {
316319

317320
function getOutFileOutputs(project: ParsedCommandLine): ReadonlyArray<string> {
318321
if (!project.options.outFile) {
319-
throw new Error("Assert - outFile must be set");
322+
return Debug.fail("outFile must be set");
320323
}
321324
const outputs: string[] = [];
322325
outputs.push(project.options.outFile);
323326
if (project.options.declaration) {
324-
const dts = changeExtension(project.options.outFile, ".d.ts");
327+
const dts = changeExtension(project.options.outFile, Extension.Dts);
325328
outputs.push(dts);
326329
if (project.options.declarationMap) {
327330
outputs.push(dts + ".map");
@@ -365,7 +368,7 @@ namespace ts {
365368
}
366369

367370
function isDeclarationFile(fileName: string) {
368-
return fileExtensionIs(fileName, ".d.ts");
371+
return fileExtensionIs(fileName, Extension.Dts);
369372
}
370373

371374
export function createBuildContext(options: BuildOptions): BuildContext {

0 commit comments

Comments
 (0)