Repository: denoland/deno
File: cli/tsc/97_ts_host.js (JavaScript)

Code before:
  "fileExists",
  "getScriptSnapshot",
  "getCompilationSettings",
  "getCurrentDirectory",
  "useCaseSensitiveFileNames",
  "getModuleSpecifierCache",
  "getGlobalTypingsCacheLocation",
  "getSourceFile",
]);
/** @type {typeof hostImpl} */
export const host = {
  log(msg) {
    ops.op_log_event(msg);
  },
};
for (const [key, value] of Object.entries(hostImpl)) {
  if (typeof value === "function" && !excluded.has(key)) {
    host[key] = (...args) => {
      return spanned(key, () => value.bind(host)(...args));
    };
  } else {
    host[key] = value;
  }
}

// @ts-ignore Undocumented function.
const exportMapCache = ts.createCacheableExportInfoMap(host);

// override the npm install @types package diagnostics to be deno specific
ts.setLocalizedDiagnosticMessages((() => {
  const nodeMessage = "Cannot find name '{0}'."; // don't offer any suggestions
  const jqueryMessage =
    "Cannot find name '{0}'. Did you mean to import jQuery? Try adding `import $ from \"npm:jquery\";`.";
  return {
    "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2580":
      nodeMessage,
    "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2591":
      nodeMessage,
    "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2581":
      jqueryMessage,
    "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2592":
      jqueryMessage,
    "Module_0_was_resolved_to_1_but_allowArbitraryExtensions_is_not_set_6263":
      "Module '{0}' was resolved to '{1}', but importing these modules is not supported.",
  };
})());

/** @param {ts.Diagnostic} diagnostic */
export function filterMapDiagnostic(diagnostic) {
  if (IGNORED_DIAGNOSTICS.includes(diagnostic.code)) {
    return false;

Review comment (suggestion):
We should try to move off `@ts-ignore` and instead just remove the `/** @internal */`s in TypeScript's codebase. I updated https://github.com/denoland/TypeScript/pull/15 as part of this change.

Code after:
  "getSourceFile",
]);
/** @type {typeof hostImpl} */
export const host = {
  log(msg) {
    ops.op_log_event(msg);
  },
};
for (const [key, value] of Object.entries(hostImpl)) {
  if (typeof value === "function" && !excluded.has(key)) {
    host[key] = (...args) => {
      return spanned(key, () => value.bind(host)(...args));
    };
  } else {
    host[key] = value;
  }
}

// override the npm install @types package diagnostics to be deno specific
ts.setLocalizedDiagnosticMessages((() => {
  const nodeMessage = "Cannot find name '{0}'."; // don't offer any suggestions
  const jqueryMessage =
    "Cannot find name '{0}'. Did you mean to import jQuery? Try adding `import $ from \"npm:jquery\";`.";
  return {
    "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2580":
      nodeMessage,
    "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2591":
      nodeMessage,
    "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2581":
      jqueryMessage,
    "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2592":
      jqueryMessage,
    "Module_0_was_resolved_to_1_but_allowArbitraryExtensions_is_not_set_6263":
      "Module '{0}' was resolved to '{1}', but importing these modules is not supported.",
  };
})());

/** @param {ts.Diagnostic} diagnostic */
export function filterMapDiagnostic(diagnostic) {
  if (IGNORED_DIAGNOSTICS.includes(diagnostic.code)) {
    return false;
  }

  // make the diagnostic for using an `export =` in an es module a warning
  if (diagnostic.code === 1203) {
    diagnostic.category = ts.DiagnosticCategory.Warning;
    if (typeof diagnostic.messageText === "string") {
      const message =
        " This will start erroring in a future version of Deno 2 " +
        "in order to align with TypeScript.";
      // seems typescript shares objects, so check if it's already been set