angular/packages/core/test/render3
Kristiyan Kostadinov 06ca0dcf27 refactor(core): remove assumptions that component will be first in directives list (#47490)
`TNode`s have the `directiveStart` and `directiveEnd` properties that indicate the indexes at which directive instances (including components) have been stored. Currently there are several places throughout the codebase which assume that if a component matches a node, its index will always be `directiveStart`.

As far as I can tell, we probably ended up accumulating these assumptions, because we needed a quick way of accessing the component instance and it happened to be conventiently stored at `directiveStart`. The reason why it's always stored at `directiveStart` is likely to match the lifecycle hook execution order from ViewEngine.

With host directives these assumptions won't be valid anymore, because we want the host directives to _always_ execute before the host component that they're on so that the host has a chance to override them. To achieve this we have to insert host directives before the component.

These changes address the issue by introducing a new `TNode.componentOffset` property which indicates the offset after `TNode.directiveStart` at which the component is stored. Furthermore, I've removed the `isComponentHost` flag since it was duplicating the information from `TNode.componentOffset` and I've audited and fixed all the places where we read `directiveStart` to account for the changed data structure.

Reasons for some of the decisions I made along the way:
* In the case of host directives, I decided to go against our current convention of executing the component lifecycle hooks before the directive, because lifeycle hooks are a chance to change the component state (e.g. in `ngOnChanges`) and running the component hooks first would allow the host directives to undo any overrides made by the host.
* I decided to go with a `componentOffset`, instead of a `componentIndex` indicating the exact index the component is at, because as the runtime is set up at the moment, it would be difficult to know what index the component is going to end up at. Another problem is that we appear to have some logic that moves the entire "directive window" by incrementing both `directiveStart` and `directiveEnd`. By using an offset, we don't have to worry about the index remaining correct.

PR Close #47490
2022-09-21 10:05:32 +02:00
..
i18n test(core): avoid TemplateFixture usages in i18n spec (#46571) 2022-06-29 10:01:35 -07:00
instructions test(core): migrate tests off of Renderer3 interfaces (#46605) 2022-06-30 09:04:56 -07:00
interfaces ci: add lint error for files with missing trailing new-line (#42478) 2021-06-04 13:31:03 -07:00
ivy fix(core): Resolve forwardRef declarations for jit (#46334) 2022-06-13 16:59:59 +00:00
jit refactor(core): change component emit to 'dependencies' (#45672) 2022-04-20 05:45:56 -07:00
perf test(core): migrate tests off of Renderer3 interfaces (#46605) 2022-06-30 09:04:56 -07:00
styling_next refactor(core): Ensure that previousOrParentTNode always belongs to current TView. (#38707) 2020-09-28 16:15:58 -04:00
util test: clean up internal testing utilities (#42177) 2021-05-26 20:07:25 +00:00
BUILD.bazel build: switch devmode output to es2015 (#44505) 2022-01-05 23:20:20 +00:00
change_detection_spec.ts refactor(core): drop unused fields from the RootContext (#46806) 2022-08-05 09:58:06 -07:00
component_ref_spec.ts feat(core): add ability to set inputs on ComponentRef (#46641) 2022-07-01 13:45:46 -07:00
di_spec.ts test(core): update di_spec.ts to use TestBed (#46522) 2022-06-27 15:15:50 -07:00
es2015-tsconfig.json fix(core): destroy hooks not set up for useClass provider using forwardRef (#44281) 2021-11-30 11:56:05 -05:00
global_utils_spec.ts feat(core): introduce getDirectiveMetadata global debugging utility (#41525) 2021-04-13 16:06:32 -07:00
i18n_debug_spec.ts build: bundle spec files for saucelabs legacy job (#44281) 2021-11-30 11:56:04 -05:00
imported_renderer2.ts refactor: add override keyword to members implementing abstract declarations (#42512) 2021-07-12 13:11:17 -07:00
instructions_spec.ts test(core): update various tests to avoid referencing TemplateFixture (#46571) 2022-06-29 10:01:35 -07:00
integration_spec.ts feat(core): support TypeScript 4.8 (#47038) 2022-08-16 16:02:47 +00:00
is_shape_of.ts refactor(core): remove assumptions that component will be first in directives list (#47490) 2022-09-21 10:05:32 +02:00
is_shape_of_spec.ts ci: add lint error for files with missing trailing new-line (#42478) 2021-06-04 13:31:03 -07:00
jit_environment_spec.ts refactor(compiler-cli): introduce declaration function to declare class metadata (#41200) 2021-04-12 10:41:17 -07:00
load_domino.ts build: clean up references to old master branch (#45856) 2022-05-04 16:23:33 -07:00
matchers.ts build: update to jasmine 4.0 (#45558) 2022-04-11 16:25:28 +00:00
matchers_spec.ts build: update to jasmine 4.0 (#45558) 2022-04-11 16:25:28 +00:00
metadata_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
node_selector_matcher_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
providers_helper.ts test(core): convert providers test utility to TestBed (#46527) 2022-06-27 15:15:00 -07:00
providers_spec.ts test(core): use TestBed & JIT instead of handwritten defs in providers_spec (#46527) 2022-06-27 15:15:00 -07:00
query_spec.ts test(core): refactor tests to use TestBed instead of hand-written instructions (#46561) 2022-06-28 21:28:21 -07:00
testing_spec.ts test: update tests to account for karma-jasmine v5.0.0 2022-07-18 19:19:00 +02:00
utils.ts build: update to jasmine 4.0 (#45558) 2022-04-11 16:25:28 +00:00
view_fixture.ts test(core): update various tests to avoid referencing TemplateFixture (#46571) 2022-06-29 10:01:35 -07:00
view_utils_spec.ts fix(core): Store ICU state in LView rather than in TView (#39233) 2020-10-21 18:33:00 -07:00