Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: split out a common typecheckFile func #344

Merged
merged 2 commits into from
Jun 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as resolve from "resolve";
import findCacheDir from "find-cache-dir";

import { RollupContext } from "./rollupcontext";
import { ConsoleContext, VerbosityLevel } from "./context";
import { ConsoleContext, IContext, VerbosityLevel } from "./context";
import { LanguageServiceHost } from "./host";
import { TsCache, convertDiagnostic, convertEmitOutput, getAllReferences } from "./tscache";
import { tsModule, setTypescriptModule } from "./tsproxy";
Expand Down Expand Up @@ -56,6 +56,15 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
}));
}

const typecheckFile = (id: string, snapshot: tsTypes.IScriptSnapshot, tcContext: IContext) =>
{
const diagnostics = getDiagnostics(id, snapshot);
printDiagnostics(tcContext, diagnostics, parsedConfig.options.pretty === true);

if (diagnostics.length > 0)
noErrors = false;
}

const pluginOptions: IOptions = Object.assign({},
{
check: true,
Expand Down Expand Up @@ -201,11 +210,8 @@ const typescript: PluginImpl<RPT2Options> = (options) =>

if (output.emitSkipped)
{
noErrors = false;
agilgur5 marked this conversation as resolved.
Show resolved Hide resolved

// always checking on fatal errors, even if options.check is set to false
const diagnostics = getDiagnostics(id, snapshot);
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true);
typecheckFile(id, snapshot, contextWrapper);

// since no output was generated, aborting compilation
cache().done();
Expand All @@ -218,13 +224,7 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
});

if (pluginOptions.check)
{
const diagnostics = getDiagnostics(id, snapshot);
if (diagnostics.length > 0)
noErrors = false;

printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true);
}
typecheckFile(id, snapshot, contextWrapper);

if (!result)
return undefined;
Expand Down Expand Up @@ -277,19 +277,15 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
return;

const snapshot = servicesHost.getScriptSnapshot(id);
if (!snapshot)
return;

const diagnostics = getDiagnostics(id, snapshot);
printDiagnostics(context, diagnostics, parsedConfig.options.pretty === true);
if (snapshot)
typecheckFile(id, snapshot, context);
});
}

if (!watchMode && !noErrors)
context.info(yellow("there were errors or warnings."));

cache().done();

generateRound++;
},

Expand Down