UNPKG

20.3 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { SecurityContext } from '../core';
9import { ParseSourceSpan } from '../parse_util';
10export declare class ParserError {
11 input: string;
12 errLocation: string;
13 ctxLocation?: any;
14 message: string;
15 constructor(message: string, input: string, errLocation: string, ctxLocation?: any);
16}
17export declare class ParseSpan {
18 start: number;
19 end: number;
20 constructor(start: number, end: number);
21 toAbsolute(absoluteOffset: number): AbsoluteSourceSpan;
22}
23export declare abstract class AST {
24 span: ParseSpan;
25 /**
26 * Absolute location of the expression AST in a source code file.
27 */
28 sourceSpan: AbsoluteSourceSpan;
29 constructor(span: ParseSpan,
30 /**
31 * Absolute location of the expression AST in a source code file.
32 */
33 sourceSpan: AbsoluteSourceSpan);
34 abstract visit(visitor: AstVisitor, context?: any): any;
35 toString(): string;
36}
37export declare abstract class ASTWithName extends AST {
38 nameSpan: AbsoluteSourceSpan;
39 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, nameSpan: AbsoluteSourceSpan);
40}
41/**
42 * Represents a quoted expression of the form:
43 *
44 * quote = prefix `:` uninterpretedExpression
45 * prefix = identifier
46 * uninterpretedExpression = arbitrary string
47 *
48 * A quoted expression is meant to be pre-processed by an AST transformer that
49 * converts it into another AST that no longer contains quoted expressions.
50 * It is meant to allow third-party developers to extend Angular template
51 * expression language. The `uninterpretedExpression` part of the quote is
52 * therefore not interpreted by the Angular's own expression parser.
53 */
54export declare class Quote extends AST {
55 prefix: string;
56 uninterpretedExpression: string;
57 location: any;
58 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, prefix: string, uninterpretedExpression: string, location: any);
59 visit(visitor: AstVisitor, context?: any): any;
60 toString(): string;
61}
62export declare class EmptyExpr extends AST {
63 visit(visitor: AstVisitor, context?: any): void;
64}
65export declare class ImplicitReceiver extends AST {
66 visit(visitor: AstVisitor, context?: any): any;
67}
68/**
69 * Receiver when something is accessed through `this` (e.g. `this.foo`). Note that this class
70 * inherits from `ImplicitReceiver`, because accessing something through `this` is treated the
71 * same as accessing it implicitly inside of an Angular template (e.g. `[attr.title]="this.title"`
72 * is the same as `[attr.title]="title"`.). Inheriting allows for the `this` accesses to be treated
73 * the same as implicit ones, except for a couple of exceptions like `$event` and `$any`.
74 * TODO: we should find a way for this class not to extend from `ImplicitReceiver` in the future.
75 */
76export declare class ThisReceiver extends ImplicitReceiver {
77 visit(visitor: AstVisitor, context?: any): any;
78}
79/**
80 * Multiple expressions separated by a semicolon.
81 */
82export declare class Chain extends AST {
83 expressions: any[];
84 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, expressions: any[]);
85 visit(visitor: AstVisitor, context?: any): any;
86}
87export declare class Conditional extends AST {
88 condition: AST;
89 trueExp: AST;
90 falseExp: AST;
91 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, condition: AST, trueExp: AST, falseExp: AST);
92 visit(visitor: AstVisitor, context?: any): any;
93}
94export declare class PropertyRead extends ASTWithName {
95 receiver: AST;
96 name: string;
97 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, nameSpan: AbsoluteSourceSpan, receiver: AST, name: string);
98 visit(visitor: AstVisitor, context?: any): any;
99}
100export declare class PropertyWrite extends ASTWithName {
101 receiver: AST;
102 name: string;
103 value: AST;
104 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, nameSpan: AbsoluteSourceSpan, receiver: AST, name: string, value: AST);
105 visit(visitor: AstVisitor, context?: any): any;
106}
107export declare class SafePropertyRead extends ASTWithName {
108 receiver: AST;
109 name: string;
110 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, nameSpan: AbsoluteSourceSpan, receiver: AST, name: string);
111 visit(visitor: AstVisitor, context?: any): any;
112}
113export declare class KeyedRead extends AST {
114 receiver: AST;
115 key: AST;
116 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, receiver: AST, key: AST);
117 visit(visitor: AstVisitor, context?: any): any;
118}
119export declare class SafeKeyedRead extends AST {
120 receiver: AST;
121 key: AST;
122 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, receiver: AST, key: AST);
123 visit(visitor: AstVisitor, context?: any): any;
124}
125export declare class KeyedWrite extends AST {
126 receiver: AST;
127 key: AST;
128 value: AST;
129 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, receiver: AST, key: AST, value: AST);
130 visit(visitor: AstVisitor, context?: any): any;
131}
132export declare class BindingPipe extends ASTWithName {
133 exp: AST;
134 name: string;
135 args: any[];
136 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, exp: AST, name: string, args: any[], nameSpan: AbsoluteSourceSpan);
137 visit(visitor: AstVisitor, context?: any): any;
138}
139export declare class LiteralPrimitive extends AST {
140 value: any;
141 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, value: any);
142 visit(visitor: AstVisitor, context?: any): any;
143}
144export declare class LiteralArray extends AST {
145 expressions: any[];
146 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, expressions: any[]);
147 visit(visitor: AstVisitor, context?: any): any;
148}
149export declare type LiteralMapKey = {
150 key: string;
151 quoted: boolean;
152};
153export declare class LiteralMap extends AST {
154 keys: LiteralMapKey[];
155 values: any[];
156 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, keys: LiteralMapKey[], values: any[]);
157 visit(visitor: AstVisitor, context?: any): any;
158}
159export declare class Interpolation extends AST {
160 strings: any[];
161 expressions: any[];
162 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, strings: any[], expressions: any[]);
163 visit(visitor: AstVisitor, context?: any): any;
164}
165export declare class Binary extends AST {
166 operation: string;
167 left: AST;
168 right: AST;
169 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, operation: string, left: AST, right: AST);
170 visit(visitor: AstVisitor, context?: any): any;
171}
172/**
173 * For backwards compatibility reasons, `Unary` inherits from `Binary` and mimics the binary AST
174 * node that was originally used. This inheritance relation can be deleted in some future major,
175 * after consumers have been given a chance to fully support Unary.
176 */
177export declare class Unary extends Binary {
178 operator: string;
179 expr: AST;
180 left: never;
181 right: never;
182 operation: never;
183 /**
184 * Creates a unary minus expression "-x", represented as `Binary` using "0 - x".
185 */
186 static createMinus(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, expr: AST): Unary;
187 /**
188 * Creates a unary plus expression "+x", represented as `Binary` using "x - 0".
189 */
190 static createPlus(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, expr: AST): Unary;
191 /**
192 * During the deprecation period this constructor is private, to avoid consumers from creating
193 * a `Unary` with the fallback properties for `Binary`.
194 */
195 private constructor();
196 visit(visitor: AstVisitor, context?: any): any;
197}
198export declare class PrefixNot extends AST {
199 expression: AST;
200 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, expression: AST);
201 visit(visitor: AstVisitor, context?: any): any;
202}
203export declare class NonNullAssert extends AST {
204 expression: AST;
205 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, expression: AST);
206 visit(visitor: AstVisitor, context?: any): any;
207}
208export declare class Call extends AST {
209 receiver: AST;
210 args: AST[];
211 argumentSpan: AbsoluteSourceSpan;
212 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, receiver: AST, args: AST[], argumentSpan: AbsoluteSourceSpan);
213 visit(visitor: AstVisitor, context?: any): any;
214}
215export declare class SafeCall extends AST {
216 receiver: AST;
217 args: AST[];
218 argumentSpan: AbsoluteSourceSpan;
219 constructor(span: ParseSpan, sourceSpan: AbsoluteSourceSpan, receiver: AST, args: AST[], argumentSpan: AbsoluteSourceSpan);
220 visit(visitor: AstVisitor, context?: any): any;
221}
222/**
223 * Records the absolute position of a text span in a source file, where `start` and `end` are the
224 * starting and ending byte offsets, respectively, of the text span in a source file.
225 */
226export declare class AbsoluteSourceSpan {
227 readonly start: number;
228 readonly end: number;
229 constructor(start: number, end: number);
230}
231export declare class ASTWithSource extends AST {
232 ast: AST;
233 source: string | null;
234 location: string;
235 errors: ParserError[];
236 constructor(ast: AST, source: string | null, location: string, absoluteOffset: number, errors: ParserError[]);
237 visit(visitor: AstVisitor, context?: any): any;
238 toString(): string;
239}
240/**
241 * TemplateBinding refers to a particular key-value pair in a microsyntax
242 * expression. A few examples are:
243 *
244 * |---------------------|--------------|---------|--------------|
245 * | expression | key | value | binding type |
246 * |---------------------|--------------|---------|--------------|
247 * | 1. let item | item | null | variable |
248 * | 2. of items | ngForOf | items | expression |
249 * | 3. let x = y | x | y | variable |
250 * | 4. index as i | i | index | variable |
251 * | 5. trackBy: func | ngForTrackBy | func | expression |
252 * | 6. *ngIf="cond" | ngIf | cond | expression |
253 * |---------------------|--------------|---------|--------------|
254 *
255 * (6) is a notable exception because it is a binding from the template key in
256 * the LHS of a HTML attribute to the expression in the RHS. All other bindings
257 * in the example above are derived solely from the RHS.
258 */
259export declare type TemplateBinding = VariableBinding | ExpressionBinding;
260export declare class VariableBinding {
261 readonly sourceSpan: AbsoluteSourceSpan;
262 readonly key: TemplateBindingIdentifier;
263 readonly value: TemplateBindingIdentifier | null;
264 /**
265 * @param sourceSpan entire span of the binding.
266 * @param key name of the LHS along with its span.
267 * @param value optional value for the RHS along with its span.
268 */
269 constructor(sourceSpan: AbsoluteSourceSpan, key: TemplateBindingIdentifier, value: TemplateBindingIdentifier | null);
270}
271export declare class ExpressionBinding {
272 readonly sourceSpan: AbsoluteSourceSpan;
273 readonly key: TemplateBindingIdentifier;
274 readonly value: ASTWithSource | null;
275 /**
276 * @param sourceSpan entire span of the binding.
277 * @param key binding name, like ngForOf, ngForTrackBy, ngIf, along with its
278 * span. Note that the length of the span may not be the same as
279 * `key.source.length`. For example,
280 * 1. key.source = ngFor, key.span is for "ngFor"
281 * 2. key.source = ngForOf, key.span is for "of"
282 * 3. key.source = ngForTrackBy, key.span is for "trackBy"
283 * @param value optional expression for the RHS.
284 */
285 constructor(sourceSpan: AbsoluteSourceSpan, key: TemplateBindingIdentifier, value: ASTWithSource | null);
286}
287export interface TemplateBindingIdentifier {
288 source: string;
289 span: AbsoluteSourceSpan;
290}
291export interface AstVisitor {
292 /**
293 * The `visitUnary` method is declared as optional for backwards compatibility. In an upcoming
294 * major release, this method will be made required.
295 */
296 visitUnary?(ast: Unary, context: any): any;
297 visitBinary(ast: Binary, context: any): any;
298 visitChain(ast: Chain, context: any): any;
299 visitConditional(ast: Conditional, context: any): any;
300 /**
301 * The `visitThisReceiver` method is declared as optional for backwards compatibility.
302 * In an upcoming major release, this method will be made required.
303 */
304 visitThisReceiver?(ast: ThisReceiver, context: any): any;
305 visitImplicitReceiver(ast: ImplicitReceiver, context: any): any;
306 visitInterpolation(ast: Interpolation, context: any): any;
307 visitKeyedRead(ast: KeyedRead, context: any): any;
308 visitKeyedWrite(ast: KeyedWrite, context: any): any;
309 visitLiteralArray(ast: LiteralArray, context: any): any;
310 visitLiteralMap(ast: LiteralMap, context: any): any;
311 visitLiteralPrimitive(ast: LiteralPrimitive, context: any): any;
312 visitPipe(ast: BindingPipe, context: any): any;
313 visitPrefixNot(ast: PrefixNot, context: any): any;
314 visitNonNullAssert(ast: NonNullAssert, context: any): any;
315 visitPropertyRead(ast: PropertyRead, context: any): any;
316 visitPropertyWrite(ast: PropertyWrite, context: any): any;
317 visitQuote(ast: Quote, context: any): any;
318 visitSafePropertyRead(ast: SafePropertyRead, context: any): any;
319 visitSafeKeyedRead(ast: SafeKeyedRead, context: any): any;
320 visitCall(ast: Call, context: any): any;
321 visitSafeCall(ast: SafeCall, context: any): any;
322 visitASTWithSource?(ast: ASTWithSource, context: any): any;
323 /**
324 * This function is optionally defined to allow classes that implement this
325 * interface to selectively decide if the specified `ast` should be visited.
326 * @param ast node to visit
327 * @param context context that gets passed to the node and all its children
328 */
329 visit?(ast: AST, context?: any): any;
330}
331export declare class RecursiveAstVisitor implements AstVisitor {
332 visit(ast: AST, context?: any): any;
333 visitUnary(ast: Unary, context: any): any;
334 visitBinary(ast: Binary, context: any): any;
335 visitChain(ast: Chain, context: any): any;
336 visitConditional(ast: Conditional, context: any): any;
337 visitPipe(ast: BindingPipe, context: any): any;
338 visitImplicitReceiver(ast: ThisReceiver, context: any): any;
339 visitThisReceiver(ast: ThisReceiver, context: any): any;
340 visitInterpolation(ast: Interpolation, context: any): any;
341 visitKeyedRead(ast: KeyedRead, context: any): any;
342 visitKeyedWrite(ast: KeyedWrite, context: any): any;
343 visitLiteralArray(ast: LiteralArray, context: any): any;
344 visitLiteralMap(ast: LiteralMap, context: any): any;
345 visitLiteralPrimitive(ast: LiteralPrimitive, context: any): any;
346 visitPrefixNot(ast: PrefixNot, context: any): any;
347 visitNonNullAssert(ast: NonNullAssert, context: any): any;
348 visitPropertyRead(ast: PropertyRead, context: any): any;
349 visitPropertyWrite(ast: PropertyWrite, context: any): any;
350 visitSafePropertyRead(ast: SafePropertyRead, context: any): any;
351 visitSafeKeyedRead(ast: SafeKeyedRead, context: any): any;
352 visitCall(ast: Call, context: any): any;
353 visitSafeCall(ast: SafeCall, context: any): any;
354 visitQuote(ast: Quote, context: any): any;
355 visitAll(asts: AST[], context: any): any;
356}
357export declare class AstTransformer implements AstVisitor {
358 visitImplicitReceiver(ast: ImplicitReceiver, context: any): AST;
359 visitThisReceiver(ast: ThisReceiver, context: any): AST;
360 visitInterpolation(ast: Interpolation, context: any): AST;
361 visitLiteralPrimitive(ast: LiteralPrimitive, context: any): AST;
362 visitPropertyRead(ast: PropertyRead, context: any): AST;
363 visitPropertyWrite(ast: PropertyWrite, context: any): AST;
364 visitSafePropertyRead(ast: SafePropertyRead, context: any): AST;
365 visitLiteralArray(ast: LiteralArray, context: any): AST;
366 visitLiteralMap(ast: LiteralMap, context: any): AST;
367 visitUnary(ast: Unary, context: any): AST;
368 visitBinary(ast: Binary, context: any): AST;
369 visitPrefixNot(ast: PrefixNot, context: any): AST;
370 visitNonNullAssert(ast: NonNullAssert, context: any): AST;
371 visitConditional(ast: Conditional, context: any): AST;
372 visitPipe(ast: BindingPipe, context: any): AST;
373 visitKeyedRead(ast: KeyedRead, context: any): AST;
374 visitKeyedWrite(ast: KeyedWrite, context: any): AST;
375 visitCall(ast: Call, context: any): AST;
376 visitSafeCall(ast: SafeCall, context: any): AST;
377 visitAll(asts: any[]): any[];
378 visitChain(ast: Chain, context: any): AST;
379 visitQuote(ast: Quote, context: any): AST;
380 visitSafeKeyedRead(ast: SafeKeyedRead, context: any): AST;
381}
382export declare class AstMemoryEfficientTransformer implements AstVisitor {
383 visitImplicitReceiver(ast: ImplicitReceiver, context: any): AST;
384 visitThisReceiver(ast: ThisReceiver, context: any): AST;
385 visitInterpolation(ast: Interpolation, context: any): Interpolation;
386 visitLiteralPrimitive(ast: LiteralPrimitive, context: any): AST;
387 visitPropertyRead(ast: PropertyRead, context: any): AST;
388 visitPropertyWrite(ast: PropertyWrite, context: any): AST;
389 visitSafePropertyRead(ast: SafePropertyRead, context: any): AST;
390 visitLiteralArray(ast: LiteralArray, context: any): AST;
391 visitLiteralMap(ast: LiteralMap, context: any): AST;
392 visitUnary(ast: Unary, context: any): AST;
393 visitBinary(ast: Binary, context: any): AST;
394 visitPrefixNot(ast: PrefixNot, context: any): AST;
395 visitNonNullAssert(ast: NonNullAssert, context: any): AST;
396 visitConditional(ast: Conditional, context: any): AST;
397 visitPipe(ast: BindingPipe, context: any): AST;
398 visitKeyedRead(ast: KeyedRead, context: any): AST;
399 visitKeyedWrite(ast: KeyedWrite, context: any): AST;
400 visitAll(asts: any[]): any[];
401 visitChain(ast: Chain, context: any): AST;
402 visitCall(ast: Call, context: any): AST;
403 visitSafeCall(ast: SafeCall, context: any): AST;
404 visitQuote(ast: Quote, context: any): AST;
405 visitSafeKeyedRead(ast: SafeKeyedRead, context: any): AST;
406}
407export declare class ParsedProperty {
408 name: string;
409 expression: ASTWithSource;
410 type: ParsedPropertyType;
411 sourceSpan: ParseSourceSpan;
412 readonly keySpan: ParseSourceSpan;
413 valueSpan: ParseSourceSpan | undefined;
414 readonly isLiteral: boolean;
415 readonly isAnimation: boolean;
416 constructor(name: string, expression: ASTWithSource, type: ParsedPropertyType, sourceSpan: ParseSourceSpan, keySpan: ParseSourceSpan, valueSpan: ParseSourceSpan | undefined);
417}
418export declare enum ParsedPropertyType {
419 DEFAULT = 0,
420 LITERAL_ATTR = 1,
421 ANIMATION = 2
422}
423export declare const enum ParsedEventType {
424 Regular = 0,
425 Animation = 1
426}
427export declare class ParsedEvent {
428 name: string;
429 targetOrPhase: string;
430 type: ParsedEventType;
431 handler: ASTWithSource;
432 sourceSpan: ParseSourceSpan;
433 handlerSpan: ParseSourceSpan;
434 readonly keySpan: ParseSourceSpan;
435 constructor(name: string, targetOrPhase: string, type: ParsedEventType, handler: ASTWithSource, sourceSpan: ParseSourceSpan, handlerSpan: ParseSourceSpan, keySpan: ParseSourceSpan);
436}
437/**
438 * ParsedVariable represents a variable declaration in a microsyntax expression.
439 */
440export declare class ParsedVariable {
441 readonly name: string;
442 readonly value: string;
443 readonly sourceSpan: ParseSourceSpan;
444 readonly keySpan: ParseSourceSpan;
445 readonly valueSpan?: ParseSourceSpan | undefined;
446 constructor(name: string, value: string, sourceSpan: ParseSourceSpan, keySpan: ParseSourceSpan, valueSpan?: ParseSourceSpan | undefined);
447}
448export declare const enum BindingType {
449 Property = 0,
450 Attribute = 1,
451 Class = 2,
452 Style = 3,
453 Animation = 4
454}
455export declare class BoundElementProperty {
456 name: string;
457 type: BindingType;
458 securityContext: SecurityContext;
459 value: ASTWithSource;
460 unit: string | null;
461 sourceSpan: ParseSourceSpan;
462 readonly keySpan: ParseSourceSpan | undefined;
463 valueSpan: ParseSourceSpan | undefined;
464 constructor(name: string, type: BindingType, securityContext: SecurityContext, value: ASTWithSource, unit: string | null, sourceSpan: ParseSourceSpan, keySpan: ParseSourceSpan | undefined, valueSpan: ParseSourceSpan | undefined);
465}