UNPKG

5.56 kBTypeScriptView Raw
1import { Dict, Nullable, Stack, SimpleElement, SimpleNode } from "@glimmer/interfaces";
2declare const EMPTY_ARRAY: readonly unknown[];
3declare function emptyArray<T>(): T[];
4declare const EMPTY_STRING_ARRAY: string[];
5declare const EMPTY_NUMBER_ARRAY: number[];
6/**
7 * This function returns `true` if the input array is the special empty array sentinel,
8 * which is sometimes used for optimizations.
9 */
10declare function isEmptyArray(input: unknown[] | readonly unknown[]): boolean;
11declare function reverse<T>(input: T[]): IterableIterator<T>;
12declare function enumerate<T>(input: Iterable<T>): IterableIterator<[
13 number,
14 T
15]>;
16type ZipEntry<T extends readonly unknown[]> = {
17 [P in keyof T]: P extends `${infer N extends number}` ? [
18 N,
19 T[P],
20 T[P]
21 ] : never;
22}[keyof T & number];
23/**
24 * Zip two tuples with the same type and number of elements.
25 */
26declare function zipTuples<T extends readonly unknown[]>(left: T, right: T): IterableIterator<ZipEntry<T>>;
27declare function zipArrays<T>(left: T[], right: T[]): IterableIterator<[
28 "retain",
29 number,
30 T,
31 T
32] | [
33 "pop",
34 number,
35 T,
36 undefined
37] | [
38 "push",
39 number,
40 undefined,
41 T
42]>;
43declare function dict<T = unknown>(): Dict<T>;
44declare function isDict<T>(u: T): u is Dict & T;
45declare function isIndexable<T>(u: T): u is object & T;
46declare class StackImpl<T> implements Stack<T> {
47 private stack;
48 current: Nullable<T>;
49 constructor(values?: T[]);
50 get size(): number;
51 push(item: T): void;
52 pop(): Nullable<T>;
53 nth(from: number): Nullable<T>;
54 isEmpty(): boolean;
55 snapshot(): T[];
56 toArray(): T[];
57}
58declare let beginTestSteps: (() => void) | undefined;
59declare let endTestSteps: (() => void) | undefined;
60declare let verifySteps: ((type: string, steps: unknown[] | ((steps: unknown[]) => void), message?: string) => void) | undefined;
61declare let logStep: ((type: string, steps: unknown) => void) | undefined;
62declare function clearElement(parent: SimpleElement): void;
63/**
64 Strongly hint runtimes to intern the provided string.
65
66 When do I need to use this function?
67
68 For the most part, never. Pre-mature optimization is bad, and often the
69 runtime does exactly what you need it to, and more often the trade-off isn't
70 worth it.
71
72 Why?
73
74 Runtimes store strings in at least 2 different representations:
75 Ropes and Symbols (interned strings). The Rope provides a memory efficient
76 data-structure for strings created from concatenation or some other string
77 manipulation like splitting.
78
79 Unfortunately checking equality of different ropes can be quite costly as
80 runtimes must resort to clever string comparison algorithms. These
81 algorithms typically cost in proportion to the length of the string.
82 Luckily, this is where the Symbols (interned strings) shine. As Symbols are
83 unique by their string content, equality checks can be done by pointer
84 comparison.
85
86 How do I know if my string is a rope or symbol?
87
88 Typically (warning general sweeping statement, but truthy in runtimes at
89 present) static strings created as part of the JS source are interned.
90 Strings often used for comparisons can be interned at runtime if some
91 criteria are met. One of these criteria can be the size of the entire rope.
92 For example, in chrome 38 a rope longer then 12 characters will not
93 intern, nor will segments of that rope.
94
95 Some numbers: http://jsperf.com/eval-vs-keys/8
96
97 Known Trick™
98
99 @private
100 @return {String} interned version of the provided string
101 */
102declare function intern(str: string): string;
103declare const SERIALIZATION_FIRST_NODE_STRING = "%+b:0%";
104declare function isSerializationFirstNode(node: SimpleNode): boolean;
105declare let assign: {
106 <T extends {}, U>(target: T, source: U): T & U;
107 <T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
108 <T_2 extends {}, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
109 (target: object, ...sources: any[]): any;
110};
111declare function values<T>(obj: {
112 [s: string]: T;
113}): T[];
114type ObjectEntry<D extends object> = {
115 [P in keyof D]: [
116 P,
117 D[P]
118 ];
119}[keyof D];
120declare function entries<D extends object>(dict: D): ObjectEntry<D>[];
121declare function keys<T extends object>(obj: T): (keyof T)[];
122declare function strip(strings: TemplateStringsArray, ...args: unknown[]): string;
123type FIXME<T, S extends string> = (T & S) | T;
124/**
125 * This constant exists to make it easier to differentiate normal logs from
126 * errant console.logs. LOCAL_LOGGER should only be used inside a
127 * LOCAL_TRACE_LOGGING check.
128 *
129 * It does not alleviate the need to check LOCAL_TRACE_LOGGING, which is used
130 * for stripping.
131 */
132declare const LOCAL_LOGGER: Console;
133/**
134 * This constant exists to make it easier to differentiate normal logs from
135 * errant console.logs. LOGGER can be used outside of LOCAL_TRACE_LOGGING checks,
136 * and is meant to be used in the rare situation where a console.* call is
137 * actually appropriate.
138 */
139declare const LOGGER: Console;
140declare function assertNever(value: never, desc?: string): never;
141export { EMPTY_ARRAY, emptyArray, EMPTY_STRING_ARRAY, EMPTY_NUMBER_ARRAY, isEmptyArray, reverse, enumerate, zipTuples, zipArrays, dict, isDict, isIndexable, StackImpl as Stack, beginTestSteps, endTestSteps, logStep, verifySteps, clearElement, intern, isSerializationFirstNode, SERIALIZATION_FIRST_NODE_STRING, assign, entries, keys, values, strip, FIXME, LOCAL_LOGGER, LOGGER, assertNever };
142//# sourceMappingURL=index.d.ts.map
\No newline at end of file