Skip to content

Commit 634a9e3

Browse files
kitsonkry
authored andcommitted
Updates to compiler.ts comments and logging.
1 parent 54aefa2 commit 634a9e3

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

js/compiler.ts

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,25 @@ type AMDRequire = (
2525
errback: AmdErrback
2626
) => void;
2727

28-
// The location that a module is being loaded from. This could be a directory,
29-
// like ".", or it could be a module specifier like
30-
// "http://gist.github.com/somefile.ts"
28+
/**
29+
* The location that a module is being loaded from. This could be a directory,
30+
* like `.`, or it could be a module specifier like
31+
* `http://gist.github.com/somefile.ts`
32+
*/
3133
type ContainingFile = string;
32-
// The internal local filename of a compiled module. It will often be something
33-
// like "/home/ry/.deno/gen/f7b4605dfbc4d3bb356e98fda6ceb1481e4a8df5.js"
34+
/**
35+
* The internal local filename of a compiled module. It will often be something
36+
* like `/home/ry/.deno/gen/f7b4605dfbc4d3bb356e98fda6ceb1481e4a8df5.js`
37+
*/
3438
type ModuleFileName = string;
35-
// The external name of a module - could be a URL or could be a relative path.
36-
// Examples "http://gist.github.com/somefile.ts" or "./somefile.ts"
39+
/**
40+
* The external name of a module - could be a URL or could be a relative path.
41+
* Examples `http://gist.github.com/somefile.ts` or `./somefile.ts`
42+
*/
3743
type ModuleSpecifier = string;
38-
// The compiled source code which is cached in .deno/gen/
44+
/**
45+
* The compiled source code which is cached in `.deno/gen/`
46+
*/
3947
type OutputCode = string;
4048

4149
/**
@@ -72,7 +80,7 @@ export class ModuleMetaData implements ts.IScriptSnapshot {
7280
public scriptVersion = "";
7381

7482
constructor(
75-
public readonly fileName: string,
83+
public readonly fileName: ModuleFileName,
7684
public readonly sourceCode = "",
7785
public outputCode = ""
7886
) {
@@ -311,7 +319,7 @@ export class DenoCompiler implements ts.LanguageServiceHost {
311319
sourceMaps.install({
312320
installPrepareStackTrace: true,
313321
getGeneratedContents: (fileName: string): string | RawSourceMap => {
314-
this._log("getGeneratedContents", fileName);
322+
this._log("compiler.getGeneratedContents", fileName);
315323
if (fileName === "gen/bundle/main.js") {
316324
assert(libdeno.mainSource.length > 0);
317325
return libdeno.mainSource;
@@ -322,7 +330,7 @@ export class DenoCompiler implements ts.LanguageServiceHost {
322330
} else {
323331
const moduleMetaData = this._moduleMetaDataMap.get(fileName);
324332
if (!moduleMetaData) {
325-
this._log("getGeneratedContents cannot find", fileName);
333+
this._log("compiler.getGeneratedContents cannot find", fileName);
326334
return "";
327335
}
328336
return moduleMetaData.outputCode;
@@ -342,7 +350,8 @@ export class DenoCompiler implements ts.LanguageServiceHost {
342350
// Deno specific compiler API
343351

344352
/**
345-
* Retrieve the output of the TypeScript compiler for a given `fileName`.
353+
* Retrieve the output of the TypeScript compiler for a given module and
354+
* cache the result.
346355
*/
347356
compile(moduleMetaData: ModuleMetaData): OutputCode {
348357
this._log("compiler.compile", moduleMetaData.fileName);
@@ -459,7 +468,7 @@ export class DenoCompiler implements ts.LanguageServiceHost {
459468
moduleSpecifier: ModuleSpecifier,
460469
containingFile: ContainingFile
461470
): ModuleFileName | undefined {
462-
this._log("resolveFileName", { moduleSpecifier, containingFile });
471+
this._log("compiler.resolveFileName", { moduleSpecifier, containingFile });
463472
const innerMap = this._fileNamesMap.get(containingFile);
464473
if (innerMap) {
465474
return innerMap.get(moduleSpecifier);
@@ -475,7 +484,7 @@ export class DenoCompiler implements ts.LanguageServiceHost {
475484
moduleSpecifier: ModuleSpecifier,
476485
containingFile: ContainingFile
477486
): ModuleMetaData {
478-
this._log("resolveModule", { moduleSpecifier, containingFile });
487+
this._log("compiler.resolveModule", { moduleSpecifier, containingFile });
479488
assert(moduleSpecifier != null && moduleSpecifier.length > 0);
480489
let fileName = this.resolveFileName(moduleSpecifier, containingFile);
481490
if (fileName && this._moduleMetaDataMap.has(fileName)) {
@@ -519,7 +528,8 @@ export class DenoCompiler implements ts.LanguageServiceHost {
519528
containingFile
520529
);
521530
}
522-
this._log("resolveModule sourceCode length ", sourceCode.length);
531+
this._log("resolveModule sourceCode length:", sourceCode.length);
532+
this._log("resolveModule has outputCode:", !!outputCode);
523533
this.setFileName(moduleSpecifier, containingFile, fileName);
524534
if (fileName && this._moduleMetaDataMap.has(fileName)) {
525535
return this._moduleMetaDataMap.get(fileName)!;
@@ -536,6 +546,7 @@ export class DenoCompiler implements ts.LanguageServiceHost {
536546
moduleSpecifier: ModuleSpecifier,
537547
containingFile: ContainingFile
538548
): ModuleFileName | undefined {
549+
// TODO should this be part of the public API of the compiler?
539550
const moduleMetaData = this.resolveModule(moduleSpecifier, containingFile);
540551
return moduleMetaData ? moduleMetaData.fileName : undefined;
541552
}
@@ -568,7 +579,8 @@ export class DenoCompiler implements ts.LanguageServiceHost {
568579
containingFile: ContainingFile,
569580
fileName: ModuleFileName
570581
): void {
571-
this._log("setFileName", { moduleSpecifier, containingFile });
582+
// TODO should this be part of the public API of the compiler?
583+
this._log("compiler.setFileName", { moduleSpecifier, containingFile });
572584
let innerMap = this._fileNamesMap.get(containingFile);
573585
if (!innerMap) {
574586
innerMap = new Map();
@@ -634,27 +646,27 @@ export class DenoCompiler implements ts.LanguageServiceHost {
634646
}
635647

636648
useCaseSensitiveFileNames(): boolean {
637-
this._log("useCaseSensitiveFileNames");
649+
this._log("useCaseSensitiveFileNames()");
638650
return true;
639651
}
640652

641653
readFile(path: string): string | undefined {
642-
this._log("readFile", path);
654+
this._log("readFile()", path);
643655
return notImplemented();
644656
}
645657

646658
fileExists(fileName: string): boolean {
647659
const moduleMetaData = this._getModuleMetaData(fileName);
648660
const exists = moduleMetaData != null;
649-
this._log("fileExists", fileName, exists);
661+
this._log("fileExists()", fileName, exists);
650662
return exists;
651663
}
652664

653665
resolveModuleNames(
654666
moduleNames: ModuleSpecifier[],
655667
containingFile: ContainingFile
656668
): ts.ResolvedModule[] {
657-
this._log("resolveModuleNames", { moduleNames, containingFile });
669+
this._log("resolveModuleNames()", { moduleNames, containingFile });
658670
return moduleNames.map(name => {
659671
let resolvedFileName;
660672
if (name === "deno") {

0 commit comments

Comments
 (0)