@angular/core 14.0.0-next.13 → 14.0.0-next.16

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 (119) hide show
  1. package/esm2020/src/application_ref.mjs +219 -47
  2. package/esm2020/src/change_detection/change_detector_ref.mjs +3 -3
  3. package/esm2020/src/change_detection/differs/default_iterable_differ.mjs +2 -2
  4. package/esm2020/src/change_detection/differs/default_keyvalue_differ.mjs +2 -2
  5. package/esm2020/src/change_detection/differs/iterable_differs.mjs +2 -2
  6. package/esm2020/src/change_detection/differs/keyvalue_differs.mjs +2 -2
  7. package/esm2020/src/compiler/compiler_facade.mjs +2 -2
  8. package/esm2020/src/compiler/compiler_facade_interface.mjs +7 -1
  9. package/esm2020/src/core.mjs +2 -2
  10. package/esm2020/src/core_private_export.mjs +2 -2
  11. package/esm2020/src/core_render3_private_export.mjs +4 -3
  12. package/esm2020/src/debug/debug_node.mjs +5 -5
  13. package/esm2020/src/di/create_injector.mjs +35 -0
  14. package/esm2020/src/di/index.mjs +4 -1
  15. package/esm2020/src/di/initializer_token.mjs +16 -0
  16. package/esm2020/src/di/injection_token.mjs +7 -1
  17. package/esm2020/src/di/injector.mjs +3 -3
  18. package/esm2020/src/di/injector_compatibility.mjs +4 -6
  19. package/esm2020/src/di/injector_token.mjs +2 -2
  20. package/esm2020/src/di/interface/defs.mjs +1 -1
  21. package/esm2020/src/di/interface/provider.mjs +1 -1
  22. package/esm2020/src/di/internal_tokens.mjs +10 -0
  23. package/esm2020/src/di/jit/injectable.mjs +3 -3
  24. package/esm2020/src/di/metadata.mjs +6 -6
  25. package/esm2020/src/di/provider_collection.mjs +224 -0
  26. package/esm2020/src/di/r3_injector.mjs +87 -157
  27. package/esm2020/src/di/scope.mjs +1 -1
  28. package/esm2020/src/errors.mjs +1 -1
  29. package/esm2020/src/linker/component_factory.mjs +1 -1
  30. package/esm2020/src/linker/ng_module_factory.mjs +1 -1
  31. package/esm2020/src/linker/template_ref.mjs +3 -3
  32. package/esm2020/src/linker/view_container_ref.mjs +15 -12
  33. package/esm2020/src/metadata/directives.mjs +1 -1
  34. package/esm2020/src/metadata/ng_module.mjs +1 -1
  35. package/esm2020/src/metadata.mjs +1 -1
  36. package/esm2020/src/render3/assert.mjs +3 -3
  37. package/esm2020/src/render3/collect_native_nodes.mjs +5 -5
  38. package/esm2020/src/render3/component.mjs +8 -8
  39. package/esm2020/src/render3/component_ref.mjs +15 -7
  40. package/esm2020/src/render3/context_discovery.mjs +4 -4
  41. package/esm2020/src/render3/definition.mjs +16 -20
  42. package/esm2020/src/render3/di.mjs +21 -21
  43. package/esm2020/src/render3/di_setup.mjs +7 -6
  44. package/esm2020/src/render3/errors.mjs +22 -4
  45. package/esm2020/src/render3/errors_di.mjs +10 -7
  46. package/esm2020/src/render3/features/inherit_definition_feature.mjs +4 -3
  47. package/esm2020/src/render3/features/standalone_feature.mjs +70 -0
  48. package/esm2020/src/render3/hooks.mjs +19 -19
  49. package/esm2020/src/render3/i18n/i18n_apply.mjs +16 -16
  50. package/esm2020/src/render3/i18n/i18n_debug.mjs +9 -9
  51. package/esm2020/src/render3/i18n/i18n_insert_before_index.mjs +2 -2
  52. package/esm2020/src/render3/i18n/i18n_parse.mjs +14 -14
  53. package/esm2020/src/render3/i18n/i18n_util.mjs +7 -7
  54. package/esm2020/src/render3/index.mjs +5 -4
  55. package/esm2020/src/render3/instructions/advance.mjs +3 -3
  56. package/esm2020/src/render3/instructions/all.mjs +2 -1
  57. package/esm2020/src/render3/instructions/change_detection.mjs +2 -2
  58. package/esm2020/src/render3/instructions/element.mjs +26 -6
  59. package/esm2020/src/render3/instructions/element_container.mjs +3 -3
  60. package/esm2020/src/render3/instructions/i18n.mjs +2 -2
  61. package/esm2020/src/render3/instructions/listener.mjs +7 -7
  62. package/esm2020/src/render3/instructions/lview_debug.mjs +26 -26
  63. package/esm2020/src/render3/instructions/projection.mjs +3 -3
  64. package/esm2020/src/render3/instructions/shared.mjs +94 -71
  65. package/esm2020/src/render3/instructions/styling.mjs +5 -5
  66. package/esm2020/src/render3/instructions/template.mjs +3 -3
  67. package/esm2020/src/render3/instructions/text.mjs +2 -2
  68. package/esm2020/src/render3/interfaces/definition.mjs +1 -1
  69. package/esm2020/src/render3/interfaces/node.mjs +10 -10
  70. package/esm2020/src/render3/interfaces/public_definitions.mjs +1 -1
  71. package/esm2020/src/render3/interfaces/styling.mjs +18 -18
  72. package/esm2020/src/render3/interfaces/type_checks.mjs +5 -5
  73. package/esm2020/src/render3/interfaces/view.mjs +1 -1
  74. package/esm2020/src/render3/jit/directive.mjs +135 -13
  75. package/esm2020/src/render3/jit/environment.mjs +2 -1
  76. package/esm2020/src/render3/jit/module.mjs +84 -27
  77. package/esm2020/src/render3/jit/partial.mjs +8 -8
  78. package/esm2020/src/render3/jit/pipe.mjs +4 -6
  79. package/esm2020/src/render3/jit/util.mjs +15 -0
  80. package/esm2020/src/render3/ng_module_ref.mjs +34 -4
  81. package/esm2020/src/render3/node_assert.mjs +8 -8
  82. package/esm2020/src/render3/node_manipulation.mjs +40 -40
  83. package/esm2020/src/render3/node_manipulation_i18n.mjs +3 -3
  84. package/esm2020/src/render3/node_selector_matcher.mjs +28 -28
  85. package/esm2020/src/render3/pipe.mjs +2 -2
  86. package/esm2020/src/render3/query.mjs +12 -12
  87. package/esm2020/src/render3/state.mjs +5 -5
  88. package/esm2020/src/render3/styling/class_differ.mjs +3 -3
  89. package/esm2020/src/render3/styling/static_styling.mjs +3 -3
  90. package/esm2020/src/render3/styling/styling_parser.mjs +17 -17
  91. package/esm2020/src/render3/util/attrs_utils.mjs +10 -10
  92. package/esm2020/src/render3/util/discovery_utils.mjs +4 -4
  93. package/esm2020/src/render3/util/injector_utils.mjs +4 -4
  94. package/esm2020/src/render3/util/view_traversal_utils.mjs +2 -2
  95. package/esm2020/src/render3/util/view_utils.mjs +3 -3
  96. package/esm2020/src/render3/view_ref.mjs +6 -6
  97. package/esm2020/src/sanitization/bypass.mjs +7 -7
  98. package/esm2020/src/sanitization/sanitization.mjs +10 -10
  99. package/esm2020/src/util/global.mjs +8 -8
  100. package/esm2020/src/util/raf.mjs +1 -1
  101. package/esm2020/src/version.mjs +1 -1
  102. package/esm2020/testing/src/logger.mjs +3 -3
  103. package/esm2020/testing/src/ng_zone_mock.mjs +3 -3
  104. package/esm2020/testing/src/r3_test_bed.mjs +34 -6
  105. package/esm2020/testing/src/r3_test_bed_compiler.mjs +45 -4
  106. package/esm2020/testing/src/resolvers.mjs +1 -1
  107. package/esm2020/testing/src/test_bed_common.mjs +5 -1
  108. package/fesm2015/core.mjs +1591 -856
  109. package/fesm2015/core.mjs.map +1 -1
  110. package/fesm2015/testing.mjs +84 -8
  111. package/fesm2015/testing.mjs.map +1 -1
  112. package/fesm2020/core.mjs +1589 -857
  113. package/fesm2020/core.mjs.map +1 -1
  114. package/fesm2020/testing.mjs +81 -8
  115. package/fesm2020/testing.mjs.map +1 -1
  116. package/{core.d.ts → index.d.ts} +14760 -14612
  117. package/package.json +4 -4
  118. package/testing/{testing.d.ts → index.d.ts} +565 -536
  119. package/testing/package.json +0 -9
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @license Angular v14.0.0-next.13
2
+ * @license Angular v14.0.0-next.16
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
6
6
 
