All files / common format.ts

98.85% Statements 258/261
100% Branches 0/0
0% Functions 0/1
98.85% Lines 258/261

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 2621x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x        
import type * as ts from "typescript";
 
export const F_READONLY: 'R' = 'R';
export const F_ABSTRACT: 'A' = 'A';
export const F_PUBLIC: '$' = '$';
export const F_PRIVATE: '#' = '#';
export const F_PROTECTED: '@' = '@';
export const F_PROPERTY: 'P' = 'P';
export const F_METHOD: 'M' = 'M';
export const F_STATIC: 'S' = 'S';
export const F_CLASS: 'C' = 'C';
export const F_INTERFACE: 'I' = 'I';
export const F_FUNCTION: 'F' = 'F';
export const F_ARROW_FUNCTION: '>' = '>';
export const F_OPTIONAL: '?' = '?';
export const F_REST: '3' = '3';
export const F_ASYNC: 'a' = 'a';
export const F_EXPORTED: 'e' = 'e';
export const F_INFERRED: '.' = '.';
export const F_OMITTED: ',' = ',';
 
/**
 * Flag attached to parameters which indicates that the parameter
 * is actually an array binding expression (aka destructured assignment).
 */
export const F_ARRAY_BINDING: '[' = '[';
 
/**
 * Flag attached to parameters which indicates that the parameter
 * is actually an object binding expression (aka destructured assignment).
 */
export const F_OBJECT_BINDING: 'O' = 'O';
 
export const T_UNION: '|' = '|';
export const T_INTERSECTION: '&' = '&';
export const T_ANY: '~' = '~';
export const T_UNKNOWN: 'U' = 'U';
export const T_VOID: 'V' = 'V';
export const T_UNDEFINED: 'u' = 'u';
export const T_NULL: 'n' = 'n';
export const T_TUPLE: 'T' = 'T';
export const T_ARRAY: '[' = '[';
export const T_THIS: 't' = 't';
export const T_GENERIC: 'g' = 'g';
export const T_MAPPED: 'm' = 'm';
export const T_TRUE: '1' = '1';
export const T_FALSE: '0' = '0';
export const T_CALLSITE: 'c' = 'c';
export const T_STAND_IN: '5' = '5';
export const T_OBJECT: 'O' = 'O';
export const T_ENUM: 'e' = 'e';
export const T_FUNCTION: 'F' = 'F';
export const T_INTRINSICS = [T_VOID, T_ANY, T_UNKNOWN, T_UNDEFINED, T_TRUE, T_FALSE, T_THIS, T_NULL];
 
export const TI_VOID: RtIntrinsicType = { TΦ: T_VOID };
export const TI_ANY: RtIntrinsicType = { TΦ: T_ANY };
export const TI_UNKNOWN: RtIntrinsicType = { TΦ: T_UNKNOWN };
export const TI_UNDEFINED: RtIntrinsicType = { TΦ: T_UNDEFINED };
export const TI_TRUE: RtIntrinsicType = { TΦ: T_TRUE };
export const TI_FALSE: RtIntrinsicType = { TΦ: T_FALSE };
export const TI_THIS: RtIntrinsicType = { TΦ: T_THIS };
export const TI_NULL: RtIntrinsicType = { TΦ: T_NULL };
 
export type Literal = number | string | bigint;
export interface InterfaceToken<T = any> {
    name: string;
    prototype: any;
    identity: symbol;
}
 
/**
 * Represents a type within the serialized emit RTTI format.
 */
export type RtType = RtDeferrableStructuralType | RtDeferrableValueType | RtDeferredType;
export type RtDeferrableStructuralType = RtIntrinsicType | RtObjectType | RtUnionType | RtIntersectionType
    | RtTupleType | RtArrayType | RtGenericType | RtMappedType | RtEnumType | RtCallSite
    | { TΦ: typeof T_STAND_IN } | RtFunctionType | Literal
;
export type RtDeferrableValueType = Function | InterfaceToken ;
export type RtDeferredType = RtDeferrableStructuralType | RtDeferredValueType;
export interface RtDeferredStructuralType { RΦ: () => RtDeferrableStructuralType; }
export interface RtDeferredValueType { LΦ: () => RtDeferrableValueType; }
 
export type RtBrandedType = {
    TΦ:
    typeof T_UNION | typeof T_INTERSECTION | typeof T_ANY | typeof T_UNKNOWN | typeof T_VOID | typeof T_UNDEFINED
    | typeof T_NULL | typeof T_TUPLE | typeof T_ARRAY | typeof T_THIS | typeof T_GENERIC | typeof T_MAPPED
    | typeof T_TRUE | typeof T_FALSE | typeof T_CALLSITE | typeof T_ENUM | typeof T_STAND_IN;
};
 
