Skip to content

Commit

Permalink
refactor(compiler): extend directive mock to avoid failing at matchin…
Browse files Browse the repository at this point in the history
…g logic

This commit updates a directive mock instance to include an extra field that a compiler code was expecting, which caused issues while processing elements with local refs and exported directives.
  • Loading branch information
AndrewKushnir committed Aug 26, 2024
1 parent 969dadc commit 0255ef9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/compiler/src/render3/view/t2_binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export function findMatchingDirectivesAndPipes(template: string, directiveSelect
// function internally).
const fakeDirective = {
selector,
exportAs: null,
inputs: {
hasBindingPropertyName() {
return false;
Expand Down
29 changes: 29 additions & 0 deletions packages/compiler/test/render3/view/binding_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,35 @@ describe('findMatchingDirectivesAndPipes', () => {
},
});
});

it('should handle directives on elements with local refs', () => {
const template = `
<input [(ngModel)]="name" #ctrl="ngModel" required />
@defer {
<my-defer-cmp [label]="abc | lowercase" [title]="abc | uppercase" />
<input [(ngModel)]="name" #ctrl="ngModel" required />
} @placeholder {}
`;
const directiveSelectors = [
'[ngModel]:not([formControlName]):not([formControl])',
'[title]',
'my-defer-cmp',
'not-matching',
];
const result = findMatchingDirectivesAndPipes(template, directiveSelectors);
expect(result).toEqual({
directives: {
// `ngModel` is used both eagerly and in a defer block, thus it's located
// in the "regular" (eager) bucket.
regular: ['[ngModel]:not([formControlName]):not([formControl])'],
deferCandidates: ['my-defer-cmp', '[title]'],
},
pipes: {
regular: [],
deferCandidates: ['lowercase', 'uppercase'],
},
});
});
});

describe('t2 binding', () => {
Expand Down

0 comments on commit 0255ef9

Please sign in to comment.