7
- import { getDebugNode, RendererFactory2, ɵstringify, ɵReflectionCapabilities, Directive, Component, Pipe, NgModule, ɵgetInjectableDef, resolveForwardRef, ɵNG_COMP_DEF, ɵRender3NgModuleRef, ApplicationInitStatus, LOCALE_ID, ɵDEFAULT_LOCALE_ID, ɵsetLocaleId, ɵRender3ComponentFactory, ɵcompileComponent, ɵNG_DIR_DEF, ɵcompileDirective, ɵNG_PIPE_DEF, ɵcompilePipe, ɵNG_MOD_DEF, ɵtransitiveScopesFor, ɵpatchComponentDefWithScope, ɵNG_INJ_DEF, ɵcompileNgModuleDefs, NgZone, Compiler, COMPILER_OPTIONS, ɵNgModuleFactory, ModuleWithComponentFactories, InjectionToken, Injector, InjectFlags, ɵsetAllowDuplicateNgModuleIdsForTest, ɵresetCompiledComponents, ɵflushModuleScopingQueueAsMuchAsPossible } from '@angular/core';
7
+ import { getDebugNode, RendererFactory2, ɵstringify, ɵReflectionCapabilities, Directive, Component, Pipe, NgModule, ɵgetInjectableDef, resolveForwardRef, ɵNG_COMP_DEF, ɵRender3NgModuleRef, ApplicationInitStatus, LOCALE_ID, ɵDEFAULT_LOCALE_ID, ɵsetLocaleId, ɵRender3ComponentFactory, ɵcompileComponent, ɵNG_DIR_DEF, ɵcompileDirective, ɵNG_PIPE_DEF, ɵcompilePipe, ɵNG_MOD_DEF, ɵtransitiveScopesFor, ɵpatchComponentDefWithScope, ɵNG_INJ_DEF, ɵcompileNgModuleDefs, NgZone, Compiler, COMPILER_OPTIONS, ɵNgModuleFactory, ModuleWithComponentFactories, InjectionToken, Injector, InjectFlags, ɵsetAllowDuplicateNgModuleIdsForTest, ɵresetCompiledComponents, ɵsetUnknownElementStrictMode, ɵsetUnknownPropertyStrictMode, ɵgetUnknownElementStrictMode, ɵgetUnknownPropertyStrictMode, ɵflushModuleScopingQueueAsMuchAsPossible } from '@angular/core';
8
8
  import { ResourceLoader } from '@angular/compiler';
