Skip to content

Commit 3783ee0

Browse files
dylhunnAndrewKushnir
authored andcommitted
refactor(compiler): Rename DirectiveInScope -> PotentialDirective (#47561)
After implementing `getPotentialTemplateDirectives`, we will use this data struture to represent both in-scope and out-of-scope directives. So this rename is an advance cleanup. PR Close #47561
1 parent e3cef4a commit 3783ee0

File tree

7 files changed

+23
-22
lines changed

7 files changed

+23
-22
lines changed

packages/compiler-cli/src/ngtsc/typecheck/api/checker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {ErrorCode} from '../../diagnostics';
1414

1515
import {FullTemplateMapping, NgTemplateDiagnostic, TypeCheckableDirectiveMeta} from './api';
1616
import {GlobalCompletion} from './completion';
17-
import {DirectiveInScope, PipeInScope} from './scope';
17+
import {PipeInScope, PotentialDirective} from './scope';
1818
import {ElementSymbol, Symbol, TcbLocation, TemplateSymbol} from './symbols';
1919

2020
/**
@@ -131,19 +131,19 @@ export interface TemplateTypeChecker {
131131
/**
132132
* Get basic metadata on the directives which are in scope for the given component.
133133
*/
134-
getDirectivesInScope(component: ts.ClassDeclaration): DirectiveInScope[]|null;
134+
getDirectivesInScope(component: ts.ClassDeclaration): PotentialDirective[]|null;
135135

136136
/**
137137
* Get basic metadata on the pipes which are in scope for the given component.
138138
*/
139139
getPipesInScope(component: ts.ClassDeclaration): PipeInScope[]|null;
140140

141141
/**
142-
* Retrieve a `Map` of potential template element tags, to either the `DirectiveInScope` that
142+
* Retrieve a `Map` of potential template element tags, to either the `PotentialDirective` that
143143
* declares them (if the tag is from a directive/component), or `null` if the tag originates from
144144
* the DOM schema.
145145
*/
146-
getPotentialElementTags(component: ts.ClassDeclaration): Map<string, DirectiveInScope|null>;
146+
getPotentialElementTags(component: ts.ClassDeclaration): Map<string, PotentialDirective|null>;
147147

148148
/**
149149
* Get the primary decorator for an Angular class (such as @Component). This does not work for

packages/compiler-cli/src/ngtsc/typecheck/api/scope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {SymbolWithValueDeclaration} from '../../util/src/typescript';
1414
/**
1515
* Metadata on a directive which is available in the scope of a template.
1616
*/
17-
export interface DirectiveInScope {
17+
export interface PotentialDirective {
1818
/**
1919
* The `ts.Symbol` for the directive class.
2020
*/

packages/compiler-cli/src/ngtsc/typecheck/api/symbols.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import ts from 'typescript';
1212
import {AbsoluteFsPath} from '../../file_system';
1313
import {SymbolWithValueDeclaration} from '../../util/src/typescript';
1414

15-
import {DirectiveInScope} from './scope';
15+
import {PotentialDirective} from './scope';
1616

1717
export enum SymbolKind {
1818
Input,
@@ -262,7 +262,7 @@ export interface TemplateSymbol {
262262
* A representation of a directive/component whose selector matches a node in a component
263263
* template.
264264
*/
265-
export interface DirectiveSymbol extends DirectiveInScope {
265+
export interface DirectiveSymbol extends PotentialDirective {
266266
kind: SymbolKind.Directive;
267267

268268
/** The `ts.Type` for the class declaration. */

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {ClassDeclaration, isNamedClassDeclaration, ReflectionHost} from '../../r
2020
import {ComponentScopeKind, ComponentScopeReader, TypeCheckScopeRegistry} from '../../scope';
2121
import {isShim} from '../../shims';
2222
import {getSourceFileOrNull, isSymbolWithValueDeclaration} from '../../util/src/typescript';
23-
import {DirectiveInScope, ElementSymbol, FullTemplateMapping, GlobalCompletion, NgTemplateDiagnostic, OptimizeFor, PipeInScope, ProgramTypeCheckAdapter, Symbol, TcbLocation, TemplateDiagnostic, TemplateId, TemplateSymbol, TemplateTypeChecker, TypeCheckableDirectiveMeta, TypeCheckingConfig} from '../api';
23+
import {ElementSymbol, FullTemplateMapping, GlobalCompletion, NgTemplateDiagnostic, OptimizeFor, PipeInScope, PotentialDirective, ProgramTypeCheckAdapter, Symbol, TcbLocation, TemplateDiagnostic, TemplateId, TemplateSymbol, TemplateTypeChecker, TypeCheckableDirectiveMeta, TypeCheckingConfig} from '../api';
2424
import {makeTemplateDiagnostic} from '../diagnostics';
2525

2626
import {CompletionEngine} from './completion';
@@ -75,7 +75,7 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker {
7575
* destroyed when the `ts.Program` changes and the `TemplateTypeCheckerImpl` as a whole is
7676
* destroyed and replaced.
7777
*/
78-
private elementTagCache = new Map<ts.ClassDeclaration, Map<string, DirectiveInScope|null>>();
78+
private elementTagCache = new Map<ts.ClassDeclaration, Map<string, PotentialDirective|null>>();
7979

8080
private isComplete = false;
8181

@@ -549,7 +549,7 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker {
549549
return builder;
550550
}
551551

552-
getDirectivesInScope(component: ts.ClassDeclaration): DirectiveInScope[]|null {
552+
getDirectivesInScope(component: ts.ClassDeclaration): PotentialDirective[]|null {
553553
const data = this.getScopeData(component);
554554
if (data === null) {
555555
return null;
@@ -572,12 +572,12 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker {
572572
return this.typeCheckScopeRegistry.getTypeCheckDirectiveMetadata(new Reference(dir));
573573
}
574574

575-
getPotentialElementTags(component: ts.ClassDeclaration): Map<string, DirectiveInScope|null> {
575+
getPotentialElementTags(component: ts.ClassDeclaration): Map<string, PotentialDirective|null> {
576576
if (this.elementTagCache.has(component)) {
577577
return this.elementTagCache.get(component)!;
578578
}
579579

580-
const tagMap = new Map<string, DirectiveInScope|null>();
580+
const tagMap = new Map<string, PotentialDirective|null>();
581581

582582
for (const tag of REGISTRY.allKnownElementNames()) {
583583
tagMap.set(tag, null);
@@ -886,7 +886,7 @@ class SingleShimTypeCheckingHost extends SingleFileTypeCheckingHost {
886886
* Cached scope information for a component.
887887
*/
888888
interface ScopeData {
889-
directives: DirectiveInScope[];
889+
directives: PotentialDirective[];
890890
pipes: PipeInScope[];
891891
isPoisoned: boolean;
892892
}

packages/language-service/src/attribute_completions.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {CssSelector, SelectorMatcher, TmplAstElement, TmplAstTemplate} from '@angular/compiler';
10-
import {DirectiveInScope, ElementSymbol, TemplateSymbol, TemplateTypeChecker, TypeCheckableDirectiveMeta} from '@angular/compiler-cli/src/ngtsc/typecheck/api';
10+
import {ElementSymbol, PotentialDirective, TemplateSymbol, TemplateTypeChecker, TypeCheckableDirectiveMeta} from '@angular/compiler-cli/src/ngtsc/typecheck/api';
1111
import ts from 'typescript';
1212

1313
import {DisplayInfoKind, unsafeCastDisplayInfoKindToScriptElementKind} from './display_parts';
@@ -116,7 +116,7 @@ export interface DirectiveAttributeCompletion {
116116
/**
117117
* The directive whose selector gave rise to this completion.
118118
*/
119-
directive: DirectiveInScope;
119+
directive: PotentialDirective;
120120
}
121121

122122
/**
@@ -135,7 +135,7 @@ export interface DirectiveInputCompletion {
135135
/**
136136
* The directive which has this input.
137137
*/
138-
directive: DirectiveInScope;
138+
directive: PotentialDirective;
139139

140140
/**
141141
* The field name on the directive class which corresponds to this input.
@@ -164,7 +164,7 @@ export interface DirectiveOutputCompletion {
164164
/**
165165
*The directive which has this output.
166166
*/
167-
directive: DirectiveInScope;
167+
directive: PotentialDirective;
168168

169169
/**
170170
* The field name on the directive class which corresponds to this output.
@@ -251,7 +251,8 @@ export function buildAttributeCompletionTable(
251251

252252
// Next, explore hypothetical directives and determine if the addition of any single attributes
253253
// can cause the directive to match the element.
254-
const directivesInScope = checker.getDirectivesInScope(component);
254+
const directivesInScope =
255+
checker.getPotentialTemplateDirectives(component).filter(d => d.isInScope);
255256
if (directivesInScope !== null) {
256257
const elementSelector = makeElementSelector(element);
257258

packages/language-service/src/completions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {AST, ASTWithSource, BindingPipe, BindingType, Call, EmptyExpr, ImplicitReceiver, LiteralPrimitive, ParsedEventType, ParseSourceSpan, PropertyRead, PropertyWrite, SafePropertyRead, TmplAstBoundAttribute, TmplAstBoundEvent, TmplAstElement, TmplAstNode, TmplAstReference, TmplAstTemplate, TmplAstText, TmplAstTextAttribute, TmplAstVariable} from '@angular/compiler';
1010
import {NgCompiler} from '@angular/compiler-cli/src/ngtsc/core';
11-
import {CompletionKind, DirectiveInScope, SymbolKind, TemplateDeclarationSymbol} from '@angular/compiler-cli/src/ngtsc/typecheck/api';
11+
import {CompletionKind, PotentialDirective, SymbolKind, TemplateDeclarationSymbol} from '@angular/compiler-cli/src/ngtsc/typecheck/api';
1212
import {BoundEvent, TextAttribute} from '@angular/compiler/src/render3/r3_ast';
1313
import ts from 'typescript';
1414

@@ -905,7 +905,7 @@ function makeReplacementSpanFromAst(node: PropertyRead|PropertyWrite|SafePropert
905905
};
906906
}
907907

908-
function tagCompletionKind(directive: DirectiveInScope|null): ts.ScriptElementKind {
908+
function tagCompletionKind(directive: PotentialDirective|null): ts.ScriptElementKind {
909909
let kind: DisplayInfoKind;
910910
if (directive === null) {
911911
kind = DisplayInfoKind.ELEMENT;

packages/language-service/src/display_parts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {isNamedClassDeclaration} from '@angular/compiler-cli/src/ngtsc/reflection';
10-
import {DirectiveInScope, ReferenceSymbol, Symbol, SymbolKind, TcbLocation, VariableSymbol} from '@angular/compiler-cli/src/ngtsc/typecheck/api';
10+
import {PotentialDirective, ReferenceSymbol, Symbol, SymbolKind, TcbLocation, VariableSymbol} from '@angular/compiler-cli/src/ngtsc/typecheck/api';
1111
import ts from 'typescript';
1212

1313

@@ -130,7 +130,7 @@ function getDocumentationFromTypeDefAtLocation(
130130
}
131131

132132
export function getDirectiveDisplayInfo(
133-
tsLS: ts.LanguageService, dir: DirectiveInScope): DisplayInfo {
133+
tsLS: ts.LanguageService, dir: PotentialDirective): DisplayInfo {
134134
const kind = dir.isComponent ? DisplayInfoKind.COMPONENT : DisplayInfoKind.DIRECTIVE;
135135
const decl = dir.tsSymbol.declarations.find(ts.isClassDeclaration);
136136
if (decl === undefined || decl.name === undefined) {

0 commit comments

Comments
 (0)