@angular/core 14.0.0-next.8 → 14.0.0-rc.1

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 (136) hide show
  1. package/esm2020/src/application_ref.mjs +232 -66
  2. package/esm2020/src/application_tokens.mjs +5 -2
  3. package/esm2020/src/change_detection/change_detection.mjs +2 -2
  4. package/esm2020/src/change_detection/change_detector_ref.mjs +3 -3
  5. package/esm2020/src/change_detection/differs/default_iterable_differ.mjs +3 -3
  6. package/esm2020/src/change_detection/differs/default_keyvalue_differ.mjs +3 -3
  7. package/esm2020/src/change_detection/differs/iterable_differs.mjs +2 -2
  8. package/esm2020/src/change_detection/differs/keyvalue_differs.mjs +2 -2
  9. package/esm2020/src/compiler/compiler_facade.mjs +2 -2
  10. package/esm2020/src/compiler/compiler_facade_interface.mjs +7 -1
  11. package/esm2020/src/console.mjs +4 -3
  12. package/esm2020/src/core.mjs +2 -2
  13. package/esm2020/src/core_private_export.mjs +5 -3
  14. package/esm2020/src/core_render3_private_export.mjs +4 -3
  15. package/esm2020/src/debug/debug_node.mjs +5 -5
  16. package/esm2020/src/di/create_injector.mjs +35 -0
  17. package/esm2020/src/di/index.mjs +4 -1
  18. package/esm2020/src/di/initializer_token.mjs +16 -0
  19. package/esm2020/src/di/injection_token.mjs +7 -1
  20. package/esm2020/src/di/injector.mjs +3 -3
  21. package/esm2020/src/di/injector_compatibility.mjs +4 -6
  22. package/esm2020/src/di/injector_token.mjs +2 -2
  23. package/esm2020/src/di/interface/defs.mjs +1 -1
  24. package/esm2020/src/di/interface/provider.mjs +1 -1
  25. package/esm2020/src/di/internal_tokens.mjs +10 -0
  26. package/esm2020/src/di/jit/injectable.mjs +3 -3
  27. package/esm2020/src/di/metadata.mjs +6 -6
  28. package/esm2020/src/di/provider_collection.mjs +224 -0
  29. package/esm2020/src/di/r3_injector.mjs +87 -157
  30. package/esm2020/src/di/scope.mjs +1 -1
  31. package/esm2020/src/errors.mjs +1 -1
  32. package/esm2020/src/linker/component_factory.mjs +1 -1
  33. package/esm2020/src/linker/ng_module_factory.mjs +1 -1
  34. package/esm2020/src/linker/template_ref.mjs +3 -3
  35. package/esm2020/src/linker/view_container_ref.mjs +15 -12
  36. package/esm2020/src/metadata/directives.mjs +1 -1
  37. package/esm2020/src/metadata/ng_module.mjs +1 -1
  38. package/esm2020/src/metadata.mjs +1 -1
  39. package/esm2020/src/platform_core_providers.mjs +3 -14
  40. package/esm2020/src/render3/assert.mjs +3 -3
  41. package/esm2020/src/render3/bindings.mjs +2 -2
  42. package/esm2020/src/render3/collect_native_nodes.mjs +5 -5
  43. package/esm2020/src/render3/component.mjs +8 -8
  44. package/esm2020/src/render3/component_ref.mjs +15 -7
  45. package/esm2020/src/render3/context_discovery.mjs +4 -4
  46. package/esm2020/src/render3/definition.mjs +19 -20
  47. package/esm2020/src/render3/di.mjs +21 -21
  48. package/esm2020/src/render3/di_setup.mjs +7 -6
  49. package/esm2020/src/render3/errors.mjs +22 -4
  50. package/esm2020/src/render3/errors_di.mjs +10 -7
  51. package/esm2020/src/render3/features/inherit_definition_feature.mjs +4 -3
  52. package/esm2020/src/render3/features/standalone_feature.mjs +70 -0
  53. package/esm2020/src/render3/hooks.mjs +19 -19
  54. package/esm2020/src/render3/i18n/i18n_apply.mjs +16 -16
  55. package/esm2020/src/render3/i18n/i18n_debug.mjs +9 -9
  56. package/esm2020/src/render3/i18n/i18n_insert_before_index.mjs +2 -2
  57. package/esm2020/src/render3/i18n/i18n_parse.mjs +14 -14
  58. package/esm2020/src/render3/i18n/i18n_util.mjs +7 -7
  59. package/esm2020/src/render3/index.mjs +5 -4
  60. package/esm2020/src/render3/instructions/advance.mjs +4 -4
  61. package/esm2020/src/render3/instructions/all.mjs +2 -1
  62. package/esm2020/src/render3/instructions/change_detection.mjs +2 -2
  63. package/esm2020/src/render3/instructions/element.mjs +47 -12
  64. package/esm2020/src/render3/instructions/element_container.mjs +3 -3
  65. package/esm2020/src/render3/instructions/i18n.mjs +2 -2
  66. package/esm2020/src/render3/instructions/listener.mjs +8 -11
  67. package/esm2020/src/render3/instructions/lview_debug.mjs +26 -26
  68. package/esm2020/src/render3/instructions/projection.mjs +3 -3
  69. package/esm2020/src/render3/instructions/shared.mjs +138 -88
  70. package/esm2020/src/render3/instructions/styling.mjs +5 -5
  71. package/esm2020/src/render3/instructions/template.mjs +3 -3
  72. package/esm2020/src/render3/instructions/text.mjs +2 -2
  73. package/esm2020/src/render3/interfaces/definition.mjs +1 -1
  74. package/esm2020/src/render3/interfaces/node.mjs +10 -10
  75. package/esm2020/src/render3/interfaces/public_definitions.mjs +1 -1
  76. package/esm2020/src/render3/interfaces/styling.mjs +18 -18
  77. package/esm2020/src/render3/interfaces/type_checks.mjs +5 -5
  78. package/esm2020/src/render3/interfaces/view.mjs +1 -1
  79. package/esm2020/src/render3/jit/directive.mjs +135 -13
  80. package/esm2020/src/render3/jit/environment.mjs +2 -1
  81. package/esm2020/src/render3/jit/module.mjs +84 -27
  82. package/esm2020/src/render3/jit/partial.mjs +8 -8
  83. package/esm2020/src/render3/jit/pipe.mjs +4 -6
  84. package/esm2020/src/render3/jit/util.mjs +15 -0
  85. package/esm2020/src/render3/ng_module_ref.mjs +34 -4
  86. package/esm2020/src/render3/node_assert.mjs +8 -8
  87. package/esm2020/src/render3/node_manipulation.mjs +40 -40
  88. package/esm2020/src/render3/node_manipulation_i18n.mjs +3 -3
  89. package/esm2020/src/render3/node_selector_matcher.mjs +28 -28
  90. package/esm2020/src/render3/pipe.mjs +2 -2
  91. package/esm2020/src/render3/query.mjs +12 -12
  92. package/esm2020/src/render3/state.mjs +21 -10
  93. package/esm2020/src/render3/styling/class_differ.mjs +3 -3
  94. package/esm2020/src/render3/styling/static_styling.mjs +3 -3
  95. package/esm2020/src/render3/styling/styling_parser.mjs +17 -17
  96. package/esm2020/src/render3/util/attrs_utils.mjs +10 -10
  97. package/esm2020/src/render3/util/discovery_utils.mjs +4 -4
  98. package/esm2020/src/render3/util/injector_utils.mjs +4 -4
  99. package/esm2020/src/render3/util/view_traversal_utils.mjs +2 -2
  100. package/esm2020/src/render3/util/view_utils.mjs +3 -3
  101. package/esm2020/src/render3/view_ref.mjs +12 -8
  102. package/esm2020/src/sanitization/bypass.mjs +7 -7
  103. package/esm2020/src/sanitization/sanitization.mjs +10 -10
  104. package/esm2020/src/testability/testability.mjs +69 -19
  105. package/esm2020/src/util/global.mjs +8 -8
  106. package/esm2020/src/util/raf.mjs +1 -1
  107. package/esm2020/src/version.mjs +1 -1
  108. package/esm2020/testing/src/logger.mjs +3 -3
  109. package/esm2020/testing/src/ng_zone_mock.mjs +3 -3
  110. package/esm2020/testing/src/r3_test_bed.mjs +38 -13
  111. package/esm2020/testing/src/r3_test_bed_compiler.mjs +45 -4
  112. package/esm2020/testing/src/resolvers.mjs +1 -1
  113. package/esm2020/testing/src/test_bed.mjs +1 -1
  114. package/esm2020/testing/src/test_bed_common.mjs +5 -1
  115. package/fesm2015/core.mjs +6637 -5790
  116. package/fesm2015/core.mjs.map +1 -1
  117. package/fesm2015/testing.mjs +88 -15
  118. package/fesm2015/testing.mjs.map +1 -1
  119. package/fesm2020/core.mjs +6590 -5749
  120. package/fesm2020/core.mjs.map +1 -1
  121. package/fesm2020/testing.mjs +85 -15
  122. package/fesm2020/testing.mjs.map +1 -1
  123. package/{core.d.ts → index.d.ts} +14774 -14596
  124. package/package.json +4 -4
  125. package/schematics/migrations/path-match-type/index.d.ts +11 -0
  126. package/schematics/migrations/path-match-type/index.js +95 -0
  127. package/schematics/migrations/path-match-type/transform.d.ts +19 -0
  128. package/schematics/migrations/path-match-type/transform.js +48 -0
  129. package/schematics/migrations/path-match-type/update_recorder.d.ts +18 -0
  130. package/schematics/migrations/path-match-type/update_recorder.js +20 -0
  131. package/schematics/migrations/path-match-type/util.d.ts +11 -0
  132. package/schematics/migrations/path-match-type/util.js +106 -0
  133. package/schematics/migrations.json +8 -3
  134. package/testing/{testing.d.ts → index.d.ts} +565 -577
  135. package/esm2020/src/change_detection/change_detection_util.mjs +0 -64
  136. package/testing/package.json +0 -9
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @license Angular v14.0.0-next.8
2
+ * @license Angular v14.0.0-rc.1
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
  *
