Skip to content

Commit 10125e0

Browse files
committed
collection, core, generator, iterable, promise
1 parent 82eabf4 commit 10125e0

14 files changed

+539
-80
lines changed

build/index.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mkdir, readdir, writeFile } from "fs/promises";
22
import path from "path";
33
import ts from "typescript";
4-
import { betterLibs, replacement } from "./replacement";
4+
import { replacement } from "./replacement";
55

66
const projectDir = process.env.PROJECT || process.cwd();
77
const distDir = path.join(projectDir, "dist", "lib");
@@ -26,13 +26,18 @@ async function main() {
2626
if (!file) {
2727
continue;
2828
}
29-
let result = betterLibs.has(libFile)
30-
? `/// <reference path="../../lib/${libFile}" />\n`
31-
: "";
32-
for (const statement of file.statements) {
33-
const res = checkStatement(statement);
34-
if (res) {
35-
result += res.getFullText(file);
29+
const repl = replacement.get(libFile);
30+
let result = repl ? `/// <reference path="../../lib/${libFile}" />\n` : "";
31+
if (!repl) {
32+
for (const statement of file.statements) {
33+
result += statement.getFullText(file);
34+
}
35+
} else {
36+
for (const statement of file.statements) {
37+
const res = checkStatement(statement, repl);
38+
if (res) {
39+
result += res.getFullText(file);
40+
}
3641
}
3742
}
3843
result += file.text.slice(file.endOfFileToken.pos);
@@ -47,7 +52,10 @@ async function main() {
4752
}
4853
}
4954

50-
function checkStatement(statement: ts.Statement): ts.Statement | undefined {
55+
function checkStatement(
56+
statement: ts.Statement,
57+
replacement: Set<string>
58+
): ts.Statement | undefined {
5159
// check for declrations
5260
if (ts.isVariableStatement(statement)) {
5361
for (const dec of statement.declarationList.declarations) {

build/replacement.ts

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
1-
export const replacement = new Set<string>([
2-
// lib.es5.d.ts
3-
"eval",
4-
"ObjectConstructor",
5-
"CallableFunction",
6-
"IArguments",
7-
"JSON",
8-
"ArrayConstructor",
9-
// lib.es2015.collection.d.ts
10-
"Map",
11-
"MapConstructor",
12-
"WeakMap",
13-
"WeakMapConstructor",
14-
"ReadonlyMap",
15-
"Set",
16-
"SetConstructor",
17-
"ReadonlySet",
18-
]);
19-
20-
export const betterLibs = new Set<string>([
21-
"lib.es5.d.ts",
22-
"lib.es2015.collection.d.ts",
1+
export const replacement = new Map([
2+
[
3+
"lib.es5.d.ts",
4+
new Set([
5+
"eval",
6+
"ObjectConstructor",
7+
"CallableFunction",
8+
"IArguments",
9+
"JSON",
10+
"ArrayConstructor",
11+
]),
12+
],
13+
[
14+
"lib.es2015.collection.d.ts",
15+
new Set([
16+
"Map",
17+
"MapConstructor",
18+
"WeakMap",
19+
"WeakMapConstructor",
20+
"ReadonlyMap",
21+
"Set",
22+
"SetConstructor",
23+
"ReadonlySet",
24+
]),
25+
],
26+
[
27+
"lib.es2015.core.d.ts",
28+
new Set(["NumberConstructor", "ObjectConstructor", "String"]),
29+
],
30+
["lib.es2015.generator.d.ts", new Set(["Generator"])],
31+
[
32+
"lib.es2015.iterable.d.ts",
33+
new Set([
34+
"Iterator",
35+
"IterableIterator",
36+
"IArguments",
37+
"PromiseConstructor",
38+
]),
39+
],
40+
["lib.es2015.promise.d.ts", new Set(["PromiseConstructor"])],
2341
]);

lib/lib.es2015.core.d.ts

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
interface NumberConstructor {
2+
/**
3+
* The value of Number.EPSILON is the difference between 1 and the smallest value greater than 1
4+
* that is representable as a Number value, which is approximately:
5+
* 2.2204460492503130808472633361816 x 10‍−‍16.
6+
*/
7+
readonly EPSILON: number;
8+
9+
/**
10+
* Returns true if passed value is finite.
11+
* Unlike the global isFinite, Number.isFinite doesn't forcibly convert the parameter to a
12+
* number. Only finite values of the type number, result in true.
13+
* @param number A numeric value.
14+
*/
15+
isFinite(number: unknown): number is number;
16+
17+
/**
18+
* Returns true if the value passed is an integer, false otherwise.
19+
* @param number A numeric value.
20+
*/
21+
isInteger(number: unknown): number is number;
22+
23+
/**
24+
* Returns a Boolean value that indicates whether a value is the reserved value NaN (not a
25+
* number). Unlike the global isNaN(), Number.isNaN() doesn't forcefully convert the parameter
26+
* to a number. Only values of the type number, that are also NaN, result in true.
27+
* @param number A numeric value.
28+
*/
29+
isNaN(number: unknown): number is number;
30+
31+
/**
32+
* Returns true if the value passed is a safe integer.
33+
* @param number A numeric value.
34+
*/
35+
isSafeInteger(number: unknown): number is number;
36+
37+
/**
38+
* The value of the largest integer n such that n and n + 1 are both exactly representable as
39+
* a Number value.
40+
* The value of Number.MAX_SAFE_INTEGER is 9007199254740991 2^53 − 1.
41+
*/
42+
readonly MAX_SAFE_INTEGER: number;
43+
44+
/**
45+
* The value of the smallest integer n such that n and n − 1 are both exactly representable as
46+
* a Number value.
47+
* The value of Number.MIN_SAFE_INTEGER is −9007199254740991 (−(2^53 − 1)).
48+
*/
49+
readonly MIN_SAFE_INTEGER: number;
50+
51+
/**
52+
* Converts a string to a floating-point number.
53+
* @param string A string that contains a floating-point number.
54+
*/
55+
parseFloat(string: string): number;
56+
57+
/**
58+
* Converts A string to an integer.
59+
* @param s A string to convert into a number.
60+
* @param radix A value between 2 and 36 that specifies the base of the number in numString.
61+
* If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.
62+
* All other strings are considered decimal.
63+
*/
64+
parseInt(string: string, radix?: number): number;
65+
}
66+
67+
interface ObjectConstructor {
68+
/**
69+
* Copy the values of all of the enumerable own properties from one or more source objects to a
70+
* target object. Returns the target object.
71+
* @param target The target object to copy to.
72+
* @param sources One or more source objects from which to copy properties
73+
*/
74+
assign<T, Ts extends readonly any[]>(
75+
target: T,
76+
...sources: Ts
77+
): UnionToIntersection<T | Ts[number]>;
78+
79+
/**
80+
* Returns an array of all symbol properties found directly on object o.
81+
* @param o Object to retrieve the symbols from.
82+
*/
83+
getOwnPropertySymbols(o: any): symbol[];
84+
85+
/**
86+
* Returns the names of the enumerable string properties and methods of an object.
87+
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
88+
*/
89+
keys(o: {}): string[];
90+
91+
/**
92+
* Returns true if the values are the same value, false otherwise.
93+
* @param value1 The first value.
94+
* @param value2 The second value.
95+
*/
96+
is(value1: any, value2: any): boolean;
97+
98+
/**
99+
* Sets the prototype of a specified object o to object proto or null. Returns the object o.
100+
* @param o The object to change its prototype.
101+
* @param proto The value of the new prototype or null.
102+
*/
103+
setPrototypeOf<T>(o: T, proto: object | null): T;
104+
}
105+
106+
interface String {
107+
/**
108+
* Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point
109+
* value of the UTF-16 encoded code point starting at the string element at position pos in
110+
* the String resulting from converting this object to a String.
111+
* If there is no element at that position, the result is undefined.
112+
* If a valid UTF-16 surrogate pair does not begin at pos, the result is the code unit at pos.
113+
*/
114+
codePointAt(pos: number): number | undefined;
115+
116+
/**
117+
* Returns true if searchString appears as a substring of the result of converting this
118+
* object to a String, at one or more positions that are
119+
* greater than or equal to position; otherwise, returns false.
120+
* @param searchString search string
121+
* @param position If position is undefined, 0 is assumed, so as to search all of the String.
122+
*/
123+
includes(searchString: string, position?: number): boolean;
124+
125+
/**
126+
* Returns true if the sequence of elements of searchString converted to a String is the
127+
* same as the corresponding elements of this object (converted to a String) starting at
128+
* endPosition – length(this). Otherwise returns false.
129+
*/
130+
endsWith(searchString: string, endPosition?: number): boolean;
131+
132+
/**
133+
* Returns the String value result of normalizing the string into the normalization form
134+
* named by form as specified in Unicode Standard Annex #15, Unicode Normalization Forms.
135+
* @param form Applicable values: "NFC", "NFD", "NFKC", or "NFKD", If not specified default
136+
* is "NFC"
137+
*/
138+
normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD"): string;
139+
140+
/**
141+
* Returns a String value that is made from count copies appended together. If count is 0,
142+
* the empty string is returned.
143+
* @param count number of copies to append
144+
*/
145+
repeat(count: number): string;
146+
147+
/**
148+
* Returns true if the sequence of elements of searchString converted to a String is the
149+
* same as the corresponding elements of this object (converted to a String) starting at
150+
* position. Otherwise returns false.
151+
*/
152+
startsWith(searchString: string, position?: number): boolean;
153+
154+
/**
155+
* Returns an `<a>` HTML anchor element and sets the name attribute to the text value
156+
* @param name
157+
*/
158+
anchor(name: string): string;
159+
160+
/** Returns a `<big>` HTML element */
161+
big(): string;
162+
163+
/** Returns a `<blink>` HTML element */
164+
blink(): string;
165+
166+
/** Returns a `<b>` HTML element */
167+
bold(): string;
168+
169+
/** Returns a `<tt>` HTML element */
170+
fixed(): string;
171+
172+
/** Returns a `<font>` HTML element and sets the color attribute value */
173+
fontcolor(color: string): string;
174+
175+
/** Returns a `<font>` HTML element and sets the size attribute value */
176+
fontsize(size: number): string;
177+
178+
/** Returns a `<font>` HTML element and sets the size attribute value */
179+
fontsize(size: string): string;
180+
181+
/** Returns an `<i>` HTML element */
182+
italics(): string;
183+
184+
/** Returns an `<a>` HTML element and sets the href attribute value */
185+
link(url: string): string;
186+
187+
/** Returns a `<small>` HTML element */
188+
small(): string;
189+
190+
/** Returns a `<strike>` HTML element */
191+
strike(): string;
192+
193+
/** Returns a `<sub>` HTML element */
194+
sub(): string;
195+
196+
/** Returns a `<sup>` HTML element */
197+
sup(): string;
198+
}

lib/lib.es2015.generator.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference no-default-lib="true"/>
2+
3+
interface Generator<T = unknown, TReturn = unknown, TNext = unknown>
4+
extends Iterator<T, TReturn, TNext> {
5+
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
6+
next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
7+
return(value: TReturn): IteratorResult<T, TReturn>;
8+
throw(e: any): IteratorResult<T, TReturn>;
9+
[Symbol.iterator](): Generator<T, TReturn, TNext>;
10+
}

lib/lib.es2015.iterable.d.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference no-default-lib="true"/>
2+
3+
interface Iterator<T, TReturn = unknown, TNext = undefined> {
4+
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
5+
next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
6+
return?(value?: TReturn): IteratorResult<T, TReturn>;
7+
throw?(e?: any): IteratorResult<T, TReturn>;
8+
}
9+
10+
interface IterableIterator<T> extends Iterator<T, undefined, void> {
11+
[Symbol.iterator](): IterableIterator<T>;
12+
}
13+
14+
interface IArguments {
15+
/** Iterator */
16+
[Symbol.iterator](): IterableIterator<unknown>;
17+
}
18+
19+
interface PromiseConstructor {
20+
/**
21+
* Creates a Promise that is resolved with an array of results when all of the provided Promises
22+
* resolve, or rejected when any Promise is rejected.
23+
* @param values An iterable of Promises.
24+
* @returns A new Promise.
25+
*/
26+
all<T>(
27+
values: Iterable<T>
28+
): Promise<(T extends PromiseLike<infer U> ? U : T)[]>;
29+
30+
/**
31+
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
32+
* or rejected.
33+
* @param values An iterable of Promises.
34+
* @returns A new Promise.
35+
*/
36+
race<T>(values: Iterable<T>): Promise<T extends PromiseLike<infer U> ? U : T>;
37+
}

0 commit comments

Comments
 (0)