@angular/compiler-cli 21.0.0-rc.1 → 21.0.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/bundles/{chunk-5UJIUEKT.js → chunk-3UWOVJPM.js} +20 -3
  2. package/bundles/{chunk-VBBJY6IR.js → chunk-67N3I5R2.js} +1675 -1523
  3. package/bundles/{chunk-DBAV4W4V.js → chunk-EZPRBQ4S.js} +2 -2
  4. package/bundles/{chunk-YVYYMXOI.js → chunk-IUWOX36C.js} +1 -1
  5. package/bundles/{chunk-DT6FD4OE.js → chunk-ZJZNLTWN.js} +1 -2
  6. package/bundles/index.js +4 -4
  7. package/bundles/linker/babel/index.js +1 -1
  8. package/bundles/linker/index.js +1 -1
  9. package/bundles/private/migrations.js +2 -2
  10. package/bundles/private/testing.js +1 -1
  11. package/bundles/private/tooling.js +1 -1
  12. package/bundles/src/bin/ng_xi18n.js +4 -4
  13. package/bundles/src/bin/ngc.js +4 -4
  14. package/linker/src/file_linker/partial_linkers/util.d.ts +1 -1
  15. package/package.json +2 -2
  16. package/src/ngtsc/docs/src/entities.d.ts +8 -2
  17. package/src/ngtsc/docs/src/extractor.d.ts +1 -0
  18. package/src/ngtsc/docs/src/type_alias_extractor.d.ts +1 -0
  19. package/src/ngtsc/typecheck/src/ops/base.d.ts +43 -0
  20. package/src/ngtsc/typecheck/src/ops/bindings.d.ts +64 -0
  21. package/src/ngtsc/typecheck/src/ops/completions.d.ts +22 -0
  22. package/src/ngtsc/typecheck/src/ops/content_projection.d.ts +34 -0
  23. package/src/ngtsc/typecheck/src/ops/context.d.ts +67 -0
  24. package/src/ngtsc/typecheck/src/ops/directive_constructor.d.ts +59 -0
  25. package/src/ngtsc/typecheck/src/ops/directive_type.d.ts +53 -0
  26. package/src/ngtsc/typecheck/src/ops/element.d.ts +26 -0
  27. package/src/ngtsc/typecheck/src/ops/events.d.ts +55 -0
  28. package/src/ngtsc/typecheck/src/ops/expression.d.ts +49 -0
  29. package/src/ngtsc/typecheck/src/ops/for_block.d.ts +32 -0
  30. package/src/ngtsc/typecheck/src/ops/host.d.ts +25 -0
  31. package/src/ngtsc/typecheck/src/ops/if_block.d.ts +28 -0
  32. package/src/ngtsc/typecheck/src/ops/inputs.d.ts +56 -0
  33. package/src/ngtsc/typecheck/src/ops/intersection_observer.d.ts +22 -0
  34. package/src/ngtsc/typecheck/src/ops/let.d.ts +29 -0
  35. package/src/ngtsc/typecheck/src/ops/references.d.ts +57 -0
  36. package/src/ngtsc/typecheck/src/ops/schema.d.ts +31 -0
  37. package/src/ngtsc/typecheck/src/ops/scope.d.ts +187 -0
  38. package/src/ngtsc/typecheck/src/ops/selectorless.d.ts +26 -0
  39. package/src/ngtsc/typecheck/src/ops/signal_forms.d.ts +40 -0
  40. package/src/ngtsc/typecheck/src/ops/switch_block.d.ts +25 -0
  41. package/src/ngtsc/typecheck/src/ops/template.d.ts +40 -0
  42. package/src/ngtsc/typecheck/src/ops/variables.d.ts +56 -0
  43. package/src/ngtsc/typecheck/src/type_check_block.d.ts +2 -274
  44. package/src/ngtsc/typecheck/src/type_check_file.d.ts +1 -1