@@ -1537,9 +1582,9 @@ class TestBedRender3 {
1537
1582
  *
1538
1583
  * @publicApi
1539
1584
  */
1540
- static initTestEnvironment(ngModule, platform, summariesOrOptions) {
1585
+ static initTestEnvironment(ngModule, platform, options) {
1541
1586
  const testBed = _getTestBedRender3();
1542
- testBed.initTestEnvironment(ngModule, platform, summariesOrOptions);
1587
+ testBed.initTestEnvironment(ngModule, platform, options);
1543
1588
  return testBed;
1544
1589
  }
1545
1590
  /**
@@ -1637,14 +1682,13 @@ class TestBedRender3 {
1637
1682
  *
1638
1683
  * @publicApi
1639
1684
  */
1640
- initTestEnvironment(ngModule, platform, summariesOrOptions) {
1685
+ initTestEnvironment(ngModule, platform, options) {
1641
1686
  if (this.platform || this.ngModule) {
1642
1687
  throw new Error('Cannot set base providers because it has already been called');
1643
1688
  }
1644
- // If `summariesOrOptions` is a function, it means that it's
1645
- // an AOT summaries factory which Ivy doesn't support.
1646
- TestBedRender3._environmentTeardownOptions =
1647
- typeof summariesOrOptions === 'function' ? undefined : summariesOrOptions?.teardown;
1689
+ TestBedRender3._environmentTeardownOptions = options?.teardown;
1690
+ TestBedRender3._environmentErrorOnUnknownElementsOption = options?.errorOnUnknownElements;
1691
+ TestBedRender3._environmentErrorOnUnknownPropertiesOption = options?.errorOnUnknownProperties;
1648
1692
  this.platform = platform;
1649
1693
  this.ngModule = ngModule;
1650
1694
  this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
@@ -1674,6 +1718,10 @@ class TestBedRender3 {
1674
1718
  this.compiler.restoreOriginalState();
1675
1719
  }
1676
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);
1677
1725
  // We have to chain a couple of try/finally blocks, because each step can
1678
1726
  // throw errors and we don't want it to interrupt the next step and we also
1679
1727
  // want an error to be thrown at the end.
@@ -1689,6 +1737,8 @@ class TestBedRender3 {
1689
1737
  finally {
1690
1738
  this._testModuleRef = null;
1691
1739
  this._instanceTeardownOptions = undefined;
1740
+ this._instanceErrorOnUnknownElementsOption = undefined;
1741
+ this._instanceErrorOnUnknownPropertiesOption = undefined;
1692
1742
  }
1693
1743
  }
1694
1744
  }
@@ -1707,9 +1757,17 @@ class TestBedRender3 {
1707
1757
  // their components scoped properly. See the `checkGlobalCompilationFinished` function
1708
1758
  // description for additional info.
1709
1759
  this.checkGlobalCompilationFinished();
1710
- // Always re-assign the teardown options, even if they're undefined.
1711
- // 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.
1712
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());
1713
1771
  this.compiler.configureTestingModule(moduleDef);
1714
1772
  }
1715
1773
  compileComponents() {
@@ -1765,7 +1823,7 @@ class TestBedRender3 {
1765
1823
  testComponentRenderer.insertRootElement(rootElId);
1766
1824
  const componentDef = type.ɵcmp;
1767
1825
  if (!componentDef) {
1768
- 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.`);
1769
1827
  }
1770
1828
  // TODO: Don't cast as `InjectionToken<boolean>`, proper type is boolean[]
1771
1829
  const noNgZone = this.inject(ComponentFixtureNoNgZone, false);
@@ -1858,6 +1916,18 @@ class TestBedRender3 {
1858
1916
  return instanceOptions?.rethrowErrors ?? environmentOptions?.rethrowErrors ??
1859
1917
  this.shouldTearDownTestingModule();
1860
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
+ }
1861
1931
  shouldTearDownTestingModule() {
1862
1932
  return this._instanceTeardownOptions?.destroyAfterEach ??
1863
1933
  TestBedRender3._environmentTeardownOptions?.destroyAfterEach ??