refactor(compiler): move matchSource into base metadata

Moves the `matchSource` into the base metadata so the binder can use it.
This commit is contained in:
Kristiyan Kostadinov
2026-04-01 10:46:42 +02:00
committed by Andrew Scott
parent 4651b93a92
commit 927ae3abc8
12 changed files with 39 additions and 17 deletions
@@ -156,6 +156,20 @@ export interface DirectiveMeta {
* Only includes the legacy animation names.
*/
animationTriggerNames: LegacyAnimationTriggerNames | null;
/** Tracks how the directive was matched. */
matchSource: MatchSource;
}
/**
* Possible ways that a directive can be matched.
*/
export enum MatchSource {
/** The directive was matched by its selector. */
Selector,
/** The directive was applied as a host directive. */
HostDirective,
}
/**
@@ -8,7 +8,7 @@
import * as e from '../../../src/expression_parser/ast';
import * as a from '../../../src/render3/r3_ast';
import {DirectiveMeta, InputOutputPropertySet} from '../../../src/render3/view/t2_api';
import {DirectiveMeta, InputOutputPropertySet, MatchSource} from '../../../src/render3/view/t2_api';
import {findMatchingDirectivesAndPipes, R3TargetBinder} from '../../../src/render3/view/t2_binder';
import {parseTemplate, ParseTemplateOptions} from '../../../src/render3/view/template';
import {CssSelector, SelectorlessMatcher, SelectorMatcher} from '../../../src/directive_matching';
@@ -44,6 +44,7 @@ function makeSelectorMatcher(): SelectorMatcher<DirectiveMeta[]> {
animationTriggerNames: null,
ngContentSelectors: null,
preserveWhitespaces: false,
matchSource: MatchSource.Selector,
},
]);
matcher.addSelectables(CssSelector.parse('[dir]'), [
@@ -58,6 +59,7 @@ function makeSelectorMatcher(): SelectorMatcher<DirectiveMeta[]> {
animationTriggerNames: null,
ngContentSelectors: null,
preserveWhitespaces: false,
matchSource: MatchSource.Selector,
},
]);
matcher.addSelectables(CssSelector.parse('[hasOutput]'), [
@@ -72,6 +74,7 @@ function makeSelectorMatcher(): SelectorMatcher<DirectiveMeta[]> {
animationTriggerNames: null,
ngContentSelectors: null,
preserveWhitespaces: false,
matchSource: MatchSource.Selector,
},
]);
matcher.addSelectables(CssSelector.parse('[hasInput]'), [
@@ -86,6 +89,7 @@ function makeSelectorMatcher(): SelectorMatcher<DirectiveMeta[]> {
animationTriggerNames: null,
ngContentSelectors: null,
preserveWhitespaces: false,
matchSource: MatchSource.Selector,
},
]);
matcher.addSelectables(CssSelector.parse('[sameSelectorAsInput]'), [
@@ -100,6 +104,7 @@ function makeSelectorMatcher(): SelectorMatcher<DirectiveMeta[]> {
animationTriggerNames: null,
ngContentSelectors: null,
preserveWhitespaces: false,
matchSource: MatchSource.Selector,
},
]);
matcher.addSelectables(CssSelector.parse('comp'), [
@@ -114,6 +119,7 @@ function makeSelectorMatcher(): SelectorMatcher<DirectiveMeta[]> {
animationTriggerNames: null,
ngContentSelectors: null,
preserveWhitespaces: false,
matchSource: MatchSource.Selector,
},
]);
@@ -133,6 +139,7 @@ function makeSelectorMatcher(): SelectorMatcher<DirectiveMeta[]> {
animationTriggerNames: null,
ngContentSelectors: null,
preserveWhitespaces: false,
matchSource: MatchSource.Selector,
},
]);
}
@@ -282,6 +289,7 @@ describe('t2 binding', () => {
animationTriggerNames: null,
ngContentSelectors: null,
preserveWhitespaces: false,
matchSource: MatchSource.Selector,
},
]);
const binder = new R3TargetBinder(matcher);
@@ -1039,6 +1047,7 @@ describe('t2 binding', () => {
preserveWhitespaces: false,
animationTriggerNames: null,
isComponent: false,
matchSource: MatchSource.Selector,
};
function makeSelectorlessMatcher(