@@ -0,0 +1,40 @@
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.dev/license
7
+ */
8
+ import { TmplAstTemplate } from '@angular/compiler';
9
+ import ts from 'typescript';
10
+ import { TcbOp } from './base';
11
+ import type { Context } from './context';
12
+ import type { Scope } from './scope';
13
+ /**
14
+ * A `TcbOp` which generates a variable for a `TmplAstTemplate`'s context.
15
+ *
16
+ * Executing this operation returns a reference to the template's context variable.
17
+ */
18
+ export declare class TcbTemplateContextOp extends TcbOp {
19
+ private tcb;
20
+ private scope;
21
+ constructor(tcb: Context, scope: Scope);
22
+ readonly optional = true;
23
+ execute(): ts.Identifier;
24
+ }
25
+ /**
26
+ * A `TcbOp` which descends into a `TmplAstTemplate`'s children and generates type-checking code for
27
+ * them.
28
+ *
29
+ * This operation wraps the children's type-checking code in an `if` block, which may include one
30
+ * or more type guard conditions that narrow types within the template body.
31
+ */
32
+ export declare class TcbTemplateBodyOp extends TcbOp {
33
+ private tcb;
34
+ private scope;
35
+ private template;
36
+ constructor(tcb: Context, scope: Scope, template: TmplAstTemplate);
37
+ get optional(): boolean;
38
+ execute(): null;
39
+ private addDirectiveGuards;
40
+ }
@@ -0,0 +1,56 @@
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.dev/license
7
+ */
8
+ import { TmplAstTemplate, TmplAstVariable } from '@angular/compiler';
9
+ import ts from 'typescript';
10
+ import { TcbOp } from './base';
11
+ import type { Context } from './context';
12
+ import type { Scope } from './scope';
13
+ /**
14
+ * A `TcbOp` which renders a variable that is implicitly available within a block (e.g. `$count`
15
+ * in a `@for` block).
16
+ *
17
+ * Executing this operation returns the identifier which can be used to refer to the variable.
18
+ */
19
+ export declare class TcbBlockImplicitVariableOp extends TcbOp {
20
+ private tcb;
21
+ private scope;
22
+ private type;
23
+ private variable;
24
+ constructor(tcb: Context, scope: Scope, type: ts.TypeNode, variable: TmplAstVariable);
25
+ readonly optional = true;
26
+ execute(): ts.Identifier;
27
+ }
28
+ /**
29
+ * A `TcbOp` which creates an expression for particular let- `TmplAstVariable` on a
30
+ * `TmplAstTemplate`'s context.
31
+ *
32
+ * Executing this operation returns a reference to the variable variable (lol).
33
+ */
34
+ export declare class TcbTemplateVariableOp extends TcbOp {
35
+ private tcb;
36
+ private scope;
37
+ private template;
38
+ private variable;
39
+ constructor(tcb: Context, scope: Scope, template: TmplAstTemplate, variable: TmplAstVariable);
40
+ get optional(): boolean;
41
+ execute(): ts.Identifier;
42
+ }
43
+ /**
44
+ * A `TcbOp` which renders a variable defined inside of block syntax (e.g. `@if (expr; as var) {}`).
45
+ *
46
+ * Executing this operation returns the identifier which can be used to refer to the variable.
47
+ */
48
+ export declare class TcbBlockVariableOp extends TcbOp {
49
+ private tcb;
50
+ private scope;
51
+ private initializer;
52
+ private variable;
53
+ constructor(tcb: Context, scope: Scope, initializer: ts.Expression, variable: TmplAstVariable);
54
+ get optional(): boolean;
55
+ execute(): ts.Identifier;
56
+ }
@@ -5,40 +5,14 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.dev/license
7
7
  */
8
- import { BoundTarget, SchemaMetadata, TmplAstBoundAttribute, TmplAstBoundEvent, TmplAstElement, TmplAstForLoopBlock, TmplAstIfBlockBranch, TmplAstLetDeclaration, TmplAstNode, TmplAstReference, TmplAstTemplate, TmplAstVariable, TmplAstHostElement, TmplAstComponent, TmplAstDirective, DirectiveOwner } from '@angular/compiler';
9
8
  import ts from 'typescript';
10
9
  import { Reference } from '../../imports';
11
- import { PipeMeta } from '../../metadata';
12
10
  import { ClassDeclaration } from '../../reflection';
13
- import { TypeCheckId, TypeCheckableDirectiveMeta, TypeCheckBlockMetadata } from '../api';
11
+ import { TypeCheckBlockMetadata } from '../api';
14
12
  import { DomSchemaChecker } from './dom';
15
13
  import { Environment } from './environment';
16
14
  import { OutOfBandDiagnosticRecorder } from './oob';
