Skip to content

Commit 5600c4f

Browse files
committed
refactor(compiler-cli): tag host directives in TCB
Add HOST_DIRECTIVE expression identifier to TCB comments to identify host directives.
1 parent ecae525 commit 5600c4f

4 files changed

Lines changed: 15 additions & 5 deletions

File tree

packages/compiler-cli/src/ngtsc/typecheck/src/comments.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export enum CommentTriviaType {
4646
/** Identifies what the TCB expression is for (for example, a directive declaration). */
4747
export enum ExpressionIdentifier {
4848
DIRECTIVE = 'DIR',
49+
HOST_DIRECTIVE = 'HOSTDIR',
4950
COMPONENT_COMPLETION = 'COMPCOMP',
5051
EVENT_PARAMETER = 'EP',
5152
VARIABLE_AS_EXPRESSION = 'VAE',

packages/compiler-cli/src/ngtsc/typecheck/src/ops/directive_constructor.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {DirectiveOwner, ParseSourceSpan, TmplAstHostElement} from '@angular/compiler';
9+
import {DirectiveOwner, MatchSource, ParseSourceSpan, TmplAstHostElement} from '@angular/compiler';
1010
import {TcbOp} from './base';
1111
import {quoteAndEscape, TcbExpr} from './codegen';
1212
import {Context} from './context';
@@ -74,7 +74,11 @@ export class TcbDirectiveCtorOp extends TcbOp {
7474
}
7575
}
7676

77-
id.addExpressionIdentifier(ExpressionIdentifier.DIRECTIVE).addParseSpanInfo(span);
77+
const identifier =
78+
this.dir.matchSource === MatchSource.HostDirective
79+
? ExpressionIdentifier.HOST_DIRECTIVE
80+
: ExpressionIdentifier.DIRECTIVE;
81+
id.addExpressionIdentifier(identifier).addParseSpanInfo(span);
7882

7983
for (const attr of boundAttrs) {
8084
// Skip text attributes if configured to do so.

packages/compiler-cli/src/ngtsc/typecheck/src/ops/directive_type.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {DirectiveOwner, ParseSourceSpan, TmplAstHostElement} from '@angular/compiler';
9+
import {DirectiveOwner, MatchSource, ParseSourceSpan, TmplAstHostElement} from '@angular/compiler';
1010
import type {Context} from './context';
1111
import type {Scope} from './scope';
1212
import {TcbOp} from './base';
@@ -59,8 +59,12 @@ export abstract class TcbDirectiveTypeOpBase extends TcbOp {
5959
span = this.node.startSourceSpan || this.node.sourceSpan;
6060
}
6161

62+
const identifier =
63+
this.dir.matchSource === MatchSource.HostDirective
64+
? ExpressionIdentifier.HOST_DIRECTIVE
65+
: ExpressionIdentifier.DIRECTIVE;
6266
const id = new TcbExpr(this.tcb.allocateId())
63-
.addExpressionIdentifier(ExpressionIdentifier.DIRECTIVE)
67+
.addExpressionIdentifier(identifier)
6468
.addParseSpanInfo(span);
6569
this.scope.addStatement(declareVariable(id, type));
6670
return id;

packages/compiler-cli/src/ngtsc/typecheck/src/ts_util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export function isDirectiveDeclaration(node: ts.Node): node is ts.TypeNode | ts.
2727
return (
2828
(ts.isTypeNode(node) || ts.isIdentifier(node)) &&
2929
ts.isVariableDeclaration(node.parent) &&
30-
hasExpressionIdentifier(sourceFile, node, ExpressionIdentifier.DIRECTIVE)
30+
(hasExpressionIdentifier(sourceFile, node, ExpressionIdentifier.DIRECTIVE) ||
31+
hasExpressionIdentifier(sourceFile, node, ExpressionIdentifier.HOST_DIRECTIVE))
3132
);
3233
}
3334

0 commit comments

Comments
 (0)