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

Fixed ES version and ignored TS compiler diagnostics that Deno ignores #77

Merged
merged 1 commit into from
Nov 24, 2023
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
14 changes: 10 additions & 4 deletions src/infer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export function programInfoException(filename_arg?: string, vendor_arg?: string,

const compilerOptions: ts.CompilerOptions = {
// This should match the version targeted in the deno version that is being used.
target: ts.ScriptTarget.ES5,
target: ts.ScriptTarget.ES2022,
module: ts.ModuleKind.CommonJS,
noImplicitAny: true,
// NOTE: We just declare Deno globally as any in order to allow users to omit it's declaration in their function files
Expand Down Expand Up @@ -406,20 +406,26 @@ export function programInfoException(filename_arg?: string, vendor_arg?: string,

Deno.removeSync(deno_d_ts);

// These diagnostic codes are ignored because Deno ignores them
// See: https://github.com/denoland/deno/blob/bf42467e215b20b36ec6b4bf30212e4beb2dd01f/cli/tsc/99_main_compiler.js#L441
const ignoredDiagnosticCodes = [1452, 2306, 2688, 2792, 5009, 5055, 5070, 7016];
const diagnostics = ts.getPreEmitDiagnostics(program);

// https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API
if (diagnostics.length) {
let fatal = 0;
console.error(`There were ${diagnostics.length} diagnostic errors.`);
diagnostics.forEach(diagnostic => {
diagnostics.filter(d => !ignoredDiagnosticCodes.includes(d.code)).forEach(diagnostic => {
if (diagnostic.file) {
if (! resolve(diagnostic.file.fileName).startsWith(vendorPath)) {
let errorPrefix = "";
const isFatal = !resolve(diagnostic.file.fileName).startsWith(vendorPath)
if (isFatal) {
fatal++;
errorPrefix = "FATAL: "
}
const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start!);
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
console.error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
console.error(`${errorPrefix}${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
} else {
console.error(`FATAL: ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`);
fatal++;
Expand Down