@angular/compiler 16.0.0 → 16.1.0-next.0

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 (35) hide show
  1. package/esm2022/src/compiler.mjs +2 -2
  2. package/esm2022/src/compiler_facade_interface.mjs +1 -1
  3. package/esm2022/src/jit_compiler_facade.mjs +2 -1
  4. package/esm2022/src/output/output_ast.mjs +16 -1
  5. package/esm2022/src/render3/partial/api.mjs +1 -1
  6. package/esm2022/src/render3/partial/class_metadata.mjs +1 -1
  7. package/esm2022/src/render3/partial/directive.mjs +5 -2
  8. package/esm2022/src/render3/partial/factory.mjs +1 -1
  9. package/esm2022/src/render3/partial/injectable.mjs +1 -1
  10. package/esm2022/src/render3/partial/injector.mjs +1 -1
  11. package/esm2022/src/render3/partial/ng_module.mjs +1 -1
  12. package/esm2022/src/render3/partial/pipe.mjs +1 -1
  13. package/esm2022/src/render3/r3_ast.mjs +2 -85
  14. package/esm2022/src/render3/view/api.mjs +1 -1
  15. package/esm2022/src/render3/view/compiler.mjs +6 -1
  16. package/esm2022/src/template/pipeline/ir/src/enums.mjs +18 -6
  17. package/esm2022/src/template/pipeline/ir/src/expression.mjs +8 -1
  18. package/esm2022/src/template/pipeline/ir/src/ops/create.mjs +1 -1
  19. package/esm2022/src/template/pipeline/src/conversion.mjs +28 -0
  20. package/esm2022/src/template/pipeline/src/emit.mjs +6 -2
  21. package/esm2022/src/template/pipeline/src/ingest.mjs +45 -8
  22. package/esm2022/src/template/pipeline/src/instruction.mjs +17 -8
  23. package/esm2022/src/template/pipeline/src/phases/chaining.mjs +4 -1
  24. package/esm2022/src/template/pipeline/src/phases/empty_elements.mjs +16 -8
  25. package/esm2022/src/template/pipeline/src/phases/generate_variables.mjs +8 -27
  26. package/esm2022/src/template/pipeline/src/phases/ng_container.mjs +29 -0
  27. package/esm2022/src/template/pipeline/src/phases/reify.mjs +10 -1
  28. package/esm2022/src/template/pipeline/src/phases/save_restore_view.mjs +46 -0
  29. package/esm2022/src/version.mjs +1 -1
  30. package/fesm2022/compiler.mjs +235 -147
  31. package/fesm2022/compiler.mjs.map +1 -1
  32. package/fesm2022/testing.mjs +1 -1
  33. package/index.d.ts +20 -33
  34. package/package.json +2 -2
  35. package/testing/index.d.ts +1 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v16.0.0
2
+ * @license Angular v16.1.0-next.0
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -1064,6 +1064,15 @@ class MapType extends Type {
1064
1064
  return visitor.visitMapType(this, context);
1065
1065
  }
1066
1066
  }
1067
+ class TransplantedType extends Type {
1068
+ constructor(type, modifiers) {
1069
+ super(modifiers);
1070
+ this.type = type;
1071
+ }
1072
+ visitType(visitor, context) {
1073
+ return visitor.visitTransplantedType(this, context);
1074
+ }
1075
+ }
1067
1076
  const DYNAMIC_TYPE = new BuiltinType(BuiltinTypeName.Dynamic);
1068
1077
  const INFERRED_TYPE = new BuiltinType(BuiltinTypeName.Inferred);
1069
1078
  const BOOL_TYPE = new BuiltinType(BuiltinTypeName.Bool);
