mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 04:48:52 -05:00
chore(types): fix type checking errors in 99_main_compiler.js (#18403)
This commit is contained in:
parent
d740a9e43d
commit
675179a176
2 changed files with 30 additions and 18 deletions
|
@ -12,7 +12,7 @@
|
||||||
// https://tc39.es/ecma262/#sec-get-object.prototype.__proto__
|
// https://tc39.es/ecma262/#sec-get-object.prototype.__proto__
|
||||||
delete Object.prototype.__proto__;
|
delete Object.prototype.__proto__;
|
||||||
|
|
||||||
((window) => {
|
((/** @type {any} */ window) => {
|
||||||
/** @type {DenoCore} */
|
/** @type {DenoCore} */
|
||||||
const core = window.Deno.core;
|
const core = window.Deno.core;
|
||||||
const ops = core.ops;
|
const ops = core.ops;
|
||||||
|
@ -48,6 +48,10 @@ delete Object.prototype.__proto__;
|
||||||
: { languageVersion: versionOrOptions ?? ts.ScriptTarget.ESNext };
|
: { languageVersion: versionOrOptions ?? ts.ScriptTarget.ESNext };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param debug {boolean}
|
||||||
|
* @param source {string}
|
||||||
|
*/
|
||||||
function setLogDebug(debug, source) {
|
function setLogDebug(debug, source) {
|
||||||
logDebug = debug;
|
logDebug = debug;
|
||||||
if (source) {
|
if (source) {
|
||||||
|
@ -55,10 +59,12 @@ delete Object.prototype.__proto__;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param msg {string} */
|
||||||
function printStderr(msg) {
|
function printStderr(msg) {
|
||||||
core.print(msg, true);
|
core.print(msg, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param args {any[]} */
|
||||||
function debug(...args) {
|
function debug(...args) {
|
||||||
if (logDebug) {
|
if (logDebug) {
|
||||||
const stringifiedArgs = args.map((arg) =>
|
const stringifiedArgs = args.map((arg) =>
|
||||||
|
@ -68,6 +74,7 @@ delete Object.prototype.__proto__;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param args {any[]} */
|
||||||
function error(...args) {
|
function error(...args) {
|
||||||
const stringifiedArgs = args.map((arg) =>
|
const stringifiedArgs = args.map((arg) =>
|
||||||
typeof arg === "string" || arg instanceof Error
|
typeof arg === "string" || arg instanceof Error
|
||||||
|
@ -78,12 +85,14 @@ delete Object.prototype.__proto__;
|
||||||
}
|
}
|
||||||
|
|
||||||
class AssertionError extends Error {
|
class AssertionError extends Error {
|
||||||
|
/** @param msg {string} */
|
||||||
constructor(msg) {
|
constructor(msg) {
|
||||||
super(msg);
|
super(msg);
|
||||||
this.name = "AssertionError";
|
this.name = "AssertionError";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param cond {boolean} */
|
||||||
function assert(cond, msg = "Assertion failed.") {
|
function assert(cond, msg = "Assertion failed.") {
|
||||||
if (!cond) {
|
if (!cond) {
|
||||||
throw new AssertionError(msg);
|
throw new AssertionError(msg);
|
||||||
|
@ -101,6 +110,7 @@ delete Object.prototype.__proto__;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param specifier {string} */
|
||||||
has(specifier) {
|
has(specifier) {
|
||||||
return this.#cache.has(specifier);
|
return this.#cache.has(specifier);
|
||||||
}
|
}
|
||||||
|
@ -245,7 +255,9 @@ delete Object.prototype.__proto__;
|
||||||
sourceFile,
|
sourceFile,
|
||||||
scriptSnapshot,
|
scriptSnapshot,
|
||||||
version,
|
version,
|
||||||
scriptSnapshot.getChangeRange(sourceFile.scriptSnapShot),
|
scriptSnapshot.getChangeRange(
|
||||||
|
/** @type {ts.IScriptSnapshot} */ (sourceFile.scriptSnapShot),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return sourceFile;
|
return sourceFile;
|
||||||
|
@ -1284,7 +1296,7 @@ delete Object.prototype.__proto__;
|
||||||
// we are caching in memory common type libraries that will be re-used by
|
// we are caching in memory common type libraries that will be re-used by
|
||||||
// tsc on when the snapshot is restored
|
// tsc on when the snapshot is restored
|
||||||
assert(
|
assert(
|
||||||
host.getSourceFile(
|
!!host.getSourceFile(
|
||||||
`${ASSETS_URL_PREFIX}${specifier}`,
|
`${ASSETS_URL_PREFIX}${specifier}`,
|
||||||
ts.ScriptTarget.ESNext,
|
ts.ScriptTarget.ESNext,
|
||||||
),
|
),
|
||||||
|
@ -1303,14 +1315,16 @@ delete Object.prototype.__proto__;
|
||||||
// remove this now that we don't need it anymore for warming up tsc
|
// remove this now that we don't need it anymore for warming up tsc
|
||||||
sourceFileCache.delete(buildSpecifier);
|
sourceFileCache.delete(buildSpecifier);
|
||||||
|
|
||||||
// exposes the two functions that are called by `tsc::exec()` when type
|
// exposes the functions that are called by `tsc::exec()` when type
|
||||||
// checking TypeScript.
|
// checking TypeScript.
|
||||||
globalThis.startup = startup;
|
/** @type {any} */
|
||||||
globalThis.exec = exec;
|
const global = globalThis;
|
||||||
globalThis.getAssets = getAssets;
|
global.startup = startup;
|
||||||
|
global.exec = exec;
|
||||||
|
global.getAssets = getAssets;
|
||||||
|
|
||||||
// exposes the functions that are called when the compiler is used as a
|
// exposes the functions that are called when the compiler is used as a
|
||||||
// language service.
|
// language service.
|
||||||
globalThis.serverInit = serverInit;
|
global.serverInit = serverInit;
|
||||||
globalThis.serverRequest = serverRequest;
|
global.serverRequest = serverRequest;
|
||||||
})(this);
|
})(this);
|
||||||
|
|
16
cli/tsc/compiler.d.ts
vendored
16
cli/tsc/compiler.d.ts
vendored
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
// Contains types that can be used to validate and check `99_main_compiler.js`
|
// Contains types that can be used to validate and check `99_main_compiler.js`
|
||||||
|
|
||||||
import * as _ts from "./dts/typescript";
|
import * as _ts from "./dts/typescript.d.ts";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace ts {
|
namespace ts {
|
||||||
|
@ -10,9 +10,10 @@ declare global {
|
||||||
var libMap: Map<string, string>;
|
var libMap: Map<string, string>;
|
||||||
var base64encode: (host: ts.CompilerHost, input: string) => string;
|
var base64encode: (host: ts.CompilerHost, input: string) => string;
|
||||||
var normalizePath: (path: string) => string;
|
var normalizePath: (path: string) => string;
|
||||||
|
|
||||||
interface SourceFile {
|
interface SourceFile {
|
||||||
version?: string;
|
version?: string;
|
||||||
fileName: string;
|
scriptSnapShot?: _ts.IScriptSnapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CompilerHost {
|
interface CompilerHost {
|
||||||
|
@ -26,16 +27,13 @@ declare global {
|
||||||
|
|
||||||
var performance: Performance;
|
var performance: Performance;
|
||||||
|
|
||||||
namespace deno {
|
function setLocalizedDiagnosticMessages(
|
||||||
function setIsNodeSourceFileCallback(
|
messages: Record<string, string>,
|
||||||
callback: (sourceFile: SourceFile) => boolean,
|
): void;
|
||||||
);
|
|
||||||
function setNodeBuiltInModuleNames(names: readonly string[]);
|
|
||||||
function setNodeOnlyGlobalNames(names: readonly string[]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ts {
|
namespace ts {
|
||||||
|
// @ts-ignore allow using an export = here
|
||||||
export = _ts;
|
export = _ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue