@angular/core 16.2.9 → 16.2.11

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.9
2
+ * @license Angular v16.2.11
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v16.2.9
2
+ * @license Angular v16.2.11
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -1687,6 +1687,93 @@ function initNgDevMode() {
1687
1687
  return false;
1688
1688
  }
1689
1689
 
1690
+ /**
1691
+ * Creates a token that can be used in a DI Provider.
1692
+ *
1693
+ * Use an `InjectionToken` whenever the type you are injecting is not reified (does not have a
1694
+ * runtime representation) such as when injecting an interface, callable type, array or
1695
+ * parameterized type.
1696
+ *
1697
+ * `InjectionToken` is parameterized on `T` which is the type of object which will be returned by
1698
+ * the `Injector`. This provides an additional level of type safety.
1699
+ *
1700
+ * <div class="alert is-helpful">
1701
+ *
1702
+ * **Important Note**: Ensure that you use the same instance of the `InjectionToken` in both the
1703
+ * provider and the injection call. Creating a new instance of `InjectionToken` in different places,
1704
+ * even with the same description, will be treated as different tokens by Angular's DI system,
1705
+ * leading to a `NullInjectorError`.
1706
+ *
1707
+ * </div>
1708
+ *
1709
+ * <code-example format="typescript" language="typescript" path="injection-token/src/main.ts"
1710
+ * region="InjectionToken"></code-example>
1711
+ *
1712
+ * When creating an `InjectionToken`, you can optionally specify a factory function which returns
1713
+ * (possibly by creating) a default value of the parameterized type `T`. This sets up the
1714
+ * `InjectionToken` using this factory as a provider as if it was defined explicitly in the
1715
+ * application's root injector. If the factory function, which takes zero arguments, needs to inject
1716
+ * dependencies, it can do so using the [`inject`](api/core/inject) function.
1717
+ * As you can see in the Tree-shakable InjectionToken example below.
1718
+ *
1719
+ * Additionally, if a `factory` is specified you can also specify the `providedIn` option, which
1720
+ * overrides the above behavior and marks the token as belonging to a particular `@NgModule` (note:
1721
+ * this option is now deprecated). As mentioned above, `'root'` is the default value for
1722
+ * `providedIn`.
1723
+ *
1724
+ * The `providedIn: NgModule` and `providedIn: 'any'` options are deprecated.
1725
+ *
1726
+ * @usageNotes
1727
+ * ### Basic Examples
1728
+ *
1729
+ * ### Plain InjectionToken
1730
+ *
1731
+ * {@example core/di/ts/injector_spec.ts region='InjectionToken'}
1732
+ *
1733
+ * ### Tree-shakable InjectionToken
1734
+ *
1735
+ * {@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'}
1736
+ *
1737
+ * @publicApi
1738
+ */
1739
+ class InjectionToken {
1740
+ /**
1741
+ * @param _desc Description for the token,
1742
+ * used only for debugging purposes,
1743
+ * it should but does not need to be unique
1744
+ * @param options Options for the token's usage, as described above
1745
+ */
1746
+ constructor(_desc, options) {
1747
+ this._desc = _desc;
1748
+ /** @internal */
1749
+ this.ngMetadataName = 'InjectionToken';
1750
+ this.ɵprov = undefined;
1751
+ if (typeof options == 'number') {
1752
+ (typeof ngDevMode === 'undefined' || ngDevMode) &&
1753
+ assertLessThan(options, 0, 'Only negative numbers are supported here');
1754
+ // This is a special hack to assign __NG_ELEMENT_ID__ to this instance.
1755
+ // See `InjectorMarkers`
1756
+ this.__NG_ELEMENT_ID__ = options;
1757
+ }
1758
+ else if (options !== undefined) {
1759
+ this.ɵprov = ɵɵdefineInjectable({
1760
+ token: this,
1761
+ providedIn: options.providedIn || 'root',
1762
+ factory: options.factory,
1763
+ });
1764
+ }
1765
+ }
1766
+ /**
1767
+ * @internal
1768
+ */
1769
+ get multi() {
1770
+ return this;
1771
+ }
1772
+ toString() {
1773
+ return `InjectionToken ${this._desc}`;
1774
+ }
1775
+ }
1776
+
1690
1777
  let _injectorProfilerContext;
1691
1778
  function getInjectorProfilerContext() {
1692
1779
  !ngDevMode && throwError('getInjectorProfilerContext should never be called in production mode');
@@ -1728,18 +1815,35 @@ function injectorProfiler(event) {
1728
1815
  * Emits an InjectorProfilerEventType.ProviderConfigured to the injector profiler. The data in the
1729
1816
  * emitted event includes the raw provider, as well as the token that provider is providing.
1730
1817
  *
1731
- * @param provider A provider object
1818
+ * @param eventProvider A provider object
1732
1819
  */
1733
- function emitProviderConfiguredEvent(provider, isViewProvider = false) {
1820
+ function emitProviderConfiguredEvent(eventProvider, isViewProvider = false) {
1734
1821
  !ngDevMode && throwError('Injector profiler should never be called in production mode');
1822
+ let token;
1823
+ // if the provider is a TypeProvider (typeof provider is function) then the token is the
1824
+ // provider itself
1825
+ if (typeof eventProvider === 'function') {
1826
+ token = eventProvider;
1827
+ }
1828
+ // if the provider is an injection token, then the token is the injection token.
1829
+ else if (eventProvider instanceof InjectionToken) {
1830
+ token = eventProvider;
1831
+ }
1832
+ // in all other cases we can access the token via the `provide` property of the provider
1833
+ else {
1834
+ token = resolveForwardRef(eventProvider.provide);
1835
+ }
1836
+ let provider = eventProvider;
1837
+ // Injection tokens may define their own default provider which gets attached to the token itself
1838
+ // as `ɵprov`. In this case, we want to emit the provider that is attached to the token, not the
1839
+ // token itself.
1840
+ if (eventProvider instanceof InjectionToken) {
1841
+ provider = eventProvider.ɵprov || eventProvider;
1842
+ }
1735
1843
  injectorProfiler({
1736
1844
  type: 2 /* InjectorProfilerEventType.ProviderConfigured */,
1737
1845
  context: getInjectorProfilerContext(),
1738
- providerRecord: {
1739
- token: typeof provider === 'function' ? provider : resolveForwardRef(provider.provide),
1740
- provider,
1741
- isViewProvider
1742
- }
1846
+ providerRecord: { token, provider, isViewProvider }
1743
1847
  });
1744
1848
  }
1745
1849
  /**
@@ -6344,93 +6448,6 @@ function setAllowDuplicateNgModuleIdsForTest(allowDuplicates) {
6344
6448
  checkForDuplicateNgModules = !allowDuplicates;
6345
6449
  }
6346
6450
 
6347
- /**
6348
- * Creates a token that can be used in a DI Provider.
6349
- *
6350
- * Use an `InjectionToken` whenever the type you are injecting is not reified (does not have a
6351
- * runtime representation) such as when injecting an interface, callable type, array or
6352
- * parameterized type.
6353
- *
6354
- * `InjectionToken` is parameterized on `T` which is the type of object which will be returned by
6355
- * the `Injector`. This provides an additional level of type safety.
6356
- *
6357
- * <div class="alert is-helpful">
6358
- *
6359
- * **Important Note**: Ensure that you use the same instance of the `InjectionToken` in both the
6360
- * provider and the injection call. Creating a new instance of `InjectionToken` in different places,
6361
- * even with the same description, will be treated as different tokens by Angular's DI system,
6362
- * leading to a `NullInjectorError`.
6363
- *
6364
- * </div>
6365
- *
6366
- * <code-example format="typescript" language="typescript" path="injection-token/src/main.ts"
6367
- * region="InjectionToken"></code-example>
6368
- *
6369
- * When creating an `InjectionToken`, you can optionally specify a factory function which returns
6370
- * (possibly by creating) a default value of the parameterized type `T`. This sets up the
6371
- * `InjectionToken` using this factory as a provider as if it was defined explicitly in the
6372
- * application's root injector. If the factory function, which takes zero arguments, needs to inject
6373
- * dependencies, it can do so using the [`inject`](api/core/inject) function.
6374
- * As you can see in the Tree-shakable InjectionToken example below.
6375
- *
6376
- * Additionally, if a `factory` is specified you can also specify the `providedIn` option, which
6377
- * overrides the above behavior and marks the token as belonging to a particular `@NgModule` (note:
6378
- * this option is now deprecated). As mentioned above, `'root'` is the default value for
6379
- * `providedIn`.
6380
- *
6381
- * The `providedIn: NgModule` and `providedIn: 'any'` options are deprecated.
6382
- *
6383
- * @usageNotes
6384
- * ### Basic Examples
6385
- *
6386
- * ### Plain InjectionToken
6387
- *
6388
- * {@example core/di/ts/injector_spec.ts region='InjectionToken'}
6389
- *
6390
- * ### Tree-shakable InjectionToken
6391
- *
6392
- * {@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'}
6393
- *
6394
- * @publicApi
6395
- */
6396
- class InjectionToken {
6397
- /**
6398
- * @param _desc Description for the token,
6399
- * used only for debugging purposes,
6400
- * it should but does not need to be unique
6401
- * @param options Options for the token's usage, as described above
6402
- */
6403
- constructor(_desc, options) {
6404
- this._desc = _desc;
6405
- /** @internal */
6406
- this.ngMetadataName = 'InjectionToken';
6407
- this.ɵprov = undefined;
6408
- if (typeof options == 'number') {
6409
- (typeof ngDevMode === 'undefined' || ngDevMode) &&
6410
- assertLessThan(options, 0, 'Only negative numbers are supported here');
6411
- // This is a special hack to assign __NG_ELEMENT_ID__ to this instance.
6412
- // See `InjectorMarkers`
6413
- this.__NG_ELEMENT_ID__ = options;
6414
- }
6415
- else if (options !== undefined) {
6416
- this.ɵprov = ɵɵdefineInjectable({
6417
- token: this,
6418
- providedIn: options.providedIn || 'root',
6419
- factory: options.factory,
6420
- });
6421
- }
6422
- }
6423
- /**
6424
- * @internal
6425
- */
6426
- get multi() {
6427
- return this;
6428
- }
6429
- toString() {
6430
- return `InjectionToken ${this._desc}`;
6431
- }
6432
- }
6433
-
6434
6451
  /**
6435
6452
  * Most of the use of `document` in Angular is from within the DI system so it is possible to simply
6436
6453
  * inject the `DOCUMENT` token and are done.
@@ -7032,6 +7049,11 @@ class R3Injector extends EnvironmentInjector {
7032
7049
  if (def && this.injectableDefInScope(def)) {
7033
7050
  // Found an injectable def and it's scoped to this injector. Pretend as if it was here
7034
7051
  // all along.
7052
+ if (ngDevMode) {
7053
+ runInInjectorProfilerContext(this, token, () => {
7054
+ emitProviderConfiguredEvent(token);
7055
+ });
7056
+ }
7035
7057
  record = makeRecord(injectableDefOrInjectorDefFactory(token), NOT_YET);
7036
7058
  }
7037
7059
  else {
@@ -10925,7 +10947,7 @@ class Version {
10925
10947
  /**
10926
10948
  * @publicApi
10927
10949
  */
10928
- const VERSION = new Version('16.2.9');
10950
+ const VERSION = new Version('16.2.11');
10929
10951
 
10930
10952
  // This default value is when checking the hierarchy for a token.
10931
10953
  //
@@ -12011,11 +12033,6 @@ function getExpressionChangedErrorDetails(lView, bindingIndex, oldValue, newValu
12011
12033
  }
12012
12034
 
12013
12035
  let currentConsumer = null;
12014
- function setLViewForConsumer(node, lView) {
12015
- (typeof ngDevMode === 'undefined' || ngDevMode) &&
12016
- assertEqual(node.lView, null, 'Consumer already associated with a view.');
12017
- node.lView = lView;
12018
- }
12019
12036
  /**
12020
12037
  * Create a new template consumer pointing at the specified LView.
12021
12038
  * Sometimes, a previously created consumer may be reused, in order to save on allocations. In that