• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values.
2// If changing the text in this section, be sure to test `configurePrerelease` too.
3export const versionMajorMinor = "4.9";
4// The following is baselined as a literal template type without intervention
5/** The version of the TypeScript compiler release */
6// eslint-disable-next-line @typescript-eslint/no-inferrable-types
7export const version: string = `${versionMajorMinor}.5`;
8
9/**
10 * Type of objects whose values are all of the same type.
11 * The `in` and `for-in` operators can *not* be safely used,
12 * since `Object.prototype` may be modified by outside code.
13 */
14export interface MapLike<T> {
15    [index: string]: T;
16}
17
18export interface SortedReadonlyArray<T> extends ReadonlyArray<T> {
19    " __sortedArrayBrand": any;
20}
21
22export interface SortedArray<T> extends Array<T> {
23    " __sortedArrayBrand": any;
24}
25
26/** Common read methods for ES6 Map/Set. */
27export interface ReadonlyCollection<K> {
28    readonly size: number;
29    has(key: K): boolean;
30    keys(): Iterator<K>;
31}
32
33/** Common write methods for ES6 Map/Set. */
34export interface Collection<K> extends ReadonlyCollection<K> {
35    delete(key: K): boolean;
36    clear(): void;
37}
38
39/** ES6 Map interface, only read methods included. */
40export interface ReadonlyESMap<K, V> extends ReadonlyCollection<K> {
41    get(key: K): V | undefined;
42    values(): Iterator<V>;
43    entries(): Iterator<[K, V]>;
44    forEach(action: (value: V, key: K) => void): void;
45}
46
47/**
48 * ES6 Map interface, only read methods included.
49 */
50export interface ReadonlyMap<T> extends ReadonlyESMap<string, T> {
51}
52
53/** ES6 Map interface. */
54export interface ESMap<K, V> extends ReadonlyESMap<K, V>, Collection<K> {
55    set(key: K, value: V): this;
56}
57
58/**
59 * ES6 Map interface.
60 */
61export interface Map<T> extends ESMap<string, T> {
62}
63
64/** @internal */
65export interface MapConstructor {
66    // eslint-disable-next-line @typescript-eslint/prefer-function-type
67    new <K, V>(iterable?: readonly (readonly [K, V])[] | ReadonlyESMap<K, V>): ESMap<K, V>;
68}
69
70/** ES6 Set interface, only read methods included. */
71export interface ReadonlySet<T> extends ReadonlyCollection<T> {
72    has(value: T): boolean;
73    values(): Iterator<T>;
74    entries(): Iterator<[T, T]>;
75    forEach(action: (value: T, key: T) => void): void;
76}
77
78/** ES6 Set interface. */
79export interface Set<T> extends ReadonlySet<T>, Collection<T> {
80    add(value: T): this;
81    delete(value: T): boolean;
82}
83
84/** @internal */
85export interface SetConstructor {
86    // eslint-disable-next-line @typescript-eslint/prefer-function-type
87    new <T>(iterable?: readonly T[] | ReadonlySet<T>): Set<T>;
88}
89
90/** ES6 Iterator type. */
91export interface Iterator<T> {
92    next(): { value: T, done?: false } | { value: void, done: true };
93}
94
95/** Array that is only intended to be pushed to, never read. */
96export interface Push<T> {
97    push(...values: T[]): void;
98    /** @internal*/ readonly length: number;
99}
100
101/** @internal */
102export type EqualityComparer<T> = (a: T, b: T) => boolean;
103
104/** @internal */
105export type Comparer<T> = (a: T, b: T) => Comparison;
106
107/** @internal */
108export const enum Comparison {
109    LessThan    = -1,
110    EqualTo     = 0,
111    GreaterThan = 1
112}
113
114/** @internal */
115namespace NativeCollections {
116    declare const self: any;
117
118    const globals = typeof globalThis !== "undefined" ? globalThis :
119              typeof global !== "undefined" ? global :
120              typeof self !== "undefined" ? self :
121              undefined;
122
123    /**
124     * Returns the native Map implementation if it is available and compatible (i.e. supports iteration).
125     */
126    export function tryGetNativeMap(): MapConstructor {
127        // Internet Explorer's Map doesn't support iteration, so don't use it.
128        const gMap = globals?.Map;
129        // eslint-disable-next-line local/no-in-operator
130        const constructor = typeof gMap !== "undefined" && "entries" in gMap.prototype && new gMap([[0, 0]]).size === 1 ? gMap : undefined;
131        if (!constructor) {
132            throw new Error("No compatible Map implementation found.");
133        }
134        return constructor;
135    }
136
137    /**
138     * Returns the native Set implementation if it is available and compatible (i.e. supports iteration).
139     */
140    export function tryGetNativeSet(): SetConstructor {
141        // Internet Explorer's Set doesn't support iteration, so don't use it.
142        const gSet = globals?.Set;
143        // eslint-disable-next-line local/no-in-operator
144        const constructor = typeof gSet !== "undefined" && "entries" in gSet.prototype && new gSet([0]).size === 1 ? gSet : undefined;
145        if (!constructor) {
146            throw new Error("No compatible Set implementation found.");
147        }
148        return constructor;
149    }
150}
151
152/** @internal */
153export const Map = NativeCollections.tryGetNativeMap();
154/** @internal */
155export const Set = NativeCollections.tryGetNativeSet();
156