8000 Type checking support for host bindings by crisbeto · Pull Request #60267 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

Type checking support for host bindings #60267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Next Next commit
refactor(compiler): add AST node for host element
Adds the `HostElement` AST node that can be used to represent the host of a directive. Also exposes the `BindingParser` type so it's easier to pass around the return value of `makeBindingParser`.
  • Loading branch information
crisbeto committed Mar 17, 2025
commit 35e460dd2acdb1b103b18d39506bca1bf8ce2ee0
5 changes: 5 additions & 0 deletions packages/compiler/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export {
UnknownBlock as TmplAstUnknownBlock,
Variable as TmplAstVariable,
ViewportDeferredTrigger as TmplAstViewportDeferredTrigger,
HostElement as TmplAstHostElement,
visitAll as tmplAstVisitAll,
Visitor as TmplAstVisitor,
} from './render3/r3_ast';
Expand Down Expand Up @@ -234,6 +235,10 @@ export {
parseTemplate,
ParseTemplateOptions,
} from './render3/view/template';

// Note: BindingParser is intentionally exported as a type only, because it should
// be constructed through `makeBindingParser`, rather than its constructor.
export {type BindingParser} from './template_parser/binding_parser';
export {createCssSelectorFromNode} from './render3/view/util';
export * from './resource_loader';
export * from './schema/dom_element_schema_registry';
Expand Down
21 changes: 21 additions & 0 deletions packages/compiler/src/render3/r3_ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,27 @@ export class Icu implements Node {
}
}

/**
* AST node that represents the host element of a directive.
* This node is used only for type checking purposes and cannot be produced from a user's template.
*/
export class HostElement implements Node {
constructor(
readonly tagNames: string[],
readonly bindings: BoundAttribute[],
readonly listeners: BoundEvent[],
readonly sourceSpan: ParseSourceSpan,
) {
if (tagNames.length === 0) {
throw new Error('HostElement must have at least one tag name.');
}
}

visit<Result>(): Result {
throw new Error(`HostElement cannot be visited`);
}
}

export interface Visitor<Result = any> {
// Returning a truthy value from `visit()` will prevent `visitAll()` from the call to the typed
// method and result returned will become the result included in `visitAll()`s result array.
Expand Down
0