Skip to content

Commit 5e3fa9b

Browse files
authored
There is no use of creating reference map with --out since its not used anyways (#51379)
* Convert some of the tests to baselines * There is no use of creating reference map with --out since its not used anyways. The changes to affectedFileList returned should be intended since --out needs saving just one file for correct output and not both
1 parent 7cf842b commit 5e3fa9b

7 files changed

+1562
-119
lines changed

src/compiler/builderState.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ namespace ts {
264264
*/
265265
export function create(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState?: Readonly<BuilderState>, disableUseFileVersionAsSignature?: boolean): BuilderState {
266266
const fileInfos = new Map<Path, FileInfo>();
267-
const referencedMap = newProgram.getCompilerOptions().module !== ModuleKind.None ? createManyToManyPathMap() : undefined;
267+
const options = newProgram.getCompilerOptions();
268+
const referencedMap = options.module !== ModuleKind.None && !outFile(options) ?
269+
createManyToManyPathMap() : undefined;
268270
const exportedModulesMap = referencedMap ? createManyToManyPathMap() : undefined;
269271
const useOldState = canReuseOldState(referencedMap, oldState);
270272

src/testRunner/unittests/tsserver/compileOnSave.ts

Lines changed: 82 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -592,51 +592,36 @@ namespace ts.projectSystem {
592592
});
593593

594594
describe("tsserverProjectSystem emit with outFile or out setting", () => {
595-
function test(opts: CompilerOptions, expectedUsesOutFile: boolean) {
596-
const f1 = {
597-
path: "/a/a.ts",
598-
content: "let x = 1"
599-
};
600-
const f2 = {
601-
path: "/a/b.ts",
602-
content: "let y = 1"
603-
};
604-
const config = {
605-
path: "/a/tsconfig.json",
606-
content: JSON.stringify({
607-
compilerOptions: opts,
608-
compileOnSave: true
609-
})
610-
};
611-
const host = createServerHost([f1, f2, config]);
612-
const session = createSession(host);
613-
session.executeCommand({
614-
seq: 1,
615-
type: "request",
616-
command: "open",
617-
arguments: { file: f1.path }
618-
} as protocol.OpenRequest);
619-
checkNumberOfProjects(session.getProjectService(), { configuredProjects: 1 });
620-
const { response } = session.executeCommand({
621-
seq: 2,
622-
type: "request",
623-
command: "compileOnSaveAffectedFileList",
624-
arguments: { file: f1.path }
625-
} as protocol.CompileOnSaveAffectedFileListRequest);
626-
assert.equal((response as protocol.CompileOnSaveAffectedFileListSingleProject[]).length, 1, "expected output for 1 project");
627-
assert.equal((response as protocol.CompileOnSaveAffectedFileListSingleProject[])[0].fileNames.length, 2, "expected output for 1 project");
628-
assert.equal((response as protocol.CompileOnSaveAffectedFileListSingleProject[])[0].projectUsesOutFile, expectedUsesOutFile, "usesOutFile");
595+
function test(subScenario: string, opts: CompilerOptions) {
596+
it(subScenario, () => {
597+
const f1 = {
598+
path: "/a/a.ts",
599+
content: "let x = 1"
600+
};
601+
const f2 = {
602+
path: "/a/b.ts",
603+
content: "let y = 1"
604+
};
605+
const config = {
606+
path: "/a/tsconfig.json",
607+
content: JSON.stringify({
608+
compilerOptions: opts,
609+
compileOnSave: true
610+
})
611+
};
612+
const host = createServerHost([f1, f2, config]);
613+
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
614+
openFilesForSession([f1], session);
615+
session.executeCommandSeq<protocol.CompileOnSaveAffectedFileListRequest>({
616+
command: protocol.CommandTypes.CompileOnSaveAffectedFileList,
617+
arguments: { file: f1.path }
618+
});
619+
baselineTsserverLogs("compileOnSave", subScenario, session);
620+
});
629621
}
630-
631-
it("projectUsesOutFile should not be returned if not set", () => {
632-
test({}, /*expectedUsesOutFile*/ false);
633-
});
634-
it("projectUsesOutFile should be true if outFile is set", () => {
635-
test({ outFile: "/a/out.js" }, /*expectedUsesOutFile*/ true);
636-
});
637-
it("projectUsesOutFile should be true if out is set", () => {
638-
test({ out: "/a/out.js" }, /*expectedUsesOutFile*/ true);
639-
});
622+
test("compileOnSaveAffectedFileList projectUsesOutFile should not be returned if not set", {});
623+
test("compileOnSaveAffectedFileList projectUsesOutFile should be true if outFile is set", { outFile: "/a/out.js" });
624+
test("compileOnSaveAffectedFileList projectUsesOutFile should be true if out is set", { out: "/a/out.js" });
640625
});
641626
});
642627

@@ -991,36 +976,6 @@ function bar() {
991976
});
992977