17
- /**
18
- * Controls how generics for the component context class will be handled during TCB generation.
19
- */
20
- export declare enum TcbGenericContextBehavior {
21
- /**
22
- * References to generic parameter bounds will be emitted via the `TypeParameterEmitter`.
23
- *
24
- * The caller must verify that all parameter bounds are emittable in order to use this mode.
25
- */
26
- UseEmitter = 0,
27
- /**
28
- * Generic parameter declarations will be copied directly from the `ts.ClassDeclaration` of the
29
- * component class.
30
- *
31
- * The caller must only use the generated TCB code in a context where such copies will still be
32
- * valid, such as an inline type check block.
33
- */
34
- CopyClassNodes = 1,
35
- /**
36
- * Any generic parameters for the component context class will be set to `any`.
37
- *
38
- * Produces a less useful type, but is always safe to use.
39
- */
40
- FallbackToAny = 2
41
- }
15
+ import { TcbGenericContextBehavior } from './ops/context';
42
16
  /**
43
17
  * Given a `ts.ClassDeclaration` for a component, and metadata regarding that component, compose a
44
18
  * "type check block" function.
@@ -64,249 +38,3 @@ export declare enum TcbGenericContextBehavior {
64
38
  * bounds) will be referenced from the generated TCB code.
65
39
  */
66
40
  export declare function generateTypeCheckBlock(env: Environment, ref: Reference<ClassDeclaration<ts.ClassDeclaration>>, name: ts.Identifier, meta: TypeCheckBlockMetadata, domSchemaChecker: DomSchemaChecker, oobRecorder: OutOfBandDiagnosticRecorder, genericContextBehavior: TcbGenericContextBehavior): ts.FunctionDeclaration;
