Skip to content

Commit 8334c9b

Browse files
authored
fix(cache): invalidate codeCache in most cases when imports change (#369)
* fix(cache): invalidate declarations when imports change - previously, the `checkImports` flag was set to `true` for type-checking, but `false` for compilation - I _believe_ it is `false` because the compiled JS shouldn't change if an import changes - though I'm not sure if that was the original intent behind the code - problematically though, compilation results can include declarations, and those _can_ change if imports change - for instance, the types of an import can change the declaration that is output - so now, only set it to `false` for compilation if declarations are _not_ needed * add `!isolatedModules` check as well - ezolenko gave a good example of enums, which can indeed cause the compiled JS code to change based on imports - so also check `!isolatedModules` as well - I thought it might be the case that the code wouldn't handle other edge cases, but couldn't think of one off the top of my head - ironically, I compared it to Babel, which transpiles per file, and Babel _requires_ `isolatedModules` to work
1 parent 63a644a commit 8334c9b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/tscache.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ export class TsCache
213213
public getCompiled(id: string, snapshot: tsTypes.IScriptSnapshot, transform: () => ICode | undefined): ICode | undefined
214214
{
215215
this.context.info(`${blue("transpiling")} '${id}'`);
216-
return this.getCached(this.codeCache, id, snapshot, false, transform);
216+
// if !isolatedModules, compiled JS code can change if its imports do (e.g. enums). also, declarations can change based on imports as well
217+
return this.getCached(this.codeCache, id, snapshot, Boolean(!this.options.isolatedModules || this.options.declaration), transform);
217218
}
218219

219220
public getSyntacticDiagnostics(id: string, snapshot: tsTypes.IScriptSnapshot, check: () => tsTypes.Diagnostic[]): IDiagnostics[]

0 commit comments

Comments
 (0)