export type RtIntrinsicIndicator = typeof T_VOID | typeof T_ANY | typeof T_UNKNOWN | typeof T_UNDEFINED | typeof T_TRUE | typeof T_FALSE | typeof T_THIS | typeof T_NULL;
export type RtIntrinsicType<T extends RtIntrinsicIndicator = RtIntrinsicIndicator> = { TΦ: T; };
export type RtVoidType = RtIntrinsicType<typeof T_VOID>;
export type RtNullType = RtIntrinsicType<typeof T_NULL>;
export type RtUndefinedType = RtIntrinsicType<typeof T_UNDEFINED>;
export type RtFalseType = RtIntrinsicType<typeof T_FALSE>;
export type RtTrueType = RtIntrinsicType<typeof T_TRUE>;
export type RtUnknownType = RtIntrinsicType<typeof T_UNKNOWN>;
export type RtAnyType = RtIntrinsicType<typeof T_ANY>;
export type RtThisType = RtIntrinsicType<typeof T_THIS>;
 
export interface RtCallSite {
    TΦ: typeof T_CALLSITE;
 
    /**
     * Type of `this`. Not currently supported, always undefined.
     */
    t: RtType;
 
    /**
     * Parameter types of the call
     */
    p: RtType[];
 
    /**
     * Type parameters (generics)
     */
    tp: RtType[];
    r: RtType;
}
 
export interface RtUnionType {
    TΦ: typeof T_UNION;
    t: RtType[];
}
 
export interface RtObjectType {
    TΦ: typeof T_OBJECT;
    n?: string;
    m: RtObjectMember[];
}
 
export interface RtFunctionType {
    TΦ: typeof T_FUNCTION;
    r: RtType;
    p: RtParameter[];
    f: string;
}
export interface RtObjectMember {
    n: string;
    f: string;
    t: RtType;
}
 
export interface RtIntersectionType {
    TΦ: typeof T_INTERSECTION;
    t: RtType[];
}
 
export interface RtArrayType {
    TΦ: typeof T_ARRAY;
    e: RtType;
}
 
export interface RtTupleElement {
    n: string;
    t: RtType;
}
 
export interface RtTupleType {
    TΦ: typeof T_TUPLE;
    e: RtTupleElement[];
}
 
export interface RtMappedType {
    TΦ: typeof T_MAPPED;
 
    /**
     * The underlying mapped type
     */
    t: RtType;
 
    /**
     * Generic parameters of this type
     */
    p: RtType[];
 
    /**
     * The resulting object members after applying the mapped type
     */
    m?: RtObjectMember[];
}
 
export interface RtGenericType {
    TΦ: typeof T_GENERIC;
    t: RtType;
    p: RtType[];
}
 
export interface RtEnumType {
    TΦ: typeof T_ENUM;
    /**
     * This will be the runtime enum object, if it exists.
     * It will be undefined for const enums.
     */
    e: any;
 
    /**
     * Name of the enum
     */
    n?: string;
 
    /**
     * Values of the enum. Only provided for constant enums.
     */
    v?: Map<string,any>;
}
 
/**
 * Represents an encoded function/method parameter.
 */
export interface RtParameter {
    /**
     * Name of the parameter. Not present when this parameter is an array or object binding.
     */
    n?: string;
 
    /**
     * Whether this parameter is an array ('a') or object ('o') binding. Additionally RtParameters
     * which have `bt` set to ',' are omitted expressions (only valid in array binding expressions).
     * Array binding is Typescript's name for "destructuring assignment", see
     * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
     * for details.
     */
    bt?: 'a' | 'o' | ',';
 
    /**
     * The bindings for this parameter slot. Only present when `bt` is set to 'a' or 'o'
     * (meaning this parameter is an array or object binding, respectively)
     */
    b?: RtParameter[];
 
    /**
     * The type of this parameter.
     */
    t?: () => any;
 
    /**
     * The initializer for this parameter. Calling may cause side effects.
     * Only present if we are not an array/object binding
     */
    v?: () => any;
 
    /**
     * The flags for this parameter.
     */
    f?: string;
}
 
export interface LiteralSerializedNode {
    $__isTSNode: true;
    node: ts.Expression;
}
 
export type RtSerialized<T> = T | {
    [K in keyof T]: T[K] | RtSerialized<T[K]> | (T[K] extends Array<any> ? LiteralSerializedNode[] : LiteralSerializedNode);
};
 
export function isLiteralNode<T>(node: T | LiteralSerializedNode): node is LiteralSerializedNode {
    return !!node['$__isTSNode'];
}