UNPKG

4.32 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 * as o from '../output/output_ast';
9export declare function typeWithParameters(type: o.Expression, numParams: number): o.ExpressionType;
10export interface R3Reference {
11 value: o.Expression;
12 type: o.Expression;
13}
14/**
15 * Result of compilation of a render3 code unit, e.g. component, directive, pipe, etc.
16 */
17export interface R3CompiledExpression {
18 expression: o.Expression;
19 type: o.Type;
20 statements: o.Statement[];
21}
22export declare function prepareSyntheticPropertyName(name: string): string;
23export declare function prepareSyntheticListenerName(name: string, phase: string): string;
24export declare function getSafePropertyAccessString(accessor: string, name: string): string;
25export declare function prepareSyntheticListenerFunctionName(name: string, phase: string): string;
26export declare function jitOnlyGuardedExpression(expr: o.Expression): o.Expression;
27export declare function devOnlyGuardedExpression(expr: o.Expression): o.Expression;
28export declare function guardedExpression(guard: string, expr: o.Expression): o.Expression;
29export declare function wrapReference(value: any): R3Reference;
30export declare function refsToArray(refs: R3Reference[], shouldForwardDeclare: boolean): o.Expression;
31/**
32 * Describes an expression that may have been wrapped in a `forwardRef()` guard.
33 *
34 * This is used when describing expressions that can refer to types that may eagerly reference types
35 * that have not yet been defined.
36 */
37export interface MaybeForwardRefExpression<T extends o.Expression = o.Expression> {
38 /**
39 * The unwrapped expression.
40 */
41 expression: T;
42 /**
43 * Specified whether the `expression` contains a reference to something that has not yet been
44 * defined, and whether the expression is still wrapped in a `forwardRef()` call.
45 *
46 * If this value is `ForwardRefHandling.None` then the `expression` is safe to use as-is.
47 *
48 * Otherwise the `expression` was wrapped in a call to `forwardRef()` and must not be eagerly
49 * evaluated. Instead it must be wrapped in a function closure that will be evaluated lazily to
50 * allow the definition of the expression to be evaluated first.
51 *
52 * In full AOT compilation it can be safe to unwrap the `forwardRef()` call up front if the
53 * expression will actually be evaluated lazily inside a function call after the value of
54 * `expression` has been defined.
55 *
56 * But in other cases, such as partial AOT compilation or JIT compilation the expression will be
57 * evaluated eagerly in top level code so will need to continue to be wrapped in a `forwardRef()`
58 * call.
59 *
60 */
61 forwardRef: ForwardRefHandling;
62}
63export declare function createMayBeForwardRefExpression<T extends o.Expression>(expression: T, forwardRef: ForwardRefHandling): MaybeForwardRefExpression<T>;
64/**
65 * Convert a `MaybeForwardRefExpression` to an `Expression`, possibly wrapping its expression in a
66 * `forwardRef()` call.
67 *
68 * If `MaybeForwardRefExpression.forwardRef` is `ForwardRefHandling.Unwrapped` then the expression
69 * was originally wrapped in a `forwardRef()` call to prevent the value from being eagerly evaluated
70 * in the code.
71 *
72 * See `packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts` and
73 * `packages/compiler/src/jit_compiler_facade.ts` for more information.
74 */
75export declare function convertFromMaybeForwardRefExpression({ expression, forwardRef }: MaybeForwardRefExpression): o.Expression;
76/**
77 * Generate an expression that has the given `expr` wrapped in the following form:
78 *
79 * ```
80 * forwardRef(() => expr)
81 * ```
82 */
83export declare function generateForwardRef(expr: o.Expression): o.Expression;
84/**
85 * Specifies how a forward ref has been handled in a MaybeForwardRefExpression
86 */
87export declare const enum ForwardRefHandling {
88 /** The expression was not wrapped in a `forwardRef()` call in the first place. */
89 None = 0,
90 /** The expression is still wrapped in a `forwardRef()` call. */
91 Wrapped = 1,
92 /** The expression was wrapped in a `forwardRef()` call but has since been unwrapped. */
93 Unwrapped = 2
94}