Skip to content

canReuseProjectReferences crashes with custom CompilerHost#getParsedCommandLine #31218

@ajafff

Description

@ajafff

TypeScript Version: 3.5.0-dev.20190502

If CompilerHost#getParsedCommandLine is present, parseProjectReferenceConfigFile uses a different branch, which doesn't set SourceFile#path. That's no big deal if getParsedCommandLine uses ts.getParsedCommandLineOfConfigFile as that one already initializes SourceFile#path.

In my case however, getParsedCommandLine uses ts.parseJsonSourceFileConfigFileContent which doesn't set SourceFile#path.
That causes updating an old Program using ts.createProgram to crash in canReuseProjectReferences because getResolvedProjectReferenceByPath(parent.sourceFile.path) returns undefined.

Note that in my particular setup I had a non-existant config file in references, but that shouldn't be necessary to trigger this bug.

If you are not able to reproduce, I can try to extract a minimal repro.

Stacktrace:

TypeError: Cannot read property 'commandLine' of undefined
    at /Users/klaus/code/wotan/node_modules/typescript/lib/typescript.js:89345:103
    at worker (/Users/klaus/code/wotan/node_modules/typescript/lib/typescript.js:90417:34)
    at /Users/klaus/code/wotan/node_modules/typescript/lib/typescript.js:90434:28
    at Object.forEach (/Users/klaus/code/wotan/node_modules/typescript/lib/typescript.js:280:30)
    at worker (/Users/klaus/code/wotan/node_modules/typescript/lib/typescript.js:90422:27)
    at forEachProjectReference (/Users/klaus/code/wotan/node_modules/typescript/lib/typescript.js:90413:20)
    at canReuseProjectReferences (/Users/klaus/code/wotan/node_modules/typescript/lib/typescript.js:89332:21)
    at tryReuseStructureFromOldProgram (/Users/klaus/code/wotan/node_modules/typescript/lib/typescript.js:89369:18)
    at Object.createProgram (/Users/klaus/code/wotan/node_modules/typescript/lib/typescript.js:89012:34)
    at ProjectHost.createProgram (/Users/klaus/code/wotan/packages/wotan/src/project-host.js:188:19)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions