fix typings so they are usable for building the project itself
Some checks failed
tagged-release / Tagged Release (push) Failing after 3m24s
Some checks failed
tagged-release / Tagged Release (push) Failing after 3m24s
This commit is contained in:
parent
4fd05e9e6f
commit
b1e0db627c
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,3 +16,4 @@
|
||||
|
||||
!/package.json
|
||||
!/rollup.config.js
|
||||
!/tsconfig.json
|
||||
|
@ -25,7 +25,7 @@ export interface TypeMap {
|
||||
|
||||
export function unwrapThis<T extends keyof TypeMap>(self: any, type: T, constr: Function, name: string, arg = "this", defaultVal?: TypeMap[T]): TypeMap[T] {
|
||||
if (typeof self === type) return self;
|
||||
if (self instanceof constr && valueKey in self) self = (self as any)[valueKey];
|
||||
if (self instanceof constr && valueKey in self) self = self[valueKey];
|
||||
if (typeof self === type) return self;
|
||||
if (defaultVal !== undefined) return defaultVal;
|
||||
throw new TypeError(name + " requires that '" + arg + "' be a " + constr.name);
|
||||
|
@ -6,8 +6,6 @@ for (let i = 97; i <= 122; i++) map[i] = j++;
|
||||
map[43] = j++;
|
||||
map[47] = j++;
|
||||
|
||||
export type Location = readonly [file: string, line: number, start: number];
|
||||
|
||||
export function decodeVLQ(val: string): number[][][] {
|
||||
const lines: number[][][] = [];
|
||||
|
||||
@ -83,10 +81,6 @@ export namespace Location {
|
||||
}
|
||||
}
|
||||
|
||||
export interface SourceMap {
|
||||
(loc: Location): Location | undefined;
|
||||
}
|
||||
|
||||
export class VLQSourceMap {
|
||||
public constructor(
|
||||
public readonly array: Map<string, [start: number, dst: Location][][]>,
|
||||
|
10
src/lib/transpiler/transpiler.d.ts
vendored
Normal file
10
src/lib/transpiler/transpiler.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
type Location = readonly [file: string, line: number, start: number];
|
||||
type SourceMap = (loc: Location) => Location | undefined;
|
||||
|
||||
type CompilerFactory = (next: Compiler) => Compiler;
|
||||
type Compiler = (filename: string, src: string, mapper: SourceMap) => (this: any, ...args: any[]) => any;
|
||||
|
||||
declare function getResource(name: string): string | undefined;
|
||||
declare function print(...args: any[]): void;
|
||||
declare function register(factory: CompilerFactory): void;
|
||||
declare function registerSource(filename: string, src: string): void;
|
@ -1,10 +0,0 @@
|
||||
import { type SourceMap } from "./map.ts";
|
||||
|
||||
declare global {
|
||||
type CompilerFactory = (next: Compiler) => Compiler;
|
||||
type Compiler = (filename: string, src: string, mapper: SourceMap) => Function;
|
||||
|
||||
function print(...args: any[]): void;
|
||||
function register(factory: CompilerFactory): void;
|
||||
function registerSource(filename: string, src: string): void;
|
||||
}
|
@ -1,17 +1,8 @@
|
||||
import { createDocumentRegistry, createLanguageService, ModuleKind, ScriptSnapshot, ScriptTarget, type Diagnostic, type CompilerOptions, type IScriptSnapshot, flattenDiagnosticMessageText, CompilerHost, LanguageService } from "typescript";
|
||||
import { SourceMap } from "./map.ts";
|
||||
|
||||
declare function getResource(name: string): string | undefined;
|
||||
declare function print(...args: any[]): void;
|
||||
declare function register(factory: CompilerFactory): void;
|
||||
declare function registerSource(filename: string, src: string): void;
|
||||
|
||||
type CompilerFactory = (next: Compiler) => Compiler;
|
||||
type Compiler = (filename: string, src: string, mapper: SourceMap) => Function;
|
||||
|
||||
const resources: Record<string, string | undefined> = {};
|
||||
|
||||
|
||||
function resource(name: string) {
|
||||
if (name in resources) return resources[name];
|
||||
else return resources[name] = getResource(name);
|
||||
|
27
src/main/resources/lib/errors.d.ts
vendored
Normal file
27
src/main/resources/lib/errors.d.ts
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
interface Error {
|
||||
message: string;
|
||||
name: string;
|
||||
}
|
||||
interface ErrorConstructor {
|
||||
(msg?: string): Error;
|
||||
new (msg?: string): Error;
|
||||
}
|
||||
|
||||
interface TypeError extends Error { }
|
||||
interface TypeErrorConstructor {
|
||||
(msg?: string): TypeError;
|
||||
new (msg?: string): TypeError;
|
||||
}
|
||||
|
||||
|
||||
interface SyntaxError extends Error { }
|
||||
interface SyntaxErrorConstructor {
|
||||
(msg?: string): SyntaxError;
|
||||
new (msg?: string): SyntaxError;
|
||||
}
|
||||
|
||||
interface RangeError extends Error { }
|
||||
interface RangeErrorConstructor {
|
||||
(msg?: string): RangeError;
|
||||
new (msg?: string): RangeError;
|
||||
}
|
4
src/main/resources/lib/globals/json.d.ts
vendored
Normal file
4
src/main/resources/lib/globals/json.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
interface JSON {
|
||||
stringify(val: any): string;
|
||||
parse(val: string): any;
|
||||
}
|
19
src/main/resources/lib/globals/map.d.ts
vendored
Normal file
19
src/main/resources/lib/globals/map.d.ts
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
interface Map<K, V> {
|
||||
readonly size: number;
|
||||
get(key: K): V;
|
||||
has(key: K): boolean;
|
||||
set(key: K, val: V): this;
|
||||
delete(key: K): boolean;
|
||||
clear(): void;
|
||||
|
||||
keys(): K[];
|
||||
values(): V[];
|
||||
entries(): [K, V][];
|
||||
|
||||
forEach(cb: (val: V, key: K, map: this) => void, self?: any): void;
|
||||
|
||||
[Symbol.iterator](): Iterator<[K, V]>;
|
||||
}
|
||||
interface MapConstructor {
|
||||
new <K, V>(iterable?: Iterable<[K, V]>): Map<K, V>;
|
||||
}
|
18
src/main/resources/lib/globals/set.d.ts
vendored
Normal file
18
src/main/resources/lib/globals/set.d.ts
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
interface Set<V> {
|
||||
readonly size: number;
|
||||
add(val: V): this;
|
||||
has(key: V): boolean;
|
||||
delete(key: V): boolean;
|
||||
clear(): void;
|
||||
|
||||
keys(): V[];
|
||||
values(): V[];
|
||||
entries(): [V, V][];
|
||||
|
||||
forEach(cb: (val: V, key: V, map: this) => void, self?: any): void;
|
||||
|
||||
[Symbol.iterator](): Iterator<V>;
|
||||
}
|
||||
interface SetConstructor {
|
||||
new <V>(iterable?: Iterable<V>): Set<V>;
|
||||
}
|
11
src/main/resources/lib/globals/weak-map.d.ts
vendored
Normal file
11
src/main/resources/lib/globals/weak-map.d.ts
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
interface WeakMap<K, V> {
|
||||
readonly size: number;
|
||||
get(key: K): V;
|
||||
set(key: K, val: V): this;
|
||||
has(key: K): boolean;
|
||||
delete(key: K): boolean;
|
||||
clear(): void;
|
||||
}
|
||||
interface WeakMapConstructor {
|
||||
new <K, V>(iterable?: Iterable<[K, V]>): WeakMap<K, V>;
|
||||
}
|
18
src/main/resources/lib/lib.d.ts
vendored
18
src/main/resources/lib/lib.d.ts
vendored
@ -1,6 +1,8 @@
|
||||
/// <reference no-default-lib="true"/>
|
||||
/// <reference path="./typing.d.ts"/>
|
||||
/// <reference path="./iterator.d.ts"/>
|
||||
/// <reference path="./async.d.ts"/>
|
||||
/// <reference path="./errors.d.ts"/>
|
||||
/// <reference path="./values/function.d.ts"/>
|
||||
/// <reference path="./values/object.d.ts"/>
|
||||
/// <reference path="./values/array.d.ts"/>
|
||||
@ -9,12 +11,20 @@
|
||||
/// <reference path="./values/string.d.ts"/>
|
||||
/// <reference path="./values/number.d.ts"/>
|
||||
/// <reference path="./values/regexp.d.ts"/>
|
||||
/// <reference path="./async.d.ts"/>
|
||||
/// <reference path="./globals/json.d.ts"/>
|
||||
/// <reference path="./globals/set.d.ts"/>
|
||||
/// <reference path="./globals/map.d.ts"/>
|
||||
/// <reference path="./globals/weak-map.d.ts"/>
|
||||
|
||||
declare function print(...args: any[]): void;
|
||||
|
||||
declare type IArguments = Array<any>;
|
||||
|
||||
declare var Error: ErrorConstructor;
|
||||
declare var TypeError: TypeErrorConstructor;
|
||||
declare var SyntaxError: SyntaxErrorConstructor;
|
||||
declare var RangeError: RangeErrorConstructor;
|
||||
|
||||
declare var Array: ArrayConstructor;
|
||||
declare var Boolean: BooleanConstructor;
|
||||
declare var Function: FunctionConstructor;
|
||||
@ -24,3 +34,9 @@ declare var Object: ObjectConstructor;
|
||||
declare var RegExp: RegExpConstructor;
|
||||
declare var String: StringConstructor;
|
||||
declare var Promise: PromiseConstructor;
|
||||
|
||||
declare var JSON: JSON;
|
||||
|
||||
declare var Set: SetConstructor;
|
||||
declare var Map: MapConstructor;
|
||||
declare var WeakMap: WeakMapConstructor;
|
4
src/main/resources/lib/typing.d.ts
vendored
4
src/main/resources/lib/typing.d.ts
vendored
@ -1,6 +1,4 @@
|
||||
declare interface Record<Key, Val> {
|
||||
[key: Key]: Val;
|
||||
}
|
||||
declare type Record<Key, Val> = { [x in Key]: Val }
|
||||
declare type InstanceType<T> = T extends new (...args: any[]) => infer T ? T : never;
|
||||
declare type ReturnType<T> = T extends (...args: any[]) => infer T ? T : never;
|
||||
declare type Arguments<T> =
|
||||
|
6
src/main/resources/lib/values/array.d.ts
vendored
6
src/main/resources/lib/values/array.d.ts
vendored
@ -3,7 +3,7 @@ declare interface Array<T> {
|
||||
[i: number]: T;
|
||||
|
||||
forEach(this: T[], cb: (val: T, i: number, self: this) => void, self?: any): void;
|
||||
join(this: T[], delim?: string): void;
|
||||
join(this: T[], delim?: string): string;
|
||||
|
||||
push(this: T[], ...elements: T[]): number;
|
||||
pop(this: T[]): T | undefined;
|
||||
@ -11,8 +11,8 @@ declare interface Array<T> {
|
||||
unshift(this: T[], ...elements: T[]): number;
|
||||
shift(this: T[]): T | undefined;
|
||||
|
||||
concat(this: T[], ...elements: (T | T[])[]): T | undefined;
|
||||
slice(this: T[], start?: number, end?: number): T | undefined;
|
||||
concat(this: T[], ...elements: (T | T[])[]): T[];
|
||||
slice(this: T[], start?: number, end?: number): T[];
|
||||
splice(this: T[], start?: number, count?: number): T[];
|
||||
splice(this: T[], start: number | undefined, count: number | undefined, ...elements: T[]): T[];
|
||||
|
||||
|
7
src/main/resources/lib/values/function.d.ts
vendored
7
src/main/resources/lib/values/function.d.ts
vendored
@ -1,11 +1,16 @@
|
||||
declare interface Function {
|
||||
prototype: unknown;
|
||||
prototype: object;
|
||||
|
||||
name: string;
|
||||
length: number;
|
||||
|
||||
valueOf(): this;
|
||||
toString(): string;
|
||||
|
||||
apply<Args extends readonly any[], Ret, Self>(this: (this: Self, ...args: Args) => Ret, self: Self, args: Args): Ret;
|
||||
apply(this: Function, self: any, args: any[]): any;
|
||||
call<Args extends readonly any[], Ret, Self>(this: (this: Self, ...args: Args) => Ret, self: Self, ...args: Args): Ret;
|
||||
call(this: Function, self: any, ...args: any): any;
|
||||
bind<T extends (...args: any[]) => any>(this: T): T;
|
||||
bind<
|
||||
Bound extends readonly any[],
|
||||
|
4
src/main/resources/lib/values/string.d.ts
vendored
4
src/main/resources/lib/values/string.d.ts
vendored
@ -7,8 +7,8 @@ declare interface String {
|
||||
|
||||
at(index: number): string | undefined;
|
||||
charAt(i: number): string | undefined;
|
||||
charCodeAt(i: number): string;
|
||||
codePointAt(i: number): string;
|
||||
charCodeAt(i: number): number;
|
||||
codePointAt(i: number): number;
|
||||
|
||||
includes(search: string, offset?: number): number;
|
||||
indexOf(search: string, offset?: number): number;
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"include": ["resources/lib/**/*.ts", "resources/lib/values/.number.d.ts"],
|
||||
"include": ["src/lib/**/*.ts", "src/main/resources/lib/lib.d.ts"],
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
@ -7,7 +7,7 @@
|
||||
"moduleResolution": "Bundler",
|
||||
"module": "ESNext",
|
||||
"target": "ESNext",
|
||||
"lib": [],
|
||||
"noLib": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
Loading…
Reference in New Issue
Block a user