@angular/core 16.2.4 → 16.2.6

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v16.2.4
2
+ * @license Angular v16.2.6
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -3556,7 +3556,7 @@ function getFactoryDef(type, throwNotFound) {
3556
3556
  *
3557
3557
  * This can be used to auto-unwrap signals in various cases, or to auto-wrap non-signal values.
3558
3558
  */
3559
- const SIGNAL = Symbol('SIGNAL');
3559
+ const SIGNAL = /* @__PURE__ */ Symbol('SIGNAL');
3560
3560
  /**
3561
3561
  * Checks if the given `value` is a reactive `Signal`.
3562
3562
  *
@@ -3734,7 +3734,9 @@ function consumerAfterComputation(node, prevConsumer) {
3734
3734
  }
3735
3735
  }
3736
3736
  // Truncate the producer tracking arrays.
3737
- for (let i = node.nextProducerIndex; i < node.producerNode.length; i++) {
3737
+ // Perf note: this is essentially truncating the length to `node.nextProducerIndex`, but
3738
+ // benchmarking has shown that individual pop operations are faster.
3739
+ while (node.producerNode.length > node.nextProducerIndex) {
3738
3740
  node.producerNode.pop();
3739
3741
  node.producerLastReadVersion.pop();
3740
3742
  node.producerIndexOfThis.pop();
@@ -3808,6 +3810,9 @@ function producerAddLiveConsumer(node, consumer, indexOfThis) {
3808
3810
  function producerRemoveLiveConsumerAtIndex(node, idx) {
3809
3811
  assertProducerNode(node);
3810
3812
  assertConsumerNode(node);
3813
+ if (typeof ngDevMode !== 'undefined' && ngDevMode && idx >= node.liveConsumerNode.length) {
3814
+ throw new Error(`Assertion error: active consumer index ${idx} is out of bounds of ${node.liveConsumerNode.length} consumers)`);
3815
+ }
3811
3816
  if (node.liveConsumerNode.length === 1) {
3812
3817
  // When removing the last live consumer, we will no longer be live. We need to remove
3813
3818
  // ourselves from our producers' tracking (which may cause consumer-producers to lose
@@ -3872,60 +3877,65 @@ function computed(computation, options) {
3872
3877
  * A dedicated symbol used before a computed value has been calculated for the first time.
3873
3878
  * Explicitly typed as `any` so we can use it as signal's value.
3874
3879
  */
3875
- const UNSET = Symbol('UNSET');
3880
+ const UNSET = /* @__PURE__ */ Symbol('UNSET');
3876
3881
  /**
3877
3882
  * A dedicated symbol used in place of a computed signal value to indicate that a given computation
3878
3883
  * is in progress. Used to detect cycles in computation chains.
3879
3884
  * Explicitly typed as `any` so we can use it as signal's value.
3880
3885
  */
3881
- const COMPUTING = Symbol('COMPUTING');
3886
+ const COMPUTING = /* @__PURE__ */ Symbol('COMPUTING');
3882
3887
  /**
3883
3888
  * A dedicated symbol used in place of a computed signal value to indicate that a given computation
3884
3889
  * failed. The thrown error is cached until the computation gets dirty again.
3885
3890
  * Explicitly typed as `any` so we can use it as signal's value.
3886
3891
  */
3887
- const ERRORED = Symbol('ERRORED');
3888
- const COMPUTED_NODE = {
3889
- ...REACTIVE_NODE,
3890
- value: UNSET,
3891
- dirty: true,
3892
- error: null,
3893
- equal: defaultEquals,
3894
- producerMustRecompute(node) {
3895
- // Force a recomputation if there's no current value, or if the current value is in the process
3896
- // of being calculated (which should throw an error).
3897
- return node.value === UNSET || node.value === COMPUTING;
3898
- },
3899
- producerRecomputeValue(node) {
3900
- if (node.value === COMPUTING) {
3901
- // Our computation somehow led to a cyclic read of itself.
3902
- throw new Error('Detected cycle in computations.');
3903
- }
3904
- const oldValue = node.value;
3905
- node.value = COMPUTING;
3906
- const prevConsumer = consumerBeforeComputation(node);
3907
- let newValue;
3908
- try {
3909
- newValue = node.computation();
3910
- }
3911
- catch (err) {
3912
- newValue = ERRORED;
3913
- node.error = err;
3914
- }
3915
- finally {
3916
- consumerAfterComputation(node, prevConsumer);
3917
- }
3918
- if (oldValue !== UNSET && oldValue !== ERRORED && newValue !== ERRORED &&
3919
- node.equal(oldValue, newValue)) {
3920
- // No change to `valueVersion` - old and new values are
3921
- // semantically equivalent.
3922
- node.value = oldValue;
3923
- return;
3924
- }
3925
- node.value = newValue;
3926
- node.version++;
3927
- },
3928
- };
3892
+ const ERRORED = /* @__PURE__ */ Symbol('ERRORED');
3893
+ // Note: Using an IIFE here to ensure that the spread assignment is not considered
3894
+ // a side-effect, ending up preserving `COMPUTED_NODE` and `REACTIVE_NODE`.
3895
+ // TODO: remove when https://github.com/evanw/esbuild/issues/3392 is resolved.
3896
+ const COMPUTED_NODE = /* @__PURE__ */ (() => {
3897
+ return {
3898
+ ...REACTIVE_NODE,
3899
+ value: UNSET,
3900
+ dirty: true,
3901
+ error: null,
3902
+ equal: defaultEquals,
3903
+ producerMustRecompute(node) {
3904
+ // Force a recomputation if there's no current value, or if the current value is in the
3905
+ // process of being calculated (which should throw an error).
3906
+ return node.value === UNSET || node.value === COMPUTING;
3907
+ },
3908
+ producerRecomputeValue(node) {
3909
+ if (node.value === COMPUTING) {
3910
+ // Our computation somehow led to a cyclic read of itself.
3911
+ throw new Error('Detected cycle in computations.');
3912
+ }
3913
+ const oldValue = node.value;
3914
+ node.value = COMPUTING;
3915
+ const prevConsumer = consumerBeforeComputation(node);
3916
+ let newValue;
3917
+ try {
3918
+ newValue = node.computation();
3919
+ }
3920
+ catch (err) {
3921
+ newValue = ERRORED;
3922
+ node.error = err;
3923
+ }
3924
+ finally {
3925
+ consumerAfterComputation(node, prevConsumer);
3926
+ }
3927
+ if (oldValue !== UNSET && oldValue !== ERRORED && newValue !== ERRORED &&
3928
+ node.equal(oldValue, newValue)) {
3929
+ // No change to `valueVersion` - old and new values are
3930
+ // semantically equivalent.
3931
+ node.value = oldValue;
3932
+ return;
3933
+ }
3934
+ node.value = newValue;
3935
+ node.version++;
3936
+ },
3937
+ };
3938
+ })();
3929
3939
 
3930
3940
  function defaultThrowError() {
3931
3941
  throw new Error();
@@ -3970,11 +3980,16 @@ function setPostSignalSetFn(fn) {
3970
3980
  postSignalSetFn = fn;
3971
3981
  return prev;
3972
3982
  }
3973
- const SIGNAL_NODE = {
3974
- ...REACTIVE_NODE,
3975
- equal: defaultEquals,
3976
- readonlyFn: undefined,
3977
- };
3983
+ // Note: Using an IIFE here to ensure that the spread assignment is not considered
3984
+ // a side-effect, ending up preserving `COMPUTED_NODE` and `REACTIVE_NODE`.
3985
+ // TODO: remove when https://github.com/evanw/esbuild/issues/3392 is resolved.
3986
+ const SIGNAL_NODE = /* @__PURE__ */ (() => {
3987
+ return {
3988
+ ...REACTIVE_NODE,
3989
+ equal: defaultEquals,
3990
+ readonlyFn: undefined,
3991
+ };
3992
+ })();
3978
3993
  function signalValueChanged(node) {
3979
3994
  node.version++;
3980
3995
  producerNotifyConsumers(node);
@@ -4067,16 +4082,21 @@ function watch(fn, schedule, allowSignalWrites) {
4067
4082
  return node.ref;
4068
4083
  }
4069
4084
  const NOOP_CLEANUP_FN = () => { };
4070
- const WATCH_NODE = {
4071
- ...REACTIVE_NODE,
4072
- consumerIsAlwaysLive: true,
4073
- consumerAllowSignalWrites: false,
4074
- consumerMarkedDirty: (node) => {
4075
- node.schedule(node.ref);
4076
- },
4077
- hasRun: false,
4078
- cleanupFn: NOOP_CLEANUP_FN,
4079
- };
4085
+ // Note: Using an IIFE here to ensure that the spread assignment is not considered
4086
+ // a side-effect, ending up preserving `COMPUTED_NODE` and `REACTIVE_NODE`.
4087
+ // TODO: remove when https://github.com/evanw/esbuild/issues/3392 is resolved.
4088
+ const WATCH_NODE = /* @__PURE__ */ (() => {
4089
+ return {
4090
+ ...REACTIVE_NODE,
4091
+ consumerIsAlwaysLive: true,
4092
+ consumerAllowSignalWrites: false,
4093
+ consumerMarkedDirty: (node) => {
4094
+ node.schedule(node.ref);
4095
+ },
4096
+ hasRun: false,
4097
+ cleanupFn: NOOP_CLEANUP_FN,
4098
+ };
4099
+ })();
4080
4100
 
4081
4101
  function setAlternateWeakRefImpl(impl) {
4082
4102
  // TODO: remove this function
@@ -10905,7 +10925,7 @@ class Version {
10905
10925
  /**
10906
10926
  * @publicApi
10907
10927
  */
10908
- const VERSION = new Version('16.2.4');
10928
+ const VERSION = new Version('16.2.6');
10909
10929
 
10910
10930
  // This default value is when checking the hierarchy for a token.
10911
10931
  //
@@ -10926,6 +10946,66 @@ const VERSION = new Version('16.2.4');
10926
10946
  // - mod2.injector.get(token, default)
10927
10947
  const NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR = {};
10928
10948
 
10949
+ const ERROR_ORIGINAL_ERROR = 'ngOriginalError';
10950
+ function wrappedError(message, originalError) {
10951
+ const msg = `${message} caused by: ${originalError instanceof Error ? originalError.message : originalError}`;
10952
+ const error = Error(msg);
10953
+ error[ERROR_ORIGINAL_ERROR] = originalError;
10954
+ return error;
10955
+ }
10956
+ function getOriginalError(error) {
10957
+ return error[ERROR_ORIGINAL_ERROR];
10958
+ }
10959
+
10960
+ /**
10961
+ * Provides a hook for centralized exception handling.
10962
+ *
10963
+ * The default implementation of `ErrorHandler` prints error messages to the `console`. To
10964
+ * intercept error handling, write a custom exception handler that replaces this default as
10965
+ * appropriate for your app.
10966
+ *
10967
+ * @usageNotes
10968
+ * ### Example
10969
+ *
10970
+ * ```
10971
+ * class MyErrorHandler implements ErrorHandler {
10972
+ * handleError(error) {
10973
+ * // do something with the exception
10974
+ * }
10975
+ * }
10976
+ *
10977
+ * @NgModule({
10978
+ * providers: [{provide: ErrorHandler, useClass: MyErrorHandler}]
10979
+ * })
10980
+ * class MyModule {}
10981
+ * ```
10982
+ *
10983
+ * @publicApi
10984
+ */
10985
+ class ErrorHandler {
10986
+ constructor() {
10987
+ /**
10988
+ * @internal
10989
+ */
10990
+ this._console = console;
10991
+ }
10992
+ handleError(error) {
10993
+ const originalError = this._findOriginalError(error);
10994
+ this._console.error('ERROR', error);
10995
+ if (originalError) {
10996
+ this._console.error('ORIGINAL ERROR', originalError);
10997
+ }
10998
+ }
10999
+ /** @internal */
11000
+ _findOriginalError(error) {
11001
+ let e = error && getOriginalError(error);
11002
+ while (e && getOriginalError(e)) {
11003
+ e = getOriginalError(e);
11004
+ }
11005
+ return e || null;
11006
+ }
11007
+ }
11008
+
10929
11009
  /**
10930
11010
  * `DestroyRef` lets you set callbacks to run for any cleanup or destruction behavior.
10931
11011
  * The scope of this destruction depends on where `DestroyRef` is injected. If `DestroyRef`
@@ -11580,14 +11660,18 @@ function afterRender(callback, options) {
11580
11660
  }
11581
11661
  let destroy;
11582
11662
  const unregisterFn = injector.get(DestroyRef).onDestroy(() => destroy?.());
11583
- const manager = injector.get(AfterRenderEventManager);
11663
+ const afterRenderEventManager = injector.get(AfterRenderEventManager);
11664
+ // Lazily initialize the handler implementation, if necessary. This is so that it can be
11665
+ // tree-shaken if `afterRender` and `afterNextRender` aren't used.
11666
+ const callbackHandler = afterRenderEventManager.handler ??= new AfterRenderCallbackHandlerImpl();
11584
11667
  const ngZone = injector.get(NgZone);
11585
- const instance = new AfterRenderCallback(() => ngZone.runOutsideAngular(callback));
11668
+ const errorHandler = injector.get(ErrorHandler, null, { optional: true });
11669
+ const instance = new AfterRenderCallback(ngZone, errorHandler, callback);
11586
11670
  destroy = () => {
11587
- manager.unregister(instance);
11671
+ callbackHandler.unregister(instance);
11588
11672
  unregisterFn();
11589
11673
  };
11590
- manager.register(instance);
11674
+ callbackHandler.register(instance);
11591
11675
  return { destroy };
11592
11676
  }
11593
11677
  /**
@@ -11640,89 +11724,117 @@ function afterNextRender(callback, options) {
11640
11724
  }
11641
11725
  let destroy;
11642
11726
  const unregisterFn = injector.get(DestroyRef).onDestroy(() => destroy?.());
11643
- const manager = injector.get(AfterRenderEventManager);
11727
+ const afterRenderEventManager = injector.get(AfterRenderEventManager);
11728
+ // Lazily initialize the handler implementation, if necessary. This is so that it can be
11729
+ // tree-shaken if `afterRender` and `afterNextRender` aren't used.
11730
+ const callbackHandler = afterRenderEventManager.handler ??= new AfterRenderCallbackHandlerImpl();
11644
11731
  const ngZone = injector.get(NgZone);
11645
- const instance = new AfterRenderCallback(() => {
11732
+ const errorHandler = injector.get(ErrorHandler, null, { optional: true });
11733
+ const instance = new AfterRenderCallback(ngZone, errorHandler, () => {
11646
11734
  destroy?.();
11647
- ngZone.runOutsideAngular(callback);
11735
+ callback();
11648
11736
  });
11649
11737
  destroy = () => {
11650
- manager.unregister(instance);
11738
+ callbackHandler.unregister(instance);
11651
11739
  unregisterFn();
11652
11740
  };
11653
- manager.register(instance);
11741
+ callbackHandler.register(instance);
11654
11742
  return { destroy };
11655
11743
  }
11656
11744
  /**
11657
11745
  * A wrapper around a function to be used as an after render callback.
11658
- * @private
11659
11746
  */
11660
11747
  class AfterRenderCallback {
11661
- constructor(callback) {
11662
- this.callback = callback;
11748
+ constructor(zone, errorHandler, callbackFn) {
11749
+ this.zone = zone;
11750
+ this.errorHandler = errorHandler;
11751
+ this.callbackFn = callbackFn;
11663
11752
  }
11664
11753
  invoke() {
11665
- this.callback();
11754
+ try {
11755
+ this.zone.runOutsideAngular(this.callbackFn);
11756
+ }
11757
+ catch (err) {
11758
+ this.errorHandler?.handleError(err);
11759
+ }
11666
11760
  }
11667
11761
  }
11668
11762
  /**
11669
- * Implements `afterRender` and `afterNextRender` callback manager logic.
11763
+ * Core functionality for `afterRender` and `afterNextRender`. Kept separate from
11764
+ * `AfterRenderEventManager` for tree-shaking.
11670
11765
  */
11671
- class AfterRenderEventManager {
11766
+ class AfterRenderCallbackHandlerImpl {
11672
11767
  constructor() {
11768
+ this.executingCallbacks = false;
11673
11769
  this.callbacks = new Set();
11674
11770
  this.deferredCallbacks = new Set();
11675
- this.renderDepth = 0;
11676
- this.runningCallbacks = false;
11677
11771
  }
11678
- /**
11679
- * Mark the beginning of a render operation (i.e. CD cycle).
11680
- * Throws if called from an `afterRender` callback.
11681
- */
11682
- begin() {
11683
- if (this.runningCallbacks) {
11772
+ validateBegin() {
11773
+ if (this.executingCallbacks) {
11684
11774
  throw new RuntimeError(102 /* RuntimeErrorCode.RECURSIVE_APPLICATION_RENDER */, ngDevMode &&
11685
11775
  'A new render operation began before the previous operation ended. ' +
11686
11776
  'Did you trigger change detection from afterRender or afterNextRender?');
11687
11777
  }
11688
- this.renderDepth++;
11689
- }
11690
- /**
11691
- * Mark the end of a render operation. Registered callbacks
11692
- * are invoked if there are no more pending operations.
11693
- */
11694
- end() {
11695
- this.renderDepth--;
11696
- if (this.renderDepth === 0) {
11697
- try {
11698
- this.runningCallbacks = true;
11699
- for (const callback of this.callbacks) {
11700
- callback.invoke();
11701
- }
11702
- }
11703
- finally {
11704
- this.runningCallbacks = false;
11705
- for (const callback of this.deferredCallbacks) {
11706
- this.callbacks.add(callback);
11707
- }
11708
- this.deferredCallbacks.clear();
11709
- }
11710
- }
11711
11778
  }
11712
11779
  register(callback) {
11713
11780
  // If we're currently running callbacks, new callbacks should be deferred
11714
11781
  // until the next render operation.
11715
- const target = this.runningCallbacks ? this.deferredCallbacks : this.callbacks;
11782
+ const target = this.executingCallbacks ? this.deferredCallbacks : this.callbacks;
11716
11783
  target.add(callback);
11717
11784
  }
11718
11785
  unregister(callback) {
11719
11786
  this.callbacks.delete(callback);
11720
11787
  this.deferredCallbacks.delete(callback);
11721
11788
  }
11722
- ngOnDestroy() {
11789
+ execute() {
11790
+ this.executingCallbacks = true;
11791
+ for (const callback of this.callbacks) {
11792
+ callback.invoke();
11793
+ }
11794
+ this.executingCallbacks = false;
11795
+ for (const callback of this.deferredCallbacks) {
11796
+ this.callbacks.add(callback);
11797
+ }
11798
+ this.deferredCallbacks.clear();
11799
+ }
11800
+ destroy() {
11723
11801
  this.callbacks.clear();
11724
11802
  this.deferredCallbacks.clear();
11725
11803
  }
11804
+ }
11805
+ /**
11806
+ * Implements core timing for `afterRender` and `afterNextRender` events.
11807
+ * Delegates to an optional `AfterRenderCallbackHandler` for implementation.
11808
+ */
11809
+ class AfterRenderEventManager {
11810
+ constructor() {
11811
+ this.renderDepth = 0;
11812
+ /* @internal */
11813
+ this.handler = null;
11814
+ }
11815
+ /**
11816
+ * Mark the beginning of a render operation (i.e. CD cycle).
11817
+ * Throws if called while executing callbacks.
11818
+ */
11819
+ begin() {
11820
+ this.handler?.validateBegin();
11821
+ this.renderDepth++;
11822
+ }
11823
+ /**
11824
+ * Mark the end of a render operation. Callbacks will be
11825
+ * executed if there are no more pending operations.
11826
+ */
11827
+ end() {
11828
+ ngDevMode && assertGreaterThan(this.renderDepth, 0, 'renderDepth must be greater than 0');
11829
+ this.renderDepth--;
11830
+ if (this.renderDepth === 0) {
11831
+ this.handler?.execute();
11832
+ }
11833
+ }
11834
+ ngOnDestroy() {
11835
+ this.handler?.destroy();
11836
+ this.handler = null;
11837
+ }
11726
11838
  /** @nocollapse */
11727
11839
  static { this.ɵprov = ɵɵdefineInjectable({
11728
11840
  token: AfterRenderEventManager,
@@ -11756,66 +11868,6 @@ function markViewDirty(lView) {
11756
11868
  return null;
11757
11869
  }
11758
11870
 
11759
- const ERROR_ORIGINAL_ERROR = 'ngOriginalError';
11760
- function wrappedError(message, originalError) {
11761
- const msg = `${message} caused by: ${originalError instanceof Error ? originalError.message : originalError}`;
11762
- const error = Error(msg);
11763
- error[ERROR_ORIGINAL_ERROR] = originalError;
11764
- return error;
11765
- }
11766
- function getOriginalError(error) {
11767
- return error[ERROR_ORIGINAL_ERROR];
11768
- }
11769
-
11770
- /**
11771
- * Provides a hook for centralized exception handling.
11772
- *
11773
- * The default implementation of `ErrorHandler` prints error messages to the `console`. To
11774
- * intercept error handling, write a custom exception handler that replaces this default as
11775
- * appropriate for your app.
11776
- *
11777
- * @usageNotes
11778
- * ### Example
11779
- *
11780
- * ```
11781
- * class MyErrorHandler implements ErrorHandler {
11782
- * handleError(error) {
11783
- * // do something with the exception
11784
- * }
11785
- * }
11786
- *
11787
- * @NgModule({
11788
- * providers: [{provide: ErrorHandler, useClass: MyErrorHandler}]
11789
- * })
11790
- * class MyModule {}
11791
- * ```
11792
- *
11793
- * @publicApi
11794
- */
11795
- class ErrorHandler {
11796
- constructor() {
11797
- /**
11798
- * @internal
11799
- */
11800
- this._console = console;
11801
- }
11802
- handleError(error) {
11803
- const originalError = this._findOriginalError(error);
11804
- this._console.error('ERROR', error);
11805
- if (originalError) {
11806
- this._console.error('ORIGINAL ERROR', originalError);
11807
- }
11808
- }
11809
- /** @internal */
11810
- _findOriginalError(error) {
11811
- let e = error && getOriginalError(error);
11812
- while (e && getOriginalError(e)) {
11813
- e = getOriginalError(e);
11814
- }
11815
- return e || null;
11816
- }
11817
- }
11818
-
11819
11871
  /**
11820
11872
  * Internal token that specifies whether DOM reuse logic
11821
11873
  * during hydration is enabled.