source: trip-planner-front/node_modules/@angular/compiler-cli/linker/src/ast/ast_value.d.ts@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 8.1 KB
Line 
1/// <amd-module name="@angular/compiler-cli/linker/src/ast/ast_value" />
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9import * as o from '@angular/compiler';
10import { AstHost, Range } from './ast_host';
11/**
12 * Represents only those types in `T` that are object types.
13 */
14declare type ObjectType<T> = Extract<T, object>;
15/**
16 * Represents the value type of an object literal.
17 */
18declare type ObjectValueType<T> = T extends Record<string, infer R> ? R : never;
19/**
20 * Represents the value type of an array literal.
21 */
22declare type ArrayValueType<T> = T extends Array<infer R> ? R : never;
23/**
24 * Ensures that `This` has its generic type `Actual` conform to the expected generic type in
25 * `Expected`, to disallow calling a method if the generic type does not conform.
26 */
27declare type ConformsTo<This, Actual, Expected> = Actual extends Expected ? This : never;
28/**
29 * Ensures that `This` is an `AstValue` whose generic type conforms to `Expected`, to disallow
30 * calling a method if the value's type does not conform.
31 */
32declare type HasValueType<This, Expected> = This extends AstValue<infer Actual, any> ? ConformsTo<This, Actual, Expected> : never;
33/**
34 * Represents only the string keys of type `T`.
35 */
36declare type PropertyKey<T> = keyof T & string;
37/**
38 * This helper class wraps an object expression along with an `AstHost` object, exposing helper
39 * methods that make it easier to extract the properties of the object.
40 *
41 * The generic `T` is used as reference type of the expected structure that is represented by this
42 * object. It does not achieve full type-safety for the provided operations in correspondence with
43 * `T`; its main goal is to provide references to a documented type and ensure that the properties
44 * that are read from the object are present.
45 *
46 * Unfortunately, the generic types are unable to prevent reading an optional property from the
47 * object without first having called `has` to ensure that the property exists. This is one example
48 * of where full type-safety is not achieved.
49 */
50export declare class AstObject<T extends object, TExpression> {
51 readonly expression: TExpression;
52 private obj;
53 private host;
54 /**
55 * Create a new `AstObject` from the given `expression` and `host`.
56 */
57 static parse<T extends object, TExpression>(expression: TExpression, host: AstHost<TExpression>): AstObject<T, TExpression>;
58 private constructor();
59 /**
60 * Returns true if the object has a property called `propertyName`.
61 */
62 has(propertyName: PropertyKey<T>): boolean;
63 /**
64 * Returns the number value of the property called `propertyName`.
65 *
66 * Throws an error if there is no such property or the property is not a number.
67 */
68 getNumber<K extends PropertyKey<T>>(this: ConformsTo<this, T[K], number>, propertyName: K): number;
69 /**
70 * Returns the string value of the property called `propertyName`.
71 *
72 * Throws an error if there is no such property or the property is not a string.
73 */
74 getString<K extends PropertyKey<T>>(this: ConformsTo<this, T[K], string>, propertyName: K): string;
75 /**
76 * Returns the boolean value of the property called `propertyName`.
77 *
78 * Throws an error if there is no such property or the property is not a boolean.
79 */
80 getBoolean<K extends PropertyKey<T>>(this: ConformsTo<this, T[K], boolean>, propertyName: K): boolean;
81 /**
82 * Returns the nested `AstObject` parsed from the property called `propertyName`.
83 *
84 * Throws an error if there is no such property or the property is not an object.
85 */
86 getObject<K extends PropertyKey<T>>(this: ConformsTo<this, T[K], object>, propertyName: K): AstObject<ObjectType<T[K]>, TExpression>;
87 /**
88 * Returns an array of `AstValue` objects parsed from the property called `propertyName`.
89 *
90 * Throws an error if there is no such property or the property is not an array.
91 */
92 getArray<K extends PropertyKey<T>>(this: ConformsTo<this, T[K], unknown[]>, propertyName: K): AstValue<ArrayValueType<T[K]>, TExpression>[];
93 /**
94 * Returns a `WrappedNodeExpr` object that wraps the expression at the property called
95 * `propertyName`.
96 *
97 * Throws an error if there is no such property.
98 */
99 getOpaque(propertyName: PropertyKey<T>): o.WrappedNodeExpr<TExpression>;
100 /**
101 * Returns the raw `TExpression` value of the property called `propertyName`.
102 *
103 * Throws an error if there is no such property.
104 */
105 getNode(propertyName: PropertyKey<T>): TExpression;
106 /**
107 * Returns an `AstValue` that wraps the value of the property called `propertyName`.
108 *
109 * Throws an error if there is no such property.
110 */
111 getValue<K extends PropertyKey<T>>(propertyName: K): AstValue<T[K], TExpression>;
112 /**
113 * Converts the AstObject to a raw JavaScript object, mapping each property value (as an
114 * `AstValue`) to the generic type (`T`) via the `mapper` function.
115 */
116 toLiteral<V>(mapper: (value: AstValue<ObjectValueType<T>, TExpression>) => V): Record<string, V>;
117 /**
118 * Converts the AstObject to a JavaScript Map, mapping each property value (as an
119 * `AstValue`) to the generic type (`T`) via the `mapper` function.
120 */
121 toMap<V>(mapper: (value: AstValue<ObjectValueType<T>, TExpression>) => V): Map<string, V>;
122 private getRequiredProperty;
123}
124/**
125 * This helper class wraps an `expression`, exposing methods that use the `host` to give
126 * access to the underlying value of the wrapped expression.
127 *
128 * The generic `T` is used as reference type of the expected type that is represented by this value.
129 * It does not achieve full type-safety for the provided operations in correspondence with `T`; its
130 * main goal is to provide references to a documented type.
131 */
132export declare class AstValue<T, TExpression> {
133 readonly expression: TExpression;
134 private host;
135 constructor(expression: TExpression, host: AstHost<TExpression>);
136 /**
137 * Get the name of the symbol represented by the given expression node, or `null` if it is not a
138 * symbol.
139 */
140 getSymbolName(): string | null;
141 /**
142 * Is this value a number?
143 */
144 isNumber(): boolean;
145 /**
146 * Parse the number from this value, or error if it is not a number.
147 */
148 getNumber(this: HasValueType<this, number>): number;
149 /**
150 * Is this value a string?
151 */
152 isString(): boolean;
153 /**
154 * Parse the string from this value, or error if it is not a string.
155 */
156 getString(this: HasValueType<this, string>): string;
157 /**
158 * Is this value a boolean?
159 */
160 isBoolean(): boolean;
161 /**
162 * Parse the boolean from this value, or error if it is not a boolean.
163 */
164 getBoolean(this: HasValueType<this, boolean>): boolean;
165 /**
166 * Is this value an object literal?
167 */
168 isObject(): boolean;
169 /**
170 * Parse this value into an `AstObject`, or error if it is not an object literal.
171 */
172 getObject(this: HasValueType<this, object>): AstObject<ObjectType<T>, TExpression>;
173 /**
174 * Is this value an array literal?
175 */
176 isArray(): boolean;
177 /**
178 * Parse this value into an array of `AstValue` objects, or error if it is not an array literal.
179 */
180 getArray(this: HasValueType<this, unknown[]>): AstValue<ArrayValueType<T>, TExpression>[];
181 /**
182 * Is this value a function expression?
183 */
184 isFunction(): boolean;
185 /**
186 * Extract the return value as an `AstValue` from this value as a function expression, or error if
187 * it is not a function expression.
188 */
189 getFunctionReturnValue<R>(this: HasValueType<this, Function>): AstValue<R, TExpression>;
190 isCallExpression(): boolean;
191 getCallee(): AstValue<unknown, TExpression>;
192 getArguments(): AstValue<unknown, TExpression>[];
193 /**
194 * Return the `TExpression` of this value wrapped in a `WrappedNodeExpr`.
195 */
196 getOpaque(): o.WrappedNodeExpr<TExpression>;
197 /**
198 * Get the range of the location of this value in the original source.
199 */
200 getRange(): Range;
201}
202export {};
Note: See TracBrowser for help on using the repository browser.