993978
describe("unittests:: tsserver:: compileOnSave:: CompileOnSaveAffectedFileListRequest with and without projectFileName in request", () => {
994-
const core: File = {
995-
path: `${tscWatch.projectRoot}/core/core.ts`,
996-
content: "let z = 10;"
997-
};
998-
const app1: File = {
999-
path: `${tscWatch.projectRoot}/app1/app.ts`,
1000-
content: "let x = 10;"
1001-
};
1002-
const app2: File = {
1003-
path: `${tscWatch.projectRoot}/app2/app.ts`,
1004-
content: "let y = 10;"
1005-
};
1006-
const app1Config: File = {
1007-
path: `${tscWatch.projectRoot}/app1/tsconfig.json`,
1008-
content: JSON.stringify({
1009-
files: ["app.ts", "../core/core.ts"],
1010-
compilerOptions: { outFile: "build/output.js" },
1011-
compileOnSave: true
1012-
})
1013-
};
1014-
const app2Config: File = {
1015-
path: `${tscWatch.projectRoot}/app2/tsconfig.json`,
1016-
content: JSON.stringify({
1017-
files: ["app.ts", "../core/core.ts"],
1018-
compilerOptions: { outFile: "build/output.js" },
1019-
compileOnSave: true
1020-
})
1021-
};
1022-
const files = [libFile, core, app1, app2, app1Config, app2Config];
1023-
1024979
function insertString(session: TestSession, file: File) {
1025980
session.executeCommandSeq<protocol.ChangeRequest>({
1026981
command: protocol.CommandTypes.Change,
@@ -1035,53 +990,62 @@ function bar() {
1035990
});
1036991
}
1037992

1038-
function getSession() {
1039-
const host = createServerHost(files);
1040-
const session = createSession(host);
1041-
openFilesForSession([app1, app2, core], session);
1042-
const service = session.getProjectService();
1043-
checkNumberOfProjects(session.getProjectService(), { configuredProjects: 2 });
1044-
const project1 = service.configuredProjects.get(app1Config.path)!;
1045-
const project2 = service.configuredProjects.get(app2Config.path)!;
1046-
checkProjectActualFiles(project1, [libFile.path, app1.path, core.path, app1Config.path]);
1047-
checkProjectActualFiles(project2, [libFile.path, app2.path, core.path, app2Config.path]);
1048-
insertString(session, app1);
1049-
insertString(session, app2);
1050-
assert.equal(project1.dirty, true);
1051-
assert.equal(project2.dirty, true);
1052-
return session;
993+
function logDirtyOfProjects(session: TestSession) {
994+
session.logger.logs.push(`Project1 is dirty: ${session.getProjectService().configuredProjects.get(`${tscWatch.projectRoot}/app1/tsconfig.json`)!.dirty}`);
995+
session.logger.logs.push(`Project2 is dirty: ${session.getProjectService().configuredProjects.get(`${tscWatch.projectRoot}/app2/tsconfig.json`)!.dirty}`);
1053996
}
1054997

1055-
it("when projectFile is specified", () => {
1056-
const session = getSession();
1057-
const response = session.executeCommandSeq<protocol.CompileOnSaveAffectedFileListRequest>({
1058-
command: protocol.CommandTypes.CompileOnSaveAffectedFileList,
1059-
arguments: {
1060-
file: core.path,
1061-
projectFileName: app1Config.path
1062-
}
1063-
}).response;
1064-
assert.deepEqual(response, [
1065-
{ projectFileName: app1Config.path, fileNames: [core.path, app1.path], projectUsesOutFile: true }
1066-
]);
1067-
assert.equal(session.getProjectService().configuredProjects.get(app1Config.path)!.dirty, false);
1068-
assert.equal(session.getProjectService().configuredProjects.get(app2Config.path)!.dirty, true);
998+
function verify(subScenario: string, commandArgs: protocol.FileRequestArgs) {
999+
it(subScenario, () => {
1000+
const core: File = {
1001+
path: `${tscWatch.projectRoot}/core/core.ts`,
1002+
content: "let z = 10;"
1003+
};
1004+
const app1: File = {
1005+
path: `${tscWatch.projectRoot}/app1/app.ts`,
1006+
content: "let x = 10;"
1007+
};
1008+
const app2: File = {
1009+
path: `${tscWatch.projectRoot}/app2/app.ts`,
1010+
content: "let y = 10;"
1011+
};
1012+
const app1Config: File = {
1013+
path: `${tscWatch.projectRoot}/app1/tsconfig.json`,
1014+
content: JSON.stringify({
1015+
files: ["app.ts", "../core/core.ts"],
1016+
compilerOptions: { outFile: "build/output.js" },
1017+
compileOnSave: true
1018+
})
1019+
};
1020+
const app2Config: File = {
1021+
path: `${tscWatch.projectRoot}/app2/tsconfig.json`,
1022+
content: JSON.stringify({
1023+
files: ["app.ts", "../core/core.ts"],
1024+
compilerOptions: { outFile: "build/output.js" },
1025+
compileOnSave: true
1026+
})
1027+
};
1028+
const files = [libFile, core, app1, app2, app1Config, app2Config];
1029+
const host = createServerHost(files);
1030+
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
1031+
openFilesForSession([app1, app2, core], session);
1032+
insertString(session, app1);
1033+
insertString(session, app2);
1034+
logDirtyOfProjects(session);
1035+
session.executeCommandSeq<protocol.CompileOnSaveAffectedFileListRequest>({
1036+
command: protocol.CommandTypes.CompileOnSaveAffectedFileList,
1037+
arguments: commandArgs
1038+
});
1039+
logDirtyOfProjects(session);
1040+
baselineTsserverLogs("compileOnSave", subScenario, session);
1041+
});
1042+
}
1043+
verify("CompileOnSaveAffectedFileListRequest when projectFile is specified", {
1044+
file: `${tscWatch.projectRoot}/core/core.ts`,
1045+
projectFileName: `${tscWatch.projectRoot}/app1/tsconfig.json`
10691046
});
1070-
1071-
it("when projectFile is not specified", () => {
1072-
const session = getSession();
1073-
const response = session.executeCommandSeq<protocol.CompileOnSaveAffectedFileListRequest>({
1074-
command: protocol.CommandTypes.CompileOnSaveAffectedFileList,
1075-
arguments: {
1076-
file: core.path
1077-
}
1078-
}).response;
1079-
assert.deepEqual(response, [
1080-
{ projectFileName: app1Config.path, fileNames: [core.path, app1.path], projectUsesOutFile: true },
1081-
{ projectFileName: app2Config.path, fileNames: [core.path, app2.path], projectUsesOutFile: true }
1082-
]);
1083-
assert.equal(session.getProjectService().configuredProjects.get(app1Config.path)!.dirty, false);
1084-
assert.equal(session.getProjectService().configuredProjects.get(app2Config.path)!.dirty, false);
1047+
verify("CompileOnSaveAffectedFileListRequest when projectFile is not specified", {
1048+
file: `${tscWatch.projectRoot}/core/core.ts`,
10851049
});
10861050
});
10871051
}

0 commit comments

Comments
 (0)