"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/testRunner/unittests/tscWatch/incremental.ts" between
TypeScript-3.6.2.tar.gz and TypeScript-3.6.3.tar.gz

About: Microsoft\PKG_DESCR_TTrsquo;s TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

incremental.ts  (TypeScript-3.6.2):incremental.ts  (TypeScript-3.6.3)
skipping to change at line 19 skipping to change at line 19
interface VerifyIncrementalWatchEmitInput { interface VerifyIncrementalWatchEmitInput {
files: ReadonlyArray<File>; files: ReadonlyArray<File>;
optionsToExtend?: CompilerOptions; optionsToExtend?: CompilerOptions;
expectedInitialEmit: ReadonlyArray<File>; expectedInitialEmit: ReadonlyArray<File>;
expectedInitialErrors: ReadonlyArray<string>; expectedInitialErrors: ReadonlyArray<string>;
modifyFs?: (host: WatchedSystem) => void; modifyFs?: (host: WatchedSystem) => void;
expectedIncrementalEmit?: ReadonlyArray<File>; expectedIncrementalEmit?: ReadonlyArray<File>;
expectedIncrementalErrors?: ReadonlyArray<string>; expectedIncrementalErrors?: ReadonlyArray<string>;
} }
function verifyIncrementalWatchEmit(input: VerifyIncrementalWatchEmitInp ut) { function verifyIncrementalWatchEmit(input: () => VerifyIncrementalWatchE mitInput) {
it("with tsc --w", () => { it("with tsc --w", () => {
verifyIncrementalWatchEmitWorker({ verifyIncrementalWatchEmitWorker({
input, input: input(),
emitAndReportErrors: createWatchOfConfigFile, emitAndReportErrors: createWatchOfConfigFile,
verifyErrors: checkOutputErrorsInitial verifyErrors: checkOutputErrorsInitial
}); });
}); });
it("with tsc", () => { it("with tsc", () => {
verifyIncrementalWatchEmitWorker({ verifyIncrementalWatchEmitWorker({
input, input: input(),
emitAndReportErrors: incrementalBuild, emitAndReportErrors: incrementalBuild,
verifyErrors: checkNormalBuildErrors verifyErrors: checkNormalBuildErrors
}); });
}); });
} }
function incrementalBuild(configFile: string, host: WatchedSystem, optio nsToExtend?: CompilerOptions) { function incrementalBuild(configFile: string, host: WatchedSystem, optio nsToExtend?: CompilerOptions) {
const reportDiagnostic = createDiagnosticReporter(host); const reportDiagnostic = createDiagnosticReporter(host);
const config = parseConfigFileWithSystem(configFile, optionsToExtend || {}, host, reportDiagnostic); const config = parseConfigFileWithSystem(configFile, optionsToExtend || {}, host, reportDiagnostic);
if (config) { if (config) {
skipping to change at line 125 skipping to change at line 125
} }
function sanitizeBuildInfo(content: string) { function sanitizeBuildInfo(content: string) {
const buildInfo = getBuildInfo(content); const buildInfo = getBuildInfo(content);
fakes.sanitizeBuildInfoProgram(buildInfo); fakes.sanitizeBuildInfoProgram(buildInfo);
return getBuildInfoText(buildInfo); return getBuildInfoText(buildInfo);
} }
function checkFileEmit(actual: Map<string>, expected: ReadonlyArray<File >) { function checkFileEmit(actual: Map<string>, expected: ReadonlyArray<File >) {
assert.equal(actual.size, expected.length, `Actual: ${JSON.stringify (arrayFrom(actual.entries()), /*replacer*/ undefined, " ")}\nExpected: ${JSON.st ringify(expected, /*replacer*/ undefined, " ")}`); assert.equal(actual.size, expected.length, `Actual: ${JSON.stringify (arrayFrom(actual.entries()), /*replacer*/ undefined, " ")}\nExpected: ${JSON.st ringify(expected, /*replacer*/ undefined, " ")}`);
expected.forEach(file => { for (const file of expected) {
let expectedContent = file.content; let expectedContent = file.content;
let actualContent = actual.get(file.path); let actualContent = actual.get(file.path);
if (isBuildInfoFile(file.path)) { if (isBuildInfoFile(file.path)) {
actualContent = actualContent && sanitizeBuildInfo(actualCon tent); actualContent = actualContent && sanitizeBuildInfo(actualCon tent);
expectedContent = sanitizeBuildInfo(expectedContent); expectedContent = sanitizeBuildInfo(expectedContent);
} }
assert.equal(actualContent, expectedContent, `Emit for ${file.pa th}`); assert.equal(actualContent, expectedContent, `Emit for ${file.pa th}`);
}); }
} }
const libFileInfo: BuilderState.FileInfo = { const libFileInfo: BuilderState.FileInfo = {
version: Harness.mockHash(libFile.content), version: Harness.mockHash(libFile.content),
signature: Harness.mockHash(libFile.content) signature: Harness.mockHash(libFile.content)
}; };
const getCanonicalFileName = createGetCanonicalFileName(/*useCaseSensiti veFileNames*/ false); const getCanonicalFileName = createGetCanonicalFileName(/*useCaseSensiti veFileNames*/ false);
function relativeToBuildInfo(buildInfoPath: string, path: string) { function relativeToBuildInfo(buildInfoPath: string, path: string) {
return getRelativePathFromFile(buildInfoPath, path, getCanonicalFile Name); return getRelativePathFromFile(buildInfoPath, path, getCanonicalFile Name);
skipping to change at line 173 skipping to change at line 173
path: `${project}/file1.js`, path: `${project}/file1.js`,
content: "var x = 10;\n" content: "var x = 10;\n"
}; };
const file2Js: File = { const file2Js: File = {
path: `${project}/file2.js`, path: `${project}/file2.js`,
content: "var y = 20;\n" content: "var y = 20;\n"
}; };
describe("own file emit without errors", () => { describe("own file emit without errors", () => {
function verify(optionsToExtend?: CompilerOptions, expectedBuild infoOptions?: CompilerOptions) { function verify(optionsToExtend?: CompilerOptions, expectedBuild infoOptions?: CompilerOptions) {
const modifiedFile2Content = file2.content.replace("y", "z") .replace("20", "10"); const modifiedFile2Content = file2.content.replace("y", "z") .replace("20", "10");
verifyIncrementalWatchEmit({ verifyIncrementalWatchEmit(() => ({
files: [libFile, file1, file2, configFile], files: [libFile, file1, file2, configFile],
optionsToExtend, optionsToExtend,
expectedInitialEmit: [ expectedInitialEmit: [
file1Js, file1Js,
file2Js, file2Js,
{ {
path: `${project}/tsconfig.tsbuildinfo`, path: `${project}/tsconfig.tsbuildinfo`,
content: getBuildInfoText({ content: getBuildInfoText({
program: { program: {
fileInfos: { fileInfos: {
skipping to change at line 229 skipping to change at line 229
}, },
referencedMap: {}, referencedMap: {},
exportedModulesMap: {}, exportedModulesMap: {},
semanticDiagnosticsPerFile: [libFilePath , file1Path, file2Path] semanticDiagnosticsPerFile: [libFilePath , file1Path, file2Path]
}, },
version version
}) })
} }
], ],
expectedIncrementalErrors: emptyArray, expectedIncrementalErrors: emptyArray,
}); }));
} }
verify(); verify();
describe("with commandline parameters that are not relative", () => { describe("with commandline parameters that are not relative", () => {
verify({ project: "tsconfig.json" }, { project: "./tsconfig. json" }); verify({ project: "tsconfig.json" }, { project: "./tsconfig. json" });
}); });
}); });
describe("own file emit with errors", () => { describe("own file emit with errors", () => {
const fileModified: File = { const fileModified: File = {
path: file2.path, path: file2.path,
skipping to change at line 262 skipping to change at line 262
code: Diagnostics.Type_0_is_not_assignable_to_type_1 .code, code: Diagnostics.Type_0_is_not_assignable_to_type_1 .code,
category: Diagnostics.Type_0_is_not_assignable_to_ty pe_1.category, category: Diagnostics.Type_0_is_not_assignable_to_ty pe_1.category,
messageText: "Type '20' is not assignable to type 's tring'." messageText: "Type '20' is not assignable to type 's tring'."
} }
] ]
]; ];
const file2Errors = [ const file2Errors = [
"file2.ts(1,7): error TS2322: Type '20' is not assignable to type 'string'.\n" "file2.ts(1,7): error TS2322: Type '20' is not assignable to type 'string'.\n"
]; ];
const modifiedFile1Content = file1.content.replace("x", "z"); const modifiedFile1Content = file1.content.replace("x", "z");
verifyIncrementalWatchEmit({ verifyIncrementalWatchEmit(() => ({
files: [libFile, file1, fileModified, configFile], files: [libFile, file1, fileModified, configFile],
expectedInitialEmit: [ expectedInitialEmit: [
file1Js, file1Js,
file2Js, file2Js,
{ {
path: `${project}/tsconfig.tsbuildinfo`, path: `${project}/tsconfig.tsbuildinfo`,
content: getBuildInfoText({ content: getBuildInfoText({
program: { program: {
fileInfos: { fileInfos: {
[libFilePath]: libFileInfo, [libFilePath]: libFileInfo,
skipping to change at line 323 skipping to change at line 323
libFilePath, libFilePath,
file1Path, file1Path,
file2ReuasableError file2ReuasableError
] ]
}, },
version version
}) })
} }
], ],
expectedIncrementalErrors: file2Errors, expectedIncrementalErrors: file2Errors,
}); }));
}); });
describe("with --out", () => { describe("with --out", () => {
const config: File = { const config: File = {
path: configFile.path, path: configFile.path,
content: JSON.stringify({ compilerOptions: { incremental: tr ue, outFile: "out.js" } }) content: JSON.stringify({ compilerOptions: { incremental: tr ue, outFile: "out.js" } })
}; };
const outFile: File = { const outFile: File = {
path: `${project}/out.js`, path: `${project}/out.js`,
content: "var x = 10;\nvar y = 20;\n" content: "var x = 10;\nvar y = 20;\n"
}; };
verifyIncrementalWatchEmit({ verifyIncrementalWatchEmit(() => ({
files: [libFile, file1, file2, config], files: [libFile, file1, file2, config],
expectedInitialEmit: [ expectedInitialEmit: [
outFile, outFile,
{ {
path: `${project}/out.tsbuildinfo`, path: `${project}/out.tsbuildinfo`,
content: getBuildInfoText({ content: getBuildInfoText({
bundle: { bundle: {
commonSourceDirectory: relativeToBuildInfo(` ${project}/out.tsbuildinfo`, `${project}/`), commonSourceDirectory: relativeToBuildInfo(` ${project}/out.tsbuildinfo`, `${project}/`),
sourceFiles: [file1Path, file2Path], sourceFiles: [file1Path, file2Path],
js: { js: {
sections: [ sections: [
{ pos: 0, end: outFile.content.lengt h, kind: BundleFileSectionKind.Text } { pos: 0, end: outFile.content.lengt h, kind: BundleFileSectionKind.Text }
] ]
}, },
}, },
version version
}) })
} }
], ],
expectedInitialErrors: emptyArray expectedInitialErrors: emptyArray
}); }));
}); });
}); });
describe("module compilation", () => { describe("module compilation", () => {
function getFileInfo(content: string): BuilderState.FileInfo { function getFileInfo(content: string): BuilderState.FileInfo {
return { return {
version: Harness.mockHash(content), version: Harness.mockHash(content),
signature: Harness.mockHash(`${content.replace("export ", "e xport declare ")}\n`) signature: Harness.mockHash(`${content.replace("export ", "e xport declare ")}\n`)
}; };
skipping to change at line 400 skipping to change at line 400
path: `${project}/file2.js`, path: `${project}/file2.js`,
content: getEmitContent("y", "20") content: getEmitContent("y", "20")
}; };
const config: File = { const config: File = {
path: configFile.path, path: configFile.path,
content: JSON.stringify({ compilerOptions: { incremental: true, module: "amd" } }) content: JSON.stringify({ compilerOptions: { incremental: true, module: "amd" } })
}; };
describe("own file emit without errors", () => { describe("own file emit without errors", () => {
const modifiedFile2Content = file2.content.replace("y", "z").rep lace("20", "10"); const modifiedFile2Content = file2.content.replace("y", "z").rep lace("20", "10");
verifyIncrementalWatchEmit({ verifyIncrementalWatchEmit(() => ({
files: [libFile, file1, file2, config], files: [libFile, file1, file2, config],
expectedInitialEmit: [ expectedInitialEmit: [
file1Js, file1Js,
file2Js, file2Js,
{ {
path: `${project}/tsconfig.tsbuildinfo`, path: `${project}/tsconfig.tsbuildinfo`,
content: getBuildInfoText({ content: getBuildInfoText({
program: { program: {
fileInfos: { fileInfos: {
[libFilePath]: libFileInfo, [libFilePath]: libFileInfo,
skipping to change at line 454 skipping to change at line 454
}, },
referencedMap: {}, referencedMap: {},
exportedModulesMap: {}, exportedModulesMap: {},
semanticDiagnosticsPerFile: [libFilePath, fi le1Path, file2Path] semanticDiagnosticsPerFile: [libFilePath, fi le1Path, file2Path]
}, },
version version
}) })
} }
], ],
expectedIncrementalErrors: emptyArray, expectedIncrementalErrors: emptyArray,
}); }));
}); });
describe("own file emit with errors", () => { describe("own file emit with errors", () => {
const fileModified: File = { const fileModified: File = {
path: file2.path, path: file2.path,
content: `export const y: string = 20;` content: `export const y: string = 20;`
}; };
const file2FileInfo: BuilderState.FileInfo = { const file2FileInfo: BuilderState.FileInfo = {
version: Harness.mockHash(fileModified.content), version: Harness.mockHash(fileModified.content),
signature: Harness.mockHash("export declare const y: string; \n") signature: Harness.mockHash("export declare const y: string; \n")
skipping to change at line 482 skipping to change at line 482
code: Diagnostics.Type_0_is_not_assignable_to_type_1 .code, code: Diagnostics.Type_0_is_not_assignable_to_type_1 .code,
category: Diagnostics.Type_0_is_not_assignable_to_ty pe_1.category, category: Diagnostics.Type_0_is_not_assignable_to_ty pe_1.category,
messageText: "Type '20' is not assignable to type 's tring'." messageText: "Type '20' is not assignable to type 's tring'."
} }
] ]
]; ];
const file2Errors = [ const file2Errors = [
"file2.ts(1,14): error TS2322: Type '20' is not assignable t o type 'string'.\n" "file2.ts(1,14): error TS2322: Type '20' is not assignable t o type 'string'.\n"
]; ];
const modifiedFile1Content = file1.content.replace("x = 10", "z = 10"); const modifiedFile1Content = file1.content.replace("x = 10", "z = 10");
verifyIncrementalWatchEmit({ verifyIncrementalWatchEmit(() => ({
files: [libFile, file1, fileModified, config], files: [libFile, file1, fileModified, config],
expectedInitialEmit: [ expectedInitialEmit: [
file1Js, file1Js,
file2Js, file2Js,
{ {
path: `${project}/tsconfig.tsbuildinfo`, path: `${project}/tsconfig.tsbuildinfo`,
content: getBuildInfoText({ content: getBuildInfoText({
program: { program: {
fileInfos: { fileInfos: {
[libFilePath]: libFileInfo, [libFilePath]: libFileInfo,
skipping to change at line 544 skipping to change at line 544
libFilePath, libFilePath,
file2ReuasableError, file2ReuasableError,
file1Path file1Path
] ]
}, },
version version
}) })
} }
], ],
expectedIncrementalErrors: file2Errors, expectedIncrementalErrors: file2Errors,
}));
it("verify that state is read correctly", () => {
const system = createWatchedSystem([libFile, file1, fileModi
fied, config], { currentDirectory: project });
incrementalBuild("tsconfig.json", system);
const command = parseConfigFileWithSystem("tsconfig.json", {
}, system, noop)!;
const builderProgram = createIncrementalProgram({
rootNames: command.fileNames,
options: command.options,
projectReferences: command.projectReferences,
configFileParsingDiagnostics: getConfigFileParsingDiagno
stics(command),
host: createIncrementalCompilerHost(command.options, sys
tem)
});
const state = builderProgram.getState();
assert.equal(state.changedFilesSet!.size, 0, "changes");
assert.equal(state.fileInfos.size, 3, "FileInfo size");
assert.deepEqual(state.fileInfos.get(libFile.path), libFileI
nfo);
assert.deepEqual(state.fileInfos.get(file1.path), getFileInf
o(file1.content));
assert.deepEqual(state.fileInfos.get(file2.path), file2FileI
nfo);
assert.deepEqual(state.compilerOptions, {
incremental: true,
module: ModuleKind.AMD,
configFilePath: config.path
});
assert.equal(state.referencedMap!.size, 0);
assert.equal(state.exportedModulesMap!.size, 0);
assert.equal(state.semanticDiagnosticsPerFile!.size, 3);
assert.deepEqual(state.semanticDiagnosticsPerFile!.get(libFi
le.path), emptyArray);
assert.deepEqual(state.semanticDiagnosticsPerFile!.get(file1
.path), emptyArray);
const { file: _, relatedInformation: __, ...rest } = file2Re
uasableError[1][0];
assert.deepEqual(state.semanticDiagnosticsPerFile!.get(file2
.path), [{
...rest,
file: state.program!.getSourceFileByPath(file2.path as P
ath)!,
relatedInformation: undefined,
reportsUnnecessary: undefined,
source: undefined
}]);
}); });
}); });
describe("with --out", () => { describe("with --out", () => {
const config: File = { const config: File = {
path: configFile.path, path: configFile.path,
content: JSON.stringify({ compilerOptions: { incremental: tr ue, module: "amd", outFile: "out.js" } }) content: JSON.stringify({ compilerOptions: { incremental: tr ue, module: "amd", outFile: "out.js" } })
}; };
const outFile: File = { const outFile: File = {
path: `${project}/out.js`, path: `${project}/out.js`,
content: `${getEmitContent("file1", "x", "10")}${getEmitCont ent("file2", "y", "20")}` content: `${getEmitContent("file1", "x", "10")}${getEmitCont ent("file2", "y", "20")}`
}; };
function getEmitContent(file: string, varName: string, value: st ring) { function getEmitContent(file: string, varName: string, value: st ring) {
return `define("${file}", ["require", "exports"], function ( require, exports) { return `define("${file}", ["require", "exports"], function ( require, exports) {
"use strict"; "use strict";
exports.__esModule = true; exports.__esModule = true;
exports.${varName} = ${value}; exports.${varName} = ${value};
}); });
`; `;
} }
verifyIncrementalWatchEmit({ verifyIncrementalWatchEmit(() => ({
files: [libFile, file1, file2, config], files: [libFile, file1, file2, config],
expectedInitialEmit: [ expectedInitialEmit: [
outFile, outFile,
{ {
path: `${project}/out.tsbuildinfo`, path: `${project}/out.tsbuildinfo`,
content: getBuildInfoText({ content: getBuildInfoText({
bundle: { bundle: {
commonSourceDirectory: relativeToBuildInfo(` ${project}/out.tsbuildinfo`, `${project}/`), commonSourceDirectory: relativeToBuildInfo(` ${project}/out.tsbuildinfo`, `${project}/`),
sourceFiles: [file1Path, file2Path], sourceFiles: [file1Path, file2Path],
js: { js: {
sections: [ sections: [
{ pos: 0, end: outFile.content.lengt h, kind: BundleFileSectionKind.Text } { pos: 0, end: outFile.content.lengt h, kind: BundleFileSectionKind.Text }
] ]
}, },
}, },
version version
}) })
} }
], ],
expectedInitialErrors: emptyArray expectedInitialErrors: emptyArray
}); }));
});
});
describe("incremental with circular references", () => {
function getFileInfo(content: string): BuilderState.FileInfo {
const signature = Harness.mockHash(content);
return { version: signature, signature };
}
const config: File = {
path: configFile.path,
content: JSON.stringify({
compilerOptions: {
incremental: true,
target: "es5",
module: "commonjs",
declaration: true,
emitDeclarationOnly: true
}
})
};
const aTs: File = {
path: `${project}/a.ts`,
content: `import { B } from "./b";
export interface A {
b: B;
}
`
};
const bTs: File = {
path: `${project}/b.ts`,
content: `import { C } from "./c";
export interface B {
b: C;
}
`
};
const cTs: File = {
path: `${project}/c.ts`,
content: `import { A } from "./a";
export interface C {
a: A;
}
`
};
const indexTs: File = {
path: `${project}/index.ts`,
content: `export { A } from "./a";
export { B } from "./b";
export { C } from "./c";
`
};
verifyIncrementalWatchEmit(() => {
const referencedMap: MapLike<string[]> = {
"./a.ts": ["./b.ts"],
"./b.ts": ["./c.ts"],
"./c.ts": ["./a.ts"],
"./index.ts": ["./a.ts", "./b.ts", "./c.ts"],
};
const initialProgram: ProgramBuildInfo = {
fileInfos: {
[libFilePath]: libFileInfo,
"./c.ts": getFileInfo(cTs.content),
"./b.ts": getFileInfo(bTs.content),
"./a.ts": getFileInfo(aTs.content),
"./index.ts": getFileInfo(indexTs.content)
},
options: {
incremental: true,
target: ScriptTarget.ES5,
module: ModuleKind.CommonJS,
declaration: true,
emitDeclarationOnly: true,
configFilePath: "./tsconfig.json"
},
referencedMap,
exportedModulesMap: referencedMap,
semanticDiagnosticsPerFile: [
libFilePath,
"./a.ts",
"./b.ts",
"./c.ts",
"./index.ts",
]
};
const { fileInfos, ...rest } = initialProgram;
const expectedADts: File = { path: `${project}/a.d.ts`, content:
aTs.content };
const expectedBDts: File = { path: `${project}/b.d.ts`, content:
bTs.content };
const expectedCDts: File = { path: `${project}/c.d.ts`, content:
cTs.content };
const expectedIndexDts: File = { path: `${project}/index.d.ts`,
content: indexTs.content };
const modifiedATsContent = aTs.content.replace("b: B;", `b: B;
foo: any;`);
return {
files: [libFile, aTs, bTs, cTs, indexTs, config],
expectedInitialEmit: [
expectedADts,
expectedBDts,
expectedCDts,
expectedIndexDts,
{
path: `${project}/tsconfig.tsbuildinfo`,
content: getBuildInfoText({
program: initialProgram,
version
})
}
],
expectedInitialErrors: emptyArray,
modifyFs: host => host.writeFile(aTs.path, modifiedATsConten
t),
expectedIncrementalEmit: [
{ path: expectedADts.path, content: modifiedATsContent }
,
expectedBDts,
expectedCDts,
expectedIndexDts,
{
path: `${project}/tsconfig.tsbuildinfo`,
content: getBuildInfoText({
program: {
fileInfos: {
[libFilePath]: libFileInfo,
"./c.ts": getFileInfo(cTs.content),
"./b.ts": getFileInfo(bTs.content),
"./a.ts": getFileInfo(modifiedATsContent
),
"./index.ts": getFileInfo(indexTs.conten
t)
},
...rest
},
version
})
}
],
expectedIncrementalErrors: emptyArray
};
}); });
}); });
}); });
} }
 End of changes. 17 change blocks. 
16 lines changed or deleted 212 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)