9
9
 
10
10
  /**
@@ -837,17 +837,27 @@ class R3TestBedCompiler {
837
837
  this.queueTypesFromModulesArray([ngModule]);
838
838
  }
839
839
  overrideComponent(component, override) {
840
+ this.verifyNoStandaloneFlagOverrides(component, override);
840
841
  this.resolvers.component.addOverride(component, override);
841
842
  this.pendingComponents.add(component);
842
843
  }
843
844
  overrideDirective(directive, override) {
845
+ this.verifyNoStandaloneFlagOverrides(directive, override);
844
846
  this.resolvers.directive.addOverride(directive, override);
845
847
  this.pendingDirectives.add(directive);
846
848
  }
847
849
  overridePipe(pipe, override) {
850
+ this.verifyNoStandaloneFlagOverrides(pipe, override);
848
851
  this.resolvers.pipe.addOverride(pipe, override);
849
852
  this.pendingPipes.add(pipe);
850
853
  }
854
+ verifyNoStandaloneFlagOverrides(type, override) {
855
+ if (override.add?.hasOwnProperty('standalone') || override.set?.hasOwnProperty('standalone') ||
856
+ override.remove?.hasOwnProperty('standalone')) {
857
+ throw new Error(`An override for the ${type.name} class has the \`standalone\` flag. ` +
858
+ `Changing the \`standalone\` flag via TestBed overrides is not supported.`);
859
+ }
860
+ }
851
861
  overrideProvider(token, provider) {
852
862
  let providerDef;
853
863
  if (provider.useFactory !== undefined) {
@@ -1066,8 +1076,24 @@ class R3TestBedCompiler {
1066
1076
  return;
1067
1077
  }
1068
1078
  this.moduleProvidersOverridden.add(moduleType);
1079
+ // NOTE: the line below triggers JIT compilation of the module injector,
1080
+ // which also invokes verification of the NgModule semantics, which produces
1081
+ // detailed error messages. The fact that the code relies on this line being
1082
+ // present here is suspicious and should be refactored in a way that the line
1083
+ // below can be moved (for ex. after an early exit check below).
1069
1084
  const injectorDef = moduleType[ɵNG_INJ_DEF];
1070
- if (this.providerOverridesByToken.size > 0) {
1085
+ // No provider overrides, exit early.
1086
+ if (this.providerOverridesByToken.size === 0)
1087
+ return;
1088
+ if (isStandaloneComponent(moduleType)) {
1089
+ // Visit all component dependencies and override providers there.
1090
+ const def = getComponentDef(moduleType);
1091
+ const dependencies = maybeUnwrapFn(def.dependencies ?? []);
1092
+ for (const dependency of dependencies) {
1093
+ this.applyProviderOverridesToModule(dependency);
1094
+ }
1095
+ }
1096
+ else {
1071
1097
  const providers = [
1072
1098
  ...injectorDef.providers,
1073
1099
  ...(this.providerOverridesByModule.get(moduleType) || [])
@@ -1142,8 +1168,11 @@ class R3TestBedCompiler {
1142
1168
  // real module, which was imported. This pattern is understood to mean that the component
1143
1169
  // should use its original scope, but that the testing module should also contain the
1144
1170
  // component in its scope.
1145
- if (!this.componentToModuleScope.has(type) ||
1146
- this.componentToModuleScope.get(type) === TestingModuleOverride.DECLARATION) {
1171
+ //
1172
+ // Note: standalone components have no associated NgModule, so the `moduleType` can be `null`.
1173
+ if (moduleType !== null &&
1174
+ (!this.componentToModuleScope.has(type) ||
1175
+ this.componentToModuleScope.get(type) === TestingModuleOverride.DECLARATION)) {
1147
1176
  this.componentToModuleScope.set(type, moduleType);
1148
1177
  }
1149
1178
  return;
@@ -1187,6 +1216,11 @@ class R3TestBedCompiler {
1187
1216
  else if (isModuleWithProviders(value)) {
1188
1217
  queueTypesFromModulesArrayRecur([value.ngModule]);
1189
1218
  }
1219
+ else if (isStandaloneComponent(value)) {
1220
+ this.queueType(value, null);
1221
+ const def = getComponentDef(value);
1222
+ queueTypesFromModulesArrayRecur(maybeUnwrapFn(def.dependencies ?? []));
1223
+ }
1190
1224
  }
1191
1225
  };
1192
1226
  queueTypesFromModulesArrayRecur(arr);
@@ -1404,6 +1438,13 @@ function initResolvers() {
1404
1438
  pipe: new PipeResolver()
1405
1439
  };
1406
1440
  }
1441
+ function isStandaloneComponent(value) {
1442
+ const def = getComponentDef(value);
1443
+ return !!def?.standalone;
1444
+ }
1445
+ function getComponentDef(value) {
1446
+ return value.ɵcmp ?? null;
1447
+ }
1407
1448
  function hasNgModuleDef(value) {
1408
1449
  return value.hasOwnProperty('ɵmod');
1409
1450
  }
@@ -1478,6 +1519,10 @@ class R3TestCompiler {
1478
1519
  */
