Skip to content

Commit 3d86b3a

Browse files
crisbetopkozlowski-opensource
authored andcommitted
refactor(compiler): account for selectorless in template binder (angular#60952)
Updates the template binder to account for the new selectorless AST nodes. This is a prerequisite to supporting template type checking of the new syntax. PR Close angular#60952
1 parent 3719752 commit 3d86b3a

File tree

4 files changed

+466
-107
lines changed

4 files changed

+466
-107
lines changed

packages/compiler-cli/src/ngtsc/indexer/src/template.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,12 @@ class TemplateVisitor extends TmplAstRecursiveVisitor {
377377

378378
/** Creates an identifier for a template element or template node. */
379379
private elementOrTemplateToIdentifier(
380-
node: TmplAstElement | TmplAstTemplate,
380+
node: TmplAstElement | TmplAstTemplate | TmplAstComponent | TmplAstDirective,
381381
): ElementIdentifier | TemplateNodeIdentifier | null {
382+
if (node instanceof TmplAstComponent || node instanceof TmplAstDirective) {
383+
throw new Error('TODO');
384+
}
385+
382386
// If this node has already been seen, return the cached result.
383387
if (this.elementAndTemplateIdentifierCache.has(node)) {
384388
return this.elementAndTemplateIdentifierCache.get(node)!;
@@ -465,7 +469,12 @@ class TemplateVisitor extends TmplAstRecursiveVisitor {
465469
if (refTarget) {
466470
let node: ElementIdentifier | TemplateNodeIdentifier | null = null;
467471
let directive: ClassDeclaration<DeclarationNode> | null = null;
468-
if (refTarget instanceof TmplAstElement || refTarget instanceof TmplAstTemplate) {
472+
if (
473+
refTarget instanceof TmplAstElement ||
474+
refTarget instanceof TmplAstTemplate ||
475+
refTarget instanceof TmplAstComponent ||
476+
refTarget instanceof TmplAstDirective
477+
) {
469478
node = this.elementOrTemplateToIdentifier(refTarget);
470479
} else {
471480
node = this.elementOrTemplateToIdentifier(refTarget.node);

packages/compiler/src/render3/view/t2_api.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import {AST} from '../../expression_parser/ast';
1010
import {
1111
BoundAttribute,
1212
BoundEvent,
13+
Component,
1314
Content,
1415
DeferredBlock,
1516
DeferredBlockError,
1617
DeferredBlockLoading,
1718
DeferredBlockPlaceholder,
1819
DeferredTrigger,
20+
Directive,
1921
Element,
2022
ForLoopBlock,
2123
ForLoopBlockEmpty,
@@ -48,7 +50,7 @@ export type ScopedNode =
4850
export type ReferenceTarget<DirectiveT> =
4951
| {
5052
directive: DirectiveT;
51-
node: Element | Template;
53+
node: Element | Template | Component | Directive;
5254
}
5355
| Element
5456
| Template;
@@ -181,7 +183,7 @@ export interface BoundTarget<DirectiveT extends DirectiveMeta> {
181183
* For a given template node (either an `Element` or a `Template`), get the set of directives
182184
* which matched the node, if any.
183185
*/
184-
getDirectivesOfNode(node: Element | Template): DirectiveT[] | null;
186+
getDirectivesOfNode(node: Element | Template | Component): DirectiveT[] | null;
185187

186188
/**
187189
* For a given `Reference`, get the reference's target - either an `Element`, a `Template`, or
@@ -270,5 +272,5 @@ export interface BoundTarget<DirectiveT extends DirectiveMeta> {
270272
/**
271273
* Whether a given node is located in a `@defer` block.
272274
*/
273-
isDeferred(node: Element): boolean;
275+
isDeferred(node: Element | Component): boolean;
274276
}

0 commit comments

Comments
 (0)