67
- /** Types that can referenced locally in a template. */
68
- type LocalSymbol = TmplAstElement | TmplAstTemplate | TmplAstVariable | TmplAstLetDeclaration | TmplAstReference | TmplAstHostElement | TmplAstComponent | TmplAstDirective;
69
- /**
70
- * A code generation operation that's involved in the construction of a Type Check Block.
71
- *
72
- * The generation of a TCB is non-linear. Bindings within a template may result in the need to
73
- * construct certain types earlier than they otherwise would be constructed. That is, if the
74
- * generation of a TCB for a template is broken down into specific operations (constructing a
75
- * directive, extracting a variable from a let- operation, etc), then it's possible for operations
76
- * earlier in the sequence to depend on operations which occur later in the sequence.
77
- *
78
- * `TcbOp` abstracts the different types of operations which are required to convert a template into
79
- * a TCB. This allows for two phases of processing for the template, where 1) a linear sequence of
80
- * `TcbOp`s is generated, and then 2) these operations are executed, not necessarily in linear
81
- * order.
82
- *
83
- * Each `TcbOp` may insert statements into the body of the TCB, and also optionally return a
84
- * `ts.Expression` which can be used to reference the operation's result.
85
- */
86
- declare abstract class TcbOp {
87
- /**
88
- * Set to true if this operation can be considered optional. Optional operations are only executed
89
- * when depended upon by other operations, otherwise they are disregarded. This allows for less
90
- * code to generate, parse and type-check, overall positively contributing to performance.
91
- */
92
- abstract readonly optional: boolean;
93
- abstract execute(): ts.Expression | null;
94
- /**
95
- * Replacement value or operation used while this `TcbOp` is executing (i.e. to resolve circular
96
- * references during its execution).
97
- *
98
- * This is usually a `null!` expression (which asks TS to infer an appropriate type), but another
99
- * `TcbOp` can be returned in cases where additional code generation is necessary to deal with
100
- * circular references.
101
- */
102
- circularFallback(): TcbOp | ts.Expression;
103
- }
104
- /**
105
- * A `TcbOp` which generates code to check event bindings on an element that correspond with the
106
- * outputs of a directive.
107
- *
108
- * Executing this operation returns nothing.
109
- */
110
- export declare class TcbDirectiveOutputsOp extends TcbOp {
111
- private tcb;
112
- private scope;
113
- private node;
114
- private inputs;
115
- private outputs;
116
- private dir;
117
- constructor(tcb: Context, scope: Scope, node: DirectiveOwner, inputs: TmplAstBoundAttribute[] | null, outputs: TmplAstBoundEvent[], dir: TypeCheckableDirectiveMeta);
118
- get optional(): boolean;
119
- execute(): null;
120
- }
121
- /**
122
- * Overall generation context for the type check block.
123
- *
124
- * `Context` handles operations during code generation which are global with respect to the whole
125
- * block. It's responsible for variable name allocation and management of any imports needed. It
126
- * also contains the template metadata itself.
127
- */
128
- export declare class Context {
129
- readonly env: Environment;
130
- readonly domSchemaChecker: DomSchemaChecker;
131
- readonly oobRecorder: OutOfBandDiagnosticRecorder;
132
- readonly id: TypeCheckId;
133
- readonly boundTarget: BoundTarget<TypeCheckableDirectiveMeta>;
134
- private pipes;
135
- readonly schemas: SchemaMetadata[];
136
- readonly hostIsStandalone: boolean;
137
- readonly hostPreserveWhitespaces: boolean;
138
- private nextId;
139
- constructor(env: Environment, domSchemaChecker: DomSchemaChecker, oobRecorder: OutOfBandDiagnosticRecorder, id: TypeCheckId, boundTarget: BoundTarget<TypeCheckableDirectiveMeta>, pipes: Map<string, PipeMeta> | null, schemas: SchemaMetadata[], hostIsStandalone: boolean, hostPreserveWhitespaces: boolean);
140
- /**
141
- * Allocate a new variable name for use within the `Context`.
142
- *
143
- * Currently this uses a monotonically increasing counter, but in the future the variable name
144
- * might change depending on the type of data being stored.
145
- */
146
- allocateId(): ts.Identifier;
147
- getPipeByName(name: string): PipeMeta | null;
148
- }
149
- /**
150
- * Local scope within the type check block for a particular template.
151
- *
152
- * The top-level template and each nested `<ng-template>` have their own `Scope`, which exist in a
153
- * hierarchy. The structure of this hierarchy mirrors the syntactic scopes in the generated type
154
- * check block, where each nested template is encased in an `if` structure.
155
- *
156
- * As a template's `TcbOp`s are executed in a given `Scope`, statements are added via
157
- * `addStatement()`. When this processing is complete, the `Scope` can be turned into a `ts.Block`
158
- * via `renderToBlock()`.
159
- *
160
- * If a `TcbOp` requires the output of another, it can call `resolve()`.
161
- */
162
- declare class Scope {
163
- private tcb;
164
- private parent;
165
- private guard;
166
- /**
167
- * A queue of operations which need to be performed to generate the TCB code for this scope.
168
- *
169
- * This array can contain either a `TcbOp` which has yet to be executed, or a `ts.Expression|null`
170
- * representing the memoized result of executing the operation. As operations are executed, their
171
- * results are written into the `opQueue`, overwriting the original operation.
172
- *
173
- * If an operation is in the process of being executed, it is temporarily overwritten here with
174
- * `INFER_TYPE_FOR_CIRCULAR_OP_EXPR`. This way, if a cycle is encountered where an operation
175
- * depends transitively on its own result, the inner operation will infer the least narrow type
176
- * that fits instead. This has the same semantics as TypeScript itself when types are referenced
177
- * circularly.
178
- */
179
- private opQueue;
180
- /**
181
- * A map of `TmplAstElement`s to the index of their `TcbElementOp` in the `opQueue`
182
- */
183
- private elementOpMap;
184
- /**
185
- * A map of `TmplAstHostElement`s to the index of their `TcbHostElementOp` in the `opQueue`
186
- */
187
- private hostElementOpMap;
188
- /**
189
- * A map of `TmplAstComponent`s to the index of their `TcbComponentNodeOp` in the `opQueue`
190
- */
191
- private componentNodeOpMap;
192
- /**
193
- * A map of maps which tracks the index of `TcbDirectiveCtorOp`s in the `opQueue` for each
194
- * directive on a `TmplAstElement` or `TmplAstTemplate` node.
195
- */
196
- private directiveOpMap;
197
- /**
198
- * A map of `TmplAstReference`s to the index of their `TcbReferenceOp` in the `opQueue`
199
- */
200
- private referenceOpMap;
201
- /**
202
- * Map of immediately nested <ng-template>s (within this `Scope`) represented by `TmplAstTemplate`
203
- * nodes to the index of their `TcbTemplateContextOp`s in the `opQueue`.
204
- */
205
- private templateCtxOpMap;
206
- /**
207
- * Map of variables declared on the template that created this `Scope` (represented by
208
- * `TmplAstVariable` nodes) to the index of their `TcbVariableOp`s in the `opQueue`, or to
209
- * pre-resolved variable identifiers.
210
- */
211
- private varMap;
212
- /**
213
- * A map of the names of `TmplAstLetDeclaration`s to the index of their op in the `opQueue`.
214
- *
215
- * Assumes that there won't be duplicated `@let` declarations within the same scope.
216
- */
217
- private letDeclOpMap;
218
- /**
219
- * Statements for this template.
220
- *
221
- * Executing the `TcbOp`s in the `opQueue` populates this array.
222
- */
223
- private statements;
224
- /**
225
- * Gets names of the for loop context variables and their types.
226
- */
227
- private static getForLoopContextVariableTypes;
228
- private constructor();
229
- /**
230
- * Constructs a `Scope` given either a `TmplAstTemplate` or a list of `TmplAstNode`s.
231
- *
232
- * @param tcb the overall context of TCB generation.
233
- * @param parentScope the `Scope` of the parent template (if any) or `null` if this is the root
234
- * `Scope`.
235
- * @param scopedNode Node that provides the scope around the child nodes (e.g. a
236
- * `TmplAstTemplate` node exposing variables to its children).
237
- * @param children Child nodes that should be appended to the TCB.
238
- * @param guard an expression that is applied to this scope for type narrowing purposes.
239
- */
240
- static forNodes(tcb: Context, parentScope: Scope | null, scopedNode: TmplAstTemplate | TmplAstIfBlockBranch | TmplAstForLoopBlock | TmplAstHostElement | null, children: TmplAstNode[] | null, guard: ts.Expression | null): Scope;
241
- /** Registers a local variable with a scope. */
242
- private static registerVariable;
243
- /**
244
- * Look up a `ts.Expression` representing the value of some operation in the current `Scope`,
245
- * including any parent scope(s). This method always returns a mutable clone of the
246
- * `ts.Expression` with the comments cleared.
247
- *
248
- * @param node a `TmplAstNode` of the operation in question. The lookup performed will depend on
249
- * the type of this node:
250
- *
251
- * Assuming `directive` is not present, then `resolve` will return:
252
- *
253
- * * `TmplAstElement` - retrieve the expression for the element DOM node
254
- * * `TmplAstTemplate` - retrieve the template context variable
255
- * * `TmplAstVariable` - retrieve a template let- variable
256
- * * `TmplAstLetDeclaration` - retrieve a template `@let` declaration
257
- * * `TmplAstReference` - retrieve variable created for the local ref
258
- *
259
- * @param directive if present, a directive type on a `TmplAstElement` or `TmplAstTemplate` to
260
- * look up instead of the default for an element or template node.
261
- */
262
- resolve(node: LocalSymbol, directive?: TypeCheckableDirectiveMeta): ts.Identifier | ts.NonNullExpression;
263
- /**
264
- * Add a statement to this scope.
265
- */
266
- addStatement(stmt: ts.Statement): void;
267
- /**
268
- * Get the statements.
269
- */
270
- render(): ts.Statement[];
271
- /**
272
- * Returns an expression of all template guards that apply to this scope, including those of
273
- * parent scopes. If no guards have been applied, null is returned.
274
- */
275
- guards(): ts.Expression | null;
276
- /** Returns whether a template symbol is defined locally within the current scope. */
277
- isLocal(node: TmplAstVariable | TmplAstLetDeclaration | TmplAstReference): boolean;
278
- private resolveLocal;
279
- /**
280
- * Like `executeOp`, but assert that the operation actually returned `ts.Expression`.
281
- */
282
- private resolveOp;
283
- /**
284
- * Execute a particular `TcbOp` in the `opQueue`.
285
- *
286
- * This method replaces the operation in the `opQueue` with the result of execution (once done)
287
- * and also protects against a circular dependency from the operation to itself by temporarily
288
- * setting the operation's result to a special expression.
289
- */
290
- private executeOp;
291
- private appendNode;
292
- private appendChildren;
293
- private checkAndAppendReferencesOfNode;
294
- private appendDirectivesAndInputsOfElementLikeNode;
295
- private appendOutputsOfElementLikeNode;
296
- private appendInputsOfSelectorlessNode;
297
- private appendOutputsOfSelectorlessNode;
298
- private appendDirectiveInputs;
299
- private getDirectiveOp;
300
- private appendSelectorlessDirectives;
301
- private appendDeepSchemaChecks;
302
- private appendIcuExpressions;
303
- private appendContentProjectionCheckOp;
304
- private appendComponentNode;
305
- private appendDeferredBlock;
306
- private appendDeferredTriggers;
307
- private appendHostElement;
308
- private validateReferenceBasedDeferredTrigger;
309
- /** Reports a diagnostic if there are any `@let` declarations that conflict with a node. */
310
- private static checkConflictingLet;
311
- }
312
- export {};
@@ -13,7 +13,7 @@ import { TypeCheckBlockMetadata, TypeCheckingConfig } from '../api';
13
13
  import { DomSchemaChecker } from './dom';
14
14
  import { Environment } from './environment';
15
15
  import { OutOfBandDiagnosticRecorder } from './oob';
16
- import { TcbGenericContextBehavior } from './type_check_block';
16
+ import { TcbGenericContextBehavior } from './ops/context';
17
17
  /**
18
18
  * An `Environment` representing the single type-checking file into which most (if not all) Type
19
19
  * Check Blocks (TCBs) will be generated.