refactor: move snapshot check into typecheckFile (#391)

- just slightly simplify / DRY up repeated code
  - this matches the style of some of the other functions in the codebase, such as `emitDeclaration`, `getAllReferences`, etc

- also fix indentation in `typecheckFile`
  - apparently I double-intended this accidentally, so make it single indent
This commit is contained in:
Anton Gilgur 2022-08-08 15:16:35 -04:00 committed by GitHub
parent 3dda648f0f
commit ed0fbd9b85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,16 +55,19 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
}));
}
const typecheckFile = (id: string, snapshot: tsTypes.IScriptSnapshot, tcContext: IContext) =>
const typecheckFile = (id: string, snapshot: tsTypes.IScriptSnapshot | undefined, tcContext: IContext) =>
{
id = normalize(id);
checkedFiles.add(id); // must come before print, as that could bail
if (!snapshot)
return;
const diagnostics = getDiagnostics(id, snapshot);
printDiagnostics(tcContext, diagnostics, parsedConfig.options.pretty !== false);
id = normalize(id);
checkedFiles.add(id); // must come before print, as that could bail
if (diagnostics.length > 0)
noErrors = false;
const diagnostics = getDiagnostics(id, snapshot);
printDiagnostics(tcContext, diagnostics, parsedConfig.options.pretty !== false);
if (diagnostics.length > 0)
noErrors = false;
}
/** to be called at the end of Rollup's build phase, before output generation */
@ -290,8 +293,7 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
return;
const snapshot = servicesHost.getScriptSnapshot(id);
if (snapshot)
typecheckFile(id, snapshot, context);
typecheckFile(id, snapshot, context);
});
}
@ -305,10 +307,8 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
return;
context.debug(() => `type-checking missed '${key}'`);
const snapshot = servicesHost.getScriptSnapshot(key);
if (snapshot)
typecheckFile(key, snapshot, contextWrapper);
typecheckFile(key, snapshot, contextWrapper);
});
buildDone();