@angular/core 15.0.0-next.3 → 15.0.0-next.4

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 (33) hide show
  1. package/esm2020/src/core_private_export.mjs +2 -2
  2. package/esm2020/src/di/index.mjs +1 -1
  3. package/esm2020/src/di/injector.mjs +1 -1
  4. package/esm2020/src/di/injector_compatibility.mjs +15 -11
  5. package/esm2020/src/di/interface/injector.mjs +1 -1
  6. package/esm2020/src/di/r3_injector.mjs +3 -2
  7. package/esm2020/src/render3/component_ref.mjs +102 -83
  8. package/esm2020/src/render3/context_discovery.mjs +7 -7
  9. package/esm2020/src/render3/di.mjs +3 -2
  10. package/esm2020/src/render3/features/host_directives_feature.mjs +2 -3
  11. package/esm2020/src/render3/instructions/element.mjs +3 -15
  12. package/esm2020/src/render3/instructions/shared.mjs +93 -106
  13. package/esm2020/src/render3/ng_module_ref.mjs +1 -1
  14. package/esm2020/src/render3/node_manipulation.mjs +15 -1
  15. package/esm2020/src/render3/util/discovery_utils.mjs +2 -2
  16. package/esm2020/src/util/is_dev_mode.mjs +11 -19
  17. package/esm2020/src/version.mjs +1 -1
  18. package/esm2020/src/zone/async-stack-tagging.mjs +28 -0
  19. package/esm2020/src/zone/ng_zone.mjs +8 -3
  20. package/esm2020/testing/src/logger.mjs +3 -3
  21. package/esm2020/testing/src/ng_zone_mock.mjs +3 -3
  22. package/esm2020/testing/src/test_bed.mjs +4 -4
  23. package/fesm2015/core.mjs +1506 -1470
  24. package/fesm2015/core.mjs.map +1 -1
  25. package/fesm2015/testing.mjs +888 -877
  26. package/fesm2015/testing.mjs.map +1 -1
  27. package/fesm2020/core.mjs +1509 -1475
  28. package/fesm2020/core.mjs.map +1 -1
  29. package/fesm2020/testing.mjs +886 -876
  30. package/fesm2020/testing.mjs.map +1 -1
  31. package/index.d.ts +60 -5
  32. package/package.json +1 -1
  33. package/testing/index.d.ts +9 -1
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @license Angular v15.0.0-next.3
2
+ * @license Angular v15.0.0-next.4
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
6
6
 
7
- import { getDebugNode as getDebugNode$1, RendererFactory2 as RendererFactory2$1, InjectionToken as InjectionToken$1, ɵstringify, ɵReflectionCapabilities, Directive, Component, Pipe, NgModule, ɵgetInjectableDef, resolveForwardRef as resolveForwardRef$1, ɵNG_COMP_DEF, ɵRender3NgModuleRef, ApplicationInitStatus, LOCALE_ID as LOCALE_ID$1, ɵ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, Injector as Injector$1, InjectFlags as InjectFlags$1, ɵsetAllowDuplicateNgModuleIdsForTest, ɵresetCompiledComponents, ɵsetUnknownElementStrictMode as ɵsetUnknownElementStrictMode$1, ɵsetUnknownPropertyStrictMode as ɵsetUnknownPropertyStrictMode$1, ɵgetUnknownElementStrictMode as ɵgetUnknownElementStrictMode$1, ɵgetUnknownPropertyStrictMode as ɵgetUnknownPropertyStrictMode$1, ɵflushModuleScopingQueueAsMuchAsPossible } from '@angular/core';
7
+ import { getDebugNode as getDebugNode$1, RendererFactory2 as RendererFactory2$1, InjectionToken as InjectionToken$1, ɵstringify, ɵReflectionCapabilities, Directive, Component, Pipe, NgModule, ɵgetInjectableDef, resolveForwardRef as resolveForwardRef$1, ɵNG_COMP_DEF, ɵRender3NgModuleRef, ApplicationInitStatus, LOCALE_ID as LOCALE_ID$1, ɵ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, ɵconvertToBitFlags, Injector as Injector$1, InjectFlags as InjectFlags$1, ɵsetAllowDuplicateNgModuleIdsForTest, ɵresetCompiledComponents, ɵsetUnknownElementStrictMode as ɵsetUnknownElementStrictMode$1, ɵsetUnknownPropertyStrictMode as ɵsetUnknownPropertyStrictMode$1, ɵgetUnknownElementStrictMode as ɵgetUnknownElementStrictMode$1, ɵgetUnknownPropertyStrictMode as ɵgetUnknownPropertyStrictMode$1, ɵflushModuleScopingQueueAsMuchAsPossible } from '@angular/core';
8
8
  import { ResourceLoader } from '@angular/compiler';
9
9
  import { Subject, Subscription } from 'rxjs';
10
10
 
@@ -2174,17 +2174,21 @@ Please check that 1) the type for the parameter at index ${index} is correct and
2174
2174
  * @publicApi
2175
2175
  */
2176
2176
  function inject$1(token, flags = InjectFlags.Default) {
2177
- if (typeof flags !== 'number') {
2178
- // While TypeScript doesn't accept it without a cast, bitwise OR with false-y values in
2179
- // JavaScript is a no-op. We can use that for a very codesize-efficient conversion from
2180
- // `InjectOptions` to `InjectFlags`.
2181
- flags = (0 /* InternalInjectFlags.Default */ | // comment to force a line break in the formatter
2182
- (flags.optional && 8 /* InternalInjectFlags.Optional */) |
2183
- (flags.host && 1 /* InternalInjectFlags.Host */) |
2184
- (flags.self && 2 /* InternalInjectFlags.Self */) |
2185
- (flags.skipSelf && 4 /* InternalInjectFlags.SkipSelf */));
2186
- }
2187
- return ɵɵinject(token, flags);
2177
+ return ɵɵinject(token, convertToBitFlags(flags));
2178
+ }
2179
+ // Converts object-based DI flags (`InjectOptions`) to bit flags (`InjectFlags`).
2180
+ function convertToBitFlags(flags) {
2181
+ if (typeof flags === 'undefined' || typeof flags === 'number') {
2182
+ return flags;
2183
+ }
2184
+ // While TypeScript doesn't accept it without a cast, bitwise OR with false-y values in
2185
+ // JavaScript is a no-op. We can use that for a very codesize-efficient conversion from
2186
+ // `InjectOptions` to `InjectFlags`.
2187
+ return (0 /* InternalInjectFlags.Default */ | // comment to force a line break in the formatter
2188
+ (flags.optional && 8 /* InternalInjectFlags.Optional */) |
2189
+ (flags.host && 1 /* InternalInjectFlags.Host */) |
2190
+ (flags.self && 2 /* InternalInjectFlags.Self */) |
2191
+ (flags.skipSelf && 4 /* InternalInjectFlags.SkipSelf */));
2188
2192
  }
2189
2193
  function injectArgs(types) {
2190
2194
  const args = [];
@@ -5239,7 +5243,7 @@ class NodeInjector {
5239
5243
  this._lView = _lView;
5240
5244
  }
5241
5245
  get(token, notFoundValue, flags) {
5242
- return getOrCreateInjectable(this._tNode, this._lView, token, flags, notFoundValue);
5246
+ return getOrCreateInjectable(this._tNode, this._lView, token, convertToBitFlags(flags), notFoundValue);
5243
5247
  }
5244
5248
  }
5245
5249
  /** Creates a `NodeInjector` for the current node. */
@@ -7136,6 +7140,7 @@ class R3Injector extends EnvironmentInjector {
7136
7140
  }
