Skip to content

createProgram calls host.getSourceFile multiple times #26259

Open
@ajafff

Description

@ajafff

TypeScript Version: 3.1.0-dev.20180807

Search Terms:

Repro

declare let oldProgram: ts.Program;
const originalHost = ts.createCompilerHost(true);
const host = {
  ... originalHost,
  getSourceFile(fileName, ...args) {
    console.log(fileName);
    return originalHost.getSoruceFile(fileName, ...args);
  }
const newProgram = ts.createProgram(oldProgram.getRootFileNames(), oldProgram.getCompilerOptions(), host, oldProgram);

Expected behavior:

Each fileName is logged once.

Actual behavior:

If structureIsReused !== Completely fileNames are logged twice: one time from tryReuseStructureFromOldProgram and another time from findSourceFile. That means these SourceFiles are requested multiple times. This is especially a problem with the default CompilerHost which has no caching. It therefore reads and parses each file multiple times, but only the last one is actually used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsThe issue relates to how you learn TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions