Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit dd0f489

Browse files
jjuddevmar
authored andcommitted
Correctly compare paths to files in the current directory. (#152)
If the tsickle main function is run against files in the same directory, then closure type comments are not added to the outputted JavaScript. For example, if you run tsickle against './hello.ts' then the outputted hello.js will not have type comments. This occurs because the sourceReplacingCompilerHost compares fileNames to determine whether we ran tsickle on the source file. 'hello.ts' is compared to './hello.ts' and we incorrectly skip the file. This is fixed by comparing the path to the files using the TypeScript sys utilities.
1 parent 5d40ad1 commit dd0f489

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/main.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,12 @@ function createSourceReplacingCompilerHost(
143143
fileName: string, languageVersion: ts.ScriptTarget,
144144
onError?: (message: string) => void): ts.SourceFile {
145145
let sourceText: string;
146-
if (substituteSource.hasOwnProperty(fileName)) {
147-
sourceText = substituteSource[fileName];
148-
return ts.createSourceFile(fileName, sourceText, languageVersion);
146+
let path: string = ts.sys.resolvePath(fileName);
147+
if (substituteSource.hasOwnProperty(path)) {
148+
sourceText = substituteSource[path];
149+
return ts.createSourceFile(path, sourceText, languageVersion);
149150
}
150-
return delegate.getSourceFile(fileName, languageVersion, onError);
151+
return delegate.getSourceFile(path, languageVersion, onError);
151152
}
152153
}
153154

@@ -182,7 +183,7 @@ function toClosureJS(options: ts.CompilerOptions, fileNames: string[]):
182183
if (diagnostics.length > 0) {
183184
return {errors: diagnostics};
184185
}
185-
tsickleOutput[fileName] = output;
186+
tsickleOutput[ts.sys.resolvePath(fileName)] = output;
186187
if (externs) {
187188
tsickleExterns += externs;
188189
}

0 commit comments

Comments
 (0)