Handle --isolatedModules and d.ts emit in the builder

This commit is contained in:
Sheetal Nandi
2019-09-11 12:52:23 -07:00
parent 2692b2e214
commit 0019cee6de
4 changed files with 55 additions and 7 deletions
+29 -3
View File
@@ -173,8 +173,7 @@ namespace ts {
const compilerOptions = newProgram.getCompilerOptions();
state.compilerOptions = compilerOptions;
// With --out or --outFile, any change affects all semantic diagnostics so no need to cache them
// With --isolatedModules, emitting changed file doesnt emit dependent files so we cant know of dependent files to retrieve errors so dont cache the errors
if (!compilerOptions.outFile && !compilerOptions.out && !compilerOptions.isolatedModules) {
if (!compilerOptions.outFile && !compilerOptions.out) {
state.semanticDiagnosticsPerFile = createMap<readonly Diagnostic[]>();
}
state.changedFilesSet = createMap<true>();
@@ -483,16 +482,43 @@ namespace ts {
return !state.semanticDiagnosticsFromOldState.size;
}
function isChangedSignagure(state: BuilderProgramState, path: Path) {
const newSignature = Debug.assertDefined(state.currentAffectedFilesSignatures).get(path);
const oldSignagure = Debug.assertDefined(state.fileInfos.get(path)).signature;
return newSignature !== oldSignagure;
}
/**
* Iterate on referencing modules that export entities from affected file
*/
function forEachReferencingModulesOfExportOfAffectedFile(state: BuilderProgramState, affectedFile: SourceFile, fn: (state: BuilderProgramState, filePath: Path) => boolean) {
// If there was change in signature (dts output) for the changed file,
// then only we need to handle pending file emit
if (!state.exportedModulesMap || state.affectedFiles!.length === 1 || !state.changedFilesSet.has(affectedFile.path)) {
if (!state.exportedModulesMap || !state.changedFilesSet.has(affectedFile.path)) {
return;
}
if (!isChangedSignagure(state, affectedFile.path)) return;
// Since isolated modules dont change js files, files affected by change in signature is itself
// But we need to cleanup semantic diagnostics and queue dts emit for affected files
if (state.compilerOptions.isolatedModules) {
const seenFileNamesMap = createMap<true>();
seenFileNamesMap.set(affectedFile.path, true);
const queue = BuilderState.getReferencedByPaths(state, affectedFile.resolvedPath);
while (queue.length > 0) {
const currentPath = queue.pop()!;
if (!seenFileNamesMap.has(currentPath)) {
seenFileNamesMap.set(currentPath, true);
const result = fn(state, currentPath);
if (result && isChangedSignagure(state, currentPath)) {
const currentSourceFile = Debug.assertDefined(state.program).getSourceFileByPath(currentPath)!;
queue.push(...BuilderState.getReferencedByPaths(state, currentSourceFile.resolvedPath));
}
}
}
}
Debug.assert(!!state.currentAffectedFilesExportedModulesMap);
const seenFileAndExportsOfFile = createMap<true>();
// Go through exported modules from cache first
+1 -1
View File
@@ -466,7 +466,7 @@ namespace ts.BuilderState {
/**
* Gets the files referenced by the the file path
*/
function getReferencedByPaths(state: Readonly<BuilderState>, referencedFilePath: Path) {
export function getReferencedByPaths(state: Readonly<BuilderState>, referencedFilePath: Path) {
return arrayFrom(mapDefinedIterator(state.referencedMap!.entries(), ([filePath, referencesInFile]) =>
referencesInFile.has(referencedFilePath) ? filePath as Path : undefined
));
@@ -21,6 +21,12 @@ exports.default = foo()(function foobar() {
});
//// [/src/obj/index.d.ts]
import { LazyAction } from './bundling';
export declare const lazyBar: LazyAction<() => void, typeof import("./lazyIndex")>;
//// [/src/obj/lazyIndex.d.ts] file written with same contents
//// [/src/obj/tsconfig.tsbuildinfo]
{
"program": {
@@ -47,7 +53,7 @@ exports.default = foo()(function foobar() {
},
"../index.ts": {
"version": "-11602502901-import { LazyAction, LazyModule } from './bundling';\r\nconst lazyModule = new LazyModule(() =>\r\n import('./lazyIndex')\r\n);\r\nexport const lazyBar = new LazyAction(lazyModule, m => m.bar);",
"signature": "18468008756-import { LazyAction } from './bundling';\r\nexport declare const lazyBar: LazyAction<(param: string) => void, typeof import(\"./lazyIndex\")>;\r\n"
"signature": "6256067474-import { LazyAction } from './bundling';\r\nexport declare const lazyBar: LazyAction<() => void, typeof import(\"./lazyIndex\")>;\r\n"
}
},
"options": {
@@ -75,7 +81,15 @@ exports.default = foo()(function foobar() {
"../lazyindex.ts": [
"../bar.ts"
]
}
},
"semanticDiagnosticsPerFile": [
"../../lib/lib.d.ts",
"../bar.ts",
"../bundling.ts",
"../global.d.ts",
"../index.ts",
"../lazyindex.ts"
]
},
"version": "FakeTSVersion"
}
@@ -118,7 +118,15 @@ exports.bar = bar_1.default;
"../lazyindex.ts": [
"../bar.ts"
]
}
},
"semanticDiagnosticsPerFile": [
"../../lib/lib.d.ts",
"../bar.ts",
"../bundling.ts",
"../global.d.ts",
"../index.ts",
"../lazyindex.ts"
]
},
"version": "FakeTSVersion"
}