1479
1520
  /** Whether test modules should be torn down by default. */
1480
1521
  const TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT = true;
1522
+ /** Whether unknown elements in templates should throw by default. */
1523
+ const THROW_ON_UNKNOWN_ELEMENTS_DEFAULT = false;
1524
+ /** Whether unknown properties in templates should throw by default. */
1525
+ const THROW_ON_UNKNOWN_PROPERTIES_DEFAULT = false;
1481
1526
  /**
1482
1527
  * An abstract class for inserting the root test component element in a platform independent way.
1483
1528
  *
@@ -1642,6 +1687,8 @@ class TestBedRender3 {
1642
1687
  throw new Error('Cannot set base providers because it has already been called');
1643
1688
  }
1644
1689
  TestBedRender3._environmentTeardownOptions = options?.teardown;
1690
+ TestBedRender3._environmentErrorOnUnknownElementsOption = options?.errorOnUnknownElements;
1691
+ TestBedRender3._environmentErrorOnUnknownPropertiesOption = options?.errorOnUnknownProperties;
1645
1692
  this.platform = platform;
1646
1693
  this.ngModule = ngModule;
1647
1694
  this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
@@ -1671,6 +1718,10 @@ class TestBedRender3 {
1671
1718
  this.compiler.restoreOriginalState();
1672
1719
  }
1673
1720
  this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
1721
+ // Restore the previous value of the "error on unknown elements" option
1722
+ ɵsetUnknownElementStrictMode(this._previousErrorOnUnknownElementsOption ?? THROW_ON_UNKNOWN_ELEMENTS_DEFAULT);
1723
+ // Restore the previous value of the "error on unknown properties" option
1724
+ ɵsetUnknownPropertyStrictMode(this._previousErrorOnUnknownPropertiesOption ?? THROW_ON_UNKNOWN_PROPERTIES_DEFAULT);
1674
1725
  // We have to chain a couple of try/finally blocks, because each step can
1675
1726
  // throw errors and we don't want it to interrupt the next step and we also
1676
1727
  // want an error to be thrown at the end.
@@ -1686,6 +1737,8 @@ class TestBedRender3 {
1686
1737
  finally {
1687
1738
  this._testModuleRef = null;
1688
1739
  this._instanceTeardownOptions = undefined;
1740
+ this._instanceErrorOnUnknownElementsOption = undefined;
1741
+ this._instanceErrorOnUnknownPropertiesOption = undefined;
1689
1742
  }
1690
1743
  }
1691
1744
  }
@@ -1704,9 +1757,17 @@ class TestBedRender3 {
1704
1757
  // their components scoped properly. See the `checkGlobalCompilationFinished` function
1705
1758
  // description for additional info.
1706
1759
  this.checkGlobalCompilationFinished();
1707
- // Always re-assign the teardown options, even if they're undefined.
1708
- // This ensures that we don't carry the options between tests.
1760
+ // Always re-assign the options, even if they're undefined.
1761
+ // This ensures that we don't carry them between tests.
1709
1762
  this._instanceTeardownOptions = moduleDef.teardown;
1763
+ this._instanceErrorOnUnknownElementsOption = moduleDef.errorOnUnknownElements;
1764
+ this._instanceErrorOnUnknownPropertiesOption = moduleDef.errorOnUnknownProperties;
1765
+ // Store the current value of the strict mode option,
1766
+ // so we can restore it later
1767
+ this._previousErrorOnUnknownElementsOption = ɵgetUnknownElementStrictMode();
1768
+ ɵsetUnknownElementStrictMode(this.shouldThrowErrorOnUnknownElements());
1769
+ this._previousErrorOnUnknownPropertiesOption = ɵgetUnknownPropertyStrictMode();
1770
+ ɵsetUnknownPropertyStrictMode(this.shouldThrowErrorOnUnknownProperties());
1710
1771
  this.compiler.configureTestingModule(moduleDef);
1711
1772
  }
1712
1773
  compileComponents() {
@@ -1762,7 +1823,7 @@ class TestBedRender3 {
1762
1823
  testComponentRenderer.insertRootElement(rootElId);
1763
1824
  const componentDef = type.ɵcmp;
1764
1825
  if (!componentDef) {
1765
- throw new Error(`It looks like '${ɵstringify(type)}' has not been IVY compiled - it has no 'ɵcmp' field`);
1826
+ throw new Error(`It looks like '${ɵstringify(type)}' has not been compiled.`);
1766
1827
  }
1767
1828
  // TODO: Don't cast as `InjectionToken<boolean>`, proper type is boolean[]
1768
1829
  const noNgZone = this.inject(ComponentFixtureNoNgZone, false);
@@ -1855,6 +1916,18 @@ class TestBedRender3 {
1855
1916
  return instanceOptions?.rethrowErrors ?? environmentOptions?.rethrowErrors ??
1856
1917
  this.shouldTearDownTestingModule();
1857
1918
  }
1919
+ shouldThrowErrorOnUnknownElements() {
1920
+ // Check if a configuration has been provided to throw when an unknown element is found
1921
+ return this._instanceErrorOnUnknownElementsOption ??
1922
+ TestBedRender3._environmentErrorOnUnknownElementsOption ??
1923
+ THROW_ON_UNKNOWN_ELEMENTS_DEFAULT;
1924
+ }
1925
+ shouldThrowErrorOnUnknownProperties() {
1926
+ // Check if a configuration has been provided to throw when an unknown property is found
1927
+ return this._instanceErrorOnUnknownPropertiesOption ??
1928
+ TestBedRender3._environmentErrorOnUnknownPropertiesOption ??
1929
+ THROW_ON_UNKNOWN_PROPERTIES_DEFAULT;
1930
+ }
1858
1931
  shouldTearDownTestingModule() {
1859
1932
  return this._instanceTeardownOptions?.destroyAfterEach ??
1860
1933
  TestBedRender3._environmentTeardownOptions?.destroyAfterEach ??