1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { LocalResolver } from '../../compiler_util/expression_converter';
|
9 | import { ConstantPool } from '../../constant_pool';
|
10 | import * as core from '../../core';
|
11 | import { AST, AstMemoryEfficientTransformer, BindingPipe, LiteralArray, LiteralMap } from '../../expression_parser/ast';
|
12 | import * as i18n from '../../i18n/i18n_ast';
|
13 | import { InterpolationConfig } from '../../ml_parser/interpolation_config';
|
14 | import { LexerRange } from '../../ml_parser/lexer';
|
15 | import * as o from '../../output/output_ast';
|
16 | import { ParseError } from '../../parse_util';
|
17 | import { CssSelector } from '../../selector';
|
18 | import { BindingParser } from '../../template_parser/binding_parser';
|
19 | import * as t from '../r3_ast';
|
20 | import { I18nContext } from './i18n/context';
|
21 | import { invalid } from './util';
|
22 | export declare const LEADING_TRIVIA_CHARS: string[];
|
23 | export declare function renderFlagCheckIfStmt(flags: core.RenderFlags, statements: o.Statement[]): o.IfStmt;
|
24 | export declare function prepareEventListenerParameters(eventAst: t.BoundEvent, handlerName?: string | null, scope?: BindingScope | null): o.Expression[];
|
25 | export interface ComponentDefConsts {
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 | prepareStatements: o.Statement[];
|
32 | |
33 |
|
34 |
|
35 | constExpressions: o.Expression[];
|
36 | |
37 |
|
38 |
|
39 | i18nVarRefsCache: Map<i18n.I18nMeta, o.ReadVarExpr>;
|
40 | }
|
41 | export declare class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver {
|
42 | private constantPool;
|
43 | private level;
|
44 | private contextName;
|
45 | private i18nContext;
|
46 | private templateIndex;
|
47 | private templateName;
|
48 | private _namespace;
|
49 | private i18nUseExternalIds;
|
50 | private _constants;
|
51 | private _dataIndex;
|
52 | private _bindingContext;
|
53 | private _prefixCode;
|
54 | |
55 |
|
56 |
|
57 |
|
58 |
|
59 | private _creationCodeFns;
|
60 | |
61 |
|
62 |
|
63 |
|
64 |
|
65 | private _updateCodeFns;
|
66 |
|
67 | private _currentIndex;
|
68 |
|
69 | private _tempVariables;
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | private _nestedTemplateFns;
|
77 | |
78 |
|
79 |
|
80 |
|
81 | private _bindingScope;
|
82 | private _valueConverter;
|
83 | private i18n;
|
84 | private _pureFunctionSlots;
|
85 | private _bindingSlots;
|
86 | private fileBasedI18nSuffix;
|
87 | private _ngContentReservedSlots;
|
88 | private _ngContentSelectorsOffset;
|
89 | private _implicitReceiverExpr;
|
90 | constructor(constantPool: ConstantPool, parentBindingScope: BindingScope, level: number, contextName: string | null, i18nContext: I18nContext | null, templateIndex: number | null, templateName: string | null, _namespace: o.ExternalReference, relativeContextFilePath: string, i18nUseExternalIds: boolean, _constants?: ComponentDefConsts);
|
91 | buildTemplateFunction(nodes: t.Node[], variables: t.Variable[], ngContentSelectorsOffset?: number, i18n?: i18n.I18nMeta): o.FunctionExpr;
|
92 | getLocal(name: string): o.Expression | null;
|
93 | notifyImplicitReceiverUse(): void;
|
94 | maybeRestoreView(): void;
|
95 | private i18nTranslate;
|
96 | private registerContextVariables;
|
97 | private i18nAppendBindings;
|
98 | private i18nBindProps;
|
99 | private i18nGenerateMainBlockVar;
|
100 | private i18nGenerateClosureVar;
|
101 | private i18nUpdateRef;
|
102 | private i18nStart;
|
103 | private i18nEnd;
|
104 | private i18nAttributesInstruction;
|
105 | private getNamespaceInstruction;
|
106 | private addNamespaceInstruction;
|
107 | /**
|
108 | * Adds an update instruction for an interpolated property or attribute, such as
|
109 | * `prop="{{value}}"` or `attr.title="{{value}}"`
|
110 | */
|
111 | private interpolatedUpdateInstruction;
|
112 | visitContent(ngContent: t.Content): void;
|
113 | visitElement(element: t.Element): void;
|
114 | visitTemplate(template: t.Template): void;
|
115 | readonly visitReference: typeof invalid;
|
116 | readonly visitVariable: typeof invalid;
|
117 | readonly visitTextAttribute: typeof invalid;
|
118 | readonly visitBoundAttribute: typeof invalid;
|
119 | readonly visitBoundEvent: typeof invalid;
|
120 | visitBoundText(text: t.BoundText): void;
|
121 | visitText(text: t.Text): void;
|
122 | visitIcu(icu: t.Icu): null;
|
123 | private allocateDataSlot;
|
124 | getConstCount(): number;
|
125 | getVarCount(): number;
|
126 | getConsts(): ComponentDefConsts;
|
127 | getNgContentSelectors(): o.Expression | null;
|
128 | private bindingContext;
|
129 | private templatePropertyBindings;
|
130 | private instructionFn;
|
131 | private processStylingUpdateInstruction;
|
132 | private creationInstruction;
|
133 | private updateInstructionWithAdvance;
|
134 | private updateInstruction;
|
135 | private addAdvanceInstructionIfNecessary;
|
136 | private allocatePureFunctionSlots;
|
137 | private allocateBindingSlots;
|
138 | |
139 |
|
140 |
|
141 |
|
142 | private getImplicitReceiverExpr;
|
143 | private convertPropertyBinding;
|
144 | |
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | private getUpdateInstructionArguments;
|
151 | |
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | private getAttributeExpressions;
|
175 | private addToConsts;
|
176 | private addAttrsToConsts;
|
177 | private prepareRefsArray;
|
178 | private prepareListenerParameter;
|
179 | }
|
180 | export declare class ValueConverter extends AstMemoryEfficientTransformer {
|
181 | private constantPool;
|
182 | private allocateSlot;
|
183 | private allocatePureFunctionSlots;
|
184 | private definePipe;
|
185 | private _pipeBindExprs;
|
186 | constructor(constantPool: ConstantPool, allocateSlot: () => number, allocatePureFunctionSlots: (numSlots: number) => number, definePipe: (name: string, localName: string, slot: number, value: o.Expression) => void);
|
187 | visitPipe(pipe: BindingPipe, context: any): AST;
|
188 | updatePipeSlotOffsets(bindingSlots: number): void;
|
189 | visitLiteralArray(array: LiteralArray, context: any): AST;
|
190 | visitLiteralMap(map: LiteralMap, context: any): AST;
|
191 | }
|
192 | /**
|
193 | * Function which is executed whenever a variable is referenced for the first time in a given
|
194 | * scope.
|
195 | *
|
196 | * It is expected that the function creates the `const localName = expression`; statement.
|
197 | */
|
198 | export declare type DeclareLocalVarCallback = (scope: BindingScope, relativeLevel: number) => o.Statement[];
|
199 | /**
|
200 | * This is used when one refers to variable such as: 'let abc = nextContext(2).$implicit`.
|
201 | * - key to the map is the string literal `"abc"`.
|
202 | * - value `retrievalLevel` is the level from which this value can be retrieved, which is 2 levels
|
203 | * up in example.
|
204 | * - value `lhs` is the left hand side which is an AST representing `abc`.
|
205 | * - value `declareLocalCallback` is a callback that is invoked when declaring the local.
|
206 | * - value `declare` is true if this value needs to be declared.
|
207 | * - value `localRef` is true if we are storing a local reference
|
208 | * - value `priority` dictates the sorting priority of this var declaration compared
|
209 | * to other var declarations on the same retrieval level. For example, if there is a
|
210 | * context variable and a local ref accessing the same parent view, the context var
|
211 | * declaration should always come before the local ref declaration.
|
212 | */
|
213 | declare type BindingData = {
|
214 | retrievalLevel: number;
|
215 | lhs: o.Expression;
|
216 | declareLocalCallback?: DeclareLocalVarCallback;
|
217 | declare: boolean;
|
218 | priority: number;
|
219 | };
|
220 | export declare class BindingScope implements LocalResolver {
|
221 | bindingLevel: number;
|
222 | private parent;
|
223 | globals?: Set<string> | undefined;
|
224 |
|
225 | private map;
|
226 | private referenceNameIndex;
|
227 | private restoreViewVariable;
|
228 | private usesRestoredViewContext;
|
229 | static createRootScope(): BindingScope;
|
230 | private constructor();
|
231 | get(name: string): o.Expression | null;
|
232 | /**
|
233 | * Create a local variable for later reference.
|
234 | *
|
235 | * @param retrievalLevel The level from which this value can be retrieved
|
236 | * @param name Name of the variable.
|
237 | * @param lhs AST representing the left hand side of the `let lhs = rhs;`.
|
238 | * @param priority The sorting priority of this var
|
239 | * @param declareLocalCallback The callback to invoke when declaring this local var
|
240 | * @param localRef Whether or not this is a local ref
|
241 | */
|
242 | set(retrievalLevel: number, name: string, lhs: o.Expression, priority?: number, declareLocalCallback?: DeclareLocalVarCallback, localRef?: true): BindingScope;
|
243 | getLocal(name: string): (o.Expression | null);
|
244 | notifyImplicitReceiverUse(): void;
|
245 | nestedScope(level: number, globals?: Set<string>): BindingScope;
|
246 | /**
|
247 | * Gets or creates a shared context variable and returns its expression. Note that
|
248 | * this does not mean that the shared variable will be declared. Variables in the
|
249 | * binding scope will be only declared if they are used.
|
250 | */
|
251 | getOrCreateSharedContextVar(retrievalLevel: number): o.ReadVarExpr;
|
252 | getSharedContextName(retrievalLevel: number): o.ReadVarExpr | null;
|
253 | maybeGenerateSharedContextVar(value: BindingData): void;
|
254 | generateSharedContextVar(retrievalLevel: number): void;
|
255 | getComponentProperty(name: string): o.Expression;
|
256 | maybeRestoreView(): void;
|
257 | restoreViewStatement(): o.Statement[];
|
258 | viewSnapshotStatements(): o.Statement[];
|
259 | isListenerScope(): boolean | null;
|
260 | variableDeclarations(): o.Statement[];
|
261 | freshReferenceName(): string;
|
262 | hasRestoreViewVariable(): boolean;
|
263 | notifyRestoredViewContextUse(): void;
|
264 | }
|
265 | /**
|
266 | * Creates a `CssSelector` given a tag name and a map of attributes
|
267 | */
|
268 | export declare function createCssSelector(elementName: string, attributes: {
|
269 | [name: string]: string;
|
270 | }): CssSelector;
|
271 | /**
|
272 | * Options that can be used to modify how a template is parsed by `parseTemplate()`.
|
273 | */
|
274 | export interface ParseTemplateOptions {
|
275 | |
276 |
|
277 |
|
278 | preserveWhitespaces?: boolean;
|
279 | |
280 |
|
281 |
|
282 | preserveLineEndings?: boolean;
|
283 | |
284 |
|
285 |
|
286 | interpolationConfig?: InterpolationConfig;
|
287 | |
288 |
|
289 |
|
290 |
|
291 | range?: LexerRange;
|
292 | |
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 | escapedString?: boolean;
|
316 | |
317 |
|
318 |
|
319 |
|
320 |
|
321 | leadingTriviaChars?: string[];
|
322 | |
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 | enableI18nLegacyMessageIdFormat?: boolean;
|
331 | |
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 | i18nNormalizeLineEndingsInICUs?: boolean;
|
340 | |
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 | alwaysAttemptHtmlToR3AstConversion?: boolean;
|
355 | |
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 | collectCommentNodes?: boolean;
|
364 | }
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 | export declare function parseTemplate(template: string, templateUrl: string, options?: ParseTemplateOptions): ParsedTemplate;
|
373 |
|
374 |
|
375 |
|
376 | export declare function makeBindingParser(interpolationConfig?: InterpolationConfig): BindingParser;
|
377 | export declare function resolveSanitizationFn(context: core.SecurityContext, isAttribute?: boolean): o.ExternalExpr | null;
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 | export declare function getTranslationDeclStmts(message: i18n.Message, variable: o.ReadVarExpr, closureVar: o.ReadVarExpr, params?: {
|
405 | [name: string]: o.Expression;
|
406 | }, transformFn?: (raw: o.ReadVarExpr) => o.Expression): o.Statement[];
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 | export interface ParsedTemplate {
|
414 | |
415 |
|
416 |
|
417 | preserveWhitespaces?: boolean;
|
418 | |
419 |
|
420 |
|
421 | interpolationConfig?: InterpolationConfig;
|
422 | |
423 |
|
424 |
|
425 |
|
426 |
|
427 | errors: ParseError[] | null;
|
428 | |
429 |
|
430 |
|
431 | nodes: t.Node[];
|
432 | |
433 |
|
434 |
|
435 | styleUrls: string[];
|
436 | |
437 |
|
438 |
|
439 | styles: string[];
|
440 | |
441 |
|
442 |
|
443 | ngContentSelectors: string[];
|
444 | |
445 |
|
446 |
|
447 |
|
448 | commentNodes?: t.Comment[];
|
449 | }
|
450 | export {};
|