Fix the assert of reporting file infos still attached to the project for circular json reference

This commit is contained in:
Sheetal Nandi
2019-07-19 15:55:22 -07:00
parent e543d8bc5a
commit aab3069e64
2 changed files with 35 additions and 1 deletions

View File

@@ -1087,7 +1087,24 @@ namespace ts.server {
project.close();
if (Debug.shouldAssert(AssertionLevel.Normal)) {
this.filenameToScriptInfo.forEach(info => Debug.assert(!info.isAttached(project), "Found script Info still attached to project", () => `${project.projectName}: ScriptInfos still attached: ${JSON.stringify(mapDefined(arrayFrom(this.filenameToScriptInfo.values()), info => info.isAttached(project) ? info : undefined))}`));
this.filenameToScriptInfo.forEach(info => Debug.assert(
!info.isAttached(project),
"Found script Info still attached to project",
() => `${project.projectName}: ScriptInfos still attached: ${JSON.stringify(
arrayFrom(
mapDefinedIterator(
this.filenameToScriptInfo.values(),
info => info.isAttached(project) ?
{
fileName: info.fileName,
projects: info.containingProjects.map(p => p.projectName),
hasMixedContent: info.hasMixedContent
} : undefined
)
),
/*replacer*/ undefined,
" "
)}`));
}
// Remove the project from pending project updates
this.pendingProjectUpdates.delete(project.getProjectName());

View File

@@ -1467,5 +1467,22 @@ var x = 10;`
openFilesForSession([{ file, projectRootPath }], session);
}
});
it("assert when removing project", () => {
const host = createServerHost([commonFile1, commonFile2, libFile]);
const service = createProjectService(host);
service.openClientFile(commonFile1.path);
const project = service.inferredProjects[0];
checkProjectActualFiles(project, [commonFile1.path, libFile.path]);
// Intentionally create scriptinfo and attach it to project
const info = service.getOrCreateScriptInfoForNormalizedPath(commonFile2.path as server.NormalizedPath, /*openedByClient*/ false)!;
info.attachToProject(project);
try {
service.applyChangesInOpenFiles(/*openFiles*/ undefined, /*changedFiles*/ undefined, [commonFile1.path]);
}
catch (e) {
assert.isTrue(e.message.indexOf("Debug Failure. False expression: Found script Info still attached to project") === 0);
}
});
});
}