@@ -1885,6 +1894,9 @@ class RecursiveAstVisitor$1 {
1885
1894
  visitMapType(type, context) {
1886
1895
  return this.visitType(type, context);
1887
1896
  }
1897
+ visitTransplantedType(type, context) {
1898
+ return type;
1899
+ }
1888
1900
  visitWrappedNodeExpr(ast, context) {
1889
1901
  return ast;
1890
1902
  }
@@ -2035,6 +2047,9 @@ function importType(id, typeParams, typeModifiers) {
2035
2047
  function expressionType(expr, typeModifiers, typeParams) {
2036
2048
  return new ExpressionType(expr, typeModifiers, typeParams);
2037
2049
  }
2050
+ function transplantedType(type, typeModifiers) {
2051
+ return new TransplantedType(type, typeModifiers);
2052
+ }
2038
2053
  function typeofExpr(expr) {
2039
2054
  return new TypeofExpr(expr);
2040
2055
  }
@@ -2112,6 +2127,7 @@ var output_ast = /*#__PURE__*/Object.freeze({
2112
2127
  ExpressionType: ExpressionType,
2113
2128
  ArrayType: ArrayType,
2114
2129
  MapType: MapType,
2130
+ TransplantedType: TransplantedType,
2115
2131
  DYNAMIC_TYPE: DYNAMIC_TYPE,
2116
2132
  INFERRED_TYPE: INFERRED_TYPE,
2117
2133
  BOOL_TYPE: BOOL_TYPE,
@@ -2172,6 +2188,7 @@ var output_ast = /*#__PURE__*/Object.freeze({
2172
2188
  importExpr: importExpr,
2173
2189
  importType: importType,
2174
2190
  expressionType: expressionType,
2191
+ transplantedType: transplantedType,
2175
2192
  typeofExpr: typeofExpr,
2176
2193
  literalArr: literalArr,
2177
2194
  literalMap: literalMap,
@@ -3855,19 +3872,6 @@ class Icu$1 {
3855
3872
  return visitor.visitIcu(this);
3856
3873
  }
3857
3874
  }
3858
- class NullVisitor {
3859
- visitElement(element) { }
3860
- visitTemplate(template) { }
3861
- visitContent(content) { }
3862
- visitVariable(variable) { }
3863
- visitReference(reference) { }
3864
- visitTextAttribute(attribute) { }
3865
- visitBoundAttribute(attribute) { }
3866
- visitBoundEvent(attribute) { }
3867
- visitText(text) { }
3868
- visitBoundText(text) { }
3869
- visitIcu(icu) { }
3870
- }
3871
3875
  class RecursiveVisitor$1 {
3872
3876
  visitElement(element) {
3873
3877
  visitAll$1(this, element.attributes);
@@ -3894,69 +3898,11 @@ class RecursiveVisitor$1 {
3894
3898
  visitBoundText(text) { }
3895
3899
  visitIcu(icu) { }
3896
3900
  }
3897
- class TransformVisitor {
3898
- visitElement(element) {
3899
- const newAttributes = transformAll(this, element.attributes);
3900
- const newInputs = transformAll(this, element.inputs);
3901
- const newOutputs = transformAll(this, element.outputs);
3902
- const newChildren = transformAll(this, element.children);
3903
- const newReferences = transformAll(this, element.references);
3904
- if (newAttributes != element.attributes || newInputs != element.inputs ||
3905
- newOutputs != element.outputs || newChildren != element.children ||
3906
- newReferences != element.references) {
3907
- return new Element$1(element.name, newAttributes, newInputs, newOutputs, newChildren, newReferences, element.sourceSpan, element.startSourceSpan, element.endSourceSpan);
3908
- }
3909
- return element;
3910
- }
3911
- visitTemplate(template) {
3912
- const newAttributes = transformAll(this, template.attributes);
3913
- const newInputs = transformAll(this, template.inputs);
3914
- const newOutputs = transformAll(this, template.outputs);
3915
- const newTemplateAttrs = transformAll(this, template.templateAttrs);
3916
- const newChildren = transformAll(this, template.children);
3917
- const newReferences = transformAll(this, template.references);
3918
- const newVariables = transformAll(this, template.variables);
3919
- if (newAttributes != template.attributes || newInputs != template.inputs ||
3920
- newOutputs != template.outputs || newTemplateAttrs != template.templateAttrs ||
3921
- newChildren != template.children || newReferences != template.references ||
3922
- newVariables != template.variables) {
3923
- return new Template(template.tagName, newAttributes, newInputs, newOutputs, newTemplateAttrs, newChildren, newReferences, newVariables, template.sourceSpan, template.startSourceSpan, template.endSourceSpan);
3924
- }
3925
- return template;
3926
- }
3927
- visitContent(content) {
3928
- return content;
3929
- }
3930
- visitVariable(variable) {
3931
- return variable;
3932
- }
3933
- visitReference(reference) {
3934
- return reference;
3935
- }
3936
- visitTextAttribute(attribute) {
3937
- return attribute;
3938
- }
3939
- visitBoundAttribute(attribute) {
3940
- return attribute;
3941
- }
3942
- visitBoundEvent(attribute) {
3943
- return attribute;
3944
- }
3945
- visitText(text) {
3946
- return text;
3947
- }
3948
- visitBoundText(text) {
3949
- return text;
3950
- }
3951
- visitIcu(icu) {
3952
- return icu;
3953
- }
3954
- }
3955
3901
  function visitAll$1(visitor, nodes) {
3956
3902
  const result = [];
3957
3903
  if (visitor.visit) {
3958
3904
  for (const node of nodes) {
3959
- const newNode = visitor.visit(node) || node.visit(visitor);
3905
+ visitor.visit(node) || node.visit(visitor);
3960
3906
  }
3961
3907
  }
3962
3908
  else {
@@ -3969,18 +3915,6 @@ function visitAll$1(visitor, nodes) {
3969
3915
  }
3970
3916
  return result;
3971
3917
  }
3972
- function transformAll(visitor, nodes) {
3973
- const result = [];
3974
- let changed = false;
3975
- for (const node of nodes) {
3976
- const newNode = node.visit(visitor);
3977
- if (newNode) {
3978
- result.push(newNode);
3979
- }
3980
- changed = changed || newNode != node;
3981
- }
3982
- return changed ? result : nodes;
3983
- }
3984
3918
 
3985
3919
  class Message {
3986
3920
  /**
@@ -8568,26 +8502,38 @@ var OpKind;
8568
8502
  * An operation to end rendering of an element previously started with `ElementStart`.
8569
8503
  */
8570
8504
  OpKind[OpKind["ElementEnd"] = 6] = "ElementEnd";
8505
+ /**
8506
+ * An operation to begin an `ng-container`.
8507
+ */
8508
+ OpKind[OpKind["ContainerStart"] = 7] = "ContainerStart";
8509
+ /**
8510
+ * An operation for an `ng-container` with no children.
8511
+ */
8512
+ OpKind[OpKind["Container"] = 8] = "Container";
8513
+ /**
8514
+ * An operation to end an `ng-container`.
8515
+ */
8516
+ OpKind[OpKind["ContainerEnd"] = 9] = "ContainerEnd";
8571
8517
  /**
8572
8518
  * An operation to render a text node.
8573
8519
  */
8574
- OpKind[OpKind["Text"] = 7] = "Text";
8520
+ OpKind[OpKind["Text"] = 10] = "Text";
8575
8521
  /**
8576
8522
  * An operation declaring an event listener for an element.
8577
8523
  */
8578
- OpKind[OpKind["Listener"] = 8] = "Listener";
8524
+ OpKind[OpKind["Listener"] = 11] = "Listener";
8579
8525
  /**
8580
8526
  * An operation to interpolate text into a text node.
8581
8527
  */
8582
- OpKind[OpKind["InterpolateText"] = 9] = "InterpolateText";
8528
+ OpKind[OpKind["InterpolateText"] = 12] = "InterpolateText";
8583
8529
  /**
8584
8530
  * An operation to bind an expression to a property of an element.
8585
8531
  */
8586
- OpKind[OpKind["Property"] = 10] = "Property";
8532
+ OpKind[OpKind["Property"] = 13] = "Property";
8587
8533
  /**
8588
8534
  * An operation to advance the runtime's implicit slot context during the update phase of a view.
8589
8535
  */
8590
- OpKind[OpKind["Advance"] = 11] = "Advance";
8536
+ OpKind[OpKind["Advance"] = 14] = "Advance";
8591
8537
  })(OpKind || (OpKind = {}));
8592
8538
  /**
8593
8539
  * Distinguishes different kinds of IR expressions.
@@ -8942,6 +8888,9 @@ function transformExpressionsInOp(op, transform, flags) {
8942
8888
  case OpKind.Element:
8943
8889
  case OpKind.ElementStart:
8944
8890
  case OpKind.ElementEnd:
8891
+ case OpKind.Container:
8892
+ case OpKind.ContainerStart:
8893
+ case OpKind.ContainerEnd:
8945
8894
  case OpKind.Template:
8946
8895
  case OpKind.Text:
8947
8896
  case OpKind.Advance:
@@ -8969,6 +8918,10 @@ function transformExpressionsInExpression(expr, transform, flags) {
8969
8918
  else if (expr instanceof ReadPropExpr) {
8970
8919
  expr.receiver = transformExpressionsInExpression(expr.receiver, transform, flags);
8971
8920
  }
8921
+ else if (expr instanceof ReadKeyExpr) {
8922
+ expr.receiver = transformExpressionsInExpression(expr.receiver, transform, flags);
8923
+ expr.index = transformExpressionsInExpression(expr.index, transform, flags);
8924
+ }
8972
8925
  else if (expr instanceof InvokeFunctionExpr) {
8973
8926
  expr.fn = transformExpressionsInExpression(expr.fn, transform, flags);
8974
8927
  for (let i = 0; i < expr.args.length; i++) {
@@ -9413,19 +9366,27 @@ function serializeAttributes({ attributes, bindings, classes, i18n, projectAs, s
9413
9366
  return literalArr(attrArray);
9414
9367
  }
9415
9368
 
9369
+ const REPLACEMENTS = new Map([
9370
+ [OpKind.ElementEnd, [OpKind.ElementStart, OpKind.Element]],
9371
+ [OpKind.ContainerEnd, [OpKind.ContainerStart, OpKind.Container]],
9372
+ ]);
9416
9373
  /**
9417
- * Replace sequences of `ElementStart` followed by `ElementEnd` with a condensed `Element`
9418
- * instruction.
9374
+ * Replace sequences of mergable elements (e.g. `ElementStart` and `ElementEnd`) with a consolidated
9375
+ * element (e.g. `Element`).
9419
9376
  */
9420
9377
  function phaseEmptyElements(cpl) {
9421
9378
  for (const [_, view] of cpl.views) {
9422
9379
  for (const op of view.create) {
9423
- if (op.kind === OpKind.ElementEnd && op.prev !== null &&
9424
- op.prev.kind === OpKind.ElementStart) {
9425
- // Transmute the `ElementStart` instruction to `Element`. This is safe as they're designed
9380
+ const opReplacements = REPLACEMENTS.get(op.kind);
9381
+ if (opReplacements === undefined) {
9382
+ continue;
9383
+ }
9384
+ const [startKind, mergedKind] = opReplacements;
9385
+ if (op.prev !== null && op.prev.kind === startKind) {
9386
+ // Transmute the start instruction to the merged version. This is safe as they're designed
9426
9387
  // to be identical apart from the `kind`.
9427
- op.prev.kind = OpKind.Element;
9428
- // Remove the `ElementEnd` instruction.
9388
+ op.prev.kind = mergedKind;
9389
+ // Remove the end instruction.
9429
9390
  OpList.remove(op);
9430
9391
  }
9431
9392
  }
@@ -9484,16 +9445,16 @@ function phaseGenerateAdvance(cpl) {
9484
9445
  // instruction type is represented as a function, which may select a specific instruction variant
9485
9446
  // depending on the exact arguments.
9486
9447
  function element(slot, tag, constIndex, localRefIndex) {
9487
- return elementStartBase(Identifiers.element, slot, tag, constIndex, localRefIndex);
9448
+ return elementOrContainerBase(Identifiers.element, slot, tag, constIndex, localRefIndex);
9488
9449
  }
9489
9450
  function elementStart(slot, tag, constIndex, localRefIndex) {
9490
- return elementStartBase(Identifiers.elementStart, slot, tag, constIndex, localRefIndex);
9451
+ return elementOrContainerBase(Identifiers.elementStart, slot, tag, constIndex, localRefIndex);
9491
9452
  }
9492
- function elementStartBase(instruction, slot, tag, constIndex, localRefIndex) {
9493
- const args = [
9494
- literal(slot),
9495
- literal(tag),
9496
- ];
9453
+ function elementOrContainerBase(instruction, slot, tag, constIndex, localRefIndex) {
9454
+ const args = [literal(slot)];
9455
+ if (tag !== null) {
9456
+ args.push(literal(tag));
9457
+ }
9497
9458
  if (localRefIndex !== null) {
9498
9459
  args.push(literal(constIndex), // might be null, but that's okay.
9499
9460
  literal(localRefIndex));
@@ -9506,6 +9467,15 @@ function elementStartBase(instruction, slot, tag, constIndex, localRefIndex) {
9506
9467
  function elementEnd() {
9507
9468
  return call(Identifiers.elementEnd, []);
9508
9469
  }
9470
+ function elementContainerStart(slot, constIndex, localRefIndex) {
9471
+ return elementOrContainerBase(Identifiers.elementContainerStart, slot, /* tag */ null, constIndex, localRefIndex);
9472
+ }
9473
+ function elementContainer(slot, constIndex, localRefIndex) {
9474
+ return elementOrContainerBase(Identifiers.elementContainer, slot, /* tag */ null, constIndex, localRefIndex);
9475
+ }
9476
+ function elementContainerEnd() {
9477
+ return call(Identifiers.elementContainerEnd, []);
9478
+ }
9509
9479
  function template(slot, templateFnRef, decls, vars, tag, constIndex) {
9510
9480
  return call(Identifiers.templateCreate, [
9511
9481
  literal(slot),
@@ -9644,6 +9614,15 @@ function reifyCreateOperations(view, ops) {
9644
9614
  case OpKind.ElementEnd:
9645
9615
  OpList.replace(op, elementEnd());
9646
9616
  break;
9617
+ case OpKind.ContainerStart:
9618
+ OpList.replace(op, elementContainerStart(op.slot, op.attributes, op.localRefs));
9619
+ break;
9620
+ case OpKind.Container:
9621
+ OpList.replace(op, elementContainer(op.slot, op.attributes, op.localRefs));
9622
+ break;
9623
+ case OpKind.ContainerEnd:
9624
+ OpList.replace(op, elementContainerEnd());
9625
+ break;
9647
9626
  case OpKind.Template:
9648
9627
  const childView = view.tpl.views.get(op.xref);
9649
9628
  OpList.replace(op, template(op.slot, variable(childView.fnName), childView.decls, childView.vars, op.tag, op.attributes));
@@ -10019,11 +9998,11 @@ function phaseGenerateVariables(cpl) {
10019
9998
  function recursivelyProcessView(view, parentScope) {
10020
9999
  // Extract a `Scope` from this view.
10021
10000
  const scope = getScopeForView(view, parentScope);
10022
- // Start the view creation block with an operation to save the current view context. This may be
10023
- // used to restore the view context in any listeners that may be present.
10024
- view.create.prepend([
10025
- createVariableOp(view.tpl.allocateXrefId(), scope.savedViewVariable, new GetCurrentViewExpr()),
10026
- ]);
10001
+ // Embedded views require an operation to save/restore the view context.
10002
+ if (view.parent !== null) {
10003
+ // Start the view creation block with an operation to save the current view context. This may be
10004
+ // used to restore the view context in any listeners that may be present.
10005
+ }
10027
10006
  for (const op of view.create) {
10028
10007
  switch (op.kind) {
10029
10008
  case OpKind.Template:
@@ -10031,22 +10010,8 @@ function recursivelyProcessView(view, parentScope) {
10031
10010
  recursivelyProcessView(view.tpl.views.get(op.xref), scope);
10032
10011
  break;
10033
10012
  case OpKind.Listener:
10034
- // Listeners get a preamble which starts with a call to restore the view.
10035
- const preambleOps = [
10036
- createVariableOp(view.tpl.allocateXrefId(), scope.viewContextVariable, new RestoreViewExpr(view.xref)),
10037
- // And includes all variables available to this view.
10038
- ...generateVariablesInScopeForView(view, scope)
10039
- ];
10040
- op.handlerOps.prepend(preambleOps);
10041
- // The "restore view" operation in listeners requires a call to `resetView` to reset the
10042
- // context prior to returning from the listener operation. Find any `return` statements in
10043
- // the listener body and wrap them in a call to reset the view.
10044
- for (const handlerOp of op.handlerOps) {
10045
- if (handlerOp.kind === OpKind.Statement &&
10046
- handlerOp.statement instanceof ReturnStatement) {
10047
- handlerOp.statement.value = new ResetViewExpr(handlerOp.statement.value);
10048
- }
10049
- }
10013
+ // Prepend variables to listener handler functions.
10014
+ op.handlerOps.prepend(generateVariablesInScopeForView(view, scope));
10050
10015
  break;
10051
10016
  }
10052
10017
  }
@@ -10066,11 +10031,6 @@ function getScopeForView(view, parent) {
10066
10031
  name: null,
10067
10032
  view: view.xref,
10068
10033
  },
10069
- savedViewVariable: {
10070
- kind: SemanticVariableKind.SavedView,
10071
- name: null,
10072
- view: view.xref,
10073
- },
10074
10034
  contextVariables: new Map(),
10075
10035
  references: [],
10076
10036
  parent,
@@ -10624,6 +10584,9 @@ const CHAINABLE = new Set([
10624
10584
  Identifiers.elementStart,
10625
10585
  Identifiers.elementEnd,
10626
10586
  Identifiers.property,
10587
+ Identifiers.elementContainerStart,
10588
+ Identifiers.elementContainerEnd,
10589
+ Identifiers.elementContainer,
10627
10590
  ]);
10628
10591
  /**
10629
10592
  * Post-process a reified view compilation and convert sequential calls to chainable instructions
@@ -10748,16 +10711,74 @@ function mergeNextContextsInOps(ops) {
10748
10711
  }
10749
10712
  }
10750
10713
 
10714
+ const CONTAINER_TAG = 'ng-container';
10715
+ /**
10716
+ * Replace an `Element` or `ElementStart` whose tag is `ng-container` with a specific op.
10717
+ */
10718
+ function phaseNgContainer(cpl) {
10719
+ for (const [_, view] of cpl.views) {
10720
+ const updatedElementXrefs = new Set();
10721
+ for (const op of view.create) {
10722
+ if (op.kind === OpKind.ElementStart && op.tag === CONTAINER_TAG) {
10723
+ // Transmute the `ElementStart` instruction to `ContainerStart`.
10724
+ op.kind = OpKind.ContainerStart;
10725
+ updatedElementXrefs.add(op.xref);
10726
+ }
10727
+ if (op.kind === OpKind.ElementEnd && updatedElementXrefs.has(op.xref)) {
10728
+ // This `ElementEnd` is associated with an `ElementStart` we already transmuted.
10729
+ op.kind = OpKind.ContainerEnd;
10730
+ }
10731
+ }
10732
+ }
10733
+ }
10734
+
10735
+ function phaseSaveRestoreView(cpl) {
10736
+ for (const view of cpl.views.values()) {
10737
+ if (view === cpl.root) {
10738
+ // Save/restore operations are not necessary for the root view.
10739
+ continue;
10740
+ }
10741
+ view.create.prepend([
10742
+ createVariableOp(view.tpl.allocateXrefId(), {
10743
+ kind: SemanticVariableKind.SavedView,
10744
+ name: null,
10745
+ view: view.xref,
10746
+ }, new GetCurrentViewExpr()),
10747
+ ]);
10748
+ for (const op of view.create) {
10749
+ if (op.kind !== OpKind.Listener) {
10750
+ continue;
10751
+ }
10752
+ op.handlerOps.prepend([
10753
+ createVariableOp(view.tpl.allocateXrefId(), {
10754
+ kind: SemanticVariableKind.Context,
10755
+ name: null,
10756
+ view: view.xref,
10757
+ }, new RestoreViewExpr(view.xref)),
10758
+ ]);
10759
+ // The "restore view" operation in listeners requires a call to `resetView` to reset the
10760
+ // context prior to returning from the listener operation. Find any `return` statements in
10761
+ // the listener body and wrap them in a call to reset the view.
10762
+ for (const handlerOp of op.handlerOps) {
10763
+ if (handlerOp.kind === OpKind.Statement &&
10764
+ handlerOp.statement instanceof ReturnStatement) {
10765
+ handlerOp.statement.value = new ResetViewExpr(handlerOp.statement.value);
10766
+ }
10767
+ }
10768
+ }
10769
+ }
10770
+ }
10771
+
10751
10772
  /**
10752
10773
  * Run all transformation phases in the correct order against a `ComponentCompilation`. After this
10753
10774
  * processing, the compilation should be in a state where it can be emitted via `emitTemplateFn`.s
10754
10775
  */
10755
10776
  function transformTemplate(cpl) {
10756
10777
  phaseGenerateVariables(cpl);
10778
+ phaseSaveRestoreView(cpl);
10757
10779
  phaseResolveNames(cpl);
10758
10780
  phaseResolveContexts(cpl);
10759
10781
  phaseLocalRefs(cpl);
10760
- phaseEmptyElements(cpl);
10761
10782
  phaseConstCollection(cpl);
10762
10783
  phaseSlotAllocation(cpl);
10763
10784
  phaseVarCounting(cpl);
@@ -10765,6 +10786,8 @@ function transformTemplate(cpl) {
10765
10786
  phaseNaming(cpl);
10766
10787
  phaseVariableOptimization(cpl, { conservative: true });
10767
10788
  phaseMergeNextContext(cpl);
10789
+ phaseNgContainer(cpl);
10790
+ phaseEmptyElements(cpl);
10768
10791
  phaseReify(cpl);
10769
10792
  phaseChaining(cpl);
10770
10793
  }
@@ -10944,6 +10967,26 @@ class ViewCompilation {
10944
10967
  }
10945
10968
  }
10946
10969
 
10970
+ const BINARY_OPERATORS = new Map([
10971
+ ['&&', BinaryOperator.And],
10972
+ ['>', BinaryOperator.Bigger],
10973
+ ['>=', BinaryOperator.BiggerEquals],
10974
+ ['&', BinaryOperator.BitwiseAnd],
10975
+ ['/', BinaryOperator.Divide],
10976
+ ['==', BinaryOperator.Equals],
10977
+ ['===', BinaryOperator.Identical],
10978
+ ['<', BinaryOperator.Lower],
10979
+ ['<=', BinaryOperator.LowerEquals],
10980
+ ['-', BinaryOperator.Minus],
10981
+ ['%', BinaryOperator.Modulo],
10982
+ ['*', BinaryOperator.Multiply],
10983
+ ['!=', BinaryOperator.NotEquals],
10984
+ ['!==', BinaryOperator.NotIdentical],
10985
+ ['??', BinaryOperator.NullishCoalesce],
10986
+ ['||', BinaryOperator.Or],
10987
+ ['+', BinaryOperator.Plus],
10988
+ ]);
10989
+
10947
10990
  /**
10948
10991
  * Process a template AST and convert it into a `ComponentCompilation` in the intermediate
10949
10992
  * representation.
@@ -11055,9 +11098,22 @@ function convertAst(ast, cpl) {
11055
11098
  else if (ast instanceof LiteralPrimitive) {
11056
11099
  return literal(ast.value);
11057
11100
  }
11101
+ else if (ast instanceof Binary) {
11102
+ const operator = BINARY_OPERATORS.get(ast.operation);
11103
+ if (operator === undefined) {
11104
+ throw new Error(`AssertionError: unknown binary operator ${ast.operation}`);
11105
+ }
11106
+ return new BinaryOperatorExpr(operator, convertAst(ast.left, cpl), convertAst(ast.right, cpl));
11107
+ }
11058
11108
  else if (ast instanceof ThisReceiver) {
11059
11109
  return new ContextExpr(cpl.root.xref);
11060
11110
  }
11111
+ else if (ast instanceof KeyedRead) {
11112
+ return new ReadKeyExpr(convertAst(ast.receiver, cpl), convertAst(ast.key, cpl));
11113
+ }
11114
+ else if (ast instanceof Chain) {
11115
+ throw new Error(`AssertionError: Chain in unknown context`);
11116
+ }
11061
11117
  else {
11062
11118
  throw new Error(`Unhandled expression type: ${ast.constructor.name}`);
11063
11119
  }
@@ -11090,13 +11146,14 @@ function ingestAttributes(op, element) {
11090
11146
  */
11091
11147
  function ingestBindings(view, op, element) {
11092
11148
  if (element instanceof Template) {
11093
- for (const attr of element.templateAttrs) {
11094
- if (typeof attr.value === 'string') {
11095
- // TODO: do we need to handle static attribute bindings here?
11096
- }
11097
- else {
11098
- view.update.push(createPropertyOp(op.xref, attr.name, convertAst(attr.value, view.tpl)));
11149
+ // TODO: Are ng-template inputs handled differently from element inputs?
11150
+ // <ng-template dir [foo]="...">
11151
+ // <item-cmp *ngFor="let item of items" [item]="item">
11152
+ for (const input of [...element.templateAttrs, ...element.inputs]) {
11153
+ if (!(input instanceof BoundAttribute)) {
11154
+ continue;
11099
11155
  }
11156
+ view.update.push(createPropertyOp(op.xref, input.name, convertAst(input.value, view.tpl)));
11100
11157
  }
11101
11158
  }
11102
11159
  else {
@@ -11105,7 +11162,29 @@ function ingestBindings(view, op, element) {
11105
11162
  }
11106
11163
  for (const output of element.outputs) {
11107
11164
  const listenerOp = createListenerOp(op.xref, output.name, op.tag);
11108
- listenerOp.handlerOps.push(createStatementOp(new ReturnStatement(convertAst(output.handler, view.tpl))));
11165
+ // if output.handler is a chain, then push each statement from the chain separately, and
11166
+ // return the last one?
11167
+ let inputExprs;
11168
+ let handler = output.handler;
11169
+ if (handler instanceof ASTWithSource) {
11170
+ handler = handler.ast;
11171
+ }
11172
+ if (handler instanceof Chain) {
11173
+ inputExprs = handler.expressions;
11174
+ }
11175
+ else {
11176
+ inputExprs = [handler];
11177
+ }
11178
+ if (inputExprs.length === 0) {
11179
+ throw new Error('Expected listener to have non-empty expression list.');
11180
+ }
11181
+ const expressions = inputExprs.map(expr => convertAst(expr, view.tpl));
11182
+ const returnExpr = expressions.pop();
11183
+ for (const expr of expressions) {
11184
+ const stmtOp = createStatementOp(new ExpressionStatement(expr));
11185
+ listenerOp.handlerOps.push(stmtOp);
11186
+ }
11187
+ listenerOp.handlerOps.push(createStatementOp(new ReturnStatement(returnExpr)));
11109
11188
  view.create.push(listenerOp);
11110
11189
  }
11111
11190
  }
@@ -21374,6 +21453,9 @@ function baseDirectiveFields(meta, constantPool, bindingParser) {
21374
21453
  if (meta.isStandalone) {
21375
21454
  definitionMap.set('standalone', literal(true));
21376
21455
  }
21456
+ if (meta.isSignal) {
21457
+ definitionMap.set('signals', literal(true));
21458
+ }
21377
21459
  return definitionMap;
21378
21460
  }
21379
21461
  /**
@@ -21544,6 +21626,7 @@ function createComponentType(meta) {
21544
21626
  typeParams.push(stringArrayAsType(meta.template.ngContentSelectors));
21545
21627
  typeParams.push(expressionType(literal(meta.isStandalone)));
21546
21628
  typeParams.push(createHostDirectivesType(meta));
21629
+ typeParams.push(expressionType(literal(meta.isSignal)));
21547
21630
  return expressionType(importExpr(Identifiers.ComponentDeclaration, typeParams));
21548
21631
  }
21549
21632
  /**
@@ -21671,6 +21754,7 @@ function createDirectiveType(meta) {
21671
21754
  typeParams.push(NONE_TYPE);
21672
21755
  typeParams.push(expressionType(literal(meta.isStandalone)));
21673
21756
  typeParams.push(createHostDirectivesType(meta));
21757
+ typeParams.push(expressionType(literal(meta.isSignal)));
21674
21758
  return expressionType(importExpr(Identifiers.DirectiveDeclaration, typeParams));
21675
21759
  }
21676
21760
  // Define and update any view queries
@@ -22334,6 +22418,7 @@ function convertDeclareDirectiveFacadeToMetadata(declaration, typeSourceSpan) {
22334
22418
  typeArgumentCount: 0,
22335
22419
  fullInheritance: false,
22336
22420
  isStandalone: declaration.isStandalone ?? false,
22421
+ isSignal: declaration.isSignal ?? false,
22337
22422
  hostDirectives: convertHostDirectivesToMetadata(declaration),
22338
22423
  };
22339
22424
  }
@@ -22625,7 +22710,7 @@ function publishFacade(global) {
22625
22710
  * @description
22626
22711
  * Entry point for all public APIs of the compiler package.
22627
22712
  */
22628
- const VERSION = new Version('16.0.0');
22713
+ const VERSION = new Version('16.1.0-next.0');
22629
22714
 
22630
22715
  class CompilerConfig {
22631
22716
  constructor({ defaultEncapsulation = ViewEncapsulation.Emulated, useJit = true, missingTranslation = null, preserveWhitespaces, strictInjectionParameters } = {}) {
@@ -24553,7 +24638,7 @@ const MINIMUM_PARTIAL_LINKER_VERSION$6 = '12.0.0';
24553
24638
  function compileDeclareClassMetadata(metadata) {
24554
24639
  const definitionMap = new DefinitionMap();
24555
24640
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$6));
24556
- definitionMap.set('version', literal('16.0.0'));
24641
+ definitionMap.set('version', literal('16.1.0-next.0'));
24557
24642
  definitionMap.set('ngImport', importExpr(Identifiers.core));
24558
24643
  definitionMap.set('type', metadata.type);
24559
24644
  definitionMap.set('decorators', metadata.decorators);
@@ -24656,12 +24741,15 @@ function compileDeclareDirectiveFromMetadata(meta) {
24656
24741
  function createDirectiveDefinitionMap(meta) {
24657
24742
  const definitionMap = new DefinitionMap();
24658
24743
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$5));
24659
- definitionMap.set('version', literal('16.0.0'));
24744
+ definitionMap.set('version', literal('16.1.0-next.0'));
24660
24745
  // e.g. `type: MyDirective`
24661
24746
  definitionMap.set('type', meta.type.value);
24662
24747
  if (meta.isStandalone) {
24663
24748
  definitionMap.set('isStandalone', literal(meta.isStandalone));
24664
24749
  }
24750
+ if (meta.isSignal) {
24751
+ definitionMap.set('isSignal', literal(meta.isSignal));
24752
+ }
24665
24753
  // e.g. `selector: 'some-dir'`
24666
24754
  if (meta.selector !== null) {
24667
24755
  definitionMap.set('selector', literal(meta.selector));
@@ -24881,7 +24969,7 @@ const MINIMUM_PARTIAL_LINKER_VERSION$4 = '12.0.0';
24881
24969
  function compileDeclareFactoryFunction(meta) {
24882
24970
  const definitionMap = new DefinitionMap();
24883
24971
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$4));
24884
- definitionMap.set('version', literal('16.0.0'));
24972
+ definitionMap.set('version', literal('16.1.0-next.0'));
24885
24973
  definitionMap.set('ngImport', importExpr(Identifiers.core));
24886
24974
  definitionMap.set('type', meta.type.value);
24887
24975
  definitionMap.set('deps', compileDependencies(meta.deps));
@@ -24916,7 +25004,7 @@ function compileDeclareInjectableFromMetadata(meta) {
24916
25004
  function createInjectableDefinitionMap(meta) {
24917
25005
  const definitionMap = new DefinitionMap();
24918
25006
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$3));
24919
- definitionMap.set('version', literal('16.0.0'));
25007
+ definitionMap.set('version', literal('16.1.0-next.0'));
24920
25008
  definitionMap.set('ngImport', importExpr(Identifiers.core));
24921
25009
  definitionMap.set('type', meta.type.value);
24922
25010
  // Only generate providedIn property if it has a non-null value
@@ -24967,7 +25055,7 @@ function compileDeclareInjectorFromMetadata(meta) {
24967
25055
  function createInjectorDefinitionMap(meta) {
24968
25056
  const definitionMap = new DefinitionMap();
24969
25057
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$2));
24970
- definitionMap.set('version', literal('16.0.0'));
25058
+ definitionMap.set('version', literal('16.1.0-next.0'));
24971
25059
  definitionMap.set('ngImport', importExpr(Identifiers.core));
24972
25060
  definitionMap.set('type', meta.type.value);
24973
25061
  definitionMap.set('providers', meta.providers);
@@ -24997,7 +25085,7 @@ function compileDeclareNgModuleFromMetadata(meta) {
24997
25085
  function createNgModuleDefinitionMap(meta) {
24998
25086
  const definitionMap = new DefinitionMap();
24999
25087
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$1));
25000
- definitionMap.set('version', literal('16.0.0'));
25088
+ definitionMap.set('version', literal('16.1.0-next.0'));
25001
25089
  definitionMap.set('ngImport', importExpr(Identifiers.core));
25002
25090
  definitionMap.set('type', meta.type.value);
25003
25091
  // We only generate the keys in the metadata if the arrays contain values.
@@ -25048,7 +25136,7 @@ function compileDeclarePipeFromMetadata(meta) {
25048
25136
  function createPipeDefinitionMap(meta) {
25049
25137
  const definitionMap = new DefinitionMap();
25050
25138
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION));
25051
- definitionMap.set('version', literal('16.0.0'));
25139
+ definitionMap.set('version', literal('16.1.0-next.0'));
25052
25140
  definitionMap.set('ngImport', importExpr(Identifiers.core));
25053
25141
  // e.g. `type: MyPipe`
25054
25142
  definitionMap.set('type', meta.type.value);
@@ -25081,5 +25169,5 @@ publishFacade(_global);
25081
25169
 
25082
25170
  // This file is not used to build this module. It is only used during editing
25083
25171
 
25084
- export { AST, ASTWithName, ASTWithSource, AbsoluteSourceSpan, ArrayType, AstMemoryEfficientTransformer, AstTransformer, Attribute, Binary, BinaryOperator, BinaryOperatorExpr, BindingPipe, BoundElementProperty, BuiltinType, BuiltinTypeName, CUSTOM_ELEMENTS_SCHEMA, Call, Chain, ChangeDetectionStrategy, CommaExpr, Comment, CompilerConfig, Conditional, ConditionalExpr, ConstantPool, CssSelector, DEFAULT_INTERPOLATION_CONFIG, DYNAMIC_TYPE, DeclareFunctionStmt, DeclareVarStmt, DomElementSchemaRegistry, EOF, Element, ElementSchemaRegistry, EmitterVisitorContext, EmptyExpr, Expansion, ExpansionCase, Expression, ExpressionBinding, ExpressionStatement, ExpressionType, ExternalExpr, ExternalReference, FactoryTarget$1 as FactoryTarget, FunctionExpr, HtmlParser, HtmlTagDefinition, I18NHtmlParser, IfStmt, ImplicitReceiver, InstantiateExpr, Interpolation, InterpolationConfig, InvokeFunctionExpr, JSDocComment, JitEvaluator, KeyedRead, KeyedWrite, LeadingComment, Lexer, LiteralArray, LiteralArrayExpr, LiteralExpr, LiteralMap, LiteralMapExpr, LiteralPrimitive, LocalizedString, MapType, MessageBundle, NONE_TYPE, NO_ERRORS_SCHEMA, NodeWithI18n, NonNullAssert, NotExpr, ParseError, ParseErrorLevel, ParseLocation, ParseSourceFile, ParseSourceSpan, ParseSpan, ParseTreeResult, ParsedEvent, ParsedProperty, ParsedPropertyType, ParsedVariable, Parser$1 as Parser, ParserError, PrefixNot, PropertyRead, PropertyWrite, R3BoundTarget, Identifiers as R3Identifiers, R3SelectorScopeMode, R3TargetBinder, R3TemplateDependencyKind, ReadKeyExpr, ReadPropExpr, ReadVarExpr, RecursiveAstVisitor, RecursiveVisitor, ResourceLoader, ReturnStatement, STRING_TYPE, SafeCall, SafeKeyedRead, SafePropertyRead, SelectorContext, SelectorListContext, SelectorMatcher, Serializer, SplitInterpolation, Statement, StmtModifier, TagContentType, TaggedTemplateExpr, TemplateBindingParseResult, TemplateLiteral, TemplateLiteralElement, Text, ThisReceiver, BoundAttribute as TmplAstBoundAttribute, BoundEvent as TmplAstBoundEvent, BoundText as TmplAstBoundText, Content as TmplAstContent, Element$1 as TmplAstElement, Icu$1 as TmplAstIcu, RecursiveVisitor$1 as TmplAstRecursiveVisitor, Reference as TmplAstReference, Template as TmplAstTemplate, Text$3 as TmplAstText, TextAttribute as TmplAstTextAttribute, Variable as TmplAstVariable, Token, TokenType, TreeError, Type, TypeModifier, TypeofExpr, Unary, UnaryOperator, UnaryOperatorExpr, VERSION, VariableBinding, Version, ViewEncapsulation, WrappedNodeExpr, WriteKeyExpr, WritePropExpr, WriteVarExpr, Xliff, Xliff2, Xmb, XmlParser, Xtb, _ParseAST, compileClassMetadata, compileComponentFromMetadata, compileDeclareClassMetadata, compileDeclareComponentFromMetadata, compileDeclareDirectiveFromMetadata, compileDeclareFactoryFunction, compileDeclareInjectableFromMetadata, compileDeclareInjectorFromMetadata, compileDeclareNgModuleFromMetadata, compileDeclarePipeFromMetadata, compileDirectiveFromMetadata, compileFactoryFunction, compileInjectable, compileInjector, compileNgModule, compilePipeFromMetadata, computeMsgId, core, createInjectableType, createMayBeForwardRefExpression, devOnlyGuardedExpression, emitDistinctChangesOnlyDefaultValue, getHtmlTagDefinition, getNsPrefix, getSafePropertyAccessString, identifierName, isIdentifier, isNgContainer, isNgContent, isNgTemplate, jsDocComment, leadingComment, literalMap, makeBindingParser, mergeNsAndName, output_ast as outputAst, parseHostBindings, parseTemplate, preserveWhitespacesDefault, publishFacade, r3JitTypeSourceSpan, sanitizeIdentifier, splitNsName, verifyHostBindings, visitAll };
25172
+ export { AST, ASTWithName, ASTWithSource, AbsoluteSourceSpan, ArrayType, AstMemoryEfficientTransformer, AstTransformer, Attribute, Binary, BinaryOperator, BinaryOperatorExpr, BindingPipe, BoundElementProperty, BuiltinType, BuiltinTypeName, CUSTOM_ELEMENTS_SCHEMA, Call, Chain, ChangeDetectionStrategy, CommaExpr, Comment, CompilerConfig, Conditional, ConditionalExpr, ConstantPool, CssSelector, DEFAULT_INTERPOLATION_CONFIG, DYNAMIC_TYPE, DeclareFunctionStmt, DeclareVarStmt, DomElementSchemaRegistry, EOF, Element, ElementSchemaRegistry, EmitterVisitorContext, EmptyExpr, Expansion, ExpansionCase, Expression, ExpressionBinding, ExpressionStatement, ExpressionType, ExternalExpr, ExternalReference, FactoryTarget$1 as FactoryTarget, FunctionExpr, HtmlParser, HtmlTagDefinition, I18NHtmlParser, IfStmt, ImplicitReceiver, InstantiateExpr, Interpolation, InterpolationConfig, InvokeFunctionExpr, JSDocComment, JitEvaluator, KeyedRead, KeyedWrite, LeadingComment, Lexer, LiteralArray, LiteralArrayExpr, LiteralExpr, LiteralMap, LiteralMapExpr, LiteralPrimitive, LocalizedString, MapType, MessageBundle, NONE_TYPE, NO_ERRORS_SCHEMA, NodeWithI18n, NonNullAssert, NotExpr, ParseError, ParseErrorLevel, ParseLocation, ParseSourceFile, ParseSourceSpan, ParseSpan, ParseTreeResult, ParsedEvent, ParsedProperty, ParsedPropertyType, ParsedVariable, Parser$1 as Parser, ParserError, PrefixNot, PropertyRead, PropertyWrite, R3BoundTarget, Identifiers as R3Identifiers, R3SelectorScopeMode, R3TargetBinder, R3TemplateDependencyKind, ReadKeyExpr, ReadPropExpr, ReadVarExpr, RecursiveAstVisitor, RecursiveVisitor, ResourceLoader, ReturnStatement, STRING_TYPE, SafeCall, SafeKeyedRead, SafePropertyRead, SelectorContext, SelectorListContext, SelectorMatcher, Serializer, SplitInterpolation, Statement, StmtModifier, TagContentType, TaggedTemplateExpr, TemplateBindingParseResult, TemplateLiteral, TemplateLiteralElement, Text, ThisReceiver, BoundAttribute as TmplAstBoundAttribute, BoundEvent as TmplAstBoundEvent, BoundText as TmplAstBoundText, Content as TmplAstContent, Element$1 as TmplAstElement, Icu$1 as TmplAstIcu, RecursiveVisitor$1 as TmplAstRecursiveVisitor, Reference as TmplAstReference, Template as TmplAstTemplate, Text$3 as TmplAstText, TextAttribute as TmplAstTextAttribute, Variable as TmplAstVariable, Token, TokenType, TransplantedType, TreeError, Type, TypeModifier, TypeofExpr, Unary, UnaryOperator, UnaryOperatorExpr, VERSION, VariableBinding, Version, ViewEncapsulation, WrappedNodeExpr, WriteKeyExpr, WritePropExpr, WriteVarExpr, Xliff, Xliff2, Xmb, XmlParser, Xtb, _ParseAST, compileClassMetadata, compileComponentFromMetadata, compileDeclareClassMetadata, compileDeclareComponentFromMetadata, compileDeclareDirectiveFromMetadata, compileDeclareFactoryFunction, compileDeclareInjectableFromMetadata, compileDeclareInjectorFromMetadata, compileDeclareNgModuleFromMetadata, compileDeclarePipeFromMetadata, compileDirectiveFromMetadata, compileFactoryFunction, compileInjectable, compileInjector, compileNgModule, compilePipeFromMetadata, computeMsgId, core, createInjectableType, createMayBeForwardRefExpression, devOnlyGuardedExpression, emitDistinctChangesOnlyDefaultValue, getHtmlTagDefinition, getNsPrefix, getSafePropertyAccessString, identifierName, isIdentifier, isNgContainer, isNgContent, isNgTemplate, jsDocComment, leadingComment, literalMap, makeBindingParser, mergeNsAndName, output_ast as outputAst, parseHostBindings, parseTemplate, preserveWhitespacesDefault, publishFacade, r3JitTypeSourceSpan, sanitizeIdentifier, splitNsName, verifyHostBindings, visitAll };
25085
25173
  //# sourceMappingURL=compiler.mjs.map