7137
7141
  get(token, notFoundValue = THROW_IF_NOT_FOUND, flags = InjectFlags.Default) {
7138
7142
  this.assertNotDestroyed();
7143
+ flags = convertToBitFlags(flags);
7139
7144
  // Set the injection context.
7140
7145
  const previousInjector = setCurrentInjector(this);
7141
7146
  const previousInjectImplementation = setInjectImplementation(undefined);
@@ -7637,7 +7642,7 @@ class Version {
7637
7642
  /**
7638
7643
  * @publicApi
7639
7644
  */
7640
- const VERSION = new Version('15.0.0-next.3');
7645
+ const VERSION = new Version('15.0.0-next.4');
7641
7646
 
7642
7647
  /**
7643
7648
  * @license
@@ -7672,29 +7677,70 @@ const NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR = {};
7672
7677
  * Use of this source code is governed by an MIT-style license that can be
7673
7678
  * found in the LICENSE file at https://angular.io/license
7674
7679
  */
7680
+ // Keeps track of the currently-active LViews.
7681
+ const TRACKED_LVIEWS = new Map();
7682
+ // Used for generating unique IDs for LViews.
7683
+ let uniqueIdCounter = 0;
7684
+ /** Gets a unique ID that can be assigned to an LView. */
7685
+ function getUniqueLViewId() {
7686
+ return uniqueIdCounter++;
7687
+ }
7688
+ /** Starts tracking an LView. */
7689
+ function registerLView(lView) {
7690
+ ngDevMode && assertNumber(lView[ID], 'LView must have an ID in order to be registered');
7691
+ TRACKED_LVIEWS.set(lView[ID], lView);
7692
+ }
7693
+ /** Gets an LView by its unique ID. */
7694
+ function getLViewById(id) {
7695
+ ngDevMode && assertNumber(id, 'ID used for LView lookup must be a number');
7696
+ return TRACKED_LVIEWS.get(id) || null;
7697
+ }
7698
+ /** Stops tracking an LView. */
7699
+ function unregisterLView(lView) {
7700
+ ngDevMode && assertNumber(lView[ID], 'Cannot stop tracking an LView that does not have an ID');
7701
+ TRACKED_LVIEWS.delete(lView[ID]);
7702
+ }
7703
+
7675
7704
  /**
7676
- * Defines a schema that allows an NgModule to contain the following:
7677
- * - Non-Angular elements named with dash case (`-`).
7678
- * - Element properties named with dash case (`-`).
7679
- * Dash case is the naming convention for custom elements.
7705
+ * @license
7706
+ * Copyright Google LLC All Rights Reserved.
7680
7707
  *
7681
- * @publicApi
7708
+ * Use of this source code is governed by an MIT-style license that can be
7709
+ * found in the LICENSE file at https://angular.io/license
7682
7710
  */
7683
- const CUSTOM_ELEMENTS_SCHEMA = {
7684
- name: 'custom-elements'
7685
- };
7686
7711
  /**
7687
- * Defines a schema that allows any property on any element.
7688
- *
7689
- * This schema allows you to ignore the errors related to any unknown elements or properties in a
7690
- * template. The usage of this schema is generally discouraged because it prevents useful validation
7691
- * and may hide real errors in your template. Consider using the `CUSTOM_ELEMENTS_SCHEMA` instead.
7712
+ * The internal view context which is specific to a given DOM element, directive or
7713
+ * component instance. Each value in here (besides the LView and element node details)
7714
+ * can be present, null or undefined. If undefined then it implies the value has not been
7715
+ * looked up yet, otherwise, if null, then a lookup was executed and nothing was found.
7692
7716
  *
7693
- * @publicApi
7717
+ * Each value will get filled when the respective value is examined within the getContext
7718
+ * function. The component, element and each directive instance will share the same instance
7719
+ * of the context.
7694
7720
  */
7695
- const NO_ERRORS_SCHEMA = {
7696
- name: 'no-errors-schema'
7697
- };
7721
+ class LContext {
7722
+ constructor(
7723
+ /**
7724
+ * ID of the component's parent view data.
7725
+ */
7726
+ lViewId,
7727
+ /**
7728
+ * The index instance of the node.
7729
+ */
7730
+ nodeIndex,
7731
+ /**
7732
+ * The instance of the DOM node that is attached to the lNode.
7733
+ */
7734
+ native) {
7735
+ this.lViewId = lViewId;
7736
+ this.nodeIndex = nodeIndex;
7737
+ this.native = native;
7738
+ }
7739
+ /** Component's parent view data. */
7740
+ get lView() {
7741
+ return getLViewById(this.lViewId);
7742
+ }
7743
+ }
7698
7744
 
7699
7745
  /**
7700
7746
  * @license
@@ -7703,336 +7749,305 @@ const NO_ERRORS_SCHEMA = {
7703
7749
  * Use of this source code is governed by an MIT-style license that can be
7704
7750
  * found in the LICENSE file at https://angular.io/license
7705
7751
  */
7706
- let shouldThrowErrorOnUnknownElement = false;
7707
- /**
7708
- * Sets a strict mode for JIT-compiled components to throw an error on unknown elements,
7709
- * instead of just logging the error.
7710
- * (for AOT-compiled ones this check happens at build time).
7711
- */
7712
- function ɵsetUnknownElementStrictMode(shouldThrow) {
7713
- shouldThrowErrorOnUnknownElement = shouldThrow;
7714
- }
7715
- /**
7716
- * Gets the current value of the strict mode.
7717
- */
7718
- function ɵgetUnknownElementStrictMode() {
7719
- return shouldThrowErrorOnUnknownElement;
7720
- }
7721
- let shouldThrowErrorOnUnknownProperty = false;
7722
- /**
7723
- * Sets a strict mode for JIT-compiled components to throw an error on unknown properties,
7724
- * instead of just logging the error.
7725
- * (for AOT-compiled ones this check happens at build time).
7726
- */
7727
- function ɵsetUnknownPropertyStrictMode(shouldThrow) {
7728
- shouldThrowErrorOnUnknownProperty = shouldThrow;
7729
- }
7730
- /**
7731
- * Gets the current value of the strict mode.
7732
- */
7733
- function ɵgetUnknownPropertyStrictMode() {
7734
- return shouldThrowErrorOnUnknownProperty;
7735
- }
7736
7752
  /**
7737
- * Validates that the element is known at runtime and produces
7738
- * an error if it's not the case.
7739
- * This check is relevant for JIT-compiled components (for AOT-compiled
7740
- * ones this check happens at build time).
7753
+ * Returns the matching `LContext` data for a given DOM node, directive or component instance.
7741
7754
  *
7742
- * The element is considered known if either:
7743
- * - it's a known HTML element
7744
- * - it's a known custom element
7745
- * - the element matches any directive
7746
- * - the element is allowed by one of the schemas
7755
+ * This function will examine the provided DOM element, component, or directive instance\'s
7756
+ * monkey-patched property to derive the `LContext` data. Once called then the monkey-patched
7757
+ * value will be that of the newly created `LContext`.
7747
7758
  *
7748
- * @param element Element to validate
7749
- * @param lView An `LView` that represents a current component that is being rendered
7750
- * @param tagName Name of the tag to check
7751
- * @param schemas Array of schemas
7752
- * @param hasDirectives Boolean indicating that the element matches any directive
7759
+ * If the monkey-patched value is the `LView` instance then the context value for that
7760
+ * target will be created and the monkey-patch reference will be updated. Therefore when this
7761
+ * function is called it may mutate the provided element\'s, component\'s or any of the associated
7762
+ * directive\'s monkey-patch values.
7763
+ *
7764
+ * If the monkey-patch value is not detected then the code will walk up the DOM until an element
7765
+ * is found which contains a monkey-patch reference. When that occurs then the provided element
7766
+ * will be updated with a new context (which is then returned). If the monkey-patch value is not
7767
+ * detected for a component/directive instance then it will throw an error (all components and
7768
+ * directives should be automatically monkey-patched by ivy).
7769
+ *
7770
+ * @param target Component, Directive or DOM Node.
7753
7771
  */
7754
- function validateElementIsKnown(element, lView, tagName, schemas, hasDirectives) {
7755
- // If `schemas` is set to `null`, that's an indication that this Component was compiled in AOT
7756
- // mode where this check happens at compile time. In JIT mode, `schemas` is always present and
7757
- // defined as an array (as an empty array in case `schemas` field is not defined) and we should
7758
- // execute the check below.
7759
- if (schemas === null)
7760
- return;
7761
- // If the element matches any directive, it's considered as valid.
7762
- if (!hasDirectives && tagName !== null) {
7763
- // The element is unknown if it's an instance of HTMLUnknownElement, or it isn't registered
7764
- // as a custom element. Note that unknown elements with a dash in their name won't be instances
7765
- // of HTMLUnknownElement in browsers that support web components.
7766
- const isUnknown =
7767
- // Note that we can't check for `typeof HTMLUnknownElement === 'function'`,
7768
- // because while most browsers return 'function', IE returns 'object'.
7769
- (typeof HTMLUnknownElement !== 'undefined' && HTMLUnknownElement &&
7770
- element instanceof HTMLUnknownElement) ||
7771
- (typeof customElements !== 'undefined' && tagName.indexOf('-') > -1 &&
7772
- !customElements.get(tagName));
7773
- if (isUnknown && !matchingSchemas(schemas, tagName)) {
7774
- const isHostStandalone = isHostComponentStandalone(lView);
7775
- const templateLocation = getTemplateLocationDetails(lView);
7776
- const schemas = `'${isHostStandalone ? '@Component' : '@NgModule'}.schemas'`;
7777
- let message = `'${tagName}' is not a known element${templateLocation}:\n`;
7778
- message += `1. If '${tagName}' is an Angular component, then verify that it is ${isHostStandalone ? 'included in the \'@Component.imports\' of this component' :
7779
- 'a part of an @NgModule where this component is declared'}.\n`;
7780
- if (tagName && tagName.indexOf('-') > -1) {
7781
- message +=
7782
- `2. If '${tagName}' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the ${schemas} of this component to suppress this message.`;
7772
+ function getLContext(target) {
7773
+ let mpValue = readPatchedData(target);
7774
+ if (mpValue) {
7775
+ // only when it's an array is it considered an LView instance
7776
+ // ... otherwise it's an already constructed LContext instance
7777
+ if (isLView(mpValue)) {
7778
+ const lView = mpValue;
7779
+ let nodeIndex;
7780
+ let component = undefined;
7781
+ let directives = undefined;
7782
+ if (isComponentInstance(target)) {
7783
+ nodeIndex = findViaComponent(lView, target);
7784
+ if (nodeIndex == -1) {
7785
+ throw new Error('The provided component was not found in the application');
7786
+ }
7787
+ component = target;
7788
+ }
7789
+ else if (isDirectiveInstance(target)) {
7790
+ nodeIndex = findViaDirective(lView, target);
7791
+ if (nodeIndex == -1) {
7792
+ throw new Error('The provided directive was not found in the application');
7793
+ }
7794
+ directives = getDirectivesAtNodeIndex(nodeIndex, lView);
7783
7795
  }
7784
7796
  else {
7785
- message +=
7786
- `2. To allow any element add 'NO_ERRORS_SCHEMA' to the ${schemas} of this component.`;
7797
+ nodeIndex = findViaNativeElement(lView, target);
7798
+ if (nodeIndex == -1) {
7799
+ return null;
7800
+ }
7787
7801
  }
7788
- if (shouldThrowErrorOnUnknownElement) {
7789
- throw new RuntimeError(304 /* RuntimeErrorCode.UNKNOWN_ELEMENT */, message);
7802
+ // the goal is not to fill the entire context full of data because the lookups
7803
+ // are expensive. Instead, only the target data (the element, component, container, ICU
7804
+ // expression or directive details) are filled into the context. If called multiple times
7805
+ // with different target values then the missing target data will be filled in.
7806
+ const native = unwrapRNode(lView[nodeIndex]);
7807
+ const existingCtx = readPatchedData(native);
7808
+ const context = (existingCtx && !Array.isArray(existingCtx)) ?
7809
+ existingCtx :
7810
+ createLContext(lView, nodeIndex, native);
7811
+ // only when the component has been discovered then update the monkey-patch
7812
+ if (component && context.component === undefined) {
7813
+ context.component = component;
7814
+ attachPatchData(context.component, context);
7790
7815
  }
7791
- else {
7792
- console.error(formatRuntimeError(304 /* RuntimeErrorCode.UNKNOWN_ELEMENT */, message));
7816
+ // only when the directives have been discovered then update the monkey-patch
7817
+ if (directives && context.directives === undefined) {
7818
+ context.directives = directives;
7819
+ for (let i = 0; i < directives.length; i++) {
7820
+ attachPatchData(directives[i], context);
7821
+ }
7822
+ }
7823
+ attachPatchData(context.native, context);
7824
+ mpValue = context;
7825
+ }
7826
+ }
7827
+ else {
7828
+ const rElement = target;
7829
+ ngDevMode && assertDomNode(rElement);
7830
+ // if the context is not found then we need to traverse upwards up the DOM
7831
+ // to find the nearest element that has already been monkey patched with data
7832
+ let parent = rElement;
7833
+ while (parent = parent.parentNode) {
7834
+ const parentContext = readPatchedData(parent);
7835
+ if (parentContext) {
7836
+ const lView = Array.isArray(parentContext) ? parentContext : parentContext.lView;
7837
+ // the edge of the app was also reached here through another means
7838
+ // (maybe because the DOM was changed manually).
7839
+ if (!lView) {
7840
+ return null;
7841
+ }
7842
+ const index = findViaNativeElement(lView, rElement);
7843
+ if (index >= 0) {
7844
+ const native = unwrapRNode(lView[index]);
7845
+ const context = createLContext(lView, index, native);
7846
+ attachPatchData(native, context);
7847
+ mpValue = context;
7848
+ break;
7849
+ }
7793
7850
  }
7794
7851
  }
7795
7852
  }
7853
+ return mpValue || null;
7796
7854
  }
7797
7855
  /**
7798
- * Validates that the property of the element is known at runtime and returns
7799
- * false if it's not the case.
7800
- * This check is relevant for JIT-compiled components (for AOT-compiled
7801
- * ones this check happens at build time).
7856
+ * Creates an empty instance of a `LContext` context
7857
+ */
7858
+ function createLContext(lView, nodeIndex, native) {
7859
+ return new LContext(lView[ID], nodeIndex, native);
7860
+ }
7861
+ /**
7862
+ * Takes a component instance and returns the view for that component.
7802
7863
  *
7803
- * The property is considered known if either:
7804
- * - it's a known property of the element
7805
- * - the element is allowed by one of the schemas
7806
- * - the property is used for animations
7807
- *
7808
- * @param element Element to validate
7809
- * @param propName Name of the property to check
7810
- * @param tagName Name of the tag hosting the property
7811
- * @param schemas Array of schemas
7812
- */
7813
- function isPropertyValid(element, propName, tagName, schemas) {
7814
- // If `schemas` is set to `null`, that's an indication that this Component was compiled in AOT
7815
- // mode where this check happens at compile time. In JIT mode, `schemas` is always present and
7816
- // defined as an array (as an empty array in case `schemas` field is not defined) and we should
7817
- // execute the check below.
7818
- if (schemas === null)
7819
- return true;
7820
- // The property is considered valid if the element matches the schema, it exists on the element,
7821
- // or it is synthetic, and we are in a browser context (web worker nodes should be skipped).
7822
- if (matchingSchemas(schemas, tagName) || propName in element || isAnimationProp(propName)) {
7823
- return true;
7824
- }
7825
- // Note: `typeof Node` returns 'function' in most browsers, but on IE it is 'object' so we
7826
- // need to account for both here, while being careful with `typeof null` also returning 'object'.
7827
- return typeof Node === 'undefined' || Node === null || !(element instanceof Node);
7828
- }
7829
- /**
7830
- * Logs or throws an error that a property is not supported on an element.
7831
- *
7832
- * @param propName Name of the invalid property
7833
- * @param tagName Name of the tag hosting the property
7834
- * @param nodeType Type of the node hosting the property
7835
- * @param lView An `LView` that represents a current component
7864
+ * @param componentInstance
7865
+ * @returns The component's view
7836
7866
  */
7837
- function handleUnknownPropertyError(propName, tagName, nodeType, lView) {
7838
- // Special-case a situation when a structural directive is applied to
7839
- // an `<ng-template>` element, for example: `<ng-template *ngIf="true">`.
7840
- // In this case the compiler generates the `ɵɵtemplate` instruction with
7841
- // the `null` as the tagName. The directive matching logic at runtime relies
7842
- // on this effect (see `isInlineTemplate`), thus using the 'ng-template' as
7843
- // a default value of the `tNode.value` is not feasible at this moment.
7844
- if (!tagName && nodeType === 4 /* TNodeType.Container */) {
7845
- tagName = 'ng-template';
7846
- }
7847
- const isHostStandalone = isHostComponentStandalone(lView);
7848
- const templateLocation = getTemplateLocationDetails(lView);
7849
- let message = `Can't bind to '${propName}' since it isn't a known property of '${tagName}'${templateLocation}.`;
7850
- const schemas = `'${isHostStandalone ? '@Component' : '@NgModule'}.schemas'`;
7851
- const importLocation = isHostStandalone ?
7852
- 'included in the \'@Component.imports\' of this component' :
7853
- 'a part of an @NgModule where this component is declared';
7854
- if (KNOWN_CONTROL_FLOW_DIRECTIVES.has(propName)) {
7855
- // Most likely this is a control flow directive (such as `*ngIf`) used in
7856
- // a template, but the directive or the `CommonModule` is not imported.
7857
- const correspondingImport = KNOWN_CONTROL_FLOW_DIRECTIVES.get(propName);
7858
- message += `\nIf the '${propName}' is an Angular control flow directive, ` +
7859
- `please make sure that either the '${correspondingImport}' directive or the 'CommonModule' is ${importLocation}.`;
7867
+ function getComponentViewByInstance(componentInstance) {
7868
+ let patchedData = readPatchedData(componentInstance);
7869
+ let lView;
7870
+ if (isLView(patchedData)) {
7871
+ const contextLView = patchedData;
7872
+ const nodeIndex = findViaComponent(contextLView, componentInstance);
7873
+ lView = getComponentLViewByIndex(nodeIndex, contextLView);
7874
+ const context = createLContext(contextLView, nodeIndex, lView[HOST]);
7875
+ context.component = componentInstance;
7876
+ attachPatchData(componentInstance, context);
7877
+ attachPatchData(context.native, context);
7860
7878
  }
7861
7879
  else {
7862
- // May be an Angular component, which is not imported/declared?
7863
- message += `\n1. If '${tagName}' is an Angular component and it has the ` +
7864
- `'${propName}' input, then verify that it is ${importLocation}.`;
7865
- // May be a Web Component?
7866
- if (tagName && tagName.indexOf('-') > -1) {
7867
- message += `\n2. If '${tagName}' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' ` +
7868
- `to the ${schemas} of this component to suppress this message.`;
7869
- message += `\n3. To allow any property add 'NO_ERRORS_SCHEMA' to ` +
7870
- `the ${schemas} of this component.`;
7871
- }
7872
- else {
7873
- // If it's expected, the error can be suppressed by the `NO_ERRORS_SCHEMA` schema.
7874
- message += `\n2. To allow any property add 'NO_ERRORS_SCHEMA' to ` +
7875
- `the ${schemas} of this component.`;
7876
- }
7880
+ const context = patchedData;
7881
+ const contextLView = context.lView;
7882
+ ngDevMode && assertLView(contextLView);
7883
+ lView = getComponentLViewByIndex(context.nodeIndex, contextLView);
7877
7884
  }
7878
- reportUnknownPropertyError(message);
7885
+ return lView;
7879
7886
  }
7880
- function reportUnknownPropertyError(message) {
7881
- if (shouldThrowErrorOnUnknownProperty) {
7882
- throw new RuntimeError(303 /* RuntimeErrorCode.UNKNOWN_BINDING */, message);
7887
+ /**
7888
+ * This property will be monkey-patched on elements, components and directives.
7889
+ */
7890
+ const MONKEY_PATCH_KEY_NAME = '__ngContext__';
7891
+ /**
7892
+ * Assigns the given data to the given target (which could be a component,
7893
+ * directive or DOM node instance) using monkey-patching.
7894
+ */
7895
+ function attachPatchData(target, data) {
7896
+ ngDevMode && assertDefined(target, 'Target expected');
7897
+ // Only attach the ID of the view in order to avoid memory leaks (see #41047). We only do this
7898
+ // for `LView`, because we have control over when an `LView` is created and destroyed, whereas
7899
+ // we can't know when to remove an `LContext`.
7900
+ if (isLView(data)) {
7901
+ target[MONKEY_PATCH_KEY_NAME] = data[ID];
7902
+ registerLView(data);
7883
7903
  }
7884
7904
  else {
7885
- console.error(formatRuntimeError(303 /* RuntimeErrorCode.UNKNOWN_BINDING */, message));
7905
+ target[MONKEY_PATCH_KEY_NAME] = data;
7886
7906
  }
7887
7907
  }
7888
7908
  /**
7889
- * WARNING: this is a **dev-mode only** function (thus should always be guarded by the `ngDevMode`)
7890
- * and must **not** be used in production bundles. The function makes megamorphic reads, which might
7891
- * be too slow for production mode and also it relies on the constructor function being available.
7892
- *
7893
- * Gets a reference to the host component def (where a current component is declared).
7894
- *
7895
- * @param lView An `LView` that represents a current component that is being rendered.
7909
+ * Returns the monkey-patch value data present on the target (which could be
7910
+ * a component, directive or a DOM node).
7896
7911
  */
7897
- function getDeclarationComponentDef(lView) {
7898
- !ngDevMode && throwError('Must never be called in production mode');
7899
- const declarationLView = lView[DECLARATION_COMPONENT_VIEW];
7900
- const context = declarationLView[CONTEXT];
7901
- // Unable to obtain a context.
7902
- if (!context)
7903
- return null;
7904
- return context.constructor ? getComponentDef$1(context.constructor) : null;
7912
+ function readPatchedData(target) {
7913
+ ngDevMode && assertDefined(target, 'Target expected');
7914
+ const data = target[MONKEY_PATCH_KEY_NAME];
7915
+ return (typeof data === 'number') ? getLViewById(data) : data || null;
7916
+ }
7917
+ function readPatchedLView(target) {
7918
+ const value = readPatchedData(target);
7919
+ if (value) {
7920
+ return (isLView(value) ? value : value.lView);
7921
+ }
7922
+ return null;
7923
+ }
7924
+ function isComponentInstance(instance) {
7925
+ return instance && instance.constructor && instance.constructor.ɵcmp;
7926
+ }
7927
+ function isDirectiveInstance(instance) {
7928
+ return instance && instance.constructor && instance.constructor.ɵdir;
7905
7929
  }
7906
7930
  /**
7907
- * WARNING: this is a **dev-mode only** function (thus should always be guarded by the `ngDevMode`)
7908
- * and must **not** be used in production bundles. The function makes megamorphic reads, which might
7909
- * be too slow for production mode.
7910
- *
7911
- * Checks if the current component is declared inside of a standalone component template.
7912
- *
7913
- * @param lView An `LView` that represents a current component that is being rendered.
7931
+ * Locates the element within the given LView and returns the matching index
7914
7932
  */
7915
- function isHostComponentStandalone(lView) {
7916
- !ngDevMode && throwError('Must never be called in production mode');
7917
- const componentDef = getDeclarationComponentDef(lView);
7918
- // Treat host component as non-standalone if we can't obtain the def.
7919
- return !!componentDef?.standalone;
7933
+ function findViaNativeElement(lView, target) {
7934
+ const tView = lView[TVIEW];
7935
+ for (let i = HEADER_OFFSET; i < tView.bindingStartIndex; i++) {
7936
+ if (unwrapRNode(lView[i]) === target) {
7937
+ return i;
7938
+ }
7939
+ }
7940
+ return -1;
7920
7941
  }
7921
7942
  /**
7922
- * WARNING: this is a **dev-mode only** function (thus should always be guarded by the `ngDevMode`)
7923
- * and must **not** be used in production bundles. The function makes megamorphic reads, which might
7924
- * be too slow for production mode.
7925
- *
7926
- * Constructs a string describing the location of the host component template. The function is used
7927
- * in dev mode to produce error messages.
7928
- *
7929
- * @param lView An `LView` that represents a current component that is being rendered.
7943
+ * Locates the next tNode (child, sibling or parent).
7930
7944
  */
7931
- function getTemplateLocationDetails(lView) {
7932
- !ngDevMode && throwError('Must never be called in production mode');
7933
- const hostComponentDef = getDeclarationComponentDef(lView);
7934
- const componentClassName = hostComponentDef?.type?.name;
7935
- return componentClassName ? ` (used in the '${componentClassName}' component template)` : '';
7945
+ function traverseNextElement(tNode) {
7946
+ if (tNode.child) {
7947
+ return tNode.child;
7948
+ }
7949
+ else if (tNode.next) {
7950
+ return tNode.next;
7951
+ }
7952
+ else {
7953
+ // Let's take the following template: <div><span>text</span></div><component/>
7954
+ // After checking the text node, we need to find the next parent that has a "next" TNode,
7955
+ // in this case the parent `div`, so that we can find the component.
7956
+ while (tNode.parent && !tNode.parent.next) {
7957
+ tNode = tNode.parent;
7958
+ }
7959
+ return tNode.parent && tNode.parent.next;
7960
+ }
7936
7961
  }
7937
7962
  /**
7938
- * The set of known control flow directives and their corresponding imports.
7939
- * We use this set to produce a more precises error message with a note
7940
- * that the `CommonModule` should also be included.
7963
+ * Locates the component within the given LView and returns the matching index
7941
7964
  */
7942
- const KNOWN_CONTROL_FLOW_DIRECTIVES = new Map([
7943
- ['ngIf', 'NgIf'], ['ngFor', 'NgFor'], ['ngSwitchCase', 'NgSwitchCase'],
7944
- ['ngSwitchDefault', 'NgSwitchDefault']
7945
- ]);
7965
+ function findViaComponent(lView, componentInstance) {
7966
+ const componentIndices = lView[TVIEW].components;
7967
+ if (componentIndices) {
7968
+ for (let i = 0; i < componentIndices.length; i++) {
7969
+ const elementComponentIndex = componentIndices[i];
7970
+ const componentView = getComponentLViewByIndex(elementComponentIndex, lView);
7971
+ if (componentView[CONTEXT] === componentInstance) {
7972
+ return elementComponentIndex;
7973
+ }
7974
+ }
7975
+ }
7976
+ else {
7977
+ const rootComponentView = getComponentLViewByIndex(HEADER_OFFSET, lView);
7978
+ const rootComponent = rootComponentView[CONTEXT];
7979
+ if (rootComponent === componentInstance) {
7980
+ // we are dealing with the root element here therefore we know that the
7981
+ // element is the very first element after the HEADER data in the lView
7982
+ return HEADER_OFFSET;
7983
+ }
7984
+ }
7985
+ return -1;
7986
+ }
7946
7987
  /**
7947
- * Returns true if the tag name is allowed by specified schemas.
7948
- * @param schemas Array of schemas
7949
- * @param tagName Name of the tag
7988
+ * Locates the directive within the given LView and returns the matching index
7950
7989
  */
7951
- function matchingSchemas(schemas, tagName) {
7952
- if (schemas !== null) {
7953
- for (let i = 0; i < schemas.length; i++) {
7954
- const schema = schemas[i];
7955
- if (schema === NO_ERRORS_SCHEMA ||
7956
- schema === CUSTOM_ELEMENTS_SCHEMA && tagName && tagName.indexOf('-') > -1) {
7957
- return true;
7990
+ function findViaDirective(lView, directiveInstance) {
7991
+ // if a directive is monkey patched then it will (by default)
7992
+ // have a reference to the LView of the current view. The
7993
+ // element bound to the directive being search lives somewhere
7994
+ // in the view data. We loop through the nodes and check their
7995
+ // list of directives for the instance.
7996
+ let tNode = lView[TVIEW].firstChild;
7997
+ while (tNode) {
7998
+ const directiveIndexStart = tNode.directiveStart;
7999
+ const directiveIndexEnd = tNode.directiveEnd;
8000
+ for (let i = directiveIndexStart; i < directiveIndexEnd; i++) {
8001
+ if (lView[i] === directiveInstance) {
8002
+ return tNode.index;
7958
8003
  }
7959
8004
  }
8005
+ tNode = traverseNextElement(tNode);
7960
8006
  }
7961
- return false;
8007
+ return -1;
7962
8008
  }
7963
-
7964
8009
  /**
7965
- * @license
7966
- * Copyright Google LLC All Rights Reserved.
8010
+ * Returns a list of directives applied to a node at a specific index. The list includes
8011
+ * directives matched by selector and any host directives, but it excludes components.
8012
+ * Use `getComponentAtNodeIndex` to find the component applied to a node.
7967
8013
  *
7968
- * Use of this source code is governed by an MIT-style license that can be
7969
- * found in the LICENSE file at https://angular.io/license
8014
+ * @param nodeIndex The node index
8015
+ * @param lView The target view data
7970
8016
  */
7971
- const ERROR_ORIGINAL_ERROR = 'ngOriginalError';
7972
- function wrappedError(message, originalError) {
7973
- const msg = `${message} caused by: ${originalError instanceof Error ? originalError.message : originalError}`;
7974
- const error = Error(msg);
7975
- error[ERROR_ORIGINAL_ERROR] = originalError;
7976
- return error;
8017
+ function getDirectivesAtNodeIndex(nodeIndex, lView) {
8018
+ const tNode = lView[TVIEW].data[nodeIndex];
8019
+ if (tNode.directiveStart === 0)
8020
+ return EMPTY_ARRAY;
8021
+ const results = [];
8022
+ for (let i = tNode.directiveStart; i < tNode.directiveEnd; i++) {
8023
+ const directiveInstance = lView[i];
8024
+ if (!isComponentInstance(directiveInstance)) {
8025
+ results.push(directiveInstance);
8026
+ }
8027
+ }
8028
+ return results;
7977
8029
  }
7978
- function getOriginalError(error) {
7979
- return error[ERROR_ORIGINAL_ERROR];
8030
+ function getComponentAtNodeIndex(nodeIndex, lView) {
8031
+ const tNode = lView[TVIEW].data[nodeIndex];
8032
+ const { directiveStart, componentOffset } = tNode;
8033
+ return componentOffset > -1 ? lView[directiveStart + componentOffset] : null;
7980
8034
  }
7981
-
7982
- /**
7983
- * @license
7984
- * Copyright Google LLC All Rights Reserved.
7985
- *
7986
- * Use of this source code is governed by an MIT-style license that can be
7987
- * found in the LICENSE file at https://angular.io/license
7988
- */
7989
8035
  /**
7990
- * Provides a hook for centralized exception handling.
7991
- *
7992
- * The default implementation of `ErrorHandler` prints error messages to the `console`. To
7993
- * intercept error handling, write a custom exception handler that replaces this default as
7994
- * appropriate for your app.
7995
- *
7996
- * @usageNotes
7997
- * ### Example
7998
- *
7999
- * ```
8000
- * class MyErrorHandler implements ErrorHandler {
8001
- * handleError(error) {
8002
- * // do something with the exception
8003
- * }
8004
- * }
8005
- *
8006
- * @NgModule({
8007
- * providers: [{provide: ErrorHandler, useClass: MyErrorHandler}]
8008
- * })
8009
- * class MyModule {}
8010
- * ```
8011
- *
8012
- * @publicApi
8036
+ * Returns a map of local references (local reference name => element or directive instance) that
8037
+ * exist on a given element.
8013
8038
  */
8014
- class ErrorHandler {
8015
- constructor() {
8016
- /**
8017
- * @internal
8018
- */
8019
- this._console = console;
8020
- }
8021
- handleError(error) {
8022
- const originalError = this._findOriginalError(error);
8023
- this._console.error('ERROR', error);
8024
- if (originalError) {
8025
- this._console.error('ORIGINAL ERROR', originalError);
8026
- }
8027
- }
8028
- /** @internal */
8029
- _findOriginalError(error) {
8030
- let e = error && getOriginalError(error);
8031
- while (e && getOriginalError(e)) {
8032
- e = getOriginalError(e);
8039
+ function discoverLocalRefs(lView, nodeIndex) {
8040
+ const tNode = lView[TVIEW].data[nodeIndex];
8041
+ if (tNode && tNode.localNames) {
8042
+ const result = {};
8043
+ let localIndex = tNode.index + 1;
8044
+ for (let i = 0; i < tNode.localNames.length; i += 2) {
8045
+ result[tNode.localNames[i]] = lView[localIndex];
8046
+ localIndex++;
8033
8047
  }
8034
- return e || null;
8048
+ return result;
8035
8049
  }
8050
+ return null;
8036
8051
  }
8037
8052
 
8038
8053
  /**
@@ -8043,46 +8058,28 @@ class ErrorHandler {
8043
8058
  * found in the LICENSE file at https://angular.io/license
8044
8059
  */
8045
8060
  /**
8046
- * Disallowed strings in the comment.
8061
+ * Defines a schema that allows an NgModule to contain the following:
8062
+ * - Non-Angular elements named with dash case (`-`).
8063
+ * - Element properties named with dash case (`-`).
8064
+ * Dash case is the naming convention for custom elements.
8047
8065
  *
8048
- * see: https://html.spec.whatwg.org/multipage/syntax.html#comments
8049
- */
8050
- const COMMENT_DISALLOWED = /^>|^->|<!--|-->|--!>|<!-$/g;
8051
- /**
8052
- * Delimiter in the disallowed strings which needs to be wrapped with zero with character.
8066
+ * @publicApi
8053
8067
  */
8054
- const COMMENT_DELIMITER = /(<|>)/;
8055
- const COMMENT_DELIMITER_ESCAPED = '\u200B$1\u200B';
8068
+ const CUSTOM_ELEMENTS_SCHEMA = {
8069
+ name: 'custom-elements'
8070
+ };
8056
8071
  /**
8057
- * Escape the content of comment strings so that it can be safely inserted into a comment node.
8058
- *
8059
- * The issue is that HTML does not specify any way to escape comment end text inside the comment.
8060
- * Consider: `<!-- The way you close a comment is with ">", and "->" at the beginning or by "-->" or
8061
- * "--!>" at the end. -->`. Above the `"-->"` is meant to be text not an end to the comment. This
8062
- * can be created programmatically through DOM APIs. (`<!--` are also disallowed.)
8063
- *
8064
- * see: https://html.spec.whatwg.org/multipage/syntax.html#comments
8065
- *
8066
- * ```
8067
- * div.innerHTML = div.innerHTML
8068
- * ```
8069
- *
8070
- * One would expect that the above code would be safe to do, but it turns out that because comment
8071
- * text is not escaped, the comment may contain text which will prematurely close the comment
8072
- * opening up the application for XSS attack. (In SSR we programmatically create comment nodes which
8073
- * may contain such text and expect them to be safe.)
8072
+ * Defines a schema that allows any property on any element.
8074
8073
  *
8075
- * This function escapes the comment text by looking for comment delimiters (`<` and `>`) and
8076
- * surrounding them with `_>_` where the `_` is a zero width space `\u200B`. The result is that if a
8077
- * comment contains any of the comment start/end delimiters (such as `<!--`, `-->` or `--!>`) the
8078
- * text it will render normally but it will not cause the HTML parser to close/open the comment.
8074
+ * This schema allows you to ignore the errors related to any unknown elements or properties in a
8075
+ * template. The usage of this schema is generally discouraged because it prevents useful validation
8076
+ * and may hide real errors in your template. Consider using the `CUSTOM_ELEMENTS_SCHEMA` instead.
8079
8077
  *
8080
- * @param value text to make safe for comment node by escaping the comment open/close character
8081
- * sequence.
8078
+ * @publicApi
8082
8079
  */
8083
- function escapeCommentText(value) {
8084
- return value.replace(COMMENT_DISALLOWED, (text) => text.replace(COMMENT_DELIMITER, COMMENT_DELIMITER_ESCAPED));
8085
- }
8080
+ const NO_ERRORS_SCHEMA = {
8081
+ name: 'no-errors-schema'
8082
+ };
8086
8083
 
8087
8084
  /**
8088
8085
  * @license
@@ -8091,403 +8088,411 @@ function escapeCommentText(value) {
8091
8088
  * Use of this source code is governed by an MIT-style license that can be
8092
8089
  * found in the LICENSE file at https://angular.io/license
8093
8090
  */
8094
- function normalizeDebugBindingName(name) {
8095
- // Attribute names with `$` (eg `x-y$`) are valid per spec, but unsupported by some browsers
8096
- name = camelCaseToDashCase(name.replace(/[$@]/g, '_'));
8097
- return `ng-reflect-${name}`;
8098
- }
8099
- const CAMEL_CASE_REGEXP = /([A-Z])/g;
8100
- function camelCaseToDashCase(input) {
8101
- return input.replace(CAMEL_CASE_REGEXP, (...m) => '-' + m[1].toLowerCase());
8102
- }
8103
- function normalizeDebugBindingValue(value) {
8104
- try {
8105
- // Limit the size of the value as otherwise the DOM just gets polluted.
8106
- return value != null ? value.toString().slice(0, 30) : value;
8107
- }
8108
- catch (e) {
8109
- return '[ERROR] Exception while trying to serialize the value';
8110
- }
8111
- }
8112
-
8091
+ let shouldThrowErrorOnUnknownElement = false;
8113
8092
  /**
8114
- * @license
8115
- * Copyright Google LLC All Rights Reserved.
8116
- *
8117
- * Use of this source code is governed by an MIT-style license that can be
8118
- * found in the LICENSE file at https://angular.io/license
8093
+ * Sets a strict mode for JIT-compiled components to throw an error on unknown elements,
8094
+ * instead of just logging the error.
8095
+ * (for AOT-compiled ones this check happens at build time).
8119
8096
  */
8120
- // Keeps track of the currently-active LViews.
8121
- const TRACKED_LVIEWS = new Map();
8122
- // Used for generating unique IDs for LViews.
8123
- let uniqueIdCounter = 0;
8124
- /** Gets a unique ID that can be assigned to an LView. */
8125
- function getUniqueLViewId() {
8126
- return uniqueIdCounter++;
8127
- }
8128
- /** Starts tracking an LView. */
8129
- function registerLView(lView) {
8130
- ngDevMode && assertNumber(lView[ID], 'LView must have an ID in order to be registered');
8131
- TRACKED_LVIEWS.set(lView[ID], lView);
8132
- }
8133
- /** Gets an LView by its unique ID. */
8134
- function getLViewById(id) {
8135
- ngDevMode && assertNumber(id, 'ID used for LView lookup must be a number');
8136
- return TRACKED_LVIEWS.get(id) || null;
8137
- }
8138
- /** Stops tracking an LView. */
8139
- function unregisterLView(lView) {
8140
- ngDevMode && assertNumber(lView[ID], 'Cannot stop tracking an LView that does not have an ID');
8141
- TRACKED_LVIEWS.delete(lView[ID]);
8097
+ function ɵsetUnknownElementStrictMode(shouldThrow) {
8098
+ shouldThrowErrorOnUnknownElement = shouldThrow;
8142
8099
  }
8143
-
8144
8100
  /**
8145
- * @license
8146
- * Copyright Google LLC All Rights Reserved.
8147
- *
8148
- * Use of this source code is governed by an MIT-style license that can be
8149
- * found in the LICENSE file at https://angular.io/license
8101
+ * Gets the current value of the strict mode.
8150
8102
  */
8103
+ function ɵgetUnknownElementStrictMode() {
8104
+ return shouldThrowErrorOnUnknownElement;
8105
+ }
8106
+ let shouldThrowErrorOnUnknownProperty = false;
8151
8107
  /**
8152
- * The internal view context which is specific to a given DOM element, directive or
8153
- * component instance. Each value in here (besides the LView and element node details)
8154
- * can be present, null or undefined. If undefined then it implies the value has not been
8155
- * looked up yet, otherwise, if null, then a lookup was executed and nothing was found.
8156
- *
8157
- * Each value will get filled when the respective value is examined within the getContext
8158
- * function. The component, element and each directive instance will share the same instance
8159
- * of the context.
8108
+ * Sets a strict mode for JIT-compiled components to throw an error on unknown properties,
8109
+ * instead of just logging the error.
8110
+ * (for AOT-compiled ones this check happens at build time).
8160
8111
  */
8161
- class LContext {
8162
- constructor(
8163
- /**
8164
- * ID of the component's parent view data.
8165
- */
8166
- lViewId,
8167
- /**
8168
- * The index instance of the node.
8169
- */
8170
- nodeIndex,
8171
- /**
8172
- * The instance of the DOM node that is attached to the lNode.
8173
- */
8174
- native) {
8175
- this.lViewId = lViewId;
8176
- this.nodeIndex = nodeIndex;
8177
- this.native = native;
8178
- }
8179
- /** Component's parent view data. */
8180
- get lView() {
8181
- return getLViewById(this.lViewId);
8182
- }
8112
+ function ɵsetUnknownPropertyStrictMode(shouldThrow) {
8113
+ shouldThrowErrorOnUnknownProperty = shouldThrow;
8183
8114
  }
8184
-
8185
8115
  /**
8186
- * @license
8187
- * Copyright Google LLC All Rights Reserved.
8188
- *
8189
- * Use of this source code is governed by an MIT-style license that can be
8190
- * found in the LICENSE file at https://angular.io/license
8116
+ * Gets the current value of the strict mode.
8191
8117
  */
8118
+ function ɵgetUnknownPropertyStrictMode() {
8119
+ return shouldThrowErrorOnUnknownProperty;
8120
+ }
8192
8121
  /**
8193
- * Returns the matching `LContext` data for a given DOM node, directive or component instance.
8194
- *
8195
- * This function will examine the provided DOM element, component, or directive instance\'s
8196
- * monkey-patched property to derive the `LContext` data. Once called then the monkey-patched
8197
- * value will be that of the newly created `LContext`.
8122
+ * Validates that the element is known at runtime and produces
8123
+ * an error if it's not the case.
8124
+ * This check is relevant for JIT-compiled components (for AOT-compiled
8125
+ * ones this check happens at build time).
8198
8126
  *
8199
- * If the monkey-patched value is the `LView` instance then the context value for that
8200
- * target will be created and the monkey-patch reference will be updated. Therefore when this
8201
- * function is called it may mutate the provided element\'s, component\'s or any of the associated
8202
- * directive\'s monkey-patch values.
8203
- *
8204
- * If the monkey-patch value is not detected then the code will walk up the DOM until an element
8205
- * is found which contains a monkey-patch reference. When that occurs then the provided element
8206
- * will be updated with a new context (which is then returned). If the monkey-patch value is not
8207
- * detected for a component/directive instance then it will throw an error (all components and
8208
- * directives should be automatically monkey-patched by ivy).
8127
+ * The element is considered known if either:
8128
+ * - it's a known HTML element
8129
+ * - it's a known custom element
8130
+ * - the element matches any directive
8131
+ * - the element is allowed by one of the schemas
8209
8132
  *
8210
- * @param target Component, Directive or DOM Node.
8133
+ * @param element Element to validate
8134
+ * @param lView An `LView` that represents a current component that is being rendered
8135
+ * @param tagName Name of the tag to check
8136
+ * @param schemas Array of schemas
8137
+ * @param hasDirectives Boolean indicating that the element matches any directive
8211
8138
  */
8212
- function getLContext(target) {
8213
- let mpValue = readPatchedData(target);
8214
- if (mpValue) {
8215
- // only when it's an array is it considered an LView instance
8216
- // ... otherwise it's an already constructed LContext instance
8217
- if (isLView(mpValue)) {
8218
- const lView = mpValue;
8219
- let nodeIndex;
8220
- let component = undefined;
8221
- let directives = undefined;
8222
- if (isComponentInstance(target)) {
8223
- nodeIndex = findViaComponent(lView, target);
8224
- if (nodeIndex == -1) {
8225
- throw new Error('The provided component was not found in the application');
8226
- }
8227
- component = target;
8228
- }
8229
- else if (isDirectiveInstance(target)) {
8230
- nodeIndex = findViaDirective(lView, target);
8231
- if (nodeIndex == -1) {
8232
- throw new Error('The provided directive was not found in the application');
8233
- }
8234
- directives = getDirectivesAtNodeIndex(nodeIndex, lView, false);
8139
+ function validateElementIsKnown(element, lView, tagName, schemas, hasDirectives) {
8140
+ // If `schemas` is set to `null`, that's an indication that this Component was compiled in AOT
8141
+ // mode where this check happens at compile time. In JIT mode, `schemas` is always present and
8142
+ // defined as an array (as an empty array in case `schemas` field is not defined) and we should
8143
+ // execute the check below.
8144
+ if (schemas === null)
8145
+ return;
8146
+ // If the element matches any directive, it's considered as valid.
8147
+ if (!hasDirectives && tagName !== null) {
8148
+ // The element is unknown if it's an instance of HTMLUnknownElement, or it isn't registered
8149
+ // as a custom element. Note that unknown elements with a dash in their name won't be instances
8150
+ // of HTMLUnknownElement in browsers that support web components.
8151
+ const isUnknown =
8152
+ // Note that we can't check for `typeof HTMLUnknownElement === 'function'`,
8153
+ // because while most browsers return 'function', IE returns 'object'.
8154
+ (typeof HTMLUnknownElement !== 'undefined' && HTMLUnknownElement &&
8155
+ element instanceof HTMLUnknownElement) ||
8156
+ (typeof customElements !== 'undefined' && tagName.indexOf('-') > -1 &&
8157
+ !customElements.get(tagName));
8158
+ if (isUnknown && !matchingSchemas(schemas, tagName)) {
8159
+ const isHostStandalone = isHostComponentStandalone(lView);
8160
+ const templateLocation = getTemplateLocationDetails(lView);
8161
+ const schemas = `'${isHostStandalone ? '@Component' : '@NgModule'}.schemas'`;
8162
+ let message = `'${tagName}' is not a known element${templateLocation}:\n`;
8163
+ message += `1. If '${tagName}' is an Angular component, then verify that it is ${isHostStandalone ? 'included in the \'@Component.imports\' of this component' :
8164
+ 'a part of an @NgModule where this component is declared'}.\n`;
8165
+ if (tagName && tagName.indexOf('-') > -1) {
8166
+ message +=
8167
+ `2. If '${tagName}' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the ${schemas} of this component to suppress this message.`;
8235
8168
  }
8236
8169
  else {
8237
- nodeIndex = findViaNativeElement(lView, target);
8238
- if (nodeIndex == -1) {
8239
- return null;
8240
- }
8241
- }
8242
- // the goal is not to fill the entire context full of data because the lookups
8243
- // are expensive. Instead, only the target data (the element, component, container, ICU
8244
- // expression or directive details) are filled into the context. If called multiple times
8245
- // with different target values then the missing target data will be filled in.
8246
- const native = unwrapRNode(lView[nodeIndex]);
8247
- const existingCtx = readPatchedData(native);
8248
- const context = (existingCtx && !Array.isArray(existingCtx)) ?
8249
- existingCtx :
8250
- createLContext(lView, nodeIndex, native);
8251
- // only when the component has been discovered then update the monkey-patch
8252
- if (component && context.component === undefined) {
8253
- context.component = component;
8254
- attachPatchData(context.component, context);
8170
+ message +=
8171
+ `2. To allow any element add 'NO_ERRORS_SCHEMA' to the ${schemas} of this component.`;
8255
8172
  }
8256
- // only when the directives have been discovered then update the monkey-patch
8257
- if (directives && context.directives === undefined) {
8258
- context.directives = directives;
8259
- for (let i = 0; i < directives.length; i++) {
8260
- attachPatchData(directives[i], context);
8261
- }
8173
+ if (shouldThrowErrorOnUnknownElement) {
8174
+ throw new RuntimeError(304 /* RuntimeErrorCode.UNKNOWN_ELEMENT */, message);
8262
8175
  }
8263
- attachPatchData(context.native, context);
8264
- mpValue = context;
8265
- }
8266
- }
8267
- else {
8268
- const rElement = target;
8269
- ngDevMode && assertDomNode(rElement);
8270
- // if the context is not found then we need to traverse upwards up the DOM
8271
- // to find the nearest element that has already been monkey patched with data
8272
- let parent = rElement;
8273
- while (parent = parent.parentNode) {
8274
- const parentContext = readPatchedData(parent);
8275
- if (parentContext) {
8276
- const lView = Array.isArray(parentContext) ? parentContext : parentContext.lView;
8277
- // the edge of the app was also reached here through another means
8278
- // (maybe because the DOM was changed manually).
8279
- if (!lView) {
8280
- return null;
8281
- }
8282
- const index = findViaNativeElement(lView, rElement);
8283
- if (index >= 0) {
8284
- const native = unwrapRNode(lView[index]);
8285
- const context = createLContext(lView, index, native);
8286
- attachPatchData(native, context);
8287
- mpValue = context;
8288
- break;
8289
- }
8176
+ else {
8177
+ console.error(formatRuntimeError(304 /* RuntimeErrorCode.UNKNOWN_ELEMENT */, message));
8290
8178
  }
8291
8179
  }
8292
8180
  }
8293
- return mpValue || null;
8294
8181
  }
8295
8182
  /**
8296
- * Creates an empty instance of a `LContext` context
8183
+ * Validates that the property of the element is known at runtime and returns
8184
+ * false if it's not the case.
8185
+ * This check is relevant for JIT-compiled components (for AOT-compiled
8186
+ * ones this check happens at build time).
8187
+ *
8188
+ * The property is considered known if either:
8189
+ * - it's a known property of the element
8190
+ * - the element is allowed by one of the schemas
8191
+ * - the property is used for animations
8192
+ *
8193
+ * @param element Element to validate
8194
+ * @param propName Name of the property to check
8195
+ * @param tagName Name of the tag hosting the property
8196
+ * @param schemas Array of schemas
8297
8197
  */
8298
- function createLContext(lView, nodeIndex, native) {
8299
- return new LContext(lView[ID], nodeIndex, native);
8198
+ function isPropertyValid(element, propName, tagName, schemas) {
8199
+ // If `schemas` is set to `null`, that's an indication that this Component was compiled in AOT
8200
+ // mode where this check happens at compile time. In JIT mode, `schemas` is always present and
8201
+ // defined as an array (as an empty array in case `schemas` field is not defined) and we should
8202
+ // execute the check below.
8203
+ if (schemas === null)
8204
+ return true;
8205
+ // The property is considered valid if the element matches the schema, it exists on the element,
8206
+ // or it is synthetic, and we are in a browser context (web worker nodes should be skipped).
8207
+ if (matchingSchemas(schemas, tagName) || propName in element || isAnimationProp(propName)) {
8208
+ return true;
8209
+ }
8210
+ // Note: `typeof Node` returns 'function' in most browsers, but on IE it is 'object' so we
8211
+ // need to account for both here, while being careful with `typeof null` also returning 'object'.
8212
+ return typeof Node === 'undefined' || Node === null || !(element instanceof Node);
8300
8213
  }
8301
8214
  /**
8302
- * Takes a component instance and returns the view for that component.
8215
+ * Logs or throws an error that a property is not supported on an element.
8303
8216
  *
8304
- * @param componentInstance
8305
- * @returns The component's view
8217
+ * @param propName Name of the invalid property
8218
+ * @param tagName Name of the tag hosting the property
8219
+ * @param nodeType Type of the node hosting the property
8220
+ * @param lView An `LView` that represents a current component
8306
8221
  */
8307
- function getComponentViewByInstance(componentInstance) {
8308
- let patchedData = readPatchedData(componentInstance);
8309
- let lView;
8310
- if (isLView(patchedData)) {
8311
- const contextLView = patchedData;
8312
- const nodeIndex = findViaComponent(contextLView, componentInstance);
8313
- lView = getComponentLViewByIndex(nodeIndex, contextLView);
8314
- const context = createLContext(contextLView, nodeIndex, lView[HOST]);
8315
- context.component = componentInstance;
8316
- attachPatchData(componentInstance, context);
8317
- attachPatchData(context.native, context);
8222
+ function handleUnknownPropertyError(propName, tagName, nodeType, lView) {
8223
+ // Special-case a situation when a structural directive is applied to
8224
+ // an `<ng-template>` element, for example: `<ng-template *ngIf="true">`.
8225
+ // In this case the compiler generates the `ɵɵtemplate` instruction with
8226
+ // the `null` as the tagName. The directive matching logic at runtime relies
8227
+ // on this effect (see `isInlineTemplate`), thus using the 'ng-template' as
8228
+ // a default value of the `tNode.value` is not feasible at this moment.
8229
+ if (!tagName && nodeType === 4 /* TNodeType.Container */) {
8230
+ tagName = 'ng-template';
8231
+ }
8232
+ const isHostStandalone = isHostComponentStandalone(lView);
8233
+ const templateLocation = getTemplateLocationDetails(lView);
8234
+ let message = `Can't bind to '${propName}' since it isn't a known property of '${tagName}'${templateLocation}.`;
8235
+ const schemas = `'${isHostStandalone ? '@Component' : '@NgModule'}.schemas'`;
8236
+ const importLocation = isHostStandalone ?
8237
+ 'included in the \'@Component.imports\' of this component' :
8238
+ 'a part of an @NgModule where this component is declared';
8239
+ if (KNOWN_CONTROL_FLOW_DIRECTIVES.has(propName)) {
8240
+ // Most likely this is a control flow directive (such as `*ngIf`) used in
8241
+ // a template, but the directive or the `CommonModule` is not imported.
8242
+ const correspondingImport = KNOWN_CONTROL_FLOW_DIRECTIVES.get(propName);
8243
+ message += `\nIf the '${propName}' is an Angular control flow directive, ` +
8244
+ `please make sure that either the '${correspondingImport}' directive or the 'CommonModule' is ${importLocation}.`;
8318
8245
  }
8319
8246
  else {
8320
- const context = patchedData;
8321
- const contextLView = context.lView;
8322
- ngDevMode && assertLView(contextLView);
8323
- lView = getComponentLViewByIndex(context.nodeIndex, contextLView);
8247
+ // May be an Angular component, which is not imported/declared?
8248
+ message += `\n1. If '${tagName}' is an Angular component and it has the ` +
8249
+ `'${propName}' input, then verify that it is ${importLocation}.`;
8250
+ // May be a Web Component?
8251
+ if (tagName && tagName.indexOf('-') > -1) {
8252
+ message += `\n2. If '${tagName}' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' ` +
8253
+ `to the ${schemas} of this component to suppress this message.`;
8254
+ message += `\n3. To allow any property add 'NO_ERRORS_SCHEMA' to ` +
8255
+ `the ${schemas} of this component.`;
8256
+ }
8257
+ else {
8258
+ // If it's expected, the error can be suppressed by the `NO_ERRORS_SCHEMA` schema.
8259
+ message += `\n2. To allow any property add 'NO_ERRORS_SCHEMA' to ` +
8260
+ `the ${schemas} of this component.`;
8261
+ }
8262
+ }
8263
+ reportUnknownPropertyError(message);
8264
+ }
8265
+ function reportUnknownPropertyError(message) {
8266
+ if (shouldThrowErrorOnUnknownProperty) {
8267
+ throw new RuntimeError(303 /* RuntimeErrorCode.UNKNOWN_BINDING */, message);
8268
+ }
8269
+ else {
8270
+ console.error(formatRuntimeError(303 /* RuntimeErrorCode.UNKNOWN_BINDING */, message));
8324
8271
  }
8325
- return lView;
8326
8272
  }
8327
8273
  /**
8328
- * This property will be monkey-patched on elements, components and directives.
8274
+ * WARNING: this is a **dev-mode only** function (thus should always be guarded by the `ngDevMode`)
8275
+ * and must **not** be used in production bundles. The function makes megamorphic reads, which might
8276
+ * be too slow for production mode and also it relies on the constructor function being available.
8277
+ *
8278
+ * Gets a reference to the host component def (where a current component is declared).
8279
+ *
8280
+ * @param lView An `LView` that represents a current component that is being rendered.
8329
8281
  */
8330
- const MONKEY_PATCH_KEY_NAME = '__ngContext__';
8282
+ function getDeclarationComponentDef(lView) {
8283
+ !ngDevMode && throwError('Must never be called in production mode');
8284
+ const declarationLView = lView[DECLARATION_COMPONENT_VIEW];
8285
+ const context = declarationLView[CONTEXT];
8286
+ // Unable to obtain a context.
8287
+ if (!context)
8288
+ return null;
8289
+ return context.constructor ? getComponentDef$1(context.constructor) : null;
8290
+ }
8331
8291
  /**
8332
- * Assigns the given data to the given target (which could be a component,
8333
- * directive or DOM node instance) using monkey-patching.
8292
+ * WARNING: this is a **dev-mode only** function (thus should always be guarded by the `ngDevMode`)
8293
+ * and must **not** be used in production bundles. The function makes megamorphic reads, which might
8294
+ * be too slow for production mode.
8295
+ *
8296
+ * Checks if the current component is declared inside of a standalone component template.
8297
+ *
8298
+ * @param lView An `LView` that represents a current component that is being rendered.
8334
8299
  */
8335
- function attachPatchData(target, data) {
8336
- ngDevMode && assertDefined(target, 'Target expected');
8337
- // Only attach the ID of the view in order to avoid memory leaks (see #41047). We only do this
8338
- // for `LView`, because we have control over when an `LView` is created and destroyed, whereas
8339
- // we can't know when to remove an `LContext`.
8340
- if (isLView(data)) {
8341
- target[MONKEY_PATCH_KEY_NAME] = data[ID];
8342
- registerLView(data);
8343
- }
8344
- else {
8345
- target[MONKEY_PATCH_KEY_NAME] = data;
8346
- }
8300
+ function isHostComponentStandalone(lView) {
8301
+ !ngDevMode && throwError('Must never be called in production mode');
8302
+ const componentDef = getDeclarationComponentDef(lView);
8303
+ // Treat host component as non-standalone if we can't obtain the def.
8304
+ return !!componentDef?.standalone;
8347
8305
  }
8348
8306
  /**
8349
- * Returns the monkey-patch value data present on the target (which could be
8350
- * a component, directive or a DOM node).
8307
+ * WARNING: this is a **dev-mode only** function (thus should always be guarded by the `ngDevMode`)
8308
+ * and must **not** be used in production bundles. The function makes megamorphic reads, which might
8309
+ * be too slow for production mode.
8310
+ *
8311
+ * Constructs a string describing the location of the host component template. The function is used
8312
+ * in dev mode to produce error messages.
8313
+ *
8314
+ * @param lView An `LView` that represents a current component that is being rendered.
8351
8315
  */
8352
- function readPatchedData(target) {
8353
- ngDevMode && assertDefined(target, 'Target expected');
8354
- const data = target[MONKEY_PATCH_KEY_NAME];
8355
- return (typeof data === 'number') ? getLViewById(data) : data || null;
8316
+ function getTemplateLocationDetails(lView) {
8317
+ !ngDevMode && throwError('Must never be called in production mode');
8318
+ const hostComponentDef = getDeclarationComponentDef(lView);
8319
+ const componentClassName = hostComponentDef?.type?.name;
8320
+ return componentClassName ? ` (used in the '${componentClassName}' component template)` : '';
8356
8321
  }
8357
- function readPatchedLView(target) {
8358
- const value = readPatchedData(target);
8359
- if (value) {
8360
- return (isLView(value) ? value : value.lView);
8322
+ /**
8323
+ * The set of known control flow directives and their corresponding imports.
8324
+ * We use this set to produce a more precises error message with a note
8325
+ * that the `CommonModule` should also be included.
8326
+ */
8327
+ const KNOWN_CONTROL_FLOW_DIRECTIVES = new Map([
8328
+ ['ngIf', 'NgIf'], ['ngFor', 'NgFor'], ['ngSwitchCase', 'NgSwitchCase'],
8329
+ ['ngSwitchDefault', 'NgSwitchDefault']
8330
+ ]);
8331
+ /**
8332
+ * Returns true if the tag name is allowed by specified schemas.
8333
+ * @param schemas Array of schemas
8334
+ * @param tagName Name of the tag
8335
+ */
8336
+ function matchingSchemas(schemas, tagName) {
8337
+ if (schemas !== null) {
8338
+ for (let i = 0; i < schemas.length; i++) {
8339
+ const schema = schemas[i];
8340
+ if (schema === NO_ERRORS_SCHEMA ||
8341
+ schema === CUSTOM_ELEMENTS_SCHEMA && tagName && tagName.indexOf('-') > -1) {
8342
+ return true;
8343
+ }
8344
+ }
8361
8345
  }
8362
- return null;
8346
+ return false;
8363
8347
  }
8364
- function isComponentInstance(instance) {
8365
- return instance && instance.constructor && instance.constructor.ɵcmp;
8348
+
8349
+ /**
8350
+ * @license
8351
+ * Copyright Google LLC All Rights Reserved.
8352
+ *
8353
+ * Use of this source code is governed by an MIT-style license that can be
8354
+ * found in the LICENSE file at https://angular.io/license
8355
+ */
8356
+ const ERROR_ORIGINAL_ERROR = 'ngOriginalError';
8357
+ function wrappedError(message, originalError) {
8358
+ const msg = `${message} caused by: ${originalError instanceof Error ? originalError.message : originalError}`;
8359
+ const error = Error(msg);
8360
+ error[ERROR_ORIGINAL_ERROR] = originalError;
8361
+ return error;
8366
8362
  }
8367
- function isDirectiveInstance(instance) {
8368
- return instance && instance.constructor && instance.constructor.ɵdir;
8363
+ function getOriginalError(error) {
8364
+ return error[ERROR_ORIGINAL_ERROR];
8369
8365
  }
8366
+
8370
8367
  /**
8371
- * Locates the element within the given LView and returns the matching index
8368
+ * @license
8369
+ * Copyright Google LLC All Rights Reserved.
8370
+ *
8371
+ * Use of this source code is governed by an MIT-style license that can be
8372
+ * found in the LICENSE file at https://angular.io/license
8372
8373
  */
8373
- function findViaNativeElement(lView, target) {
8374
- const tView = lView[TVIEW];
8375
- for (let i = HEADER_OFFSET; i < tView.bindingStartIndex; i++) {
8376
- if (unwrapRNode(lView[i]) === target) {
8377
- return i;
8374
+ /**
8375
+ * Provides a hook for centralized exception handling.
8376
+ *
8377
+ * The default implementation of `ErrorHandler` prints error messages to the `console`. To
8378
+ * intercept error handling, write a custom exception handler that replaces this default as
8379
+ * appropriate for your app.
8380
+ *
8381
+ * @usageNotes
8382
+ * ### Example
8383
+ *
8384
+ * ```
8385
+ * class MyErrorHandler implements ErrorHandler {
8386
+ * handleError(error) {
8387
+ * // do something with the exception
8388
+ * }
8389
+ * }
8390
+ *
8391
+ * @NgModule({
8392
+ * providers: [{provide: ErrorHandler, useClass: MyErrorHandler}]
8393
+ * })
8394
+ * class MyModule {}
8395
+ * ```
8396
+ *
8397
+ * @publicApi
8398
+ */
8399
+ class ErrorHandler {
8400
+ constructor() {
8401
+ /**
8402
+ * @internal
8403
+ */
8404
+ this._console = console;
8405
+ }
8406
+ handleError(error) {
8407
+ const originalError = this._findOriginalError(error);
8408
+ this._console.error('ERROR', error);
8409
+ if (originalError) {
8410
+ this._console.error('ORIGINAL ERROR', originalError);
8411
+ }
8412
+ }
8413
+ /** @internal */
8414
+ _findOriginalError(error) {
8415
+ let e = error && getOriginalError(error);
8416
+ while (e && getOriginalError(e)) {
8417
+ e = getOriginalError(e);
8378
8418
  }
8419
+ return e || null;
8379
8420
  }
8380
- return -1;
8381
8421
  }
8422
+
8382
8423
  /**
8383
- * Locates the next tNode (child, sibling or parent).
8424
+ * @license
8425
+ * Copyright Google LLC All Rights Reserved.
8426
+ *
8427
+ * Use of this source code is governed by an MIT-style license that can be
8428
+ * found in the LICENSE file at https://angular.io/license
8384
8429
  */
8385
- function traverseNextElement(tNode) {
8386
- if (tNode.child) {
8387
- return tNode.child;
8388
- }
8389
- else if (tNode.next) {
8390
- return tNode.next;
8391
- }
8392
- else {
8393
- // Let's take the following template: <div><span>text</span></div><component/>
8394
- // After checking the text node, we need to find the next parent that has a "next" TNode,
8395
- // in this case the parent `div`, so that we can find the component.
8396
- while (tNode.parent && !tNode.parent.next) {
8397
- tNode = tNode.parent;
8398
- }
8399
- return tNode.parent && tNode.parent.next;
8400
- }
8401
- }
8402
8430
  /**
8403
- * Locates the component within the given LView and returns the matching index
8431
+ * Disallowed strings in the comment.
8432
+ *
8433
+ * see: https://html.spec.whatwg.org/multipage/syntax.html#comments
8404
8434
  */
8405
- function findViaComponent(lView, componentInstance) {
8406
- const componentIndices = lView[TVIEW].components;
8407
- if (componentIndices) {
8408
- for (let i = 0; i < componentIndices.length; i++) {
8409
- const elementComponentIndex = componentIndices[i];
8410
- const componentView = getComponentLViewByIndex(elementComponentIndex, lView);
8411
- if (componentView[CONTEXT] === componentInstance) {
8412
- return elementComponentIndex;
8413
- }
8414
- }
8415
- }
8416
- else {
8417
- const rootComponentView = getComponentLViewByIndex(HEADER_OFFSET, lView);
8418
- const rootComponent = rootComponentView[CONTEXT];
8419
- if (rootComponent === componentInstance) {
8420
- // we are dealing with the root element here therefore we know that the
8421
- // element is the very first element after the HEADER data in the lView
8422
- return HEADER_OFFSET;
8423
- }
8424
- }
8425
- return -1;
8426
- }
8435
+ const COMMENT_DISALLOWED = /^>|^->|<!--|-->|--!>|<!-$/g;
8427
8436
  /**
8428
- * Locates the directive within the given LView and returns the matching index
8437
+ * Delimiter in the disallowed strings which needs to be wrapped with zero with character.
8429
8438
  */
8430
- function findViaDirective(lView, directiveInstance) {
8431
- // if a directive is monkey patched then it will (by default)
8432
- // have a reference to the LView of the current view. The
8433
- // element bound to the directive being search lives somewhere
8434
- // in the view data. We loop through the nodes and check their
8435
- // list of directives for the instance.
8436
- let tNode = lView[TVIEW].firstChild;
8437
- while (tNode) {
8438
- const directiveIndexStart = tNode.directiveStart;
8439
- const directiveIndexEnd = tNode.directiveEnd;
8440
- for (let i = directiveIndexStart; i < directiveIndexEnd; i++) {
8441
- if (lView[i] === directiveInstance) {
8442
- return tNode.index;
8443
- }
8444
- }
8445
- tNode = traverseNextElement(tNode);
8446
- }
8447
- return -1;
8448
- }
8439
+ const COMMENT_DELIMITER = /(<|>)/;
8440
+ const COMMENT_DELIMITER_ESCAPED = '\u200B$1\u200B';
8449
8441
  /**
8450
- * Returns a list of directives extracted from the given view based on the
8451
- * provided list of directive index values.
8442
+ * Escape the content of comment strings so that it can be safely inserted into a comment node.
8452
8443
  *
8453
- * @param nodeIndex The node index
8454
- * @param lView The target view data
8455
- * @param includeComponents Whether or not to include components in returned directives
8444
+ * The issue is that HTML does not specify any way to escape comment end text inside the comment.
8445
+ * Consider: `<!-- The way you close a comment is with ">", and "->" at the beginning or by "-->" or
8446
+ * "--!>" at the end. -->`. Above the `"-->"` is meant to be text not an end to the comment. This
8447
+ * can be created programmatically through DOM APIs. (`<!--` are also disallowed.)
8448
+ *
8449
+ * see: https://html.spec.whatwg.org/multipage/syntax.html#comments
8450
+ *
8451
+ * ```
8452
+ * div.innerHTML = div.innerHTML
8453
+ * ```
8454
+ *
8455
+ * One would expect that the above code would be safe to do, but it turns out that because comment
8456
+ * text is not escaped, the comment may contain text which will prematurely close the comment
8457
+ * opening up the application for XSS attack. (In SSR we programmatically create comment nodes which
8458
+ * may contain such text and expect them to be safe.)
8459
+ *
8460
+ * This function escapes the comment text by looking for comment delimiters (`<` and `>`) and
8461
+ * surrounding them with `_>_` where the `_` is a zero width space `\u200B`. The result is that if a
8462
+ * comment contains any of the comment start/end delimiters (such as `<!--`, `-->` or `--!>`) the
8463
+ * text it will render normally but it will not cause the HTML parser to close/open the comment.
8464
+ *
8465
+ * @param value text to make safe for comment node by escaping the comment open/close character
8466
+ * sequence.
8456
8467
  */
8457
- function getDirectivesAtNodeIndex(nodeIndex, lView, includeComponents) {
8458
- const tNode = lView[TVIEW].data[nodeIndex];
8459
- if (tNode.directiveStart === 0)
8460
- return EMPTY_ARRAY;
8461
- const results = [];
8462
- for (let i = tNode.directiveStart; i < tNode.directiveEnd; i++) {
8463
- const directiveInstance = lView[i];
8464
- if (!isComponentInstance(directiveInstance) || includeComponents) {
8465
- results.push(directiveInstance);
8466
- }
8467
- }
8468
- return results;
8469
- }
8470
- function getComponentAtNodeIndex(nodeIndex, lView) {
8471
- const tNode = lView[TVIEW].data[nodeIndex];
8472
- const { directiveStart, componentOffset } = tNode;
8473
- return componentOffset > -1 ? lView[directiveStart + componentOffset] : null;
8468
+ function escapeCommentText(value) {
8469
+ return value.replace(COMMENT_DISALLOWED, (text) => text.replace(COMMENT_DELIMITER, COMMENT_DELIMITER_ESCAPED));
8474
8470
  }
8471
+
8475
8472
  /**
8476
- * Returns a map of local references (local reference name => element or directive instance) that
8477
- * exist on a given element.
8473
+ * @license
8474
+ * Copyright Google LLC All Rights Reserved.
8475
+ *
8476
+ * Use of this source code is governed by an MIT-style license that can be
8477
+ * found in the LICENSE file at https://angular.io/license
8478
8478
  */
8479
- function discoverLocalRefs(lView, nodeIndex) {
8480
- const tNode = lView[TVIEW].data[nodeIndex];
8481
- if (tNode && tNode.localNames) {
8482
- const result = {};
8483
- let localIndex = tNode.index + 1;
8484
- for (let i = 0; i < tNode.localNames.length; i += 2) {
8485
- result[tNode.localNames[i]] = lView[localIndex];
8486
- localIndex++;
8487
- }
8488
- return result;
8479
+ function normalizeDebugBindingName(name) {
8480
+ // Attribute names with `$` (eg `x-y$`) are valid per spec, but unsupported by some browsers
8481
+ name = camelCaseToDashCase(name.replace(/[$@]/g, '_'));
8482
+ return `ng-reflect-${name}`;
8483
+ }
8484
+ const CAMEL_CASE_REGEXP = /([A-Z])/g;
8485
+ function camelCaseToDashCase(input) {
8486
+ return input.replace(CAMEL_CASE_REGEXP, (...m) => '-' + m[1].toLowerCase());
8487
+ }
8488
+ function normalizeDebugBindingValue(value) {
8489
+ try {
8490
+ // Limit the size of the value as otherwise the DOM just gets polluted.
8491
+ return value != null ? value.toString().slice(0, 30) : value;
8492
+ }
8493
+ catch (e) {
8494
+ return '[ERROR] Exception while trying to serialize the value';
8489
8495
  }
8490
- return null;
8491
8496
  }
8492
8497
 
8493
8498
  /**
@@ -9651,6 +9656,19 @@ function writeDirectClass(renderer, element, newValue) {
9651
9656
  }
9652
9657
  ngDevMode && ngDevMode.rendererSetClassName++;
9653
9658
  }
9659
+ /** Sets up the static DOM attributes on an `RNode`. */
9660
+ function setupStaticAttributes(renderer, element, tNode) {
9661
+ const { mergedAttrs, classes, styles } = tNode;
9662
+ if (mergedAttrs !== null) {
9663
+ setUpAttributes(renderer, element, mergedAttrs);
9664
+ }
9665
+ if (classes !== null) {
9666
+ writeDirectClass(renderer, element, classes);
9667
+ }
9668
+ if (styles !== null) {
9669
+ writeDirectStyle(renderer, element, styles);
9670
+ }
9671
+ }
9654
9672
 
9655
9673
  /**
9656
9674
  * @license
@@ -12871,28 +12889,6 @@ function setNgReflectProperties(lView, element, type, dataValue, value) {
12871
12889
  }
12872
12890
  }
12873
12891
  }
12874
- /**
12875
- * Instantiate a root component.
12876
- */
12877
- function instantiateRootComponent(tView, lView, def) {
12878
- const rootTNode = getCurrentTNode();
12879
- if (tView.firstCreatePass) {
12880
- if (def.providersResolver)
12881
- def.providersResolver(def);
12882
- const directiveIndex = allocExpando(tView, lView, 1, null);
12883
- ngDevMode &&
12884
- assertEqual(directiveIndex, rootTNode.directiveStart, 'Because this is a root component the allocated expando should match the TNode component.');
12885
- configureViewWithDirective(tView, rootTNode, lView, directiveIndex, def);
12886
- initializeInputAndOutputAliases(tView, rootTNode);
12887
- }
12888
- const directive = getNodeInjectable(lView, tView, rootTNode.directiveStart + rootTNode.componentOffset, rootTNode);
12889
- attachPatchData(directive, lView);
12890
- const native = getNativeByTNode(rootTNode, lView);
12891
- if (native) {
12892
- attachPatchData(native, lView);
12893
- }
12894
- return directive;
12895
- }
12896
12892
  /**
12897
12893
  * Resolve the matched directives on a node.
12898
12894
  */
@@ -12902,59 +12898,16 @@ function resolveDirectives(tView, lView, tNode, localRefs) {
12902
12898
  ngDevMode && assertFirstCreatePass(tView);
12903
12899
  let hasDirectives = false;
12904
12900
  if (getBindingsEnabled()) {
12905
- const directiveDefsMatchedBySelectors = findDirectiveDefMatches(tView, lView, tNode);
12906
- const directiveDefs = directiveDefsMatchedBySelectors ?
12907
- findHostDirectiveDefs$1(directiveDefsMatchedBySelectors, tView, lView, tNode) :
12908
- null;
12901
+ const directiveDefs = findDirectiveDefMatches(tView, lView, tNode);
12909
12902
  const exportsMap = localRefs === null ? null : { '': -1 };
12910
12903
  if (directiveDefs !== null) {
12911
- hasDirectives = true;
12912
- initTNodeFlags(tNode, tView.data.length, directiveDefs.length);
12913
- // When the same token is provided by several directives on the same node, some rules apply in
12914
- // the viewEngine:
12915
- // - viewProviders have priority over providers
12916
- // - the last directive in NgModule.declarations has priority over the previous one
12917
- // So to match these rules, the order in which providers are added in the arrays is very
12918
- // important.
12904
+ // Publishes the directive types to DI so they can be injected. Needs to
12905
+ // happen in a separate pass before the TNode flags have been initialized.
12919
12906
  for (let i = 0; i < directiveDefs.length; i++) {
12920
- const def = directiveDefs[i];
12921
- if (def.providersResolver)
12922
- def.providersResolver(def);
12907
+ diPublicInInjector(getOrCreateNodeInjectorForNode(tNode, lView), tView, directiveDefs[i].type);
12923
12908
  }
12924
- let preOrderHooksFound = false;
12925
- let preOrderCheckHooksFound = false;
12926
- let directiveIdx = allocExpando(tView, lView, directiveDefs.length, null);
12927
- ngDevMode &&
12928
- assertSame(directiveIdx, tNode.directiveStart, 'TNode.directiveStart should point to just allocated space');
12929
- for (let i = 0; i < directiveDefs.length; i++) {
12930
- const def = directiveDefs[i];
12931
- // Merge the attrs in the order of matches. This assumes that the first directive is the
12932
- // component itself, so that the component has the least priority.
12933
- tNode.mergedAttrs = mergeHostAttrs(tNode.mergedAttrs, def.hostAttrs);
12934
- configureViewWithDirective(tView, tNode, lView, directiveIdx, def);
12935
- saveNameToExportMap(directiveIdx, def, exportsMap);
12936
- if (def.contentQueries !== null)
12937
- tNode.flags |= 4 /* TNodeFlags.hasContentQuery */;
12938
- if (def.hostBindings !== null || def.hostAttrs !== null || def.hostVars !== 0)
12939
- tNode.flags |= 64 /* TNodeFlags.hasHostBindings */;
12940
- const lifeCycleHooks = def.type.prototype;
12941
- // Only push a node index into the preOrderHooks array if this is the first
12942
- // pre-order hook found on this node.
12943
- if (!preOrderHooksFound &&
12944
- (lifeCycleHooks.ngOnChanges || lifeCycleHooks.ngOnInit || lifeCycleHooks.ngDoCheck)) {
12945
- // We will push the actual hook function into this array later during dir instantiation.
12946
- // We cannot do it now because we must ensure hooks are registered in the same
12947
- // order that directives are created (i.e. injection order).
12948
- (tView.preOrderHooks || (tView.preOrderHooks = [])).push(tNode.index);
12949
- preOrderHooksFound = true;
12950
- }
12951
- if (!preOrderCheckHooksFound && (lifeCycleHooks.ngOnChanges || lifeCycleHooks.ngDoCheck)) {
12952
- (tView.preOrderCheckHooks || (tView.preOrderCheckHooks = [])).push(tNode.index);
12953
- preOrderCheckHooksFound = true;
12954
- }
12955
- directiveIdx++;
12956
- }
12957
- initializeInputAndOutputAliases(tView, tNode);
12909
+ hasDirectives = true;
12910
+ initializeDirectives(tView, lView, tNode, directiveDefs, exportsMap);
12958
12911
  }
12959
12912
  if (exportsMap)
12960
12913
  cacheMatchingLocalNames(tNode, localRefs, exportsMap);
@@ -12963,17 +12916,66 @@ function resolveDirectives(tView, lView, tNode, localRefs) {
12963
12916
  tNode.mergedAttrs = mergeHostAttrs(tNode.mergedAttrs, tNode.attrs);
12964
12917
  return hasDirectives;
12965
12918
  }
12919
+ /** Initializes the data structures necessary for a list of directives to be instantiated. */
12920
+ function initializeDirectives(tView, lView, tNode, directives, exportsMap) {
12921
+ ngDevMode && assertFirstCreatePass(tView);
12922
+ initTNodeFlags(tNode, tView.data.length, directives.length);
12923
+ // When the same token is provided by several directives on the same node, some rules apply in
12924
+ // the viewEngine:
12925
+ // - viewProviders have priority over providers
12926
+ // - the last directive in NgModule.declarations has priority over the previous one
12927
+ // So to match these rules, the order in which providers are added in the arrays is very
12928
+ // important.
12929
+ for (let i = 0; i < directives.length; i++) {
12930
+ const def = directives[i];
12931
+ if (def.providersResolver)
12932
+ def.providersResolver(def);
12933
+ }
12934
+ let preOrderHooksFound = false;
12935
+ let preOrderCheckHooksFound = false;
12936
+ let directiveIdx = allocExpando(tView, lView, directives.length, null);
12937
+ ngDevMode &&
12938
+ assertSame(directiveIdx, tNode.directiveStart, 'TNode.directiveStart should point to just allocated space');
12939
+ for (let i = 0; i < directives.length; i++) {
12940
+ const def = directives[i];
12941
+ // Merge the attrs in the order of matches. This assumes that the first directive is the
12942
+ // component itself, so that the component has the least priority.
12943
+ tNode.mergedAttrs = mergeHostAttrs(tNode.mergedAttrs, def.hostAttrs);
12944
+ configureViewWithDirective(tView, tNode, lView, directiveIdx, def);
12945
+ saveNameToExportMap(directiveIdx, def, exportsMap);
12946
+ if (def.contentQueries !== null)
12947
+ tNode.flags |= 4 /* TNodeFlags.hasContentQuery */;
12948
+ if (def.hostBindings !== null || def.hostAttrs !== null || def.hostVars !== 0)
12949
+ tNode.flags |= 64 /* TNodeFlags.hasHostBindings */;
12950
+ const lifeCycleHooks = def.type.prototype;
12951
+ // Only push a node index into the preOrderHooks array if this is the first
12952
+ // pre-order hook found on this node.
12953
+ if (!preOrderHooksFound &&
12954
+ (lifeCycleHooks.ngOnChanges || lifeCycleHooks.ngOnInit || lifeCycleHooks.ngDoCheck)) {
12955
+ // We will push the actual hook function into this array later during dir instantiation.
12956
+ // We cannot do it now because we must ensure hooks are registered in the same
12957
+ // order that directives are created (i.e. injection order).
12958
+ (tView.preOrderHooks || (tView.preOrderHooks = [])).push(tNode.index);
12959
+ preOrderHooksFound = true;
12960
+ }
12961
+ if (!preOrderCheckHooksFound && (lifeCycleHooks.ngOnChanges || lifeCycleHooks.ngDoCheck)) {
12962
+ (tView.preOrderCheckHooks || (tView.preOrderCheckHooks = [])).push(tNode.index);
12963
+ preOrderCheckHooksFound = true;
12964
+ }
12965
+ directiveIdx++;
12966
+ }
12967
+ initializeInputAndOutputAliases(tView, tNode);
12968
+ }
12966
12969
  /**
12967
12970
  * Add `hostBindings` to the `TView.hostBindingOpCodes`.
12968
12971
  *
12969
12972
  * @param tView `TView` to which the `hostBindings` should be added.
12970
12973
  * @param tNode `TNode` the element which contains the directive
12971
- * @param lView `LView` current `LView`
12972
12974
  * @param directiveIdx Directive index in view.
12973
12975
  * @param directiveVarsIdx Where will the directive's vars be stored
12974
12976
  * @param def `ComponentDef`/`DirectiveDef`, which contains the `hostVars`/`hostBindings` to add.
12975
12977
  */
12976
- function registerHostBindingOpCodes(tView, tNode, lView, directiveIdx, directiveVarsIdx, def) {
12978
+ function registerHostBindingOpCodes(tView, tNode, directiveIdx, directiveVarsIdx, def) {
12977
12979
  ngDevMode && assertFirstCreatePass(tView);
12978
12980
  const hostBindings = def.hostBindings;
12979
12981
  if (hostBindings) {
@@ -13074,7 +13076,7 @@ function invokeHostBindingsInCreationMode(def, directive) {
13074
13076
  * Matches the current node against all available selectors.
13075
13077
  * If a component is matched (at most one), it is returned in first position in the array.
13076
13078
  */
13077
- function findDirectiveDefMatches(tView, viewData, tNode) {
13079
+ function findDirectiveDefMatches(tView, lView, tNode) {
13078
13080
  ngDevMode && assertFirstCreatePass(tView);
13079
13081
  ngDevMode && assertTNodeType(tNode, 3 /* TNodeType.AnyRNode */ | 12 /* TNodeType.AnyContainer */);
13080
13082
  const registry = tView.directiveRegistry;
@@ -13084,22 +13086,45 @@ function findDirectiveDefMatches(tView, viewData, tNode) {
13084
13086
  const def = registry[i];
13085
13087
  if (isNodeMatchingSelectorList(tNode, def.selectors, /* isProjectionMode */ false)) {
13086
13088
  matches || (matches = ngDevMode ? new MatchesArray() : []);
13087
- diPublicInInjector(getOrCreateNodeInjectorForNode(tNode, viewData), tView, def.type);
13088
13089
  if (isComponentDef(def)) {
13089
13090
  if (ngDevMode) {
13090
13091
  assertTNodeType(tNode, 2 /* TNodeType.Element */, `"${tNode.value}" tags cannot be used as component hosts. ` +
13091
13092
  `Please use a different tag to activate the ${stringify(def.type)} component.`);
13092
13093
  if (isComponentHost(tNode)) {
13093
- // If another component has been matched previously, it's the first element in the
13094
- // `matches` array, see how we store components/directives in `matches` below.
13095
- throwMultipleComponentError(tNode, matches[0].type, def.type);
13094
+ throwMultipleComponentError(tNode, matches.find(isComponentDef).type, def.type);
13096
13095
  }
13097
13096
  }
13098
- markAsComponentHost(tView, tNode, 0);
13099
- // The component is always stored first with directives after.
13100
- matches.unshift(def);
13097
+ // Components are inserted at the front of the matches array so that their lifecycle
13098
+ // hooks run before any directive lifecycle hooks. This appears to be for ViewEngine
13099
+ // compatibility. This logic doesn't make sense with host directives, because it
13100
+ // would allow the host directives to undo any overrides the host may have made.
13101
+ // To handle this case, the host directives of components are inserted at the beginning
13102
+ // of the array, followed by the component. As such, the insertion order is as follows:
13103
+ // 1. Host directives belonging to the selector-matched component.
13104
+ // 2. Selector-matched component.
13105
+ // 3. Host directives belonging to selector-matched directives.
13106
+ // 4. Selector-matched directives.
13107
+ if (def.findHostDirectiveDefs !== null) {
13108
+ const hostDirectiveMatches = [];
13109
+ def.findHostDirectiveDefs(hostDirectiveMatches, def, tView, lView, tNode);
13110
+ // Add all host directives declared on this component, followed by the component itself.
13111
+ // Host directives should execute first so the host has a chance to override changes
13112
+ // to the DOM made by them.
13113
+ matches.unshift(...hostDirectiveMatches, def);
13114
+ // Component is offset starting from the beginning of the host directives array.
13115
+ const componentOffset = hostDirectiveMatches.length;
13116
+ markAsComponentHost(tView, tNode, componentOffset);
13117
+ }
13118
+ else {
13119
+ // No host directives on this component, just add the
13120
+ // component def to the beginning of the matches.
13121
+ matches.unshift(def);
13122
+ markAsComponentHost(tView, tNode, 0);
13123
+ }
13101
13124
  }
13102
13125
  else {
13126
+ // Append any host directives to the matches first.
13127
+ def.findHostDirectiveDefs?.(matches, def, tView, lView, tNode);
13103
13128
  matches.push(def);
13104
13129
  }
13105
13130
  }
@@ -13119,26 +13144,6 @@ function markAsComponentHost(tView, hostTNode, componentOffset) {
13119
13144
  (tView.components || (tView.components = ngDevMode ? new TViewComponents() : []))
13120
13145
  .push(hostTNode.index);
13121
13146
  }
13122
- /**
13123
- * Given an array of directives that were matched by their selectors, this function
13124
- * produces a new array that also includes any host directives that have to be applied.
13125
- * @param selectorMatches Directives matched in a template based on their selectors.
13126
- * @param tView Current TView.
13127
- * @param lView Current LView.
13128
- * @param tNode Current TNode that is being matched.
13129
- */
13130
- function findHostDirectiveDefs$1(selectorMatches, tView, lView, tNode) {
13131
- const matches = [];
13132
- for (const def of selectorMatches) {
13133
- if (def.findHostDirectiveDefs === null) {
13134
- matches.push(def);
13135
- }
13136
- else {
13137
- def.findHostDirectiveDefs(matches, def, tView, lView, tNode);
13138
- }
13139
- }
13140
- return matches;
13141
- }
13142
13147
  /** Caches local names and their matching directive indices for query and template lookups. */
13143
13148
  function cacheMatchingLocalNames(tNode, localRefs, exportsMap) {
13144
13149
  if (localRefs) {
@@ -13206,7 +13211,7 @@ function configureViewWithDirective(tView, tNode, lView, directiveIndex, def) {
13206
13211
  const nodeInjectorFactory = new NodeInjectorFactory(directiveFactory, isComponentDef(def), ɵɵdirectiveInject);
13207
13212
  tView.blueprint[directiveIndex] = nodeInjectorFactory;
13208
13213
  lView[directiveIndex] = nodeInjectorFactory;
13209
- registerHostBindingOpCodes(tView, tNode, lView, directiveIndex, allocExpando(tView, lView, def.hostVars, NO_CHANGE), def);
13214
+ registerHostBindingOpCodes(tView, tNode, directiveIndex, allocExpando(tView, lView, def.hostVars, NO_CHANGE), def);
13210
13215
  }
13211
13216
  function addComponentLogic(lView, hostTNode, def) {
13212
13217
  const native = getNativeByTNode(hostTNode, lView);
@@ -14129,6 +14134,7 @@ class ChainedInjector {
14129
14134
  this.parentInjector = parentInjector;
14130
14135
  }
14131
14136
  get(token, notFoundValue, flags) {
14137
+ flags = convertToBitFlags(flags);
14132
14138
  const value = this.injector.get(token, NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR, flags);
14133
14139
  if (value !== NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR ||
14134
14140
  notFoundValue === NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR) {
@@ -14205,42 +14211,23 @@ class ComponentFactory extends ComponentFactory$1 {
14205
14211
  let component;
14206
14212
  let tElementNode;
14207
14213
  try {
14208
- const componentView = createRootComponentView(hostRNode, this.componentDef, rootLView, rendererFactory, hostRenderer);
14214
+ const rootDirectives = [this.componentDef];
14215
+ const hostTNode = createRootComponentTNode(rootLView, hostRNode);
14216
+ const componentView = createRootComponentView(hostTNode, hostRNode, this.componentDef, rootDirectives, rootLView, rendererFactory, hostRenderer);
14217
+ tElementNode = getTNode(rootTView, HEADER_OFFSET);
14218
+ // TODO(crisbeto): in practice `hostRNode` should always be defined, but there are some tests
14219
+ // where the renderer is mocked out and `undefined` is returned. We should update the tests so
14220
+ // that this check can be removed.
14209
14221
  if (hostRNode) {
14210
- if (rootSelectorOrNode) {
14211
- setUpAttributes(hostRenderer, hostRNode, ['ng-version', VERSION.full]);
14212
- }
14213
- else {
14214
- // If host element is created as a part of this function call (i.e. `rootSelectorOrNode`
14215
- // is not defined), also apply attributes and classes extracted from component selector.
14216
- // Extract attributes and classes from the first selector only to match VE behavior.
14217
- const { attrs, classes } = extractAttrsAndClassesFromSelector(this.componentDef.selectors[0]);
14218
- if (attrs) {
14219
- setUpAttributes(hostRenderer, hostRNode, attrs);
14220
- }
14221
- if (classes && classes.length > 0) {
14222
- writeDirectClass(hostRenderer, hostRNode, classes.join(' '));
14223
- }
14224
- }
14222
+ setRootNodeAttributes(hostRenderer, this.componentDef, hostRNode, rootSelectorOrNode);
14225
14223
  }
14226
- tElementNode = getTNode(rootTView, HEADER_OFFSET);
14227
14224
  if (projectableNodes !== undefined) {
14228
- const projection = tElementNode.projection = [];
14229
- for (let i = 0; i < this.ngContentSelectors.length; i++) {
14230
- const nodesforSlot = projectableNodes[i];
14231
- // Projectable nodes can be passed as array of arrays or an array of iterables (ngUpgrade
14232
- // case). Here we do normalize passed data structure to be an array of arrays to avoid
14233
- // complex checks down the line.
14234
- // We also normalize the length of the passed in projectable nodes (to match the number of
14235
- // <ng-container> slots defined by a component).
14236
- projection.push(nodesforSlot != null ? Array.from(nodesforSlot) : null);
14237
- }
14225
+ projectNodes(tElementNode, this.ngContentSelectors, projectableNodes);
14238
14226
  }
14239
14227
  // TODO: should LifecycleHooksFeature and other host features be generated by the compiler and
14240
14228
  // executed here?
14241
14229
  // Angular 5 reference: https://stackblitz.com/edit/lifecycle-hooks-vcref
14242
- component =
14243
- createRootComponent(componentView, this.componentDef, rootLView, [LifecycleHooksFeature]);
14230
+ component = createRootComponent(componentView, this.componentDef, rootDirectives, rootLView, [LifecycleHooksFeature]);
14244
14231
  renderView(rootTView, rootLView, null);
14245
14232
  }
14246
14233
  finally {
@@ -14311,11 +14298,22 @@ const NULL_INJECTOR = {
14311
14298
  throwProviderNotFoundError(token, 'NullInjector');
14312
14299
  }
14313
14300
  };
14301
+ /** Creates a TNode that can be used to instantiate a root component. */
14302
+ function createRootComponentTNode(lView, rNode) {
14303
+ const tView = lView[TVIEW];
14304
+ const index = HEADER_OFFSET;
14305
+ ngDevMode && assertIndexInRange(lView, index);
14306
+ lView[index] = rNode;
14307
+ // '#host' is added here as we don't know the real host DOM name (we don't want to read it) and at
14308
+ // the same time we want to communicate the debug `TNode` that this is a special `TNode`
14309
+ // representing a host element.
14310
+ return getOrCreateTNode(tView, index, 2 /* TNodeType.Element */, '#host', null);
14311
+ }
14314
14312
  /**
14315
14313
  * Creates the root component view and the root component node.
14316
14314
  *
14317
14315
  * @param rNode Render host element.
14318
- * @param def ComponentDef
14316
+ * @param rootComponentDef ComponentDef
14319
14317
  * @param rootView The parent view where the host node is stored
14320
14318
  * @param rendererFactory Factory to be used for creating child renderers.
14321
14319
  * @param hostRenderer The current renderer
@@ -14323,72 +14321,96 @@ const NULL_INJECTOR = {
14323
14321
  *
14324
14322
  * @returns Component view created
14325
14323
  */
14326
- function createRootComponentView(rNode, def, rootView, rendererFactory, hostRenderer, sanitizer) {
14324
+ function createRootComponentView(tNode, rNode, rootComponentDef, rootDirectives, rootView, rendererFactory, hostRenderer, sanitizer) {
14327
14325
  const tView = rootView[TVIEW];
14328
- const index = HEADER_OFFSET;
14329
- ngDevMode && assertIndexInRange(rootView, index);
14330
- rootView[index] = rNode;
14331
- // '#host' is added here as we don't know the real host DOM name (we don't want to read it) and at
14332
- // the same time we want to communicate the debug `TNode` that this is a special `TNode`
14333
- // representing a host element.
14334
- const tNode = getOrCreateTNode(tView, index, 2 /* TNodeType.Element */, '#host', null);
14335
- const mergedAttrs = tNode.mergedAttrs = def.hostAttrs;
14336
- if (mergedAttrs !== null) {
14337
- computeStaticStyling(tNode, mergedAttrs, true);
14338
- if (rNode !== null) {
14339
- setUpAttributes(hostRenderer, rNode, mergedAttrs);
14340
- if (tNode.classes !== null) {
14341
- writeDirectClass(hostRenderer, rNode, tNode.classes);
14342
- }
14343
- if (tNode.styles !== null) {
14344
- writeDirectStyle(hostRenderer, rNode, tNode.styles);
14345
- }
14346
- }
14347
- }
14348
- const viewRenderer = rendererFactory.createRenderer(rNode, def);
14349
- const componentView = createLView(rootView, getOrCreateComponentTView(def), null, def.onPush ? 32 /* LViewFlags.Dirty */ : 16 /* LViewFlags.CheckAlways */, rootView[index], tNode, rendererFactory, viewRenderer, sanitizer || null, null, null);
14326
+ applyRootComponentStyling(rootDirectives, tNode, rNode, hostRenderer);
14327
+ const viewRenderer = rendererFactory.createRenderer(rNode, rootComponentDef);
14328
+ const componentView = createLView(rootView, getOrCreateComponentTView(rootComponentDef), null, rootComponentDef.onPush ? 32 /* LViewFlags.Dirty */ : 16 /* LViewFlags.CheckAlways */, rootView[tNode.index], tNode, rendererFactory, viewRenderer, sanitizer || null, null, null);
14350
14329
  if (tView.firstCreatePass) {
14351
- diPublicInInjector(getOrCreateNodeInjectorForNode(tNode, rootView), tView, def.type);
14330
+ diPublicInInjector(getOrCreateNodeInjectorForNode(tNode, rootView), tView, rootComponentDef.type);
14352
14331
  markAsComponentHost(tView, tNode, 0);
14353
- initTNodeFlags(tNode, rootView.length, 1);
14354
14332
  }
14355
14333
  addToViewTree(rootView, componentView);
14356
14334
  // Store component view at node index, with node as the HOST
14357
- return rootView[index] = componentView;
14335
+ return rootView[tNode.index] = componentView;
14336
+ }
14337
+ /** Sets up the styling information on a root component. */
14338
+ function applyRootComponentStyling(rootDirectives, tNode, rNode, hostRenderer) {
14339
+ for (const def of rootDirectives) {
14340
+ tNode.mergedAttrs = mergeHostAttrs(tNode.mergedAttrs, def.hostAttrs);
14341
+ }
14342
+ if (tNode.mergedAttrs !== null) {
14343
+ computeStaticStyling(tNode, tNode.mergedAttrs, true);
14344
+ if (rNode !== null) {
14345
+ setupStaticAttributes(hostRenderer, rNode, tNode);
14346
+ }
14347
+ }
14358
14348
  }
14359
14349
  /**
14360
14350
  * Creates a root component and sets it up with features and host bindings.Shared by
14361
14351
  * renderComponent() and ViewContainerRef.createComponent().
14362
14352
  */
14363
- function createRootComponent(componentView, componentDef, rootLView, hostFeatures) {
14353
+ function createRootComponent(componentView, rootComponentDef, rootDirectives, rootLView, hostFeatures) {
14354
+ const rootTNode = getCurrentTNode();
14355
+ ngDevMode && assertDefined(rootTNode, 'tNode should have been already created');
14364
14356
  const tView = rootLView[TVIEW];
14365
- // Create directive instance with factory() and store at next index in viewData
14366
- const component = instantiateRootComponent(tView, rootLView, componentDef);
14367
- // Root view only contains an instance of this component,
14368
- // so we use a reference to that component instance as a context.
14357
+ const native = getNativeByTNode(rootTNode, rootLView);
14358
+ initializeDirectives(tView, rootLView, rootTNode, rootDirectives, null);
14359
+ for (let i = 0; i < rootDirectives.length; i++) {
14360
+ const directiveIndex = rootTNode.directiveStart + i;
14361
+ const directiveInstance = getNodeInjectable(rootLView, tView, directiveIndex, rootTNode);
14362
+ attachPatchData(directiveInstance, rootLView);
14363
+ }
14364
+ invokeDirectivesHostBindings(tView, rootLView, rootTNode);
14365
+ if (native) {
14366
+ attachPatchData(native, rootLView);
14367
+ }
14368
+ // We're guaranteed for the `componentOffset` to be positive here
14369
+ // since a root component always matches a component def.
14370
+ ngDevMode &&
14371
+ assertGreaterThan(rootTNode.componentOffset, -1, 'componentOffset must be great than -1');
14372
+ const component = getNodeInjectable(rootLView, tView, rootTNode.directiveStart + rootTNode.componentOffset, rootTNode);
14369
14373
  componentView[CONTEXT] = rootLView[CONTEXT] = component;
14370
14374
  if (hostFeatures !== null) {
14371
14375
  for (const feature of hostFeatures) {
14372
- feature(component, componentDef);
14376
+ feature(component, rootComponentDef);
14373
14377
  }
14374
14378
  }
14375
14379
  // We want to generate an empty QueryList for root content queries for backwards
14376
14380
  // compatibility with ViewEngine.
14377
- if (componentDef.contentQueries) {
14378
- const tNode = getCurrentTNode();
14379
- ngDevMode && assertDefined(tNode, 'TNode expected');
14380
- componentDef.contentQueries(1 /* RenderFlags.Create */, component, tNode.directiveStart);
14381
+ executeContentQueries(tView, rootTNode, componentView);
14382
+ return component;
14383
+ }
14384
+ /** Sets the static attributes on a root component. */
14385
+ function setRootNodeAttributes(hostRenderer, componentDef, hostRNode, rootSelectorOrNode) {
14386
+ if (rootSelectorOrNode) {
14387
+ setUpAttributes(hostRenderer, hostRNode, ['ng-version', VERSION.full]);
14381
14388
  }
14382
- const rootTNode = getCurrentTNode();
14383
- ngDevMode && assertDefined(rootTNode, 'tNode should have been already created');
14384
- if (tView.firstCreatePass &&
14385
- (componentDef.hostBindings !== null || componentDef.hostAttrs !== null)) {
14386
- setSelectedIndex(rootTNode.index);
14387
- const rootTView = rootLView[TVIEW];
14388
- registerHostBindingOpCodes(rootTView, rootTNode, rootLView, rootTNode.directiveStart, rootTNode.directiveEnd, componentDef);
14389
- invokeHostBindingsInCreationMode(componentDef, component);
14389
+ else {
14390
+ // If host element is created as a part of this function call (i.e. `rootSelectorOrNode`
14391
+ // is not defined), also apply attributes and classes extracted from component selector.
14392
+ // Extract attributes and classes from the first selector only to match VE behavior.
14393
+ const { attrs, classes } = extractAttrsAndClassesFromSelector(componentDef.selectors[0]);
14394
+ if (attrs) {
14395
+ setUpAttributes(hostRenderer, hostRNode, attrs);
14396
+ }
14397
+ if (classes && classes.length > 0) {
14398
+ writeDirectClass(hostRenderer, hostRNode, classes.join(' '));
14399
+ }
14400
+ }
14401
+ }
14402
+ /** Projects the `projectableNodes` that were specified when creating a root component. */
14403
+ function projectNodes(tNode, ngContentSelectors, projectableNodes) {
14404
+ const projection = tNode.projection = [];
14405
+ for (let i = 0; i < ngContentSelectors.length; i++) {
14406
+ const nodesforSlot = projectableNodes[i];
14407
+ // Projectable nodes can be passed as array of arrays or an array of iterables (ngUpgrade
14408
+ // case). Here we do normalize passed data structure to be an array of arrays to avoid
14409
+ // complex checks down the line.
14410
+ // We also normalize the length of the passed in projectable nodes (to match the number of
14411
+ // <ng-container> slots defined by a component).
14412
+ projection.push(nodesforSlot != null ? Array.from(nodesforSlot) : null);
14390
14413
  }
14391
- return component;
14392
14414
  }
14393
14415
  /**
14394
14416
  * Used to enable lifecycle hooks on the root component.
@@ -14695,10 +14717,9 @@ function findHostDirectiveDefs(matches, def, tView, lView, tNode) {
14695
14717
  // TODO(crisbeto): assert that the def exists.
14696
14718
  // Host directives execute before the host so that its host bindings can be overwritten.
14697
14719
  findHostDirectiveDefs(matches, hostDirectiveDef, tView, lView, tNode);
14720
+ matches.push(hostDirectiveDef);
14698
14721
  }
14699
14722
  }
14700
- // Push the def itself at the end since it needs to execute after the host directives.
14701
- matches.push(def);
14702
14723
  }
14703
14724
  /**
14704
14725
  * Converts an array in the form of `['publicName', 'alias', 'otherPublicName', 'otherAlias']` into
@@ -15657,18 +15678,7 @@ function ɵɵelementStart(index, name, attrsIndex, localRefsIndex) {
15657
15678
  elementStartFirstCreatePass(adjustedIndex, tView, lView, native, name, attrsIndex, localRefsIndex) :
15658
15679
  tView.data[adjustedIndex];
15659
15680
  setCurrentTNode(tNode, true);
15660
- const mergedAttrs = tNode.mergedAttrs;
15661
- if (mergedAttrs !== null) {
15662
- setUpAttributes(renderer, native, mergedAttrs);
15663
- }
15664
- const classes = tNode.classes;
15665
- if (classes !== null) {
15666
- writeDirectClass(renderer, native, classes);
15667
- }
15668
- const styles = tNode.styles;
15669
- if (styles !== null) {
15670
- writeDirectStyle(renderer, native, styles);
15671
- }
15681
+ setupStaticAttributes(renderer, native, tNode);
15672
15682
  if ((tNode.flags & 32 /* TNodeFlags.isDetached */) !== 32 /* TNodeFlags.isDetached */) {
15673
15683
  // In the i18n case, the translation may have removed this element, so only add it if it is not
15674
15684
  // detached. See `TNodeType.Placeholder` and `LFrame.inI18n` for more context.
@@ -22358,7 +22368,7 @@ function getDirectives(node) {
22358
22368
  return [];
22359
22369
  }
22360
22370
  if (context.directives === undefined) {
22361
- context.directives = getDirectivesAtNodeIndex(nodeIndex, lView, false);
22371
+ context.directives = getDirectivesAtNodeIndex(nodeIndex, lView);
22362
22372
  }
22363
22373
  // The `directives` in this case are a named array called `LComponentView`. Clone the
22364
22374
  // result so we don't expose an internal data structure in the user's console.
@@ -26135,7 +26145,7 @@ class TestBedImpl {
26135
26145
  return TestBedImpl.INSTANCE.overrideProvider(token, provider);
26136
26146
  }
26137
26147
  static inject(token, notFoundValue, flags) {
26138
- return TestBedImpl.INSTANCE.inject(token, notFoundValue, flags);
26148
+ return TestBedImpl.INSTANCE.inject(token, notFoundValue, ɵconvertToBitFlags(flags));
26139
26149
  }
26140
26150
  /** @deprecated from v9.0.0 use TestBed.inject */
26141
26151
  static get(token, notFoundValue = Injector$1.THROW_IF_NOT_FOUND, flags = InjectFlags$1.Default) {
@@ -26268,7 +26278,7 @@ class TestBedImpl {
26268
26278
  return this;
26269
26279
  }
26270
26280
  const UNDEFINED = {};
26271
- const result = this.testModuleRef.injector.get(token, UNDEFINED, flags);
26281
+ const result = this.testModuleRef.injector.get(token, UNDEFINED, ɵconvertToBitFlags(flags));
26272
26282
  return result === UNDEFINED ? this.compiler.injector.get(token, notFoundValue, flags) :
26273
26283
  result;
26274
26284
  }